12
12
#error JSON_TEST_SRC must point to test source directory
13
13
#endif
14
14
15
- #ifndef ARRAY_SIZE
16
- #define ARRAY_SIZE (arr ) (sizeof (arr) / sizeof ((arr)[0 ]))
17
- #endif
18
-
19
15
std::string srcdir (JSON_TEST_SRC);
20
- static bool test_failed = false ;
21
-
22
- #define d_assert (expr ) { if (!(expr)) { test_failed = true ; fprintf (stderr, " %s failed\n " , filename.c_str ()); } }
23
- #define f_assert (expr ) { if (!(expr)) { test_failed = true ; fprintf (stderr, " %s failed\n " , __func__); } }
24
16
25
17
static std::string rtrim (std::string s)
26
18
{
@@ -41,9 +33,9 @@ static void runtest(std::string filename, const std::string& jdata)
41
33
bool testResult = val.read (jdata);
42
34
43
35
if (wantPass) {
44
- d_assert (testResult == true );
36
+ assert (testResult == true );
45
37
} else {
46
- d_assert (testResult == false );
38
+ assert (testResult == false );
47
39
}
48
40
49
41
if (wantRoundTrip) {
@@ -141,30 +133,30 @@ void unescape_unicode_test()
141
133
bool testResult;
142
134
// Escaped ASCII (quote)
143
135
testResult = val.read (" [\"\\ u0022\" ]" );
144
- f_assert (testResult);
145
- f_assert (val[0 ].get_str () == " \" " );
136
+ assert (testResult);
137
+ assert (val[0 ].get_str () == " \" " );
146
138
// Escaped Basic Plane character, two-byte UTF-8
147
139
testResult = val.read (" [\"\\ u0191\" ]" );
148
- f_assert (testResult);
149
- f_assert (val[0 ].get_str () == " \xc6\x91 " );
140
+ assert (testResult);
141
+ assert (val[0 ].get_str () == " \xc6\x91 " );
150
142
// Escaped Basic Plane character, three-byte UTF-8
151
143
testResult = val.read (" [\"\\ u2191\" ]" );
152
- f_assert (testResult);
153
- f_assert (val[0 ].get_str () == " \xe2\x86\x91 " );
144
+ assert (testResult);
145
+ assert (val[0 ].get_str () == " \xe2\x86\x91 " );
154
146
// Escaped Supplementary Plane character U+1d161
155
147
testResult = val.read (" [\"\\ ud834\\ udd61\" ]" );
156
- f_assert (testResult);
157
- f_assert (val[0 ].get_str () == " \xf0\x9d\x85\xa1 " );
148
+ assert (testResult);
149
+ assert (val[0 ].get_str () == " \xf0\x9d\x85\xa1 " );
158
150
}
159
151
160
152
int main (int argc, char *argv[])
161
153
{
162
- for (unsigned int fidx = 0 ; fidx < ARRAY_SIZE ( filenames); fidx++ ) {
163
- runtest_file (filenames[fidx] );
154
+ for (const auto & f: filenames) {
155
+ runtest_file (f );
164
156
}
165
157
166
158
unescape_unicode_test ();
167
159
168
- return test_failed ? 1 : 0 ;
160
+ return 0 ;
169
161
}
170
162
0 commit comments