File: fix-json-test.patch

package info (click to toggle)
ibm-3270 4.3ga10-5
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 115,140 kB
  • sloc: xml: 610,537; ansic: 148,024; python: 8,664; sh: 6,360; makefile: 1,186; exp: 281; perl: 223; pascal: 129; tcl: 105; cpp: 21
file content (84 lines) | stat: -rw-r--r-- 2,770 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
Index: ibm-3270-4.3ga10/Common/Test/json_test.c
===================================================================
--- ibm-3270-4.3ga10.orig/Common/Test/json_test.c
+++ ibm-3270-4.3ga10/Common/Test/json_test.c
@@ -33,9 +33,11 @@
 #include "globals.h"
 
 #include <assert.h>
+#include <math.h>
 #include <signal.h>
 #include <setjmp.h>
 #include <fcntl.h>
+#include <float.h>
 
 #include "json.h"
 #include "sa_malloc.h"
@@ -64,13 +66,17 @@ static int old_stderr;
 #define SIGABRT_START \
     signal(SIGABRT, sigabrt); \
     (void)dup2(dev_null, 2); \
-    if (!setjmp(jbuf)) {
+    if (!sigsetjmp(jbuf, 1)) {
 #define SIGABRT_END \
     } \
     signal(SIGABRT, SIG_DFL); \
     (void)dup2(old_stderr, 2); \
     assert(got_sigabrt);
 
+bool double_equals(double a, double b) {
+    return fabs(a - b) < DBL_EPSILON;
+}
+
 static void positive_parse_tests(void);
 static void negative_parse_tests(void);
 static void get_tests(void);
@@ -247,9 +253,9 @@ positive_parse_tests(void)
     assert(errcode == JE_OK);
     assert(json_is_array(j));
     assert(json_array_length(j) == 3);
-    assert(json_double_value(json_array_element(j, 0)) == 1.2);
-    assert(json_double_value(json_array_element(j, 1)) == 2.3);
-    assert(json_double_value(json_array_element(j, 2)) == 3.4);
+    assert(double_equals(json_double_value(json_array_element(j, 0)), 1.2));
+    assert(double_equals(json_double_value(json_array_element(j, 1)), 2.3));
+    assert(double_equals(json_double_value(json_array_element(j, 2)), 3.4));
     CLEAN_UP_BOTH;
 
     /* Test an empty array. */
@@ -670,7 +676,7 @@ get_tests(void)
 #define TEST_DOUBLE "3.14"
     json_parse_s(TEST_DOUBLE, &j, &e);
     d = json_double_value(j);
-    assert(d == 3.14);
+    assert(double_equals(d, 3.14));
     CLEAN_UP_BOTH;
 
     json_parse_s(TEST_INT, &j, &e);
@@ -857,7 +863,7 @@ set_tests(void)
     /* Construct a double. */
     j = json_double(1.2345);
     assert(json_is_double(j));
-    assert(json_double_value(j) == 1.2345);
+    assert(double_equals(json_double_value(j), 1.2345));
     json_free(j);
 
     /* Construct an object. */
@@ -998,7 +1004,7 @@ clone_tests(void)
     j = json_double(3.14);
     k = json_clone(j);
     assert(json_is_double(k));
-    assert(json_double_value(k) == 3.14);
+    assert(double_equals(json_double_value(k), 3.14));
     json_free(k);
     CLEAN_UP;
 
@@ -1043,7 +1049,7 @@ clone_tests(void)
     assert(json_array_length(k) == 2);
     assert(json_is_array(json_array_element(k, 0)));
     assert(json_integer_value(json_array_element(json_array_element(k, 0), 0)) == 1);
-    assert(json_double_value(json_array_element(k, 1)) == 9.99);
+    assert(double_equals(json_double_value(json_array_element(k, 1)), 9.99));
     json_free(k);
     CLEAN_UP;
 }