]> git.ipfire.org Git - thirdparty/json-c.git/commitdiff
Fix json_object_get_boolean() doc for the object and array cases (always returns...
authorEric Haszlakiewicz <erh+git@nimenees.com>
Mon, 17 Aug 2020 14:55:54 +0000 (14:55 +0000)
committerEric Haszlakiewicz <erh+git@nimenees.com>
Mon, 17 Aug 2020 14:57:21 +0000 (14:57 +0000)
See also issue #658.

json_object.h
tests/test_cast.c
tests/test_cast.expected

index a54541c86f8b042cf9094ec7c0eabce0275c74fd..036be64a15484f925534eb682d30f2a5aa5d1ce7 100644 (file)
@@ -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.
  * 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
- * 1 if it has a non zero length. If any other object type is passed
- * 1 will be returned if the object is not NULL.
+ * 1 if it has a non zero length. 
+ * 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
  * @returns a json_bool
index fb63e0d88ab364265ba755c35cf2feb3fcc9d7f7..fc769f51312a7614ee9d3c6d9a0e5e00f14e1fe1 100644 (file)
@@ -28,6 +28,11 @@ int main(int argc, char **argv)
                \"int64_number\": 2147483649,\n\
                \"negative_number\": -321321321,\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: 9223372036854775809 = INT64_MAX + 2 */
@@ -49,6 +54,11 @@ int main(int argc, char **argv)
        getit(new_obj, "int64_number");
        getit(new_obj, "negative_number");
        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.
        printf("\n================================\n");
index 347d540cc7a24b905a1c1875935448ab1f60c211..6a19de9a865ca74d7eb4593095b681f781356399 100644 (file)
@@ -7,6 +7,11 @@ Parsed input: {
                "int64_number": 2147483649,
                "negative_number": -321321321,
                "a_null": null,
+               "empty_array": [],
+               "nonempty_array": [ 123 ],
+               "array_with_zero": [ 0 ],
+               "empty_object": {},
+               "nonempty_object": { "a": 123 },
        }
 Result is not NULL
 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_boolean()=0
 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