# HG changeset patch # User Olaf Wintermann # Date 1729417194 -7200 # Node ID 0bb7258366a06f11e839fcb57387f5249cd0d740 # Parent 9d02bb5dcc3c15ca1d3733ff76708ce1eb1e1a99 add test for parsing json with multiple incomplete tokens diff -r 9d02bb5dcc3c -r 0bb7258366a0 tests/test_json.c --- a/tests/test_json.c Sun Oct 20 10:49:38 2024 +0200 +++ b/tests/test_json.c Sun Oct 20 11:39:54 2024 +0200 @@ -95,10 +95,64 @@ } } +CX_TEST(test_json_object_incomplete_token) { + cxstring text = cx_str( + "{\"message\":\"success\" , \"__timestamp\":1729348561}"); + cxstring parts[16]; + size_t nparts = 0; // split the json text into mulple parts + for(size_t i=0;itype == CX_JSON_STRING); + CX_TEST_ASSERT(cxJsonIsInteger(timestamp)); + CX_TEST_ASSERT(cxJsonAsInteger(timestamp) == 1729348561); + + // this recursively frees everything else + cxJsonValueFree(obj); + + // we only have one object that already contained all the data + result = cxJsonNext(&json, &obj); + CX_TEST_ASSERT(result == 0); + + cxJsonDestroy(&json); + } +} + CxTestSuite *cx_test_suite_json(void) { CxTestSuite *suite = cx_test_suite_new("json"); cx_test_register(suite, test_json_simple_object); + cx_test_register(suite, test_json_object_incomplete_token); return suite; }