]> granicus.if.org Git - json-c/commitdiff
Extend test_double_serializer to check NaN and Infinity handling.
authorEric Haszlakiewicz <erh+git@nimenees.com>
Sat, 23 Nov 2019 03:56:33 +0000 (22:56 -0500)
committerEric Haszlakiewicz <erh+git@nimenees.com>
Sat, 23 Nov 2019 03:56:33 +0000 (22:56 -0500)
tests/test_double_serializer.c
tests/test_double_serializer.expected

index 5752bc3f88dd105eb9d53c0932251a8d5e02472b..2cec24fb76a625aad68ed1c7a226384cb1ca593d 100644 (file)
@@ -8,6 +8,9 @@
 #include "json_object.h"
 #include "json_object_private.h"
 
+/* Avoid compiler warnings about diving by constant zero */
+double zero_dot_zero = 0.0;
+
 int main()
 {
        struct json_object *obj = json_object_new_double(0.5);
@@ -80,4 +83,15 @@ int main()
        printf("obj(-12.0).to_string(default format)=%s\n", json_object_to_json_string(obj));
        json_object_put(obj);
 
+       /* Test NaN handling */
+       obj = json_object_new_double(zero_dot_zero / zero_dot_zero);
+       printf("obj(0.0/0.0)=%s\n", json_object_to_json_string(obj));
+
+       /* Test Infinity and -Infinity handling */
+       obj = json_object_new_double(1.0/zero_dot_zero);
+       printf("obj(1.0/0.0)=%s\n", json_object_to_json_string(obj));
+
+       obj = json_object_new_double(-1.0/zero_dot_zero);
+       printf("obj(-1.0/0.0)=%s\n", json_object_to_json_string(obj));
+
 }
index d3aef72477d62af608784be6e44057e1ba3f8407..221d832d7e52e449869712fe7f0a13a9be86953a 100644 (file)
@@ -17,3 +17,6 @@ obj(12.0).to_string(%.0f)=12
 obj(12.0).to_string(%.0g)=1e+01
 obj(12.0).to_string(%.1g)=12.0
 obj(-12.0).to_string(default format)=-12.0
+obj(0.0/0.0)=NaN
+obj(1.0/0.0)=Infinity
+obj(-1.0/0.0)=-Infinity