Fix json_object_get_boolean() doc for the object and array cases (always returns 0), and add those cases to the test_cast test.
See also issue #658.
This commit is contained in:
@@ -656,8 +656,9 @@ JSON_EXPORT struct json_object *json_object_new_boolean(json_bool b);
|
|||||||
* The type is coerced to a json_bool if the passed object is not a json_bool.
|
* The type is coerced to a json_bool if the passed object is not a json_bool.
|
||||||
* integer and double objects will return 0 if there value is zero
|
* integer and double objects will return 0 if there value is zero
|
||||||
* or 1 otherwise. If the passed object is a string it will return
|
* or 1 otherwise. If the passed object is a string it will return
|
||||||
* 1 if it has a non zero length. If any other object type is passed
|
* 1 if it has a non zero length.
|
||||||
* 1 will be returned if the object is not NULL.
|
* If any other object type is passed 0 will be returned, even non-empty
|
||||||
|
* json_type_array and json_type_object objects.
|
||||||
*
|
*
|
||||||
* @param obj the json_object instance
|
* @param obj the json_object instance
|
||||||
* @returns a json_bool
|
* @returns a json_bool
|
||||||
|
|||||||
@@ -28,6 +28,11 @@ int main(int argc, char **argv)
|
|||||||
\"int64_number\": 2147483649,\n\
|
\"int64_number\": 2147483649,\n\
|
||||||
\"negative_number\": -321321321,\n\
|
\"negative_number\": -321321321,\n\
|
||||||
\"a_null\": null,\n\
|
\"a_null\": null,\n\
|
||||||
|
\"empty_array\": [],\n\
|
||||||
|
\"nonempty_array\": [ 123 ],\n\
|
||||||
|
\"array_with_zero\": [ 0 ],\n\
|
||||||
|
\"empty_object\": {},\n\
|
||||||
|
\"nonempty_object\": { \"a\": 123 },\n\
|
||||||
}";
|
}";
|
||||||
/* Note: 2147483649 = INT_MAX + 2 */
|
/* Note: 2147483649 = INT_MAX + 2 */
|
||||||
/* Note: 9223372036854775809 = INT64_MAX + 2 */
|
/* Note: 9223372036854775809 = INT64_MAX + 2 */
|
||||||
@@ -49,6 +54,11 @@ int main(int argc, char **argv)
|
|||||||
getit(new_obj, "int64_number");
|
getit(new_obj, "int64_number");
|
||||||
getit(new_obj, "negative_number");
|
getit(new_obj, "negative_number");
|
||||||
getit(new_obj, "a_null");
|
getit(new_obj, "a_null");
|
||||||
|
getit(new_obj, "empty_array");
|
||||||
|
getit(new_obj, "nonempty_array");
|
||||||
|
getit(new_obj, "array_with_zero");
|
||||||
|
getit(new_obj, "empty_object");
|
||||||
|
getit(new_obj, "nonempty_object");
|
||||||
|
|
||||||
// Now check the behaviour of the json_object_is_type() function.
|
// Now check the behaviour of the json_object_is_type() function.
|
||||||
printf("\n================================\n");
|
printf("\n================================\n");
|
||||||
|
|||||||
@@ -7,6 +7,11 @@ Parsed input: {
|
|||||||
"int64_number": 2147483649,
|
"int64_number": 2147483649,
|
||||||
"negative_number": -321321321,
|
"negative_number": -321321321,
|
||||||
"a_null": null,
|
"a_null": null,
|
||||||
|
"empty_array": [],
|
||||||
|
"nonempty_array": [ 123 ],
|
||||||
|
"array_with_zero": [ 0 ],
|
||||||
|
"empty_object": {},
|
||||||
|
"nonempty_object": { "a": 123 },
|
||||||
}
|
}
|
||||||
Result is not NULL
|
Result is not NULL
|
||||||
new_obj.string_of_digits json_object_get_type()=string
|
new_obj.string_of_digits json_object_get_type()=string
|
||||||
@@ -57,6 +62,36 @@ new_obj.a_null json_object_get_int64()=0
|
|||||||
new_obj.a_null json_object_get_uint64()=0
|
new_obj.a_null json_object_get_uint64()=0
|
||||||
new_obj.a_null json_object_get_boolean()=0
|
new_obj.a_null json_object_get_boolean()=0
|
||||||
new_obj.a_null json_object_get_double()=0.000000
|
new_obj.a_null json_object_get_double()=0.000000
|
||||||
|
new_obj.empty_array json_object_get_type()=array
|
||||||
|
new_obj.empty_array json_object_get_int()=0
|
||||||
|
new_obj.empty_array json_object_get_int64()=0
|
||||||
|
new_obj.empty_array json_object_get_uint64()=0
|
||||||
|
new_obj.empty_array json_object_get_boolean()=0
|
||||||
|
new_obj.empty_array json_object_get_double()=0.000000
|
||||||
|
new_obj.nonempty_array json_object_get_type()=array
|
||||||
|
new_obj.nonempty_array json_object_get_int()=0
|
||||||
|
new_obj.nonempty_array json_object_get_int64()=0
|
||||||
|
new_obj.nonempty_array json_object_get_uint64()=0
|
||||||
|
new_obj.nonempty_array json_object_get_boolean()=0
|
||||||
|
new_obj.nonempty_array json_object_get_double()=0.000000
|
||||||
|
new_obj.array_with_zero json_object_get_type()=array
|
||||||
|
new_obj.array_with_zero json_object_get_int()=0
|
||||||
|
new_obj.array_with_zero json_object_get_int64()=0
|
||||||
|
new_obj.array_with_zero json_object_get_uint64()=0
|
||||||
|
new_obj.array_with_zero json_object_get_boolean()=0
|
||||||
|
new_obj.array_with_zero json_object_get_double()=0.000000
|
||||||
|
new_obj.empty_object json_object_get_type()=object
|
||||||
|
new_obj.empty_object json_object_get_int()=0
|
||||||
|
new_obj.empty_object json_object_get_int64()=0
|
||||||
|
new_obj.empty_object json_object_get_uint64()=0
|
||||||
|
new_obj.empty_object json_object_get_boolean()=0
|
||||||
|
new_obj.empty_object json_object_get_double()=0.000000
|
||||||
|
new_obj.nonempty_object json_object_get_type()=object
|
||||||
|
new_obj.nonempty_object json_object_get_int()=0
|
||||||
|
new_obj.nonempty_object json_object_get_int64()=0
|
||||||
|
new_obj.nonempty_object json_object_get_uint64()=0
|
||||||
|
new_obj.nonempty_object json_object_get_boolean()=0
|
||||||
|
new_obj.nonempty_object json_object_get_double()=0.000000
|
||||||
|
|
||||||
================================
|
================================
|
||||||
json_object_is_type: null,boolean,double,int,object,array,string
|
json_object_is_type: null,boolean,double,int,object,array,string
|
||||||
|
|||||||
Reference in New Issue
Block a user