| 57 CX_TEST_DO { |
57 CX_TEST_DO { |
| 58 int result; |
58 int result; |
| 59 |
59 |
| 60 CxJson json; |
60 CxJson json; |
| 61 cxJsonInit(&json); |
61 cxJsonInit(&json); |
| 62 cxJsonFill(&json, text.ptr, text.length); |
62 cxJsonFill(&json, text); |
| 63 |
63 |
| 64 // parse the big fat object |
64 // parse the big fat object |
| 65 CxJsonValue *obj; |
65 CxJsonValue *obj; |
| 66 result = cxJsonNext(&json, &obj); |
66 result = cxJsonNext(&json, &obj); |
| 67 CX_TEST_ASSERT(result == 1); |
67 CX_TEST_ASSERT(result == 1); |
| 189 CxJson json; |
189 CxJson json; |
| 190 CxJsonValue *obj = NULL; |
190 CxJsonValue *obj = NULL; |
| 191 |
191 |
| 192 for(int i=0;i<5;i++) { |
192 for(int i=0;i<5;i++) { |
| 193 cxJsonInit(&json); |
193 cxJsonInit(&json); |
| 194 cxJsonFill(&json, tests[i].ptr, tests[i].length); |
194 cxJsonFill(&json, tests[i]); |
| 195 result = cxJsonNext(&json, &obj); |
195 result = cxJsonNext(&json, &obj); |
| 196 |
196 |
| 197 CX_TEST_ASSERT(result == -1); |
197 CX_TEST_ASSERT(result == -1); |
| 198 CX_TEST_ASSERT(obj == NULL); |
198 CX_TEST_ASSERT(obj == NULL); |
| 199 cxJsonDestroy(&json); |
199 cxJsonDestroy(&json); |
| 205 CxJson json; |
205 CxJson json; |
| 206 CxJsonValue *d1; |
206 CxJsonValue *d1; |
| 207 cxstring text = cx_str("{\"test\": [{},{\"foo\": [[{\"bar\":[4, 2, [null, {\"key\": 47}]]}]]}]}"); |
207 cxstring text = cx_str("{\"test\": [{},{\"foo\": [[{\"bar\":[4, 2, [null, {\"key\": 47}]]}]]}]}"); |
| 208 CX_TEST_DO { |
208 CX_TEST_DO { |
| 209 cxJsonInit(&json); |
209 cxJsonInit(&json); |
| 210 cxJsonFill(&json, text.ptr, text.length); |
210 cxJsonFill(&json, text); |
| 211 cxJsonNext(&json, &d1); |
211 cxJsonNext(&json, &d1); |
| 212 |
212 |
| 213 CX_TEST_ASSERT(d1 != NULL); |
213 CX_TEST_ASSERT(d1 != NULL); |
| 214 CX_TEST_ASSERT(cxJsonIsObject(d1)); |
214 CX_TEST_ASSERT(cxJsonIsObject(d1)); |
| 215 CxJsonValue *d2 = cxJsonObjGet(d1, "test"); |
215 CxJsonValue *d2 = cxJsonObjGet(d1, "test"); |
| 244 |
244 |
| 245 cxJsonDestroy(&json); |
245 cxJsonDestroy(&json); |
| 246 } |
246 } |
| 247 } |
247 } |
| 248 |
248 |
| |
249 CX_TEST(test_json_number) { |
| |
250 CxJson json; |
| |
251 cxJsonInit(&json); |
| |
252 CX_TEST_DO { |
| |
253 CxJsonValue *v; |
| |
254 |
| |
255 cxJsonNext(&json, &v); |
| |
256 } |
| |
257 cxJsonDestroy(&json); |
| |
258 } |
| |
259 |
| 249 CxTestSuite *cx_test_suite_json(void) { |
260 CxTestSuite *cx_test_suite_json(void) { |
| 250 CxTestSuite *suite = cx_test_suite_new("json"); |
261 CxTestSuite *suite = cx_test_suite_new("json"); |
| 251 |
262 |
| 252 cx_test_register(suite, test_json_init_default); |
263 cx_test_register(suite, test_json_init_default); |
| 253 cx_test_register(suite, test_json_simple_object); |
264 cx_test_register(suite, test_json_simple_object); |