1 /* radare - LGPL - Copyright 2020 - thestr4ng3r, Yaroslav Stavnichiy */
2 /* r_json based on nxjson by Yaroslav Stavnichiy */
3
4 #include <r_util/r_json.h>
5 #include <r_util/r_strbuf.h>
6 #include "minunit.h"
7
8 typedef struct json_test_t {
9 const char *json;
10 int (*check)(RJson *j);
11 } JsonTest;
12
check_expected_0(RJson * j)13 static int check_expected_0(RJson *j) {
14 RJson *child_0, *child_1, *child_2;
15 mu_assert_eq (j->type, R_JSON_OBJECT, "object type");
16 mu_assert_eq (j->children.count, 16, "object size");
17 child_0 = j->children.first;
18 mu_assert_notnull (child_0, "object child");
19 mu_assert_notnull (child_0->key, "object child key not null");
20 mu_assert_streq (child_0->key, "some-int", "object child key");
21 mu_assert_eq (child_0->type, R_JSON_INTEGER, "integer type");
22 mu_assert_eq (child_0->num.u_value, 195, "integer value");
23 child_0 = child_0->next;
24 mu_assert_notnull (child_0, "object child");
25 mu_assert_notnull (child_0->key, "object child key not null");
26 mu_assert_streq (child_0->key, "array1", "object child key");
27 mu_assert_eq (child_0->type, R_JSON_ARRAY, "array type");
28 mu_assert_eq (child_0->children.count, 7, "array size");
29 child_1 = child_0->children.first;
30 mu_assert_notnull (child_1, "array child");
31 mu_assert_null (child_1->key, "array child key");
32 mu_assert_eq (child_1->type, R_JSON_INTEGER, "integer type");
33 mu_assert_eq (child_1->num.u_value, 3, "integer value");
34 child_1 = child_1->next;
35 mu_assert_notnull (child_1, "array child");
36 mu_assert_null (child_1->key, "array child key");
37 mu_assert_eq (child_1->type, R_JSON_DOUBLE, "double type");
38 mu_assert ("double value",
39 child_1->num.dbl_value < (5.1 + 1.0e-13)
40 && child_1->num.dbl_value > (5.1 - 1.0e-13));
41 child_1 = child_1->next;
42 mu_assert_notnull (child_1, "array child");
43 mu_assert_null (child_1->key, "array child key");
44 mu_assert_eq (child_1->type, R_JSON_INTEGER, "integer type");
45 mu_assert_eq (child_1->num.u_value, -7, "integer value");
46 child_1 = child_1->next;
47 mu_assert_notnull (child_1, "array child");
48 mu_assert_null (child_1->key, "array child key");
49 mu_assert_eq (child_1->type, R_JSON_STRING, "string type");
50 mu_assert_streq (child_1->str_value, "nine", "string value");
51 child_1 = child_1->next;
52 mu_assert_notnull (child_1, "array child");
53 mu_assert_null (child_1->key, "array child key");
54 mu_assert_eq (child_1->type, R_JSON_BOOLEAN, "boolean type");
55 mu_assert_eq (child_1->num.u_value, 1, "boolean value");
56 child_1 = child_1->next;
57 mu_assert_notnull (child_1, "array child");
58 mu_assert_null (child_1->key, "array child key");
59 mu_assert_eq (child_1->type, R_JSON_BOOLEAN, "boolean type");
60 mu_assert_eq (child_1->num.u_value, 0, "boolean value");
61 child_1 = child_1->next;
62 mu_assert_notnull (child_1, "array child");
63 mu_assert_null (child_1->key, "array child key");
64 mu_assert_eq (child_1->type, R_JSON_STRING, "string type");
65 mu_assert_streq (child_1->str_value, "last", "string value");
66 child_1 = child_1->next;
67 mu_assert_null (child_1, "last child null");
68 child_0 = child_0->next;
69 mu_assert_notnull (child_0, "object child");
70 mu_assert_notnull (child_0->key, "object child key not null");
71 mu_assert_streq (child_0->key, "array2", "object child key");
72 mu_assert_eq (child_0->type, R_JSON_ARRAY, "array type");
73 mu_assert_eq (child_0->children.count, 2, "array size");
74 child_1 = child_0->children.first;
75 mu_assert_notnull (child_1, "array child");
76 mu_assert_null (child_1->key, "array child key");
77 mu_assert_eq (child_1->type, R_JSON_STRING, "string type");
78 mu_assert_streq (child_1->str_value, "/*", "string value");
79 child_1 = child_1->next;
80 mu_assert_notnull (child_1, "array child");
81 mu_assert_null (child_1->key, "array child key");
82 mu_assert_eq (child_1->type, R_JSON_STRING, "string type");
83 mu_assert_streq (child_1->str_value, "*/", "string value");
84 child_1 = child_1->next;
85 mu_assert_null (child_1, "last child null");
86 child_0 = child_0->next;
87 mu_assert_notnull (child_0, "object child");
88 mu_assert_notnull (child_0->key, "object child key not null");
89 mu_assert_streq (child_0->key, "some-bool", "object child key");
90 mu_assert_eq (child_0->type, R_JSON_BOOLEAN, "boolean type");
91 mu_assert_eq (child_0->num.u_value, 1, "boolean value");
92 child_0 = child_0->next;
93 mu_assert_notnull (child_0, "object child");
94 mu_assert_notnull (child_0->key, "object child key not null");
95 mu_assert_streq (child_0->key, "other-bool", "object child key");
96 mu_assert_eq (child_0->type, R_JSON_BOOLEAN, "boolean type");
97 mu_assert_eq (child_0->num.u_value, 0, "boolean value");
98 child_0 = child_0->next;
99 mu_assert_notnull (child_0, "object child");
100 mu_assert_notnull (child_0->key, "object child key not null");
101 mu_assert_streq (child_0->key, "some-dbl", "object child key");
102 mu_assert_eq (child_0->type, R_JSON_DOUBLE, "double type");
103 mu_assert ("double value",
104 child_0->num.dbl_value < (-1.0e-4 + 1.0e-13)
105 && child_0->num.dbl_value > (-1.0e-4 - 1.0e-13));
106 child_0 = child_0->next;
107 mu_assert_notnull (child_0, "object child");
108 mu_assert_notnull (child_0->key, "object child key not null");
109 mu_assert_streq (child_0->key, "some-null", "object child key");
110 mu_assert_eq (child_0->type, R_JSON_NULL, "null type");
111 child_0 = child_0->next;
112 mu_assert_notnull (child_0, "object child");
113 mu_assert_notnull (child_0->key, "object child key not null");
114 mu_assert_streq (child_0->key, "hello", "object child key");
115 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
116 mu_assert_streq (child_0->str_value, "world!", "string value");
117 child_0 = child_0->next;
118 mu_assert_notnull (child_0, "object child");
119 mu_assert_notnull (child_0->key, "object child key not null");
120 mu_assert_streq (child_0->key, "str1", "object child key");
121 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
122 mu_assert_streq (child_0->str_value, "//", "string value");
123 child_0 = child_0->next;
124 mu_assert_notnull (child_0, "object child");
125 mu_assert_notnull (child_0->key, "object child key not null");
126 mu_assert_streq (child_0->key, "str2", "object child key");
127 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
128 mu_assert_streq (child_0->str_value, "\\", "string value");
129 child_0 = child_0->next;
130 mu_assert_notnull (child_0, "object child");
131 mu_assert_notnull (child_0->key, "object child key not null");
132 mu_assert_streq (child_0->key, "str3", "object child key");
133 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
134 mu_assert_streq (child_0->str_value, "text /*text*/ text", "string value");
135 child_0 = child_0->next;
136 mu_assert_notnull (child_0, "object child");
137 mu_assert_notnull (child_0->key, "object child key not null");
138 mu_assert_streq (child_0->key, "str4", "object child key");
139 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
140 mu_assert_streq (child_0->str_value, "\\text\\", "string value");
141 child_0 = child_0->next;
142 mu_assert_notnull (child_0, "object child");
143 mu_assert_notnull (child_0->key, "object child key not null");
144 mu_assert_streq (child_0->key, "str5", "object child key");
145 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
146 mu_assert_streq (child_0->str_value, "?text?", "string value");
147 child_0 = child_0->next;
148 mu_assert_notnull (child_0, "object child");
149 mu_assert_notnull (child_0->key, "object child key not null");
150 mu_assert_streq (child_0->key, "str\t6\\", "object child key");
151 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
152 mu_assert_streq (child_0->str_value, "text\ntext\ttext", "string value");
153 child_0 = child_0->next;
154 mu_assert_notnull (child_0, "object child");
155 mu_assert_notnull (child_0->key, "object child key not null");
156 mu_assert_streq (child_0->key, "str7", "object child key");
157 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
158 mu_assert_streq (child_0->str_value, "text\xe1\x88\xb4text\xe5\x99\xb8", "string value");
159 child_0 = child_0->next;
160 mu_assert_notnull (child_0, "object child");
161 mu_assert_notnull (child_0->key, "object child key not null");
162 mu_assert_streq (child_0->key, "obj", "object child key");
163 mu_assert_eq (child_0->type, R_JSON_OBJECT, "object type");
164 mu_assert_eq (child_0->children.count, 2, "object size");
165 child_1 = child_0->children.first;
166 mu_assert_notnull (child_1, "object child");
167 mu_assert_notnull (child_1->key, "object child key not null");
168 mu_assert_streq (child_1->key, "KEY", "object child key");
169 mu_assert_eq (child_1->type, R_JSON_STRING, "string type");
170 mu_assert_streq (child_1->str_value, "VAL", "string value");
171 child_1 = child_1->next;
172 mu_assert_notnull (child_1, "object child");
173 mu_assert_notnull (child_1->key, "object child key not null");
174 mu_assert_streq (child_1->key, "obj", "object child key");
175 mu_assert_eq (child_1->type, R_JSON_OBJECT, "object type");
176 mu_assert_eq (child_1->children.count, 1, "object size");
177 child_2 = child_1->children.first;
178 mu_assert_notnull (child_2, "object child");
179 mu_assert_notnull (child_2->key, "object child key not null");
180 mu_assert_streq (child_2->key, "KEY", "object child key");
181 mu_assert_eq (child_2->type, R_JSON_STRING, "string type");
182 mu_assert_streq (child_2->str_value, "VAL", "string value");
183 child_2 = child_2->next;
184 mu_assert_null (child_2, "last child null");
185 child_1 = child_1->next;
186 mu_assert_null (child_1, "last child null");
187 child_0 = child_0->next;
188 mu_assert_null (child_0, "last child null");
189 return MU_PASSED;
190 }
191
check_expected_4(RJson * j)192 static int check_expected_4(RJson *j) {
193 RJson *child_0;
194 mu_assert_eq (j->type, R_JSON_ARRAY, "array type");
195 mu_assert_eq (j->children.count, 4, "array size");
196 child_0 = j->children.first;
197 mu_assert_notnull (child_0, "array child");
198 mu_assert_null (child_0->key, "array child key");
199 mu_assert_eq (child_0->type, R_JSON_INTEGER, "integer type");
200 mu_assert_eq (child_0->num.u_value, 1, "integer value");
201 child_0 = child_0->next;
202 mu_assert_notnull (child_0, "array child");
203 mu_assert_null (child_0->key, "array child key");
204 mu_assert_eq (child_0->type, R_JSON_INTEGER, "integer type");
205 mu_assert_eq (child_0->num.u_value, 2, "integer value");
206 child_0 = child_0->next;
207 mu_assert_notnull (child_0, "array child");
208 mu_assert_null (child_0->key, "array child key");
209 mu_assert_eq (child_0->type, R_JSON_INTEGER, "integer type");
210 mu_assert_eq (child_0->num.u_value, 3, "integer value");
211 child_0 = child_0->next;
212 mu_assert_notnull (child_0, "array child");
213 mu_assert_null (child_0->key, "array child key");
214 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
215 mu_assert_streq (child_0->str_value, "last", "string value");
216 child_0 = child_0->next;
217 mu_assert_null (child_0, "last child null");
218 return MU_PASSED;
219 }
220
check_expected_5(RJson * j)221 static int check_expected_5(RJson *j) {
222 mu_assert_eq (j->type, R_JSON_STRING, "string type");
223 mu_assert_streq (j->str_value, "string value", "string value");
224 return MU_PASSED;
225 }
226
check_expected_6(RJson * j)227 static int check_expected_6(RJson *j) {
228 mu_assert_eq (j->type, R_JSON_BOOLEAN, "boolean type");
229 mu_assert_eq (j->num.u_value, 1, "boolean value");
230 return MU_PASSED;
231 }
232
check_expected_7(RJson * j)233 static int check_expected_7(RJson *j) {
234 mu_assert_eq (j->type, R_JSON_DOUBLE, "double type");
235 mu_assert ("double value",
236 j->num.dbl_value < (-1.0e-2 + 1.0e-13)
237 && j->num.dbl_value > (-1.0e-2 - 1.0e-13));
238 return MU_PASSED;
239 }
240
check_expected_8(RJson * j)241 static int check_expected_8(RJson *j) {
242 mu_assert_eq (j->type, R_JSON_NULL, "null type");
243 return MU_PASSED;
244 }
245
check_expected_9(RJson * j)246 static int check_expected_9(RJson *j) {
247 RJson *child_0, *child_1, *child_2, *child_3, *child_4, *child_5;
248 mu_assert_eq (j->type, R_JSON_OBJECT, "object type");
249 mu_assert_eq (j->children.count, 1, "object size");
250 child_0 = j->children.first;
251 mu_assert_notnull (child_0, "object child");
252 mu_assert_notnull (child_0->key, "object child key not null");
253 mu_assert_streq (child_0->key, "glossary", "object child key");
254 mu_assert_eq (child_0->type, R_JSON_OBJECT, "object type");
255 mu_assert_eq (child_0->children.count, 2, "object size");
256 child_1 = child_0->children.first;
257 mu_assert_notnull (child_1, "object child");
258 mu_assert_notnull (child_1->key, "object child key not null");
259 mu_assert_streq (child_1->key, "title", "object child key");
260 mu_assert_eq (child_1->type, R_JSON_STRING, "string type");
261 mu_assert_streq (child_1->str_value, "example glossary", "string value");
262 child_1 = child_1->next;
263 mu_assert_notnull (child_1, "object child");
264 mu_assert_notnull (child_1->key, "object child key not null");
265 mu_assert_streq (child_1->key, "GlossDiv", "object child key");
266 mu_assert_eq (child_1->type, R_JSON_OBJECT, "object type");
267 mu_assert_eq (child_1->children.count, 2, "object size");
268 child_2 = child_1->children.first;
269 mu_assert_notnull (child_2, "object child");
270 mu_assert_notnull (child_2->key, "object child key not null");
271 mu_assert_streq (child_2->key, "title", "object child key");
272 mu_assert_eq (child_2->type, R_JSON_STRING, "string type");
273 mu_assert_streq (child_2->str_value, "S", "string value");
274 child_2 = child_2->next;
275 mu_assert_notnull (child_2, "object child");
276 mu_assert_notnull (child_2->key, "object child key not null");
277 mu_assert_streq (child_2->key, "GlossList", "object child key");
278 mu_assert_eq (child_2->type, R_JSON_ARRAY, "array type");
279 mu_assert_eq (child_2->children.count, 1, "array size");
280 child_3 = child_2->children.first;
281 mu_assert_notnull (child_3, "array child");
282 mu_assert_null (child_3->key, "array child key");
283 mu_assert_eq (child_3->type, R_JSON_OBJECT, "object type");
284 mu_assert_eq (child_3->children.count, 7, "object size");
285 child_4 = child_3->children.first;
286 mu_assert_notnull (child_4, "object child");
287 mu_assert_notnull (child_4->key, "object child key not null");
288 mu_assert_streq (child_4->key, "ID", "object child key");
289 mu_assert_eq (child_4->type, R_JSON_STRING, "string type");
290 mu_assert_streq (child_4->str_value, "SGML", "string value");
291 child_4 = child_4->next;
292 mu_assert_notnull (child_4, "object child");
293 mu_assert_notnull (child_4->key, "object child key not null");
294 mu_assert_streq (child_4->key, "SortAs", "object child key");
295 mu_assert_eq (child_4->type, R_JSON_STRING, "string type");
296 mu_assert_streq (child_4->str_value, "SGML", "string value");
297 child_4 = child_4->next;
298 mu_assert_notnull (child_4, "object child");
299 mu_assert_notnull (child_4->key, "object child key not null");
300 mu_assert_streq (child_4->key, "GlossTerm", "object child key");
301 mu_assert_eq (child_4->type, R_JSON_STRING, "string type");
302 mu_assert_streq (child_4->str_value, "Standard Generalized Markup Language", "string value");
303 child_4 = child_4->next;
304 mu_assert_notnull (child_4, "object child");
305 mu_assert_notnull (child_4->key, "object child key not null");
306 mu_assert_streq (child_4->key, "Acronym", "object child key");
307 mu_assert_eq (child_4->type, R_JSON_STRING, "string type");
308 mu_assert_streq (child_4->str_value, "SGML", "string value");
309 child_4 = child_4->next;
310 mu_assert_notnull (child_4, "object child");
311 mu_assert_notnull (child_4->key, "object child key not null");
312 mu_assert_streq (child_4->key, "Abbrev", "object child key");
313 mu_assert_eq (child_4->type, R_JSON_STRING, "string type");
314 mu_assert_streq (child_4->str_value, "ISO 8879:1986", "string value");
315 child_4 = child_4->next;
316 mu_assert_notnull (child_4, "object child");
317 mu_assert_notnull (child_4->key, "object child key not null");
318 mu_assert_streq (child_4->key, "GlossDef", "object child key");
319 mu_assert_eq (child_4->type, R_JSON_STRING, "string type");
320 mu_assert_streq (child_4->str_value, "A meta-markup language, used to create markup languages such as DocBoo"
321 "k.", "string value");
322 child_4 = child_4->next;
323 mu_assert_notnull (child_4, "object child");
324 mu_assert_notnull (child_4->key, "object child key not null");
325 mu_assert_streq (child_4->key, "GlossSeeAlso", "object child key");
326 mu_assert_eq (child_4->type, R_JSON_ARRAY, "array type");
327 mu_assert_eq (child_4->children.count, 3, "array size");
328 child_5 = child_4->children.first;
329 mu_assert_notnull (child_5, "array child");
330 mu_assert_null (child_5->key, "array child key");
331 mu_assert_eq (child_5->type, R_JSON_STRING, "string type");
332 mu_assert_streq (child_5->str_value, "GML", "string value");
333 child_5 = child_5->next;
334 mu_assert_notnull (child_5, "array child");
335 mu_assert_null (child_5->key, "array child key");
336 mu_assert_eq (child_5->type, R_JSON_STRING, "string type");
337 mu_assert_streq (child_5->str_value, "XML", "string value");
338 child_5 = child_5->next;
339 mu_assert_notnull (child_5, "array child");
340 mu_assert_null (child_5->key, "array child key");
341 mu_assert_eq (child_5->type, R_JSON_STRING, "string type");
342 mu_assert_streq (child_5->str_value, "markup", "string value");
343 child_5 = child_5->next;
344 mu_assert_null (child_5, "last child null");
345 child_4 = child_4->next;
346 mu_assert_null (child_4, "last child null");
347 child_3 = child_3->next;
348 mu_assert_null (child_3, "last child null");
349 child_2 = child_2->next;
350 mu_assert_null (child_2, "last child null");
351 child_1 = child_1->next;
352 mu_assert_null (child_1, "last child null");
353 child_0 = child_0->next;
354 mu_assert_null (child_0, "last child null");
355 return MU_PASSED;
356 }
357
check_expected_10(RJson * j)358 static int check_expected_10(RJson *j) {
359 RJson *child_0;
360 mu_assert_eq (j->type, R_JSON_OBJECT, "object type");
361 mu_assert_eq (j->children.count, 3, "object size");
362 child_0 = j->children.first;
363 mu_assert_notnull (child_0, "object child");
364 mu_assert_notnull (child_0->key, "object child key not null");
365 mu_assert_streq (child_0->key, "this", "object child key");
366 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
367 mu_assert_streq (child_0->str_value, "is", "string value");
368 child_0 = child_0->next;
369 mu_assert_notnull (child_0, "object child");
370 mu_assert_notnull (child_0->key, "object child key not null");
371 mu_assert_streq (child_0->key, "really", "object child key");
372 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
373 mu_assert_streq (child_0->str_value, "simple", "string value");
374 child_0 = child_0->next;
375 mu_assert_notnull (child_0, "object child");
376 mu_assert_notnull (child_0->key, "object child key not null");
377 mu_assert_streq (child_0->key, "json", "object child key");
378 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
379 mu_assert_streq (child_0->str_value, "right?", "string value");
380 child_0 = child_0->next;
381 mu_assert_null (child_0, "last child null");
382 return MU_PASSED;
383 }
384
check_expected_11(RJson * j)385 static int check_expected_11(RJson *j) {
386 mu_assert_eq (j->type, R_JSON_BOOLEAN, "boolean type");
387 mu_assert_eq (j->num.u_value, 0, "boolean value");
388 return MU_PASSED;
389 }
390
check_expected_13(RJson * j)391 static int check_expected_13(RJson *j) {
392 mu_assert_eq (j->type, R_JSON_INTEGER, "integer type");
393 mu_assert_eq (j->num.u_value, 1221, "integer value");
394 return MU_PASSED;
395 }
396
check_expected_14(RJson * j)397 static int check_expected_14(RJson *j) {
398 RJson *child_0;
399 mu_assert_eq (j->type, R_JSON_OBJECT, "object type");
400 mu_assert_eq (j->children.count, 0, "object size");
401 child_0 = j->children.first;
402 mu_assert_null (child_0, "last child null");
403 return MU_PASSED;
404 }
405
check_expected_19(RJson * j)406 static int check_expected_19(RJson *j) {
407 RJson *child_0, *child_1, *child_2;
408 mu_assert_eq (j->type, R_JSON_ARRAY, "array type");
409 mu_assert_eq (j->children.count, 9, "array size");
410 child_0 = j->children.first;
411 mu_assert_notnull (child_0, "array child");
412 mu_assert_null (child_0->key, "array child key");
413 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
414 mu_assert_streq (child_0->str_value, "foo", "string value");
415 child_0 = child_0->next;
416 mu_assert_notnull (child_0, "array child");
417 mu_assert_null (child_0->key, "array child key");
418 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
419 mu_assert_streq (child_0->str_value, "bar", "string value");
420 child_0 = child_0->next;
421 mu_assert_notnull (child_0, "array child");
422 mu_assert_null (child_0->key, "array child key");
423 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
424 mu_assert_streq (child_0->str_value, "baz", "string value");
425 child_0 = child_0->next;
426 mu_assert_notnull (child_0, "array child");
427 mu_assert_null (child_0->key, "array child key");
428 mu_assert_eq (child_0->type, R_JSON_BOOLEAN, "boolean type");
429 mu_assert_eq (child_0->num.u_value, 1, "boolean value");
430 child_0 = child_0->next;
431 mu_assert_notnull (child_0, "array child");
432 mu_assert_null (child_0->key, "array child key");
433 mu_assert_eq (child_0->type, R_JSON_BOOLEAN, "boolean type");
434 mu_assert_eq (child_0->num.u_value, 0, "boolean value");
435 child_0 = child_0->next;
436 mu_assert_notnull (child_0, "array child");
437 mu_assert_null (child_0->key, "array child key");
438 mu_assert_eq (child_0->type, R_JSON_NULL, "null type");
439 child_0 = child_0->next;
440 mu_assert_notnull (child_0, "array child");
441 mu_assert_null (child_0->key, "array child key");
442 mu_assert_eq (child_0->type, R_JSON_OBJECT, "object type");
443 mu_assert_eq (child_0->children.count, 1, "object size");
444 child_1 = child_0->children.first;
445 mu_assert_notnull (child_1, "object child");
446 mu_assert_notnull (child_1->key, "object child key not null");
447 mu_assert_streq (child_1->key, "key", "object child key");
448 mu_assert_eq (child_1->type, R_JSON_STRING, "string type");
449 mu_assert_streq (child_1->str_value, "value", "string value");
450 child_1 = child_1->next;
451 mu_assert_null (child_1, "last child null");
452 child_0 = child_0->next;
453 mu_assert_notnull (child_0, "array child");
454 mu_assert_null (child_0->key, "array child key");
455 mu_assert_eq (child_0->type, R_JSON_ARRAY, "array type");
456 mu_assert_eq (child_0->children.count, 4, "array size");
457 child_1 = child_0->children.first;
458 mu_assert_notnull (child_1, "array child");
459 mu_assert_null (child_1->key, "array child key");
460 mu_assert_eq (child_1->type, R_JSON_NULL, "null type");
461 child_1 = child_1->next;
462 mu_assert_notnull (child_1, "array child");
463 mu_assert_null (child_1->key, "array child key");
464 mu_assert_eq (child_1->type, R_JSON_NULL, "null type");
465 child_1 = child_1->next;
466 mu_assert_notnull (child_1, "array child");
467 mu_assert_null (child_1->key, "array child key");
468 mu_assert_eq (child_1->type, R_JSON_NULL, "null type");
469 child_1 = child_1->next;
470 mu_assert_notnull (child_1, "array child");
471 mu_assert_null (child_1->key, "array child key");
472 mu_assert_eq (child_1->type, R_JSON_ARRAY, "array type");
473 mu_assert_eq (child_1->children.count, 0, "array size");
474 child_2 = child_1->children.first;
475 mu_assert_null (child_2, "last child null");
476 child_1 = child_1->next;
477 mu_assert_null (child_1, "last child null");
478 child_0 = child_0->next;
479 mu_assert_notnull (child_0, "array child");
480 mu_assert_null (child_0->key, "array child key");
481 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
482 mu_assert_streq (child_0->str_value, "\n\x0d\\", "string value");
483 child_0 = child_0->next;
484 mu_assert_null (child_0, "last child null");
485 return MU_PASSED;
486 }
487
check_expected_22(RJson * j)488 static int check_expected_22(RJson *j) {
489 mu_assert_eq (j->type, R_JSON_STRING, "string type");
490 mu_assert_streq (j->str_value, "\xf0\x90\x8c\x82M\xd0\xb0\xe4\xba\x8c\xf0\x90\x8c\x82", "string value");
491 return MU_PASSED;
492 }
493
check_expected_23(RJson * j)494 static int check_expected_23(RJson *j) {
495 RJson *child_0, *child_1, *child_2, *child_3, *child_4, *child_5;
496 mu_assert_eq (j->type, R_JSON_OBJECT, "object type");
497 mu_assert_eq (j->children.count, 1, "object size");
498 child_0 = j->children.first;
499 mu_assert_notnull (child_0, "object child");
500 mu_assert_notnull (child_0->key, "object child key not null");
501 mu_assert_streq (child_0->key, "glossary", "object child key");
502 mu_assert_eq (child_0->type, R_JSON_OBJECT, "object type");
503 mu_assert_eq (child_0->children.count, 2, "object size");
504 child_1 = child_0->children.first;
505 mu_assert_notnull (child_1, "object child");
506 mu_assert_notnull (child_1->key, "object child key not null");
507 mu_assert_streq (child_1->key, "title", "object child key");
508 mu_assert_eq (child_1->type, R_JSON_STRING, "string type");
509 mu_assert_streq (child_1->str_value, "example glossary", "string value");
510 child_1 = child_1->next;
511 mu_assert_notnull (child_1, "object child");
512 mu_assert_notnull (child_1->key, "object child key not null");
513 mu_assert_streq (child_1->key, "GlossDiv", "object child key");
514 mu_assert_eq (child_1->type, R_JSON_OBJECT, "object type");
515 mu_assert_eq (child_1->children.count, 2, "object size");
516 child_2 = child_1->children.first;
517 mu_assert_notnull (child_2, "object child");
518 mu_assert_notnull (child_2->key, "object child key not null");
519 mu_assert_streq (child_2->key, "title", "object child key");
520 mu_assert_eq (child_2->type, R_JSON_STRING, "string type");
521 mu_assert_streq (child_2->str_value, "S", "string value");
522 child_2 = child_2->next;
523 mu_assert_notnull (child_2, "object child");
524 mu_assert_notnull (child_2->key, "object child key not null");
525 mu_assert_streq (child_2->key, "GlossList", "object child key");
526 mu_assert_eq (child_2->type, R_JSON_ARRAY, "array type");
527 mu_assert_eq (child_2->children.count, 1, "array size");
528 child_3 = child_2->children.first;
529 mu_assert_notnull (child_3, "array child");
530 mu_assert_null (child_3->key, "array child key");
531 mu_assert_eq (child_3->type, R_JSON_OBJECT, "object type");
532 mu_assert_eq (child_3->children.count, 7, "object size");
533 child_4 = child_3->children.first;
534 mu_assert_notnull (child_4, "object child");
535 mu_assert_notnull (child_4->key, "object child key not null");
536 mu_assert_streq (child_4->key, "ID", "object child key");
537 mu_assert_eq (child_4->type, R_JSON_STRING, "string type");
538 mu_assert_streq (child_4->str_value, "SGML", "string value");
539 child_4 = child_4->next;
540 mu_assert_notnull (child_4, "object child");
541 mu_assert_notnull (child_4->key, "object child key not null");
542 mu_assert_streq (child_4->key, "SortAs", "object child key");
543 mu_assert_eq (child_4->type, R_JSON_STRING, "string type");
544 mu_assert_streq (child_4->str_value, "SGML", "string value");
545 child_4 = child_4->next;
546 mu_assert_notnull (child_4, "object child");
547 mu_assert_notnull (child_4->key, "object child key not null");
548 mu_assert_streq (child_4->key, "GlossTerm", "object child key");
549 mu_assert_eq (child_4->type, R_JSON_STRING, "string type");
550 mu_assert_streq (child_4->str_value, "Standard Generalized Markup Language", "string value");
551 child_4 = child_4->next;
552 mu_assert_notnull (child_4, "object child");
553 mu_assert_notnull (child_4->key, "object child key not null");
554 mu_assert_streq (child_4->key, "Acronym", "object child key");
555 mu_assert_eq (child_4->type, R_JSON_STRING, "string type");
556 mu_assert_streq (child_4->str_value, "SGML", "string value");
557 child_4 = child_4->next;
558 mu_assert_notnull (child_4, "object child");
559 mu_assert_notnull (child_4->key, "object child key not null");
560 mu_assert_streq (child_4->key, "Abbrev", "object child key");
561 mu_assert_eq (child_4->type, R_JSON_STRING, "string type");
562 mu_assert_streq (child_4->str_value, "ISO 8879:1986", "string value");
563 child_4 = child_4->next;
564 mu_assert_notnull (child_4, "object child");
565 mu_assert_notnull (child_4->key, "object child key not null");
566 mu_assert_streq (child_4->key, "GlossDef", "object child key");
567 mu_assert_eq (child_4->type, R_JSON_STRING, "string type");
568 mu_assert_streq (child_4->str_value, "A meta-markup language, used to create markup languages such as DocBoo"
569 "k.", "string value");
570 child_4 = child_4->next;
571 mu_assert_notnull (child_4, "object child");
572 mu_assert_notnull (child_4->key, "object child key not null");
573 mu_assert_streq (child_4->key, "GlossSeeAlso", "object child key");
574 mu_assert_eq (child_4->type, R_JSON_ARRAY, "array type");
575 mu_assert_eq (child_4->children.count, 3, "array size");
576 child_5 = child_4->children.first;
577 mu_assert_notnull (child_5, "array child");
578 mu_assert_null (child_5->key, "array child key");
579 mu_assert_eq (child_5->type, R_JSON_STRING, "string type");
580 mu_assert_streq (child_5->str_value, "GML", "string value");
581 child_5 = child_5->next;
582 mu_assert_notnull (child_5, "array child");
583 mu_assert_null (child_5->key, "array child key");
584 mu_assert_eq (child_5->type, R_JSON_STRING, "string type");
585 mu_assert_streq (child_5->str_value, "XML", "string value");
586 child_5 = child_5->next;
587 mu_assert_notnull (child_5, "array child");
588 mu_assert_null (child_5->key, "array child key");
589 mu_assert_eq (child_5->type, R_JSON_STRING, "string type");
590 mu_assert_streq (child_5->str_value, "markup", "string value");
591 child_5 = child_5->next;
592 mu_assert_null (child_5, "last child null");
593 child_4 = child_4->next;
594 mu_assert_null (child_4, "last child null");
595 child_3 = child_3->next;
596 mu_assert_null (child_3, "last child null");
597 child_2 = child_2->next;
598 mu_assert_null (child_2, "last child null");
599 child_1 = child_1->next;
600 mu_assert_null (child_1, "last child null");
601 child_0 = child_0->next;
602 mu_assert_null (child_0, "last child null");
603 return MU_PASSED;
604 }
605
check_expected_24(RJson * j)606 static int check_expected_24(RJson *j) {
607 RJson *child_0;
608 mu_assert_eq (j->type, R_JSON_ARRAY, "array type");
609 mu_assert_eq (j->children.count, 5, "array size");
610 child_0 = j->children.first;
611 mu_assert_notnull (child_0, "array child");
612 mu_assert_null (child_0->key, "array child key");
613 mu_assert_eq (child_0->type, R_JSON_DOUBLE, "double type");
614 mu_assert ("double value",
615 child_0->num.dbl_value < (1.1999999999999999e-4 + 1.0e-13)
616 && child_0->num.dbl_value > (1.1999999999999999e-4 - 1.0e-13));
617 child_0 = child_0->next;
618 mu_assert_notnull (child_0, "array child");
619 mu_assert_null (child_0->key, "array child key");
620 mu_assert_eq (child_0->type, R_JSON_DOUBLE, "double type");
621 mu_assert ("double value",
622 child_0->num.dbl_value < (6.0e-6 + 1.0e-13)
623 && child_0->num.dbl_value > (6.0e-6 - 1.0e-13));
624 child_0 = child_0->next;
625 mu_assert_notnull (child_0, "array child");
626 mu_assert_null (child_0->key, "array child key");
627 mu_assert_eq (child_0->type, R_JSON_DOUBLE, "double type");
628 mu_assert ("double value",
629 child_0->num.dbl_value < (6.0e-6 + 1.0e-13)
630 && child_0->num.dbl_value > (6.0e-6 - 1.0e-13));
631 child_0 = child_0->next;
632 mu_assert_notnull (child_0, "array child");
633 mu_assert_null (child_0->key, "array child key");
634 mu_assert_eq (child_0->type, R_JSON_DOUBLE, "double type");
635 mu_assert ("double value",
636 child_0->num.dbl_value < (1.0e-6 + 1.0e-13)
637 && child_0->num.dbl_value > (1.0e-6 - 1.0e-13));
638 child_0 = child_0->next;
639 mu_assert_notnull (child_0, "array child");
640 mu_assert_null (child_0->key, "array child key");
641 mu_assert_eq (child_0->type, R_JSON_DOUBLE, "double type");
642 mu_assert ("double value",
643 child_0->num.dbl_value < (1.0e-6 + 1.0e-13)
644 && child_0->num.dbl_value > (1.0e-6 - 1.0e-13));
645 child_0 = child_0->next;
646 mu_assert_null (child_0, "last child null");
647 return MU_PASSED;
648 }
649
check_expected_25(RJson * j)650 static int check_expected_25(RJson *j) {
651 RJson *child_0;
652 mu_assert_eq (j->type, R_JSON_ARRAY, "array type");
653 mu_assert_eq (j->children.count, 4, "array size");
654 child_0 = j->children.first;
655 mu_assert_notnull (child_0, "array child");
656 mu_assert_null (child_0->key, "array child key");
657 mu_assert_eq (child_0->type, R_JSON_DOUBLE, "double type");
658 mu_assert ("double value",
659 child_0->num.dbl_value < (10.0 + 1.0e-13)
660 && child_0->num.dbl_value > (10.0 - 1.0e-13));
661 child_0 = child_0->next;
662 mu_assert_notnull (child_0, "array child");
663 mu_assert_null (child_0->key, "array child key");
664 mu_assert_eq (child_0->type, R_JSON_DOUBLE, "double type");
665 mu_assert ("double value",
666 child_0->num.dbl_value < (10.0 + 1.0e-13)
667 && child_0->num.dbl_value > (10.0 - 1.0e-13));
668 child_0 = child_0->next;
669 mu_assert_notnull (child_0, "array child");
670 mu_assert_null (child_0->key, "array child key");
671 mu_assert_eq (child_0->type, R_JSON_DOUBLE, "double type");
672 mu_assert ("double value",
673 child_0->num.dbl_value < (3.141569 + 1.0e-13)
674 && child_0->num.dbl_value > (3.141569 - 1.0e-13));
675 child_0 = child_0->next;
676 mu_assert_notnull (child_0, "array child");
677 mu_assert_null (child_0->key, "array child key");
678 mu_assert_eq (child_0->type, R_JSON_DOUBLE, "double type");
679 mu_assert ("double value",
680 child_0->num.dbl_value < (1000.0 + 1.0e-13)
681 && child_0->num.dbl_value > (1000.0 - 1.0e-13));
682 child_0 = child_0->next;
683 mu_assert_null (child_0, "last child null");
684 return MU_PASSED;
685 }
686
check_expected_26(RJson * j)687 static int check_expected_26(RJson *j) {
688 mu_assert_eq (j->type, R_JSON_STRING, "string type");
689 mu_assert_streq (j->str_value, "", "string value");
690 return MU_PASSED;
691 }
692
check_expected_27(RJson * j)693 static int check_expected_27(RJson *j) {
694 RJson *child_0, *child_1;
695 mu_assert_eq (j->type, R_JSON_OBJECT, "object type");
696 mu_assert_eq (j->children.count, 2, "object size");
697 child_0 = j->children.first;
698 mu_assert_notnull (child_0, "object child");
699 mu_assert_notnull (child_0->key, "object child key not null");
700 mu_assert_streq (child_0->key, "some", "object child key");
701 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
702 mu_assert_streq (child_0->str_value, "utf-8", "string value");
703 child_0 = child_0->next;
704 mu_assert_notnull (child_0, "object child");
705 mu_assert_notnull (child_0->key, "object child key not null");
706 mu_assert_streq (child_0->key, "strings", "object child key");
707 mu_assert_eq (child_0->type, R_JSON_ARRAY, "array type");
708 mu_assert_eq (child_0->children.count, 3, "array size");
709 child_1 = child_0->children.first;
710 mu_assert_notnull (child_1, "array child");
711 mu_assert_null (child_1->key, "array child key");
712 mu_assert_eq (child_1->type, R_JSON_STRING, "string type");
713 mu_assert_streq (child_1->str_value, "\xd0\xad\xd1\x82\xd0\xbe", "string value");
714 child_1 = child_1->next;
715 mu_assert_notnull (child_1, "array child");
716 mu_assert_null (child_1->key, "array child key");
717 mu_assert_eq (child_1->type, R_JSON_STRING, "string type");
718 mu_assert_streq (child_1->str_value, "\xd1\x80\xd1\x83\xd1\x81\xd1\x81\xd0\xba\xd0\xb8\xd0\xb9", "string value");
719 child_1 = child_1->next;
720 mu_assert_notnull (child_1, "array child");
721 mu_assert_null (child_1->key, "array child key");
722 mu_assert_eq (child_1->type, R_JSON_STRING, "string type");
723 mu_assert_streq (child_1->str_value, "\xd1\x82\xd0\xb5\xd0\xba\xd1\x81\xd1\x82", "string value");
724 child_1 = child_1->next;
725 mu_assert_null (child_1, "last child null");
726 child_0 = child_0->next;
727 mu_assert_null (child_0, "last child null");
728 return MU_PASSED;
729 }
730
check_expected_28(RJson * j)731 static int check_expected_28(RJson *j) {
732 mu_assert_eq (j->type, R_JSON_INTEGER, "integer type");
733 mu_assert_eq (j->num.u_value, 2009, "integer value");
734 return MU_PASSED;
735 }
736
check_expected_29(RJson * j)737 static int check_expected_29(RJson *j) {
738 RJson *child_0;
739 mu_assert_eq (j->type, R_JSON_OBJECT, "object type");
740 mu_assert_eq (j->children.count, 1, "object size");
741 child_0 = j->children.first;
742 mu_assert_notnull (child_0, "object child");
743 mu_assert_notnull (child_0->key, "object child key not null");
744 mu_assert_streq (child_0->key, "U+10ABCD", "object child key");
745 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
746 mu_assert_streq (child_0->str_value, "\xf4\x8a\xaf\x8d", "string value");
747 child_0 = child_0->next;
748 mu_assert_null (child_0, "last child null");
749 return MU_PASSED;
750 }
751
check_expected_30(RJson * j)752 static int check_expected_30(RJson *j) {
753 RJson *child_0;
754 mu_assert_eq (j->type, R_JSON_ARRAY, "array type");
755 mu_assert_eq (j->children.count, 11, "array size");
756 child_0 = j->children.first;
757 mu_assert_notnull (child_0, "array child");
758 mu_assert_null (child_0->key, "array child key");
759 mu_assert_eq (child_0->type, R_JSON_INTEGER, "integer type");
760 mu_assert_eq (child_0->num.u_value, 1, "integer value");
761 child_0 = child_0->next;
762 mu_assert_notnull (child_0, "array child");
763 mu_assert_null (child_0->key, "array child key");
764 mu_assert_eq (child_0->type, R_JSON_INTEGER, "integer type");
765 mu_assert_eq (child_0->num.u_value, 2, "integer value");
766 child_0 = child_0->next;
767 mu_assert_notnull (child_0, "array child");
768 mu_assert_null (child_0->key, "array child key");
769 mu_assert_eq (child_0->type, R_JSON_INTEGER, "integer type");
770 mu_assert_eq (child_0->num.u_value, 3, "integer value");
771 child_0 = child_0->next;
772 mu_assert_notnull (child_0, "array child");
773 mu_assert_null (child_0->key, "array child key");
774 mu_assert_eq (child_0->type, R_JSON_INTEGER, "integer type");
775 mu_assert_eq (child_0->num.u_value, 4, "integer value");
776 child_0 = child_0->next;
777 mu_assert_notnull (child_0, "array child");
778 mu_assert_null (child_0->key, "array child key");
779 mu_assert_eq (child_0->type, R_JSON_INTEGER, "integer type");
780 mu_assert_eq (child_0->num.u_value, 5, "integer value");
781 child_0 = child_0->next;
782 mu_assert_notnull (child_0, "array child");
783 mu_assert_null (child_0->key, "array child key");
784 mu_assert_eq (child_0->type, R_JSON_INTEGER, "integer type");
785 mu_assert_eq (child_0->num.u_value, 6, "integer value");
786 child_0 = child_0->next;
787 mu_assert_notnull (child_0, "array child");
788 mu_assert_null (child_0->key, "array child key");
789 mu_assert_eq (child_0->type, R_JSON_INTEGER, "integer type");
790 mu_assert_eq (child_0->num.u_value, 7, "integer value");
791 child_0 = child_0->next;
792 mu_assert_notnull (child_0, "array child");
793 mu_assert_null (child_0->key, "array child key");
794 mu_assert_eq (child_0->type, R_JSON_INTEGER, "integer type");
795 mu_assert_eq (child_0->num.u_value, 123456789, "integer value");
796 child_0 = child_0->next;
797 mu_assert_notnull (child_0, "array child");
798 mu_assert_null (child_0->key, "array child key");
799 mu_assert_eq (child_0->type, R_JSON_INTEGER, "integer type");
800 mu_assert_eq (child_0->num.u_value, -123456789, "integer value");
801 child_0 = child_0->next;
802 mu_assert_notnull (child_0, "array child");
803 mu_assert_null (child_0->key, "array child key");
804 mu_assert_eq (child_0->type, R_JSON_INTEGER, "integer type");
805 mu_assert_eq (child_0->num.u_value, 2147483647, "integer value");
806 child_0 = child_0->next;
807 mu_assert_notnull (child_0, "array child");
808 mu_assert_null (child_0->key, "array child key");
809 mu_assert_eq (child_0->type, R_JSON_INTEGER, "integer type");
810 mu_assert_eq (child_0->num.u_value, -2147483647, "integer value");
811 child_0 = child_0->next;
812 mu_assert_null (child_0, "last child null");
813 return MU_PASSED;
814 }
815
check_expected_31(RJson * j)816 static int check_expected_31(RJson *j) {
817 RJson *child_0;
818 mu_assert_eq (j->type, R_JSON_ARRAY, "array type");
819 mu_assert_eq (j->children.count, 1, "array size");
820 child_0 = j->children.first;
821 mu_assert_notnull (child_0, "array child");
822 mu_assert_null (child_0->key, "array child key");
823 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
824 mu_assert_streq (child_0->str_value, "\xd0\x94\xd0\xb0 \xd0\x9c\xd1 \xd0\x95\xd0\xb1\xd0\xb0 \xd0\x9c\xd0\xb0\xd0\xb9\xd0\xba\xd0\xb0\xd1\x82\xd0\xb0", "string value");
825 child_0 = child_0->next;
826 mu_assert_null (child_0, "last child null");
827 return MU_PASSED;
828 }
829
check_expected_32(RJson * j)830 static int check_expected_32(RJson *j) {
831 RJson *child_0;
832 mu_assert_eq (j->type, R_JSON_OBJECT, "object type");
833 mu_assert_eq (j->children.count, 1, "object size");
834 child_0 = j->children.first;
835 mu_assert_notnull (child_0, "object child");
836 mu_assert_notnull (child_0->key, "object child key not null");
837 mu_assert_streq (child_0->key, "bad thing", "object child key");
838 mu_assert_eq (child_0->type, R_JSON_INTEGER, "integer type");
839 mu_assert_eq (child_0->num.u_value, 10, "integer value");
840 child_0 = child_0->next;
841 mu_assert_null (child_0, "last child null");
842 return MU_PASSED;
843 }
844
check_expected_35(RJson * j)845 static int check_expected_35(RJson *j) {
846 mu_assert_eq (j->type, R_JSON_DOUBLE, "double type");
847 mu_assert ("double value",
848 j->num.dbl_value < (1000.0 + 1.0e-13)
849 && j->num.dbl_value > (1000.0 - 1.0e-13));
850 return MU_PASSED;
851 }
852
check_expected_36(RJson * j)853 static int check_expected_36(RJson *j) {
854 mu_assert_eq (j->type, R_JSON_DOUBLE, "double type");
855 mu_assert ("double value",
856 j->num.dbl_value < (10.0 + 1.0e-13)
857 && j->num.dbl_value > (10.0 - 1.0e-13));
858 return MU_PASSED;
859 }
860
check_expected_37(RJson * j)861 static int check_expected_37(RJson *j) {
862 RJson *child_0;
863 mu_assert_eq (j->type, R_JSON_OBJECT, "object type");
864 mu_assert_eq (j->children.count, 3, "object size");
865 child_0 = j->children.first;
866 mu_assert_notnull (child_0, "object child");
867 mu_assert_notnull (child_0->key, "object child key not null");
868 mu_assert_streq (child_0->key, "boolean, true", "object child key");
869 mu_assert_eq (child_0->type, R_JSON_BOOLEAN, "boolean type");
870 mu_assert_eq (child_0->num.u_value, 1, "boolean value");
871 child_0 = child_0->next;
872 mu_assert_notnull (child_0, "object child");
873 mu_assert_notnull (child_0->key, "object child key not null");
874 mu_assert_streq (child_0->key, "boolean, false", "object child key");
875 mu_assert_eq (child_0->type, R_JSON_BOOLEAN, "boolean type");
876 mu_assert_eq (child_0->num.u_value, 0, "boolean value");
877 child_0 = child_0->next;
878 mu_assert_notnull (child_0, "object child");
879 mu_assert_notnull (child_0->key, "object child key not null");
880 mu_assert_streq (child_0->key, "null", "object child key");
881 mu_assert_eq (child_0->type, R_JSON_NULL, "null type");
882 child_0 = child_0->next;
883 mu_assert_null (child_0, "last child null");
884 return MU_PASSED;
885 }
886
check_expected_38(RJson * j)887 static int check_expected_38(RJson *j) {
888 RJson *child_0;
889 mu_assert_eq (j->type, R_JSON_ARRAY, "array type");
890 mu_assert_eq (j->children.count, 1, "array size");
891 child_0 = j->children.first;
892 mu_assert_notnull (child_0, "array child");
893 mu_assert_null (child_0->key, "array child key");
894 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
895 mu_assert_streq (child_0->str_value, "\n foo / bar \x0d\x0c\\\xef\xbf\xbf\t\x08\"\\ and you can't escape thi"
896 "\\s", "string value");
897 child_0 = child_0->next;
898 mu_assert_null (child_0, "last child null");
899 return MU_PASSED;
900 }
901
check_expected_39(RJson * j)902 static int check_expected_39(RJson *j) {
903 RJson *child_0;
904 mu_assert_eq (j->type, R_JSON_ARRAY, "array type");
905 mu_assert_eq (j->children.count, 3, "array size");
906 child_0 = j->children.first;
907 mu_assert_notnull (child_0, "array child");
908 mu_assert_null (child_0->key, "array child key");
909 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
910 mu_assert_streq (child_0->str_value, "\n foo / bar \x0d\x0c\\\xef\xbf\xbf\t\x08\"\\", "string value");
911 child_0 = child_0->next;
912 mu_assert_notnull (child_0, "array child");
913 mu_assert_null (child_0->key, "array child key");
914 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
915 mu_assert_streq (child_0->str_value, "\"and this string has an escape at the beginning", "string value");
916 child_0 = child_0->next;
917 mu_assert_notnull (child_0, "array child");
918 mu_assert_null (child_0->key, "array child key");
919 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
920 mu_assert_streq (child_0->str_value, "and this string has no escapes", "string value");
921 child_0 = child_0->next;
922 mu_assert_null (child_0, "last child null");
923 return MU_PASSED;
924 }
925
check_expected_40(RJson * j)926 static int check_expected_40(RJson *j) {
927 mu_assert_eq (j->type, R_JSON_STRING, "string type");
928 mu_assert_streq (j->str_value, "la di dah. this is a string, and I can do this, \n, but not this\n", "string value");
929 return MU_PASSED;
930 }
931
check_expected_43(RJson * j)932 static int check_expected_43(RJson *j) {
933 mu_assert_eq (j->type, R_JSON_INTEGER, "integer type");
934 mu_assert_eq (j->num.u_value, 123, "integer value");
935 return MU_PASSED;
936 }
937
check_expected_45(RJson * j)938 static int check_expected_45(RJson *j) {
939 RJson *child_0;
940 mu_assert_eq (j->type, R_JSON_ARRAY, "array type");
941 mu_assert_eq (j->children.count, 4, "array size");
942 child_0 = j->children.first;
943 mu_assert_notnull (child_0, "array child");
944 mu_assert_null (child_0->key, "array child key");
945 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
946 mu_assert_streq (child_0->str_value, "\xd0\x94\xd0\xb0", "string value");
947 child_0 = child_0->next;
948 mu_assert_notnull (child_0, "array child");
949 mu_assert_null (child_0->key, "array child key");
950 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
951 mu_assert_streq (child_0->str_value, "\xd0\x9c\xd1\x83", "string value");
952 child_0 = child_0->next;
953 mu_assert_notnull (child_0, "array child");
954 mu_assert_null (child_0->key, "array child key");
955 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
956 mu_assert_streq (child_0->str_value, "\xd0\x95\xd0\xb1\xd0\xb0", "string value");
957 child_0 = child_0->next;
958 mu_assert_notnull (child_0, "array child");
959 mu_assert_null (child_0->key, "array child key");
960 mu_assert_eq (child_0->type, R_JSON_STRING, "string type");
961 mu_assert_streq (child_0->str_value, "\xd0\x9c\xd0\xb0\xd0\xb9\xd0\xba\xd0\xb0\xd1\x82\xd0\xb0", "string value");
962 child_0 = child_0->next;
963 mu_assert_null (child_0, "last child null");
964 return MU_PASSED;
965 }
966
check_expected_46(RJson * j)967 static int check_expected_46(RJson *j) {
968 mu_assert_eq (j->type, R_JSON_STRING, "string type");
969 mu_assert_streq (j->str_value, "foobar", "string value");
970 return MU_PASSED;
971 }
972
check_expected_48(RJson * j)973 static int check_expected_48(RJson *j) {
974 mu_assert_eq (j->type, R_JSON_STRING, "string type");
975 mu_assert_streq (j->str_value, "\xd0\x9f\xd1\x80\xd0\xbe\xd0\xb2\xd0\xb5\xd1\x80\xd0\xba\xd0\xb0", "string value");
976 return MU_PASSED;
977 }
978
979 JsonTest tests[] = {
980 { // 0
981 " {\n \"some-int\": 195,\n \"array1\": [ 3, 5.1, -7, \"nin"
982 "e\", /*11,*/ true, false, \"last\" ],\n \"array2\":[\"/*\",\"*/\""
983 "],\n \"some-bool\": true,\n \"other-bool\": false,\n \""
984 "some-dbl\": -1e-4,\n \"some-null\": null,\n \"hello\": \"wor"
985 "ld!\",\n \"str1\": \"//\",\n \"str2\": \"\\\\\",\n \"st"
986 "r3\": \"text /*text*/ text\",\n \"str4\": \"\\\\text\\\\\",\n "
987 " \"str5\": \"\\?text\\?\",\n \"str\\t6\\\\\": \"text\\ntext\\tte"
988 "xt\",\n \"str7\": \"text\\u1234text\\u5678\",\n //\"other\":"
989 " \"/OTHER/\",\n \"obj\": {\"KEY\":\"VAL\", \"obj\":{\"KEY\":\"VAL"
990 "\"}}\n }\n",
991 check_expected_0
992 }, { // 1
993 "\"unterminated string",
994 NULL
995 }, { // 2
996 "{\"key\":\"val\"",
997 NULL
998 }, { // 3
999 "[ \"unterminated \\string\\\" ]\n",
1000 NULL
1001 }, { // 4
1002 "// array\n[1,2,3,\"last\"]",
1003 check_expected_4
1004 }, { // 5
1005 "\"string value\"\n",
1006 check_expected_5
1007 }, { // 6
1008 "true",
1009 check_expected_6
1010 }, { // 7
1011 "-1e-2",
1012 check_expected_7
1013 }, { // 8
1014 "null",
1015 check_expected_8
1016 }, { // 9
1017 "{ \"glossary\": { /* you */ \"title\": /**/ \"example glossary\", /*sh"
1018 "ould*/\"GlossDiv\": { \"title\": /*never*/\"S\", /*ever*/\"GlossList\""
1019 ": [ { \"ID\": \"SGML\", \"SortAs\": \"SGML\", \"GlossTerm\": \"Standar"
1020 "d Generalized Markup Language\", \"Acronym\": \"SGML\", \"Abbrev\": \""
1021 "ISO 8879:1986\", \"GlossDef\": \"A meta-markup language, used to creat"
1022 "e markup languages such as DocBook.\", /*see*/\"GlossSeeAlso\":/*comin"
1023 "g*/[/*out*/\"GML\"/*of*/,/*the*/\"XML\"/*parser!*/, \"markup\"] /*hey*"
1024 "/}/*ho*/]/*hey*/}/*ho*/} } // and the parser won't even get this far,"
1025 " so chill. /* hah!\n",
1026 check_expected_9
1027 }, { // 10
1028 "{\n \"this\": \"is\", // ignore this\n \"really\": \"simple\",\n /*"
1029 " ignore\nthis\ntoo * / \n** //\n(/\n******/\n \"json\": \"right?\"\n}"
1030 "\n",
1031 check_expected_10
1032 }, { // 11
1033 "falsex\n",
1034 check_expected_11
1035 }, { // 12
1036 "{ \"123\":\n",
1037 NULL
1038 }, { // 13
1039 "1221 21\n",
1040 check_expected_13
1041 }, { // 14
1042 "\n{}\n{}\n",
1043 check_expected_14
1044 }, { // 15
1045 "[",
1046 NULL
1047 }, { // 16
1048 "{\n",
1049 NULL
1050 }, { // 17
1051 "[ \"foo\", \"bar\"\n",
1052 NULL
1053 }, { // 18
1054 "]\n",
1055 NULL
1056 }, { // 19
1057 "[\"foo\",\n \"bar\", \"baz\",\n true,false,null,{\"key\":\"value\"},\n"
1058 " [null,null,null,[]],\n \"\\n\\r\\\\\"\n]\n",
1059 check_expected_19
1060 }, { // 20
1061 "[ 100000000000000000000000000000, -100000000000000000000000000000, \"e"
1062 "nd\" ]\n",
1063 NULL
1064 }, { // 21
1065 "[\"this\",\"is\",\"what\",\"should\",\"be\",\n \"a happy bit of json\""
1066 ",\n \"but someone, misspelled \\\"true\\\"\", ture,\n \"who says JSON "
1067 "is easy for humans to generate?\"]\n",
1068 NULL
1069 }, { // 22
1070 "/* This string contains Unicode surrogate \xf0\x90\x8c\x82 both in UTF"
1071 "-8 and escaped */ \"\xf0\x90\x8c\x82\\u004d\\u0430\\u4e8c\\ud800\\udf0"
1072 "2\"\n",
1073 check_expected_22
1074 }, { // 23
1075 "{ \"glossary\": { \"title\": \"example glossary\", \"GlossDiv\": { \"t"
1076 "itle\": \"S\", \"GlossList\": [ { \"ID\": \"SGML\", \"SortAs\": \"SGML"
1077 "\", \"GlossTerm\": \"Standard Generalized Markup Language\", \"Acronym"
1078 "\": \"SGML\", \"Abbrev\": \"ISO 8879:1986\", \"GlossDef\": \"A meta-ma"
1079 "rkup language, used to create markup languages such as DocBook.\", \"G"
1080 "lossSeeAlso\": [\"GML\", \"XML\", \"markup\"] } ] } } }\n",
1081 check_expected_23
1082 }, { // 24
1083 "[0.00011999999999999999, 6E-06, 6E-06, 1E-06, 1E-06]\n",
1084 check_expected_24
1085 }, { // 25
1086 "[ 0.1e2, 1e1, 3.141569, 10000000000000e-10]\n",
1087 check_expected_25
1088 }, { // 26
1089 "\"\"\n",
1090 check_expected_26
1091 }, { // 27
1092 "{\"some\":\"utf-8\", \"strings\":[\"\xd0\xad\xd1\x82\xd0\xbe\",\"\xd1"
1093 "\x80\xd1\x83\xd1\x81\xd1\x81\xd0\xba\xd0\xb8\xd0\xb9\",\"\xd1\x82\xd0"
1094 "\xb5\xd0\xba\xd1\x81\xd1\x82\"]}",
1095 check_expected_27
1096 }, { // 28
1097 "2009-10-20@20:38:21.539575\n",
1098 check_expected_28
1099 }, { // 29
1100 "{ \"U+10ABCD\": \"\xf4\x8a\xaf\x8d\" }\n\n",
1101 check_expected_29
1102 }, { // 30
1103 "[ 1,2,3,4,5,6,7,\n 123456789 , -123456789,\n 2147483647, -2147483647"
1104 " ]\n",
1105 check_expected_30
1106 }, { // 31
1107 "/* invalid utf-8 */ [\"\xd0\x94\xd0\xb0 \xd0\x9c\xd1 \xd0\x95\xd0\xb1"
1108 "\xd0\xb0 \xd0\x9c\xd0\xb0\xd0\xb9\xd0\xba\xd0\xb0\xd1\x82\xd0\xb0\"]\n",
1109 check_expected_31
1110 }, { // 32
1111 "{ \"bad thing\": 010 }\n",
1112 check_expected_32
1113 }, { // 33
1114 "[\n\t\t\"foo\", true,\n\t\ttrue, \"blue\",\n\t\t\"baby where are you?"
1115 "\", \"oh boo hoo!\",\n - \n]\n\n",
1116 NULL
1117 }, { // 34
1118 "}\n",
1119 NULL
1120 }, { // 35
1121 "10.e2\n",
1122 check_expected_35
1123 }, { // 36
1124 "10e\n",
1125 check_expected_36
1126 }, { // 37
1127 "{\n\t\"boolean, true\": true,\n\t\"boolean, false\": false,\n\t\"null"
1128 "\": null\n}\n",
1129 check_expected_37
1130 }, { // 38
1131 "[\"\\n foo \\/ bar \\r\\f\\\\\\uffff\\t\\b\\\"\\\\ and you can't escap"
1132 "e thi\\s\"]\n",
1133 check_expected_38
1134 }, { // 39
1135 "[\"\\n foo \\/ bar \\r\\f\\\\\\uffff\\t\\b\\\"\\\\\",\n \"\\\"and this"
1136 " string has an escape at the beginning\",\n \"and this string has no e"
1137 "scapes\" ]\n",
1138 check_expected_39
1139 }, { // 40
1140 "\"la di dah. this is a string, and I can do this, \\n, but not this\n"
1141 "\"\n",
1142 check_expected_40
1143 }, { // 41
1144 "/*",
1145 NULL
1146 }, { // 42
1147 "/*abc /",
1148 NULL
1149 }, { // 43
1150 "/*/\\*/ 123",
1151 check_expected_43
1152 }, { // 44
1153 "/*/ 123",
1154 NULL
1155 }, { // 45
1156 "[\"\\u0414\\u0430\",\n \"\\u041c\\u0443\",\n \"\\u0415\\u0431\\u0430\""
1157 ",\n \"\\u041c\\u0430\\u0439\\u043a\\u0430\\u0442\\u0430\"]\n",
1158 check_expected_45
1159 }, { // 46
1160 "\"\\u0066\\u006f\\u006f\\u0062\\u0061\\u0072\"\n",
1161 check_expected_46
1162 }, { // 47
1163 "/* invalid unicode surrogate */ \"\\ud800\"\n",
1164 NULL
1165 }, { // 48
1166 "\"\\u041F\\u0440\\u043E\\u0432\\u0435\\u0440\\u043a\\u0430\"",
1167 check_expected_48
1168 }, { // 49
1169 "\"\\u04FG\"",
1170 NULL
1171 }, { // 50
1172 "\"\\u0",
1173 NULL
1174 }, { // 51
1175 "\"\\u04\"",
1176 NULL
1177 }, { // 52
1178 "{,}\n",
1179 NULL
1180 }, { // 53
1181 "[,]\n",
1182 NULL
1183 }, { // 54
1184 "[{}{}]\n",
1185 NULL
1186 }, { // 55
1187 "[42,/*nope*/,1337]\n",
1188 NULL
1189 }, { // 56
1190 "{\"hello\":42,/*stuff*/,\"invalid\":123}\n",
1191 NULL
1192 }
1193 };
1194
test_json(int test_number,char * input,int (* check)(RJson * j))1195 static int test_json(int test_number, char *input, int (*check)(RJson *j)) {
1196 RJson *json = r_json_parse (input);
1197 if (!check) {
1198 mu_assert_null (json, "parse failure expected");
1199 } else {
1200 mu_assert_notnull (json, "parse failed");
1201 if (!check (json)) {
1202 return MU_ERR;
1203 }
1204 r_json_free (json);
1205 }
1206 mu_end;
1207 }
1208
all_tests(void)1209 static int all_tests(void) {
1210 size_t i;
1211 for (i = 1; i < sizeof (tests) / sizeof (tests[0]); i++) {
1212 char *input = strdup (tests[i].json);
1213 char testname[256];
1214 snprintf (testname, sizeof(testname), "test_json (%u)", (unsigned int)i);
1215 mu_run_test_named (test_json, testname, i, input, tests[i].check);
1216 free (input);
1217 }
1218 return tests_passed != tests_run;
1219 }
1220
main(void)1221 int main(void) {
1222 return all_tests ();
1223 }
1224