| 213 } |
213 } |
| 214 } |
214 } |
| 215 |
215 |
| 216 CX_TEST(test_json_from_string_multiple_values) { |
216 CX_TEST(test_json_from_string_multiple_values) { |
| 217 CxJsonStatus status; |
217 CxJsonStatus status; |
| 218 CxJsonValue *obj = NULL; |
218 CxJsonValue *obj; |
| 219 CX_TEST_DO { |
219 CX_TEST_DO { |
| |
220 obj = NULL; |
| 220 status = cxJsonFromString(NULL, "{ \"obj1\": \"hello\" }\n\"value2\"\n", &obj); |
221 status = cxJsonFromString(NULL, "{ \"obj1\": \"hello\" }\n\"value2\"\n", &obj); |
| 221 |
222 CX_TEST_ASSERT(obj != NULL); |
| 222 // TODO: what is the expected behavior here? Is this an error or do we ignore the second value? |
223 CX_TEST_ASSERT(obj->type == CX_JSON_NOTHING); |
| |
224 CX_TEST_ASSERT(status == CX_JSON_FORMAT_ERROR_UNEXPECTED_TOKEN); |
| |
225 |
| |
226 obj = NULL; |
| |
227 status = cxJsonFromString(NULL, "\"value\" \n ] syntax error [", &obj); |
| |
228 CX_TEST_ASSERT(obj != NULL); |
| |
229 CX_TEST_ASSERT(obj->type == CX_JSON_NOTHING); |
| |
230 CX_TEST_ASSERT(status == CX_JSON_FORMAT_ERROR_UNEXPECTED_TOKEN); |
| |
231 } |
| |
232 } |
| |
233 |
| |
234 CX_TEST(test_json_from_string_untrimmed) { |
| |
235 CxJsonStatus status; |
| |
236 CxJsonValue *obj; |
| |
237 CX_TEST_DO { |
| |
238 obj = NULL; |
| |
239 status = cxJsonFromString(NULL, "\n\t{ \"obj1\": \"hello\" } \n", &obj); |
| 223 CX_TEST_ASSERT(status == CX_JSON_NO_ERROR); |
240 CX_TEST_ASSERT(status == CX_JSON_NO_ERROR); |
| 224 CX_TEST_ASSERT(cxJsonIsObject(obj)); |
241 CX_TEST_ASSERT(cxJsonIsObject(obj)); |
| 225 // CX_TEST_ASSERT(status == CX_JSON_FORMAT_ERROR_UNEXPECTED_TOKEN); |
242 CxJsonValue *obj1 = cxJsonObjGet(obj, "obj1"); |
| 226 |
243 CX_TEST_ASSERT(cxJsonIsString(obj1)); |
| 227 cxJsonValueFree(obj); |
244 CX_TEST_ASSERT(cx_strcmp(cxJsonAsCxString(obj1), "hello") == 0); |
| 228 |
245 |
| 229 // TODO: this really should be an error in theory |
|
| 230 status = cxJsonFromString(NULL, "\"value\" \n ] syntax error [", &obj); |
|
| 231 CX_TEST_ASSERT(status == CX_JSON_NO_ERROR); |
|
| 232 CX_TEST_ASSERT(cxJsonIsString(obj)); |
|
| 233 // CX_TEST_ASSERT(status == CX_JSON_FORMAT_ERROR_UNEXPECTED_TOKEN); |
|
| 234 |
|
| 235 cxJsonValueFree(obj); |
246 cxJsonValueFree(obj); |
| 236 } |
247 } |
| 237 } |
248 } |
| 238 |
249 |
| 239 CX_TEST(test_json_escaped_strings) { |
250 CX_TEST(test_json_escaped_strings) { |
| 928 CX_TEST_ASSERT(cxJsonIsNumber(v)); |
939 CX_TEST_ASSERT(cxJsonIsNumber(v)); |
| 929 CX_TEST_ASSERT(cxJsonAsInteger(v) == 10); |
940 CX_TEST_ASSERT(cxJsonAsInteger(v) == 10); |
| 930 cxJsonValueFree(v); |
941 cxJsonValueFree(v); |
| 931 // read remaining '\n' |
942 // read remaining '\n' |
| 932 result = cxJsonNext(&json, &v); |
943 result = cxJsonNext(&json, &v); |
| 933 CX_TEST_ASSERT(result == CX_JSON_INCOMPLETE_DATA); |
944 CX_TEST_ASSERT(result == CX_JSON_NO_DATA); |
| 934 // read string |
945 // read string |
| 935 cxJsonFill(&json, "\"hello world\"\n"); |
946 cxJsonFill(&json, "\"hello world\"\n"); |
| 936 result = cxJsonNext(&json, &v); |
947 result = cxJsonNext(&json, &v); |
| 937 CX_TEST_ASSERT(result == CX_JSON_NO_ERROR); |
948 CX_TEST_ASSERT(result == CX_JSON_NO_ERROR); |
| 938 CX_TEST_ASSERT(cxJsonIsString(v)); |
949 CX_TEST_ASSERT(cxJsonIsString(v)); |
| 1563 cx_test_register(suite, test_json_simple_object); |
1574 cx_test_register(suite, test_json_simple_object); |
| 1564 cx_test_register(suite, test_json_large_object); |
1575 cx_test_register(suite, test_json_large_object); |
| 1565 cx_test_register(suite, test_json_from_string); |
1576 cx_test_register(suite, test_json_from_string); |
| 1566 cx_test_register(suite, test_json_from_string_errors); |
1577 cx_test_register(suite, test_json_from_string_errors); |
| 1567 cx_test_register(suite, test_json_from_string_multiple_values); |
1578 cx_test_register(suite, test_json_from_string_multiple_values); |
| |
1579 cx_test_register(suite, test_json_from_string_untrimmed); |
| 1568 cx_test_register(suite, test_json_escaped_strings); |
1580 cx_test_register(suite, test_json_escaped_strings); |
| 1569 cx_test_register(suite, test_json_escaped_unicode_strings); |
1581 cx_test_register(suite, test_json_escaped_unicode_strings); |
| 1570 cx_test_register(suite, test_json_escaped_unicode_malformed); |
1582 cx_test_register(suite, test_json_escaped_unicode_malformed); |
| 1571 cx_test_register(suite, test_json_escaped_end_of_string); |
1583 cx_test_register(suite, test_json_escaped_end_of_string); |
| 1572 cx_test_register(suite, test_json_object_incomplete_token); |
1584 cx_test_register(suite, test_json_object_incomplete_token); |