tests/test_json.c

changeset 941
9077724b75a0
parent 939
0bb7258366a0
child 946
b428424c0214
equal deleted inserted replaced
940:bbf41b9c2658 941:9077724b75a0
146 146
147 cxJsonDestroy(&json); 147 cxJsonDestroy(&json);
148 } 148 }
149 } 149 }
150 150
151 CX_TEST(test_json_object_error) {
152 cxstring text0 = cx_str(
153 "{\n"
154 "\t\"message\":\"success\",\n"
155 "\t\"data\":{\n"
156 "\t\t\"obj\":{\n"
157 "\t\t\t\"array\": [1, 2, 3, ?syntaxerror? ]\n"
158 "\t\t\"}\n"
159 "\t},\n"
160 "\t\"timestamp\":1729348561,\n"
161 "}"
162 );
163 cxstring text1 = cx_str("{ \"string\" }");
164 cxstring text2 = cx_str("{ \"a\" : }");
165 cxstring text3 = cx_str("{ \"a\" : \"b\" ]");
166 cxstring text4 = cx_str("{ \"name\": \"value\" ]");
167
168 cxstring tests[] = { text0, text1, text2, text3, text4 };
169
170 CX_TEST_DO {
171 int result;
172 CxJson json;
173 CxJsonValue *obj = NULL;
174
175 for(int i=0;i<5;i++) {
176 cxJsonInit(&json);
177 cxJsonFill(&json, tests[i].ptr, tests[i].length);
178 result = cxJsonNext(&json, &obj);
179
180 CX_TEST_ASSERT(result == -1);
181 CX_TEST_ASSERT(obj == NULL);
182 cxJsonDestroy(&json);
183 }
184 }
185 }
186
151 CxTestSuite *cx_test_suite_json(void) { 187 CxTestSuite *cx_test_suite_json(void) {
152 CxTestSuite *suite = cx_test_suite_new("json"); 188 CxTestSuite *suite = cx_test_suite_new("json");
153 189
154 cx_test_register(suite, test_json_simple_object); 190 cx_test_register(suite, test_json_simple_object);
155 cx_test_register(suite, test_json_object_incomplete_token); 191 cx_test_register(suite, test_json_object_incomplete_token);
192 cx_test_register(suite, test_json_object_error);
156 193
157 return suite; 194 return suite;
158 } 195 }
159 196

mercurial