tests/test_json.c

changeset 1543
7b66371d6da3
parent 1513
4d641c6a2f82
child 1547
12da0654e4a9
equal deleted inserted replaced
1542:197450c2b0b3 1543:7b66371d6da3
237 "test\xf0\x9f\xaf\xb1" "AA") 237 "test\xf0\x9f\xaf\xb1" "AA")
238 ); 238 );
239 239
240 CxJsonValue *mixed2 = cxJsonObjGet(obj, "mixed2"); 240 CxJsonValue *mixed2 = cxJsonObjGet(obj, "mixed2");
241 char test[16]; 241 char test[16];
242 strncpy(test, mixed2->value.string.ptr, 15); 242 strncpy(test, mixed2->string.ptr, 15);
243 CX_TEST_ASSERT(cxJsonIsString(mixed2)); 243 CX_TEST_ASSERT(cxJsonIsString(mixed2));
244 CX_TEST_ASSERT(0 == cx_strcmp( 244 CX_TEST_ASSERT(0 == cx_strcmp(
245 cxJsonAsCxString(mixed2), 245 cxJsonAsCxString(mixed2),
246 "123\xce\xa3\xf0\x9f\xaf\x85ß") 246 "123\xce\xa3\xf0\x9f\xaf\x85ß")
247 ); 247 );
248 248
1394 writer.frac_max_digits = 3; 1394 writer.frac_max_digits = 3;
1395 cxJsonWrite(&buf, num, cxBufferWriteFunc, &writer); 1395 cxJsonWrite(&buf, num, cxBufferWriteFunc, &writer);
1396 CX_TEST_ASSERT(0 == cx_strcmp(cx_strn(buf.space, buf.size), "3.141")); 1396 CX_TEST_ASSERT(0 == cx_strcmp(cx_strn(buf.space, buf.size), "3.141"));
1397 1397
1398 // test 6 digits, but two are left of the decimal point 1398 // test 6 digits, but two are left of the decimal point
1399 num->value.number = 47.110815; 1399 num->number = 47.110815;
1400 cxBufferReset(&buf); 1400 cxBufferReset(&buf);
1401 writer.frac_max_digits = 6; 1401 writer.frac_max_digits = 6;
1402 cxJsonWrite(&buf, num, cxBufferWriteFunc, &writer); 1402 cxJsonWrite(&buf, num, cxBufferWriteFunc, &writer);
1403 CX_TEST_ASSERT(0 == cx_strcmp(cx_strn(buf.space, buf.size), "47.110815")); 1403 CX_TEST_ASSERT(0 == cx_strcmp(cx_strn(buf.space, buf.size), "47.110815"));
1404 1404
1405 // test 4 digits with exponent 1405 // test 4 digits with exponent
1406 num->value.number = 5.11223344e23; 1406 num->number = 5.11223344e23;
1407 cxBufferReset(&buf); 1407 cxBufferReset(&buf);
1408 writer.frac_max_digits = 4; 1408 writer.frac_max_digits = 4;
1409 cxJsonWrite(&buf, num, cxBufferWriteFunc, &writer); 1409 cxJsonWrite(&buf, num, cxBufferWriteFunc, &writer);
1410 CX_TEST_ASSERT(0 == cx_strcmp(cx_strn(buf.space, buf.size), "5.1122e+23")); 1410 CX_TEST_ASSERT(0 == cx_strcmp(cx_strn(buf.space, buf.size), "5.1122e+23"));
1411 } 1411 }

mercurial