| 140 CX_TEST_ASSERT(result == CX_JSON_INCOMPLETE_DATA); |
140 CX_TEST_ASSERT(result == CX_JSON_INCOMPLETE_DATA); |
| 141 } |
141 } |
| 142 cxJsonFill(&json, parts[nparts - 1]); |
142 cxJsonFill(&json, parts[nparts - 1]); |
| 143 result = cxJsonNext(&json, &obj); |
143 result = cxJsonNext(&json, &obj); |
| 144 CX_TEST_ASSERT(result == CX_JSON_NO_ERROR); |
144 CX_TEST_ASSERT(result == CX_JSON_NO_ERROR); |
| 145 CX_TEST_ASSERT(obj); |
145 CX_TEST_ASSERT(cxJsonIsObject(obj)); |
| 146 |
146 |
| 147 CxJsonValue *message = cxJsonObjGet(obj, "message"); |
147 CxJsonValue *message = cxJsonObjGet(obj, "message"); |
| 148 CX_TEST_ASSERT(cxJsonIsString(message)); |
148 CX_TEST_ASSERT(cxJsonIsString(message)); |
| 149 CX_TEST_ASSERT(0 == cx_strcmp( |
149 CX_TEST_ASSERT(0 == cx_strcmp( |
| 150 cxJsonAsCxString(message), |
150 cxJsonAsCxString(message), |
| 157 |
157 |
| 158 // this recursively frees everything else |
158 // this recursively frees everything else |
| 159 cxJsonValueFree(obj); |
159 cxJsonValueFree(obj); |
| 160 |
160 |
| 161 // now there is everything read |
161 // now there is everything read |
| |
162 result = cxJsonNext(&json, &obj); |
| |
163 CX_TEST_ASSERT(result == CX_JSON_NO_DATA); |
| |
164 |
| |
165 cxJsonDestroy(&json); |
| |
166 } |
| |
167 } |
| |
168 |
| |
169 CX_TEST(test_json_subsequent_fill) { |
| |
170 cxstring text = cx_str( |
| |
171 "{\"message\":\"success\" , \"__timestamp\":1729348561}"); |
| |
172 |
| |
173 cxstring part1 = cx_strsubsl(text, 0, 25); |
| |
174 cxstring part2 = cx_strsubs(text, 25); |
| |
175 |
| |
176 CX_TEST_DO { |
| |
177 CxJson json; |
| |
178 cxJsonInit(&json, NULL); |
| |
179 CxJsonValue *obj; |
| |
180 |
| |
181 cxJsonFill(&json, part1); |
| |
182 cxJsonFill(&json, part2); |
| |
183 CxJsonStatus result = cxJsonNext(&json, &obj); |
| |
184 CX_TEST_ASSERT(result == CX_JSON_NO_ERROR); |
| |
185 CX_TEST_ASSERT(cxJsonIsObject(obj)); |
| |
186 |
| |
187 CxJsonValue *message = cxJsonObjGet(obj, "message"); |
| |
188 CX_TEST_ASSERT(cxJsonIsString(message)); |
| |
189 CX_TEST_ASSERT(0 == cx_strcmp( |
| |
190 cxJsonAsCxString(message), |
| |
191 cx_str("success")) |
| |
192 ); |
| |
193 CxJsonValue *timestamp = cxJsonObjGet(obj, "__timestamp"); |
| |
194 CX_TEST_ASSERT(message->type == CX_JSON_STRING); |
| |
195 CX_TEST_ASSERT(cxJsonIsInteger(timestamp)); |
| |
196 CX_TEST_ASSERT(cxJsonAsInteger(timestamp) == 1729348561); |
| |
197 |
| |
198 cxJsonValueFree(obj); |
| 162 result = cxJsonNext(&json, &obj); |
199 result = cxJsonNext(&json, &obj); |
| 163 CX_TEST_ASSERT(result == CX_JSON_NO_DATA); |
200 CX_TEST_ASSERT(result == CX_JSON_NO_DATA); |
| 164 |
201 |
| 165 cxJsonDestroy(&json); |
202 cxJsonDestroy(&json); |
| 166 } |
203 } |
| 406 |
443 |
| 407 cx_test_register(suite, test_json_init_default); |
444 cx_test_register(suite, test_json_init_default); |
| 408 cx_test_register(suite, test_json_simple_object); |
445 cx_test_register(suite, test_json_simple_object); |
| 409 cx_test_register(suite, test_json_object_incomplete_token); |
446 cx_test_register(suite, test_json_object_incomplete_token); |
| 410 cx_test_register(suite, test_json_object_error); |
447 cx_test_register(suite, test_json_object_error); |
| |
448 cx_test_register(suite, test_json_subsequent_fill); |
| 411 cx_test_register(suite, test_json_large_nesting_depth); |
449 cx_test_register(suite, test_json_large_nesting_depth); |
| 412 cx_test_register(suite, test_json_number); |
450 cx_test_register(suite, test_json_number); |
| 413 cx_test_register(suite, test_json_multiple_values); |
451 cx_test_register(suite, test_json_multiple_values); |
| 414 cx_test_register(suite, test_json_allocator); |
452 cx_test_register(suite, test_json_allocator); |
| 415 cx_test_register(suite, test_json_allocator_parse_error); |
453 cx_test_register(suite, test_json_allocator_parse_error); |