tests/test_json.c

changeset 1156
96f16b5a0029
parent 1154
afd12f31d28a
child 1157
3565ae61a5a2
equal deleted inserted replaced
1155:b77d56a27e9c 1156:96f16b5a0029
220 cxJsonAsCxString(mixed2), 220 cxJsonAsCxString(mixed2),
221 CX_STR("123\u03a3\xf0\x9f\xaf\x85ß")) 221 CX_STR("123\u03a3\xf0\x9f\xaf\x85ß"))
222 ); 222 );
223 223
224 cxJsonValueFree(obj); 224 cxJsonValueFree(obj);
225 }
226 cxJsonDestroy(&json);
227 }
228
229 CX_TEST(test_json_escaped_unicode_malformed) {
230 CxJson json;
231 cxJsonInit(&json, NULL);
232 CxJsonValue *obj;
233 CxJsonStatus result;
234 CX_TEST_DO {
235 cxJsonFill(&json, "\"too few \\u123 digits\"");
236 result = cxJsonNext(&json, &obj);
237 CX_TEST_ASSERT(result == CX_JSON_NO_ERROR);
238 CX_TEST_ASSERT(cxJsonIsString(obj));
239 CX_TEST_ASSERT(0 == cx_strcmp(
240 cxJsonAsCxString(obj),
241 CX_STR("too few \\u123 digits")
242 ));
243 cxJsonFill(&json, "\"too many \\u00E456 digits\"");
244 result = cxJsonNext(&json, &obj);
245 CX_TEST_ASSERT(result == CX_JSON_NO_ERROR);
246 CX_TEST_ASSERT(cxJsonIsString(obj));
247 CX_TEST_ASSERT(0 == cx_strcmp(
248 cxJsonAsCxString(obj),
249 CX_STR("too many ä56 digits")
250 ));
251 cxJsonFill(&json, "\"only high \\uD800 surrogate\"");
252 result = cxJsonNext(&json, &obj);
253 CX_TEST_ASSERT(result == CX_JSON_NO_ERROR);
254 CX_TEST_ASSERT(cxJsonIsString(obj));
255 CX_TEST_ASSERT(0 == cx_strcmp(
256 cxJsonAsCxString(obj),
257 CX_STR("only high \\uD800 surrogate")
258 ));
259 cxJsonFill(&json, "\"only low \\uDC00 surrogate\"");
260 result = cxJsonNext(&json, &obj);
261 CX_TEST_ASSERT(result == CX_JSON_NO_ERROR);
262 CX_TEST_ASSERT(cxJsonIsString(obj));
263 CX_TEST_ASSERT(0 == cx_strcmp(
264 cxJsonAsCxString(obj),
265 CX_STR("only low \\uDC00 surrogate")
266 ));
267 cxJsonFill(&json, "\"two high \\uD800\\uD800 surrogates\"");
268 result = cxJsonNext(&json, &obj);
269 CX_TEST_ASSERT(result == CX_JSON_NO_ERROR);
270 CX_TEST_ASSERT(cxJsonIsString(obj));
271 CX_TEST_ASSERT(0 == cx_strcmp(
272 cxJsonAsCxString(obj),
273 CX_STR("two high \\uD800\\uD800 surrogates")
274 ));
275 cxJsonFill(&json, "\"high plus bullshit \\uD800\\u567 foo\"");
276 result = cxJsonNext(&json, &obj);
277 CX_TEST_ASSERT(result == CX_JSON_NO_ERROR);
278 CX_TEST_ASSERT(cxJsonIsString(obj));
279 CX_TEST_ASSERT(0 == cx_strcmp(
280 cxJsonAsCxString(obj),
281 CX_STR("high plus bullshit \\uD800\\u567 foo")
282 ));
225 } 283 }
226 cxJsonDestroy(&json); 284 cxJsonDestroy(&json);
227 } 285 }
228 286
229 CX_TEST(test_json_escaped_end_of_string) { 287 CX_TEST(test_json_escaped_end_of_string) {
1124 1182
1125 cx_test_register(suite, test_json_init_default); 1183 cx_test_register(suite, test_json_init_default);
1126 cx_test_register(suite, test_json_simple_object); 1184 cx_test_register(suite, test_json_simple_object);
1127 cx_test_register(suite, test_json_escaped_strings); 1185 cx_test_register(suite, test_json_escaped_strings);
1128 cx_test_register(suite, test_json_escaped_unicode_strings); 1186 cx_test_register(suite, test_json_escaped_unicode_strings);
1187 cx_test_register(suite, test_json_escaped_unicode_malformed);
1129 cx_test_register(suite, test_json_escaped_end_of_string); 1188 cx_test_register(suite, test_json_escaped_end_of_string);
1130 cx_test_register(suite, test_json_object_incomplete_token); 1189 cx_test_register(suite, test_json_object_incomplete_token);
1131 cx_test_register(suite, test_json_token_wrongly_completed); 1190 cx_test_register(suite, test_json_token_wrongly_completed);
1132 cx_test_register(suite, test_json_object_error); 1191 cx_test_register(suite, test_json_object_error);
1133 cx_test_register(suite, test_json_subsequent_fill); 1192 cx_test_register(suite, test_json_subsequent_fill);

mercurial