test/json.c

changeset 43
73c1ced3a620
parent 42
3c989bc611c6
child 44
3bac2715ccb9
equal deleted inserted replaced
42:3c989bc611c6 43:73c1ced3a620
379 CX_TEST_ASSERT(obj->test2->i == -1234567); 379 CX_TEST_ASSERT(obj->test2->i == -1234567);
380 380
381 free(obj); 381 free(obj);
382 } 382 }
383 } 383 }
384
385 CX_TEST(testJsonToObjectWithArray) {
386 const char *jsonStr =
387 "{"
388 "\"test\":\"hello world\","
389 "\"test2List\":[ {\"name\":\"elm0\", \"i\":0}, {\"name\":\"elm1\", \"i\":1} ]"
390 "}";
391
392 CxJsonValue *json;
393 cxJsonFromString(NULL, jsonStr, &json);
394
395 CX_TEST_DO {
396 Test5 *obj = dbuJsonToObject(test5_class, NULL, json);
397
398 CX_TEST_ASSERT(obj);
399 CX_TEST_ASSERT(!cx_strcmp(obj->test, "hello world"));
400 CX_TEST_ASSERT(obj->test2List);
401 CX_TEST_ASSERT(cxListSize(obj->test2List) == 2);
402
403 Test2 *elm0 = cxListAt(obj->test2List, 0);
404 Test2 *elm1 = cxListAt(obj->test2List, 1);
405
406 CX_TEST_ASSERT(elm0);
407 CX_TEST_ASSERT(elm1);
408
409 CX_TEST_ASSERT(!cx_strcmp(elm0->name, "elm0"));
410 CX_TEST_ASSERT(elm0->i == 0);
411
412 CX_TEST_ASSERT(!cx_strcmp(elm1->name, "elm1"));
413 CX_TEST_ASSERT(elm1->i == 1);
414
415 free(obj);
416 }
417 }

mercurial