tests/test_json.c

changeset 1075
0cc4b63a0ae0
parent 1072
c89283cd559b
child 1078
ffa8bb4e9288
equal deleted inserted replaced
1074:e8e2813cdda6 1075:0cc4b63a0ae0
192 cxJsonDestroy(&json); 192 cxJsonDestroy(&json);
193 } 193 }
194 } 194 }
195 195
196 CX_TEST(test_json_token_wrongly_completed) { 196 CX_TEST(test_json_token_wrongly_completed) {
197 CxTestingAllocator talloc;
198 cx_testing_allocator_init(&talloc);
199 const CxAllocator *alloc = &talloc.base;
200
197 cxstring text = cx_str("{\"number\": 47110815!}"); 201 cxstring text = cx_str("{\"number\": 47110815!}");
198 cxstring part1 = cx_strsubsl(text, 0, 16); 202 cxstring part1 = cx_strsubsl(text, 0, 16);
199 cxstring part2 = cx_strsubs(text, 16); 203 cxstring part2 = cx_strsubs(text, 16);
200 204
201 CxJson json; 205 CX_TEST_DO {
202 cxJsonInit(&json, NULL); 206 CxJson json;
203 CX_TEST_DO { 207 cxJsonInit(&json, alloc);
208
204 CxJsonStatus result; 209 CxJsonStatus result;
205 CxJsonValue *obj; 210 CxJsonValue *obj;
206 211
207 cxJsonFill(&json, part1); 212 cxJsonFill(&json, part1);
208 result = cxJsonNext(&json, &obj); 213 result = cxJsonNext(&json, &obj);
209 CX_TEST_ASSERT(result == CX_JSON_INCOMPLETE_DATA); 214 CX_TEST_ASSERT(result == CX_JSON_INCOMPLETE_DATA);
210 cxJsonFill(&json, part2); 215 cxJsonFill(&json, part2);
211 result = cxJsonNext(&json, &obj); 216 result = cxJsonNext(&json, &obj);
212 CX_TEST_ASSERT(result == CX_JSON_FORMAT_ERROR_NUMBER); 217 CX_TEST_ASSERT(result == CX_JSON_FORMAT_ERROR_NUMBER);
213 CX_TEST_ASSERT(obj->type == CX_JSON_NOTHING); 218 CX_TEST_ASSERT(obj->type == CX_JSON_NOTHING);
214 } 219
215 cxJsonDestroy(&json); 220 cxJsonDestroy(&json);
221 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
222 }
223 cx_testing_allocator_destroy(&talloc);
216 } 224 }
217 225
218 CX_TEST(test_json_subsequent_fill) { 226 CX_TEST(test_json_subsequent_fill) {
219 cxstring text = cx_str( 227 cxstring text = cx_str(
220 "{\"message\":\"success\" , \"__timestamp\":1729348561}"); 228 "{\"message\":\"success\" , \"__timestamp\":1729348561}");

mercurial