tests/test_json.c

changeset 973
05910a8994f7
parent 966
1aa7ec3e46e7
child 975
96bf02371aef
equal deleted inserted replaced
972:a9a1d07a6840 973:05910a8994f7
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);
128 cxJsonInit(&json); 128 cxJsonInit(&json);
129 CxJsonValue *obj; 129 CxJsonValue *obj;
130 130
131 size_t part = 0; 131 size_t part = 0;
132 while(part < nparts) { 132 while(part < nparts) {
133 cxJsonFill(&json, parts[part].ptr, parts[part].length); 133 cxJsonFill(&json, parts[part]);
134 part++; 134 part++;
135 result = cxJsonNext(&json, &obj); 135 result = cxJsonNext(&json, &obj);
136 136
137 if(result != 0) { 137 if(result != 0) {
138 break; 138 break;
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);

mercurial