711 CX_TEST_ASSERT(!cxJsonIsBool(v)); |
711 CX_TEST_ASSERT(!cxJsonIsBool(v)); |
712 CX_TEST_ASSERT(cxJsonIsNull(v)); |
712 CX_TEST_ASSERT(cxJsonIsNull(v)); |
713 cxJsonValueFree(v); |
713 cxJsonValueFree(v); |
714 } |
714 } |
715 cxJsonDestroy(&json); |
715 cxJsonDestroy(&json); |
|
716 } |
|
717 |
|
718 CX_TEST(test_json_array) { |
|
719 CxTestingAllocator talloc; |
|
720 cx_testing_allocator_init(&talloc); |
|
721 const CxAllocator *allocator = &talloc.base; |
|
722 CX_TEST_DO { |
|
723 CxJsonValue *arr = cxJsonCreateArr(allocator); |
|
724 cxJsonArrAddIntegers(arr, (int64_t[]){ 0, 3, 6, 9, 12, 15}, 6); |
|
725 CX_TEST_ASSERT(cxJsonArrSize(arr) == 6); |
|
726 CxJsonValue *e = cxJsonArrGet(arr, 3); |
|
727 CX_TEST_ASSERT(cxJsonIsNumber(e)); |
|
728 CX_TEST_ASSERT(cxJsonAsInteger(e) == 9); |
|
729 CX_TEST_ASSERT(cxJsonAsDouble(e) == 9.0); |
|
730 CX_TEST_ASSERT(cxJsonArrSize(arr) == 6); |
|
731 e = cxJsonArrGet(arr, 6); |
|
732 CX_TEST_ASSERT(!cxJsonIsNumber(e)); |
|
733 // also not null, because "nothing" is not null |
|
734 CX_TEST_ASSERT(!cxJsonIsNull(e)); |
|
735 CX_TEST_ASSERT(e->type == CX_JSON_NOTHING); |
|
736 CxJsonValue *removed = cxJsonArrRemove(arr, 2); |
|
737 CX_TEST_ASSERT(cxJsonIsNumber(removed)); |
|
738 CX_TEST_ASSERT(cxJsonAsInteger(removed) == 6); |
|
739 CX_TEST_ASSERT(cxJsonArrSize(arr) == 5); |
|
740 e = cxJsonArrRemove(arr, 5); |
|
741 CX_TEST_ASSERT(e == NULL); |
|
742 cxJsonValueFree(arr); |
|
743 // the removed element still needs to be freed |
|
744 CX_TEST_ASSERT(!cx_testing_allocator_verify(&talloc)); |
|
745 cxJsonValueFree(removed); |
|
746 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
|
747 } |
|
748 cx_testing_allocator_destroy(&talloc); |
716 } |
749 } |
717 |
750 |
718 CX_TEST(test_json_array_iterator) { |
751 CX_TEST(test_json_array_iterator) { |
719 CxJson json; |
752 CxJson json; |
720 cxJsonInit(&json, NULL); |
753 cxJsonInit(&json, NULL); |
1197 cx_test_register(suite, test_json_subsequent_fill); |
1230 cx_test_register(suite, test_json_subsequent_fill); |
1198 cx_test_register(suite, test_json_large_nesting_depth); |
1231 cx_test_register(suite, test_json_large_nesting_depth); |
1199 cx_test_register(suite, test_json_number); |
1232 cx_test_register(suite, test_json_number); |
1200 cx_test_register(suite, test_json_number_format_errors); |
1233 cx_test_register(suite, test_json_number_format_errors); |
1201 cx_test_register(suite, test_json_multiple_values); |
1234 cx_test_register(suite, test_json_multiple_values); |
|
1235 cx_test_register(suite, test_json_array); |
1202 cx_test_register(suite, test_json_array_iterator); |
1236 cx_test_register(suite, test_json_array_iterator); |
1203 cx_test_register(suite, test_json_allocator); |
1237 cx_test_register(suite, test_json_allocator); |
1204 cx_test_register(suite, test_json_allocator_parse_error); |
1238 cx_test_register(suite, test_json_allocator_parse_error); |
1205 cx_test_register(suite, test_json_create_value); |
1239 cx_test_register(suite, test_json_create_value); |
1206 cx_test_register(suite, test_json_write_default_format); |
1240 cx_test_register(suite, test_json_write_default_format); |