mirror of
https://github.com/json-c/json-c.git
synced 2026-03-26 16:39:06 +08:00
modify partial functions and testcase, in order to support automatic conversion for int64/uint64
This commit is contained in:
@@ -15,9 +15,11 @@ int main()
|
||||
struct json_object *int1 = json_object_new_int(0);
|
||||
struct json_object *int2 = json_object_new_int(1);
|
||||
struct json_object *int3 = json_object_new_int(1);
|
||||
struct json_object *int4 = json_object_new_int(-1);
|
||||
struct json_object *uint1 = json_object_new_uint64(0);
|
||||
struct json_object *uint2 = json_object_new_uint64(1);
|
||||
struct json_object *uint3 = json_object_new_uint64(1);
|
||||
struct json_object *uint4 = json_object_new_uint64((uint64_t)INT64_MAX + 100);
|
||||
|
||||
if (!json_object_equal(int1, int2))
|
||||
printf("JSON integer comparison is correct\n");
|
||||
@@ -49,12 +51,54 @@ int main()
|
||||
else
|
||||
printf("JSON same usigned integer comparison failed\n");
|
||||
|
||||
if (json_object_equal(int2, uint2))
|
||||
printf("JSON integer & usigned integer comparison is correct\n");
|
||||
else
|
||||
printf("JSON integer & usigned integer comparison failed\n");
|
||||
|
||||
if (!json_object_equal(int2, uint4))
|
||||
printf("JSON integer & usigned integer comparison is correct\n");
|
||||
else
|
||||
printf("JSON integer & usigned integer comparison failed\n");
|
||||
|
||||
if (!json_object_equal(int4, uint2))
|
||||
printf("JSON integer & usigned integer comparison is correct\n");
|
||||
else
|
||||
printf("JSON integer & usigned integer comparison failed\n");
|
||||
|
||||
if (!json_object_equal(int4, uint4))
|
||||
printf("JSON integer & usigned integer comparison is correct\n");
|
||||
else
|
||||
printf("JSON integer & usigned integer comparison failed\n");
|
||||
|
||||
if (json_object_equal(uint2, int2))
|
||||
printf("JSON usigned integer & integer comparison is correct\n");
|
||||
else
|
||||
printf("JSON usigned integer & integer comparison failed\n");
|
||||
|
||||
if (!json_object_equal(uint2, int4))
|
||||
printf("JSON usigned integer & integer comparison is correct\n");
|
||||
else
|
||||
printf("JSON usigned integer & integer comparison failed\n");
|
||||
|
||||
if (!json_object_equal(uint4, int2))
|
||||
printf("JSON usigned integer & integer comparison is correct\n");
|
||||
else
|
||||
printf("JSON usigned integer & integer comparison failed\n");
|
||||
|
||||
if (!json_object_equal(uint4, int4))
|
||||
printf("JSON usigned integer & integer comparison is correct\n");
|
||||
else
|
||||
printf("JSON usigned integer & integer comparison failed\n");
|
||||
|
||||
json_object_put(int1);
|
||||
json_object_put(int2);
|
||||
json_object_put(int3);
|
||||
json_object_put(int4);
|
||||
json_object_put(uint1);
|
||||
json_object_put(uint2);
|
||||
json_object_put(uint3);
|
||||
json_object_put(uint4);
|
||||
|
||||
/* string tests */
|
||||
struct json_object *str1 = json_object_new_string("TESTSTRING");
|
||||
|
||||
@@ -4,6 +4,14 @@ JSON same integer comparison is correct
|
||||
JSON usigned integer comparison is correct
|
||||
JSON same usigned object comparison is correct
|
||||
JSON same usigned integer comparison is correct
|
||||
JSON integer & usigned integer comparison is correct
|
||||
JSON integer & usigned integer comparison is correct
|
||||
JSON integer & usigned integer comparison is correct
|
||||
JSON integer & usigned integer comparison is correct
|
||||
JSON usigned integer & integer comparison is correct
|
||||
JSON usigned integer & integer comparison is correct
|
||||
JSON usigned integer & integer comparison is correct
|
||||
JSON usigned integer & integer comparison is correct
|
||||
Comparing equal strings is correct
|
||||
Comparing different strings is correct
|
||||
Comparing equal doubles is correct
|
||||
|
||||
@@ -25,13 +25,27 @@ int main(int argc, char **argv)
|
||||
tmp = json_object_new_int64(321321321);
|
||||
json_object_int_inc(tmp, 321321321);
|
||||
assert(json_object_get_int(tmp) == 642642642);
|
||||
json_object_uint_inc(tmp, 321321321U);
|
||||
assert(json_object_get_int(tmp) == 963963963);
|
||||
json_object_put(tmp);
|
||||
printf("INT64 ADD PASSED\n");
|
||||
tmp = json_object_new_int64(INT64_MAX);
|
||||
json_object_int_inc(tmp, 100);
|
||||
assert(json_object_get_int64(tmp) == INT64_MAX);
|
||||
assert(json_object_get_uint64(tmp) == (uint64_t)INT64_MAX + 100U);
|
||||
json_object_int_inc(tmp, -100);
|
||||
assert(json_object_get_int64(tmp) != INT64_MAX);
|
||||
assert(json_object_get_int64(tmp) == INT64_MAX);
|
||||
assert(json_object_get_uint64(tmp) == (uint64_t)INT64_MAX);
|
||||
json_object_put(tmp);
|
||||
tmp = json_object_new_int64(100);
|
||||
json_object_uint_inc(tmp, 100);
|
||||
assert(json_object_get_int64(tmp) == 200);
|
||||
json_object_uint_inc(tmp, (uint64_t)INT64_MAX);
|
||||
assert(json_object_get_int64(tmp) == INT64_MAX);
|
||||
assert(json_object_get_uint64(tmp) == (uint64_t)INT64_MAX+200);
|
||||
json_object_uint_inc(tmp, UINT64_MAX);
|
||||
assert(json_object_get_int64(tmp) == INT64_MAX);
|
||||
assert(json_object_get_uint64(tmp) == UINT64_MAX);
|
||||
json_object_put(tmp);
|
||||
printf("INT64 ADD OVERFLOW PASSED\n");
|
||||
tmp = json_object_new_int64(INT64_MIN);
|
||||
@@ -45,14 +59,28 @@ int main(int argc, char **argv)
|
||||
json_object_uint_inc(tmp, 321321321);
|
||||
assert(json_object_get_uint64(tmp) == 642642642);
|
||||
json_object_put(tmp);
|
||||
// uint64 + negative int64--> negative int64
|
||||
tmp = json_object_new_uint64(400);
|
||||
json_object_int_inc(tmp, -200);
|
||||
assert(json_object_get_int64(tmp) == 200);
|
||||
assert(json_object_get_uint64(tmp) == 200);
|
||||
json_object_put(tmp);
|
||||
printf("UINT64 ADD PASSED\n");
|
||||
tmp = json_object_new_uint64(UINT64_MAX);
|
||||
json_object_uint_inc(tmp, 100);
|
||||
assert(json_object_get_uint64(tmp) == UINT64_MAX);
|
||||
json_object_uint_inc(tmp, -100);
|
||||
assert(json_object_get_uint64(tmp) != INT64_MAX);
|
||||
json_object_put(tmp);
|
||||
tmp = json_object_new_uint64(UINT64_MAX - 100);
|
||||
json_object_uint_inc(tmp, 200);
|
||||
assert(json_object_get_uint64(tmp) == UINT64_MAX);
|
||||
json_object_put(tmp);
|
||||
printf("UINT64 ADD OVERFLOW PASSED\n");
|
||||
tmp = json_object_new_uint64(100);
|
||||
json_object_int_inc(tmp, -200);
|
||||
assert(json_object_get_int64(tmp) == -100);
|
||||
assert(json_object_get_uint64(tmp) == 0);
|
||||
json_object_put(tmp);
|
||||
printf("UINT64 ADD UNDERFLOW PASSED\n");
|
||||
|
||||
printf("PASSED\n");
|
||||
return 0;
|
||||
|
||||
@@ -6,4 +6,5 @@ INT64 ADD OVERFLOW PASSED
|
||||
INT64 ADD UNDERFLOW PASSED
|
||||
UINT64 ADD PASSED
|
||||
UINT64 ADD OVERFLOW PASSED
|
||||
UINT64 ADD UNDERFLOW PASSED
|
||||
PASSED
|
||||
|
||||
Reference in New Issue
Block a user