@@ -656,7 +656,8 @@ int32_t json_object_get_int(const struct json_object *jso) | |||||
} else { | } else { | ||||
if (jso->o.c_int.cint.c_uint64 >= INT64_MAX) | if (jso->o.c_int.cint.c_uint64 >= INT64_MAX) | ||||
cint64 = INT64_MAX; | cint64 = INT64_MAX; | ||||
cint64 = (int64_t)jso->o.c_int.cint.c_uint64; | |||||
else | |||||
cint64 = (int64_t)jso->o.c_int.cint.c_uint64; | |||||
} | } | ||||
if (o_type == json_type_string) | if (o_type == json_type_string) | ||||
@@ -208,8 +208,50 @@ int main() | |||||
else | else | ||||
printf("Comparing different objects is incorrect\n"); | printf("Comparing different objects is incorrect\n"); | ||||
/* iterate over jso2 keys to see if any exist that are not in jso1 */ | |||||
json_object_object_add(obj2, "test3", json_object_new_int(320)); | |||||
json_object_object_add(obj2, "test6", json_object_new_int(321)); | |||||
if (!json_object_equal(obj1, obj2)) | |||||
printf("Comparing different objects is correct\n"); | |||||
else | |||||
printf("Comparing different objects is incorrect\n"); | |||||
/* iterate over jso1 keys and see if they exist in jso1 */ | |||||
json_object_object_add(obj1, "test6", json_object_new_int(321)); | |||||
if (json_object_equal(obj1, obj2)) | |||||
printf("Comparing different objects is correct\n"); | |||||
else | |||||
printf("Comparing different objects is incorrect\n"); | |||||
json_object_object_add(obj1, "test7", json_object_new_int(322)); | |||||
if (!json_object_equal(obj1, obj2)) | |||||
printf("Comparing different objects is correct\n"); | |||||
else | |||||
printf("Comparing different objects is incorrect\n"); | |||||
json_object_put(obj1); | json_object_put(obj1); | ||||
json_object_put(obj2); | json_object_put(obj2); | ||||
/* different types tests */ | |||||
struct json_object *int5 = json_object_new_int(0); | |||||
struct json_object *dbl5 = json_object_new_double(3.14159); | |||||
if (!json_object_equal(int5, NULL)) | |||||
printf("JSON integer and NULL comparison is correct\n"); | |||||
else | |||||
printf("JSON integer and NULL comparison failed\n"); | |||||
if (!json_object_equal(NULL, dbl5)) | |||||
printf("JSON NULL and double comparison is correct\n"); | |||||
else | |||||
printf("JSON NULL and double comparison failed\n"); | |||||
if (!json_object_equal(int5, dbl5)) | |||||
printf("JSON integer and double comparison is correct\n"); | |||||
else | |||||
printf("JSON integer and double comparison failed\n"); | |||||
json_object_put(int5); | |||||
json_object_put(dbl5); | |||||
return 0; | return 0; | ||||
} | } |
@@ -22,3 +22,9 @@ Comparing different arrays is correct | |||||
Comparing different arrays (one empty) is correct | Comparing different arrays (one empty) is correct | ||||
Comparing JSON object with different key order is correct | Comparing JSON object with different key order is correct | ||||
Comparing different objects is correct | Comparing different objects is correct | ||||
Comparing different objects is correct | |||||
Comparing different objects is correct | |||||
Comparing different objects is correct | |||||
JSON integer and NULL comparison is correct | |||||
JSON NULL and double comparison is correct | |||||
JSON integer and double comparison is correct |
@@ -19,6 +19,7 @@ static const char *json_str1 = | |||||
" \"glossary\": {" | " \"glossary\": {" | ||||
" \"title\": \"example glossary\"," | " \"title\": \"example glossary\"," | ||||
" \"GlossDiv\": {" | " \"GlossDiv\": {" | ||||
" \"number\": 16446744073709551615," | |||||
" \"title\": \"S\"," | " \"title\": \"S\"," | ||||
" \"null_obj\": null, " | " \"null_obj\": null, " | ||||
" \"exixt\": false," | " \"exixt\": false," | ||||
@@ -11,6 +11,7 @@ Printing JSON objects for visual inspection | |||||
"glossary":{ | "glossary":{ | ||||
"title":"example glossary", | "title":"example glossary", | ||||
"GlossDiv":{ | "GlossDiv":{ | ||||
"number":16446744073709551615, | |||||
"title":"S", | "title":"S", | ||||
"null_obj":null, | "null_obj":null, | ||||
"exixt":false, | "exixt":false, | ||||
@@ -48,8 +48,17 @@ int main(int argc, char **argv) | |||||
json_object_int_inc(tmp, -200); | json_object_int_inc(tmp, -200); | ||||
assert(json_object_get_int64(tmp) == 200); | assert(json_object_get_int64(tmp) == 200); | ||||
assert(json_object_get_uint64(tmp) == 200); | assert(json_object_get_uint64(tmp) == 200); | ||||
json_object_int_inc(tmp, 200); | |||||
assert(json_object_get_int64(tmp) == 400); | |||||
assert(json_object_get_uint64(tmp) == 400); | |||||
json_object_put(tmp); | json_object_put(tmp); | ||||
printf("UINT64 ADD PASSED\n"); | printf("UINT64 ADD PASSED\n"); | ||||
tmp = json_object_new_uint64(UINT64_MAX-50); | |||||
json_object_int_inc(tmp, 100); | |||||
assert(json_object_get_int64(tmp) == INT64_MAX); | |||||
assert(json_object_get_uint64(tmp) == UINT64_MAX); | |||||
json_object_put(tmp); | |||||
printf("UINT64 ADD OVERFLOW PASSED\n"); | |||||
tmp = json_object_new_uint64(100); | tmp = json_object_new_uint64(100); | ||||
json_object_int_inc(tmp, -200); | json_object_int_inc(tmp, -200); | ||||
assert(json_object_get_int64(tmp) == -100); | assert(json_object_get_int64(tmp) == -100); | ||||
@@ -5,5 +5,6 @@ INT64 ADD PASSED | |||||
INT64 ADD OVERFLOW PASSED | INT64 ADD OVERFLOW PASSED | ||||
INT64 ADD UNDERFLOW PASSED | INT64 ADD UNDERFLOW PASSED | ||||
UINT64 ADD PASSED | UINT64 ADD PASSED | ||||
UINT64 ADD OVERFLOW PASSED | |||||
UINT64 ADD UNDERFLOW PASSED | UINT64 ADD UNDERFLOW PASSED | ||||
PASSED | PASSED |
@@ -16,12 +16,15 @@ int main(int argc, char **argv) | |||||
json_object_put(tmp); | json_object_put(tmp); | ||||
printf("INT64 PASSED\n"); | printf("INT64 PASSED\n"); | ||||
tmp=json_object_new_uint64(123); | tmp=json_object_new_uint64(123); | ||||
assert (json_object_get_boolean(tmp)==1); | |||||
assert (json_object_get_int(tmp)==123); | assert (json_object_get_int(tmp)==123); | ||||
assert (json_object_get_int64(tmp)==123); | assert (json_object_get_int64(tmp)==123); | ||||
assert (json_object_get_uint64(tmp)==123); | assert (json_object_get_uint64(tmp)==123); | ||||
assert (json_object_get_double(tmp)==123.000000); | |||||
json_object_set_uint64(tmp,(uint64_t)321321321); | json_object_set_uint64(tmp,(uint64_t)321321321); | ||||
assert (json_object_get_uint64(tmp)==321321321); | assert (json_object_get_uint64(tmp)==321321321); | ||||
json_object_set_uint64(tmp,9223372036854775808U); | json_object_set_uint64(tmp,9223372036854775808U); | ||||
assert (json_object_get_int(tmp)==INT32_MAX); | |||||
assert (json_object_get_uint64(tmp)==9223372036854775808U); | assert (json_object_get_uint64(tmp)==9223372036854775808U); | ||||
json_object_put(tmp); | json_object_put(tmp); | ||||
printf("UINT64 PASSED\n"); | printf("UINT64 PASSED\n"); | ||||
@@ -40,9 +43,11 @@ int main(int argc, char **argv) | |||||
json_object_set_double(tmp,6435.34); | json_object_set_double(tmp,6435.34); | ||||
assert (json_object_get_double(tmp)==6435.34); | assert (json_object_get_double(tmp)==6435.34); | ||||
json_object_set_double(tmp,2e21); | json_object_set_double(tmp,2e21); | ||||
assert (json_object_get_int(tmp)==INT32_MAX); | |||||
assert (json_object_get_int64(tmp)==INT64_MAX); | assert (json_object_get_int64(tmp)==INT64_MAX); | ||||
assert (json_object_get_uint64(tmp)==UINT64_MAX); | assert (json_object_get_uint64(tmp)==UINT64_MAX); | ||||
json_object_set_double(tmp,-2e21); | json_object_set_double(tmp,-2e21); | ||||
assert (json_object_get_int(tmp)==INT32_MIN); | |||||
assert (json_object_get_int64(tmp)==INT64_MIN); | assert (json_object_get_int64(tmp)==INT64_MIN); | ||||
assert (json_object_get_uint64(tmp)==0); | assert (json_object_get_uint64(tmp)==0); | ||||
json_object_put(tmp); | json_object_put(tmp); | ||||
@@ -62,6 +67,27 @@ int main(int argc, char **argv) | |||||
json_object_put(tmp); | json_object_put(tmp); | ||||
printf("STRING PASSED\n"); | printf("STRING PASSED\n"); | ||||
#define STR "STR" | |||||
#define DOUBLE "123.123" | |||||
#define DOUBLE_E "12E+3" | |||||
#define DOUBLE_STR "123.123STR" | |||||
#define DOUBLE_OVER "1.8E+308" | |||||
#define DOUBLE_OVER_NEGATIVE "-1.8E+308" | |||||
tmp=json_object_new_string(STR); | |||||
assert (json_object_get_double(tmp)==0.0); | |||||
json_object_set_string(tmp,DOUBLE); | |||||
assert (json_object_get_double(tmp)==123.123000); | |||||
json_object_set_string(tmp,DOUBLE_E); | |||||
assert (json_object_get_double(tmp)==12000.000000); | |||||
json_object_set_string(tmp,DOUBLE_STR); | |||||
assert (json_object_get_double(tmp)==0.0); | |||||
json_object_set_string(tmp,DOUBLE_OVER); | |||||
assert (json_object_get_double(tmp)==0.0); | |||||
json_object_set_string(tmp,DOUBLE_OVER_NEGATIVE); | |||||
assert (json_object_get_double(tmp)==0.0); | |||||
json_object_put(tmp); | |||||
printf("STRINGTODOUBLE PASSED\n"); | |||||
tmp = json_tokener_parse("1.234"); | tmp = json_tokener_parse("1.234"); | ||||
json_object_set_double(tmp, 12.3); | json_object_set_double(tmp, 12.3); | ||||
const char *serialized = json_object_to_json_string(tmp); | const char *serialized = json_object_to_json_string(tmp); | ||||
@@ -4,5 +4,6 @@ UINT64 PASSED | |||||
BOOL PASSED | BOOL PASSED | ||||
DOUBLE PASSED | DOUBLE PASSED | ||||
STRING PASSED | STRING PASSED | ||||
STRINGTODOUBLE PASSED | |||||
PARSE AND SET PASSED | PARSE AND SET PASSED | ||||
PASSED | PASSED |