qobject: Fix qnum_to_string() to use sufficient precision
[qemu/ar7.git] / tests / check-qjson.c
blobca8fb816e9327f401362d11d6afb52cbae03a061
1 /*
2 * Copyright IBM, Corp. 2009
3 * Copyright (c) 2013, 2015 Red Hat Inc.
5 * Authors:
6 * Anthony Liguori <aliguori@us.ibm.com>
7 * Markus Armbruster <armbru@redhat.com>
9 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
10 * See the COPYING.LIB file in the top-level directory.
14 #include "qemu/osdep.h"
16 #include "qapi/error.h"
17 #include "qapi/qmp/qbool.h"
18 #include "qapi/qmp/qjson.h"
19 #include "qapi/qmp/qlit.h"
20 #include "qapi/qmp/qnull.h"
21 #include "qapi/qmp/qnum.h"
22 #include "qapi/qmp/qstring.h"
23 #include "qemu/unicode.h"
24 #include "qemu-common.h"
26 static QString *from_json_str(const char *jstr, bool single, Error **errp)
28 char quote = single ? '\'' : '"';
29 char *qjstr = g_strdup_printf("%c%s%c", quote, jstr, quote);
30 QString *ret = qobject_to(QString, qobject_from_json(qjstr, errp));
32 g_free(qjstr);
33 return ret;
36 static char *to_json_str(QString *str)
38 QString *json = qobject_to_json(QOBJECT(str));
39 char *jstr;
41 if (!json) {
42 return NULL;
44 /* peel off double quotes */
45 jstr = g_strndup(qstring_get_str(json) + 1,
46 qstring_get_length(json) - 2);
47 qobject_unref(json);
48 return jstr;
51 static void escaped_string(void)
53 struct {
54 /* Content of JSON string to parse with qobject_from_json() */
55 const char *json_in;
56 /* Expected parse output; to unparse with qobject_to_json() */
57 const char *utf8_out;
58 int skip;
59 } test_cases[] = {
60 { "\\b\\f\\n\\r\\t\\\\\\\"", "\b\f\n\r\t\\\"" },
61 { "\\/\\'", "/'", .skip = 1 },
62 { "single byte utf-8 \\u0020", "single byte utf-8 ", .skip = 1 },
63 { "double byte utf-8 \\u00A2", "double byte utf-8 \xc2\xa2" },
64 { "triple byte utf-8 \\u20AC", "triple byte utf-8 \xe2\x82\xac" },
65 { "quadruple byte utf-8 \\uD834\\uDD1E", /* U+1D11E */
66 "quadruple byte utf-8 \xF0\x9D\x84\x9E" },
67 { "\\", NULL },
68 { "\\z", NULL },
69 { "\\ux", NULL },
70 { "\\u1x", NULL },
71 { "\\u12x", NULL },
72 { "\\u123x", NULL },
73 { "\\u12345", "\341\210\2645" },
74 { "\\u0000x", "\xC0\x80x" },
75 { "unpaired leading surrogate \\uD800", NULL },
76 { "unpaired leading surrogate \\uD800\\uCAFE", NULL },
77 { "unpaired leading surrogate \\uD800\\uD801\\uDC02", NULL },
78 { "unpaired trailing surrogate \\uDC00", NULL },
79 { "backward surrogate pair \\uDC00\\uD800", NULL },
80 { "noncharacter U+FDD0 \\uFDD0", NULL },
81 { "noncharacter U+FDEF \\uFDEF", NULL },
82 { "noncharacter U+1FFFE \\uD87F\\uDFFE", NULL },
83 { "noncharacter U+10FFFF \\uDC3F\\uDFFF", NULL },
86 int i, j;
87 QString *cstr;
88 char *jstr;
90 for (i = 0; test_cases[i].json_in; i++) {
91 for (j = 0; j < 2; j++) {
92 if (test_cases[i].utf8_out) {
93 cstr = from_json_str(test_cases[i].json_in, j, &error_abort);
94 g_assert_cmpstr(qstring_get_try_str(cstr),
95 ==, test_cases[i].utf8_out);
96 if (!test_cases[i].skip) {
97 jstr = to_json_str(cstr);
98 g_assert_cmpstr(jstr, ==, test_cases[i].json_in);
99 g_free(jstr);
101 qobject_unref(cstr);
102 } else {
103 cstr = from_json_str(test_cases[i].json_in, j, NULL);
104 g_assert(!cstr);
110 static void string_with_quotes(void)
112 const char *test_cases[] = {
113 "\"the bee's knees\"",
114 "'double quote \"'",
115 NULL
117 int i;
118 QString *str;
119 char *cstr;
121 for (i = 0; test_cases[i]; i++) {
122 str = qobject_to(QString,
123 qobject_from_json(test_cases[i], &error_abort));
124 g_assert(str);
125 cstr = g_strndup(test_cases[i] + 1, strlen(test_cases[i]) - 2);
126 g_assert_cmpstr(qstring_get_str(str), ==, cstr);
127 g_free(cstr);
128 qobject_unref(str);
132 static void utf8_string(void)
135 * Most test cases are scraped from Markus Kuhn's UTF-8 decoder
136 * capability and stress test at
137 * http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt
139 static const struct {
140 /* Content of JSON string to parse with qobject_from_json() */
141 const char *json_in;
142 /* Expected parse output */
143 const char *utf8_out;
144 /* Expected unparse output, defaults to @json_in */
145 const char *json_out;
146 } test_cases[] = {
147 /* 0 Control characters */
150 * Note: \x00 is impossible, other representations of
151 * U+0000 are covered under 4.3
153 "\x01\x02\x03\x04\x05\x06\x07"
154 "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"
155 "\x10\x11\x12\x13\x14\x15\x16\x17"
156 "\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F",
157 NULL,
158 "\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007"
159 "\\b\\t\\n\\u000B\\f\\r\\u000E\\u000F"
160 "\\u0010\\u0011\\u0012\\u0013\\u0014\\u0015\\u0016\\u0017"
161 "\\u0018\\u0019\\u001A\\u001B\\u001C\\u001D\\u001E\\u001F",
163 /* 1 Some correct UTF-8 text */
165 /* a bit of German */
166 "Falsches \xC3\x9C" "ben von Xylophonmusik qu\xC3\xA4lt"
167 " jeden gr\xC3\xB6\xC3\x9F" "eren Zwerg.",
168 "Falsches \xC3\x9C" "ben von Xylophonmusik qu\xC3\xA4lt"
169 " jeden gr\xC3\xB6\xC3\x9F" "eren Zwerg.",
170 "Falsches \\u00DCben von Xylophonmusik qu\\u00E4lt"
171 " jeden gr\\u00F6\\u00DFeren Zwerg.",
174 /* a bit of Greek */
175 "\xCE\xBA\xE1\xBD\xB9\xCF\x83\xCE\xBC\xCE\xB5",
176 "\xCE\xBA\xE1\xBD\xB9\xCF\x83\xCE\xBC\xCE\xB5",
177 "\\u03BA\\u1F79\\u03C3\\u03BC\\u03B5",
179 /* '%' character when not interpolating */
181 "100%",
182 "100%",
184 /* 2 Boundary condition test cases */
185 /* 2.1 First possible sequence of a certain length */
187 * 2.1.1 1 byte U+0020
188 * Control characters are already covered by their own test
189 * case under 0. Test the first 1 byte non-control character
190 * here.
193 " ",
194 " ",
196 /* 2.1.2 2 bytes U+0080 */
198 "\xC2\x80",
199 "\xC2\x80",
200 "\\u0080",
202 /* 2.1.3 3 bytes U+0800 */
204 "\xE0\xA0\x80",
205 "\xE0\xA0\x80",
206 "\\u0800",
208 /* 2.1.4 4 bytes U+10000 */
210 "\xF0\x90\x80\x80",
211 "\xF0\x90\x80\x80",
212 "\\uD800\\uDC00",
214 /* 2.1.5 5 bytes U+200000 */
216 "\xF8\x88\x80\x80\x80",
217 NULL,
218 "\\uFFFD",
220 /* 2.1.6 6 bytes U+4000000 */
222 "\xFC\x84\x80\x80\x80\x80",
223 NULL,
224 "\\uFFFD",
226 /* 2.2 Last possible sequence of a certain length */
227 /* 2.2.1 1 byte U+007F */
229 "\x7F",
230 "\x7F",
231 "\\u007F",
233 /* 2.2.2 2 bytes U+07FF */
235 "\xDF\xBF",
236 "\xDF\xBF",
237 "\\u07FF",
240 * 2.2.3 3 bytes U+FFFC
241 * The last possible sequence is actually U+FFFF. But that's
242 * a noncharacter, and already covered by its own test case
243 * under 5.3. Same for U+FFFE. U+FFFD is the last character
244 * in the BMP, and covered under 2.3. Because of U+FFFD's
245 * special role as replacement character, it's worth testing
246 * U+FFFC here.
249 "\xEF\xBF\xBC",
250 "\xEF\xBF\xBC",
251 "\\uFFFC",
253 /* 2.2.4 4 bytes U+1FFFFF */
255 "\xF7\xBF\xBF\xBF",
256 NULL,
257 "\\uFFFD",
259 /* 2.2.5 5 bytes U+3FFFFFF */
261 "\xFB\xBF\xBF\xBF\xBF",
262 NULL,
263 "\\uFFFD",
265 /* 2.2.6 6 bytes U+7FFFFFFF */
267 "\xFD\xBF\xBF\xBF\xBF\xBF",
268 NULL,
269 "\\uFFFD",
271 /* 2.3 Other boundary conditions */
273 /* last one before surrogate range: U+D7FF */
274 "\xED\x9F\xBF",
275 "\xED\x9F\xBF",
276 "\\uD7FF",
279 /* first one after surrogate range: U+E000 */
280 "\xEE\x80\x80",
281 "\xEE\x80\x80",
282 "\\uE000",
285 /* last one in BMP: U+FFFD */
286 "\xEF\xBF\xBD",
287 "\xEF\xBF\xBD",
288 "\\uFFFD",
291 /* last one in last plane: U+10FFFD */
292 "\xF4\x8F\xBF\xBD",
293 "\xF4\x8F\xBF\xBD",
294 "\\uDBFF\\uDFFD"
297 /* first one beyond Unicode range: U+110000 */
298 "\xF4\x90\x80\x80",
299 NULL,
300 "\\uFFFD",
302 /* 3 Malformed sequences */
303 /* 3.1 Unexpected continuation bytes */
304 /* 3.1.1 First continuation byte */
306 "\x80",
307 NULL,
308 "\\uFFFD",
310 /* 3.1.2 Last continuation byte */
312 "\xBF",
313 NULL,
314 "\\uFFFD",
316 /* 3.1.3 2 continuation bytes */
318 "\x80\xBF",
319 NULL,
320 "\\uFFFD\\uFFFD",
322 /* 3.1.4 3 continuation bytes */
324 "\x80\xBF\x80",
325 NULL,
326 "\\uFFFD\\uFFFD\\uFFFD",
328 /* 3.1.5 4 continuation bytes */
330 "\x80\xBF\x80\xBF",
331 NULL,
332 "\\uFFFD\\uFFFD\\uFFFD\\uFFFD",
334 /* 3.1.6 5 continuation bytes */
336 "\x80\xBF\x80\xBF\x80",
337 NULL,
338 "\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD",
340 /* 3.1.7 6 continuation bytes */
342 "\x80\xBF\x80\xBF\x80\xBF",
343 NULL,
344 "\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD",
346 /* 3.1.8 7 continuation bytes */
348 "\x80\xBF\x80\xBF\x80\xBF\x80",
349 NULL,
350 "\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD",
352 /* 3.1.9 Sequence of all 64 possible continuation bytes */
354 "\x80\x81\x82\x83\x84\x85\x86\x87"
355 "\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F"
356 "\x90\x91\x92\x93\x94\x95\x96\x97"
357 "\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F"
358 "\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7"
359 "\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF"
360 "\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7"
361 "\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF",
362 NULL,
363 "\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD"
364 "\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD"
365 "\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD"
366 "\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD"
367 "\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD"
368 "\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD"
369 "\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD"
370 "\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD",
372 /* 3.2 Lonely start characters */
373 /* 3.2.1 All 32 first bytes of 2-byte sequences, followed by space */
375 "\xC0 \xC1 \xC2 \xC3 \xC4 \xC5 \xC6 \xC7 "
376 "\xC8 \xC9 \xCA \xCB \xCC \xCD \xCE \xCF "
377 "\xD0 \xD1 \xD2 \xD3 \xD4 \xD5 \xD6 \xD7 "
378 "\xD8 \xD9 \xDA \xDB \xDC \xDD \xDE \xDF ",
379 NULL,
380 "\\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD "
381 "\\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD "
382 "\\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD "
383 "\\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD ",
385 /* 3.2.2 All 16 first bytes of 3-byte sequences, followed by space */
387 "\xE0 \xE1 \xE2 \xE3 \xE4 \xE5 \xE6 \xE7 "
388 "\xE8 \xE9 \xEA \xEB \xEC \xED \xEE \xEF ",
389 NULL,
390 "\\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD "
391 "\\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD ",
393 /* 3.2.3 All 8 first bytes of 4-byte sequences, followed by space */
395 "\xF0 \xF1 \xF2 \xF3 \xF4 \xF5 \xF6 \xF7 ",
396 NULL,
397 "\\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD ",
399 /* 3.2.4 All 4 first bytes of 5-byte sequences, followed by space */
401 "\xF8 \xF9 \xFA \xFB ",
402 NULL,
403 "\\uFFFD \\uFFFD \\uFFFD \\uFFFD ",
405 /* 3.2.5 All 2 first bytes of 6-byte sequences, followed by space */
407 "\xFC \xFD ",
408 NULL,
409 "\\uFFFD \\uFFFD ",
411 /* 3.3 Sequences with last continuation byte missing */
412 /* 3.3.1 2-byte sequence with last byte missing (U+0000) */
414 "\xC0",
415 NULL,
416 "\\uFFFD",
418 /* 3.3.2 3-byte sequence with last byte missing (U+0000) */
420 "\xE0\x80",
421 NULL,
422 "\\uFFFD",
424 /* 3.3.3 4-byte sequence with last byte missing (U+0000) */
426 "\xF0\x80\x80",
427 NULL,
428 "\\uFFFD",
430 /* 3.3.4 5-byte sequence with last byte missing (U+0000) */
432 "\xF8\x80\x80\x80",
433 NULL,
434 "\\uFFFD",
436 /* 3.3.5 6-byte sequence with last byte missing (U+0000) */
438 "\xFC\x80\x80\x80\x80",
439 NULL,
440 "\\uFFFD",
442 /* 3.3.6 2-byte sequence with last byte missing (U+07FF) */
444 "\xDF",
445 NULL,
446 "\\uFFFD",
448 /* 3.3.7 3-byte sequence with last byte missing (U+FFFF) */
450 "\xEF\xBF",
451 NULL,
452 "\\uFFFD",
454 /* 3.3.8 4-byte sequence with last byte missing (U+1FFFFF) */
456 "\xF7\xBF\xBF",
457 NULL,
458 "\\uFFFD",
460 /* 3.3.9 5-byte sequence with last byte missing (U+3FFFFFF) */
462 "\xFB\xBF\xBF\xBF",
463 NULL,
464 "\\uFFFD",
466 /* 3.3.10 6-byte sequence with last byte missing (U+7FFFFFFF) */
468 "\xFD\xBF\xBF\xBF\xBF",
469 NULL,
470 "\\uFFFD",
472 /* 3.4 Concatenation of incomplete sequences */
474 "\xC0\xE0\x80\xF0\x80\x80\xF8\x80\x80\x80\xFC\x80\x80\x80\x80"
475 "\xDF\xEF\xBF\xF7\xBF\xBF\xFB\xBF\xBF\xBF\xFD\xBF\xBF\xBF\xBF",
476 NULL,
477 "\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD"
478 "\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD",
480 /* 3.5 Impossible bytes */
482 "\xFE",
483 NULL,
484 "\\uFFFD",
487 "\xFF",
488 NULL,
489 "\\uFFFD",
492 "\xFE\xFE\xFF\xFF",
493 NULL,
494 "\\uFFFD\\uFFFD\\uFFFD\\uFFFD",
496 /* 4 Overlong sequences */
497 /* 4.1 Overlong '/' */
499 "\xC0\xAF",
500 NULL,
501 "\\uFFFD",
504 "\xE0\x80\xAF",
505 NULL,
506 "\\uFFFD",
509 "\xF0\x80\x80\xAF",
510 NULL,
511 "\\uFFFD",
514 "\xF8\x80\x80\x80\xAF",
515 NULL,
516 "\\uFFFD",
519 "\xFC\x80\x80\x80\x80\xAF",
520 NULL,
521 "\\uFFFD",
524 * 4.2 Maximum overlong sequences
525 * Highest Unicode value that is still resulting in an
526 * overlong sequence if represented with the given number of
527 * bytes. This is a boundary test for safe UTF-8 decoders.
530 /* \U+007F */
531 "\xC1\xBF",
532 NULL,
533 "\\uFFFD",
536 /* \U+07FF */
537 "\xE0\x9F\xBF",
538 NULL,
539 "\\uFFFD",
543 * \U+FFFC
544 * The actual maximum would be U+FFFF, but that's a
545 * noncharacter. Testing U+FFFC seems more useful. See
546 * also 2.2.3
548 "\xF0\x8F\xBF\xBC",
549 NULL,
550 "\\uFFFD",
553 /* \U+1FFFFF */
554 "\xF8\x87\xBF\xBF\xBF",
555 NULL,
556 "\\uFFFD",
559 /* \U+3FFFFFF */
560 "\xFC\x83\xBF\xBF\xBF\xBF",
561 NULL,
562 "\\uFFFD",
564 /* 4.3 Overlong representation of the NUL character */
566 /* \U+0000 */
567 "\xC0\x80",
568 "\xC0\x80",
569 "\\u0000",
572 /* \U+0000 */
573 "\xE0\x80\x80",
574 NULL,
575 "\\uFFFD",
578 /* \U+0000 */
579 "\xF0\x80\x80\x80",
580 NULL,
581 "\\uFFFD",
584 /* \U+0000 */
585 "\xF8\x80\x80\x80\x80",
586 NULL,
587 "\\uFFFD",
590 /* \U+0000 */
591 "\xFC\x80\x80\x80\x80\x80",
592 NULL,
593 "\\uFFFD",
595 /* 5 Illegal code positions */
596 /* 5.1 Single UTF-16 surrogates */
598 /* \U+D800 */
599 "\xED\xA0\x80",
600 NULL,
601 "\\uFFFD",
604 /* \U+DB7F */
605 "\xED\xAD\xBF",
606 NULL,
607 "\\uFFFD",
610 /* \U+DB80 */
611 "\xED\xAE\x80",
612 NULL,
613 "\\uFFFD",
616 /* \U+DBFF */
617 "\xED\xAF\xBF",
618 NULL,
619 "\\uFFFD",
622 /* \U+DC00 */
623 "\xED\xB0\x80",
624 NULL,
625 "\\uFFFD",
628 /* \U+DF80 */
629 "\xED\xBE\x80",
630 NULL,
631 "\\uFFFD",
634 /* \U+DFFF */
635 "\xED\xBF\xBF",
636 NULL,
637 "\\uFFFD",
639 /* 5.2 Paired UTF-16 surrogates */
641 /* \U+D800\U+DC00 */
642 "\xED\xA0\x80\xED\xB0\x80",
643 NULL,
644 "\\uFFFD\\uFFFD",
647 /* \U+D800\U+DFFF */
648 "\xED\xA0\x80\xED\xBF\xBF",
649 NULL,
650 "\\uFFFD\\uFFFD",
653 /* \U+DB7F\U+DC00 */
654 "\xED\xAD\xBF\xED\xB0\x80",
655 NULL,
656 "\\uFFFD\\uFFFD",
659 /* \U+DB7F\U+DFFF */
660 "\xED\xAD\xBF\xED\xBF\xBF",
661 NULL,
662 "\\uFFFD\\uFFFD",
665 /* \U+DB80\U+DC00 */
666 "\xED\xAE\x80\xED\xB0\x80",
667 NULL,
668 "\\uFFFD\\uFFFD",
671 /* \U+DB80\U+DFFF */
672 "\xED\xAE\x80\xED\xBF\xBF",
673 NULL,
674 "\\uFFFD\\uFFFD",
677 /* \U+DBFF\U+DC00 */
678 "\xED\xAF\xBF\xED\xB0\x80",
679 NULL,
680 "\\uFFFD\\uFFFD",
683 /* \U+DBFF\U+DFFF */
684 "\xED\xAF\xBF\xED\xBF\xBF",
685 NULL,
686 "\\uFFFD\\uFFFD",
688 /* 5.3 Other illegal code positions */
689 /* BMP noncharacters */
691 /* \U+FFFE */
692 "\xEF\xBF\xBE",
693 NULL,
694 "\\uFFFD",
697 /* \U+FFFF */
698 "\xEF\xBF\xBF",
699 NULL,
700 "\\uFFFD",
703 /* U+FDD0 */
704 "\xEF\xB7\x90",
705 NULL,
706 "\\uFFFD",
709 /* U+FDEF */
710 "\xEF\xB7\xAF",
711 NULL,
712 "\\uFFFD",
714 /* Plane 1 .. 16 noncharacters */
716 /* U+1FFFE U+1FFFF U+2FFFE U+2FFFF ... U+10FFFE U+10FFFF */
717 "\xF0\x9F\xBF\xBE\xF0\x9F\xBF\xBF"
718 "\xF0\xAF\xBF\xBE\xF0\xAF\xBF\xBF"
719 "\xF0\xBF\xBF\xBE\xF0\xBF\xBF\xBF"
720 "\xF1\x8F\xBF\xBE\xF1\x8F\xBF\xBF"
721 "\xF1\x9F\xBF\xBE\xF1\x9F\xBF\xBF"
722 "\xF1\xAF\xBF\xBE\xF1\xAF\xBF\xBF"
723 "\xF1\xBF\xBF\xBE\xF1\xBF\xBF\xBF"
724 "\xF2\x8F\xBF\xBE\xF2\x8F\xBF\xBF"
725 "\xF2\x9F\xBF\xBE\xF2\x9F\xBF\xBF"
726 "\xF2\xAF\xBF\xBE\xF2\xAF\xBF\xBF"
727 "\xF2\xBF\xBF\xBE\xF2\xBF\xBF\xBF"
728 "\xF3\x8F\xBF\xBE\xF3\x8F\xBF\xBF"
729 "\xF3\x9F\xBF\xBE\xF3\x9F\xBF\xBF"
730 "\xF3\xAF\xBF\xBE\xF3\xAF\xBF\xBF"
731 "\xF3\xBF\xBF\xBE\xF3\xBF\xBF\xBF"
732 "\xF4\x8F\xBF\xBE\xF4\x8F\xBF\xBF",
733 NULL,
734 "\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD"
735 "\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD"
736 "\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD"
737 "\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD",
741 int i, j;
742 QString *str;
743 const char *json_in, *utf8_out, *utf8_in, *json_out, *tail;
744 char *end, *in, *jstr;
746 for (i = 0; test_cases[i].json_in; i++) {
747 for (j = 0; j < 2; j++) {
748 json_in = test_cases[i].json_in;
749 utf8_out = test_cases[i].utf8_out;
750 utf8_in = test_cases[i].utf8_out ?: test_cases[i].json_in;
751 json_out = test_cases[i].json_out ?: test_cases[i].json_in;
753 /* Parse @json_in, expect @utf8_out */
754 if (utf8_out) {
755 str = from_json_str(json_in, j, &error_abort);
756 g_assert_cmpstr(qstring_get_try_str(str), ==, utf8_out);
757 qobject_unref(str);
758 } else {
759 str = from_json_str(json_in, j, NULL);
760 g_assert(!str);
762 * Failure may be due to any sequence, but *all* sequences
763 * are expected to fail. Test each one in isolation.
765 for (tail = json_in; *tail; tail = end) {
766 mod_utf8_codepoint(tail, 6, &end);
767 if (*end == ' ') {
768 end++;
770 in = g_strndup(tail, end - tail);
771 str = from_json_str(in, j, NULL);
772 g_assert(!str);
773 g_free(in);
777 /* Unparse @utf8_in, expect @json_out */
778 str = qstring_from_str(utf8_in);
779 jstr = to_json_str(str);
780 g_assert_cmpstr(jstr, ==, json_out);
781 qobject_unref(str);
782 g_free(jstr);
784 /* Parse @json_out right back, unless it has replacements */
785 if (!strstr(json_out, "\\uFFFD")) {
786 str = from_json_str(json_out, j, &error_abort);
787 g_assert_cmpstr(qstring_get_try_str(str), ==, utf8_in);
788 qobject_unref(str);
794 static void int_number(void)
796 struct {
797 const char *encoded;
798 int64_t decoded;
799 const char *reencoded;
800 } test_cases[] = {
801 { "0", 0 },
802 { "1234", 1234 },
803 { "1", 1 },
804 { "-32", -32 },
805 { "-0", 0, "0" },
808 int i;
809 QNum *qnum;
810 int64_t ival;
811 uint64_t uval;
812 QString *str;
814 for (i = 0; test_cases[i].encoded; i++) {
815 qnum = qobject_to(QNum,
816 qobject_from_json(test_cases[i].encoded,
817 &error_abort));
818 g_assert(qnum);
819 g_assert(qnum_get_try_int(qnum, &ival));
820 g_assert_cmpint(ival, ==, test_cases[i].decoded);
821 if (test_cases[i].decoded >= 0) {
822 g_assert(qnum_get_try_uint(qnum, &uval));
823 g_assert_cmpuint(uval, ==, (uint64_t)test_cases[i].decoded);
824 } else {
825 g_assert(!qnum_get_try_uint(qnum, &uval));
827 g_assert_cmpfloat(qnum_get_double(qnum), ==,
828 (double)test_cases[i].decoded);
830 str = qobject_to_json(QOBJECT(qnum));
831 g_assert_cmpstr(qstring_get_str(str), ==,
832 test_cases[i].reencoded ?: test_cases[i].encoded);
833 qobject_unref(str);
835 qobject_unref(qnum);
839 static void uint_number(void)
841 struct {
842 const char *encoded;
843 uint64_t decoded;
844 const char *reencoded;
845 } test_cases[] = {
846 { "9223372036854775808", (uint64_t)1 << 63 },
847 { "18446744073709551615", UINT64_MAX },
850 int i;
851 QNum *qnum;
852 int64_t ival;
853 uint64_t uval;
854 QString *str;
856 for (i = 0; test_cases[i].encoded; i++) {
857 qnum = qobject_to(QNum,
858 qobject_from_json(test_cases[i].encoded,
859 &error_abort));
860 g_assert(qnum);
861 g_assert(qnum_get_try_uint(qnum, &uval));
862 g_assert_cmpuint(uval, ==, test_cases[i].decoded);
863 g_assert(!qnum_get_try_int(qnum, &ival));
864 g_assert_cmpfloat(qnum_get_double(qnum), ==,
865 (double)test_cases[i].decoded);
867 str = qobject_to_json(QOBJECT(qnum));
868 g_assert_cmpstr(qstring_get_str(str), ==,
869 test_cases[i].reencoded ?: test_cases[i].encoded);
870 qobject_unref(str);
872 qobject_unref(qnum);
876 static void float_number(void)
878 struct {
879 const char *encoded;
880 double decoded;
881 const char *reencoded;
882 } test_cases[] = {
883 { "32.43", 32.43 },
884 { "0.222", 0.222 },
885 { "-32.12313", -32.12313, "-32.123130000000003" },
886 { "-32.20e-10", -32.20e-10, "-3.22e-09" },
887 { "18446744073709551616", 0x1p64, "1.8446744073709552e+19" },
888 { "-9223372036854775809", -0x1p63, "-9.2233720368547758e+18" },
891 int i;
892 QNum *qnum;
893 int64_t ival;
894 uint64_t uval;
895 QString *str;
897 for (i = 0; test_cases[i].encoded; i++) {
898 qnum = qobject_to(QNum,
899 qobject_from_json(test_cases[i].encoded,
900 &error_abort));
901 g_assert(qnum);
902 g_assert_cmpfloat(qnum_get_double(qnum), ==, test_cases[i].decoded);
903 g_assert(!qnum_get_try_int(qnum, &ival));
904 g_assert(!qnum_get_try_uint(qnum, &uval));
906 str = qobject_to_json(QOBJECT(qnum));
907 g_assert_cmpstr(qstring_get_str(str), ==,
908 test_cases[i].reencoded ?: test_cases[i].encoded);
909 qobject_unref(str);
911 qobject_unref(qnum);
915 static void keyword_literal(void)
917 QObject *obj;
918 QBool *qbool;
919 QNull *null;
920 QString *str;
922 obj = qobject_from_json("true", &error_abort);
923 qbool = qobject_to(QBool, obj);
924 g_assert(qbool);
925 g_assert(qbool_get_bool(qbool) == true);
927 str = qobject_to_json(obj);
928 g_assert(strcmp(qstring_get_str(str), "true") == 0);
929 qobject_unref(str);
931 qobject_unref(qbool);
933 obj = qobject_from_json("false", &error_abort);
934 qbool = qobject_to(QBool, obj);
935 g_assert(qbool);
936 g_assert(qbool_get_bool(qbool) == false);
938 str = qobject_to_json(obj);
939 g_assert(strcmp(qstring_get_str(str), "false") == 0);
940 qobject_unref(str);
942 qobject_unref(qbool);
944 obj = qobject_from_json("null", &error_abort);
945 g_assert(obj != NULL);
946 g_assert(qobject_type(obj) == QTYPE_QNULL);
948 null = qnull();
949 g_assert(QOBJECT(null) == obj);
951 qobject_unref(obj);
952 qobject_unref(null);
955 static void interpolation_valid(void)
957 long long value_lld = 0x123456789abcdefLL;
958 int64_t value_d64 = value_lld;
959 long value_ld = (long)value_lld;
960 int value_d = (int)value_lld;
961 unsigned long long value_llu = 0xfedcba9876543210ULL;
962 uint64_t value_u64 = value_llu;
963 unsigned long value_lu = (unsigned long)value_llu;
964 unsigned value_u = (unsigned)value_llu;
965 double value_f = 2.323423423;
966 const char *value_s = "hello world";
967 QObject *value_p = QOBJECT(qnull());
968 QBool *qbool;
969 QNum *qnum;
970 QString *qstr;
971 QObject *qobj;
973 /* bool */
975 qbool = qobject_to(QBool, qobject_from_jsonf_nofail("%i", false));
976 g_assert(qbool);
977 g_assert(qbool_get_bool(qbool) == false);
978 qobject_unref(qbool);
980 /* Test that non-zero values other than 1 get collapsed to true */
981 qbool = qobject_to(QBool, qobject_from_jsonf_nofail("%i", 2));
982 g_assert(qbool);
983 g_assert(qbool_get_bool(qbool) == true);
984 qobject_unref(qbool);
986 /* number */
988 qnum = qobject_to(QNum, qobject_from_jsonf_nofail("%d", value_d));
989 g_assert_cmpint(qnum_get_int(qnum), ==, value_d);
990 qobject_unref(qnum);
992 qnum = qobject_to(QNum, qobject_from_jsonf_nofail("%ld", value_ld));
993 g_assert_cmpint(qnum_get_int(qnum), ==, value_ld);
994 qobject_unref(qnum);
996 qnum = qobject_to(QNum, qobject_from_jsonf_nofail("%lld", value_lld));
997 g_assert_cmpint(qnum_get_int(qnum), ==, value_lld);
998 qobject_unref(qnum);
1000 qnum = qobject_to(QNum, qobject_from_jsonf_nofail("%" PRId64, value_d64));
1001 g_assert_cmpint(qnum_get_int(qnum), ==, value_lld);
1002 qobject_unref(qnum);
1004 qnum = qobject_to(QNum, qobject_from_jsonf_nofail("%u", value_u));
1005 g_assert_cmpuint(qnum_get_uint(qnum), ==, value_u);
1006 qobject_unref(qnum);
1008 qnum = qobject_to(QNum, qobject_from_jsonf_nofail("%lu", value_lu));
1009 g_assert_cmpuint(qnum_get_uint(qnum), ==, value_lu);
1010 qobject_unref(qnum);
1012 qnum = qobject_to(QNum, qobject_from_jsonf_nofail("%llu", value_llu));
1013 g_assert_cmpuint(qnum_get_uint(qnum), ==, value_llu);
1014 qobject_unref(qnum);
1016 qnum = qobject_to(QNum, qobject_from_jsonf_nofail("%" PRIu64, value_u64));
1017 g_assert_cmpuint(qnum_get_uint(qnum), ==, value_llu);
1018 qobject_unref(qnum);
1020 qnum = qobject_to(QNum, qobject_from_jsonf_nofail("%f", value_f));
1021 g_assert(qnum_get_double(qnum) == value_f);
1022 qobject_unref(qnum);
1024 /* string */
1026 qstr = qobject_to(QString,
1027 qobject_from_jsonf_nofail("%s", value_s));
1028 g_assert_cmpstr(qstring_get_try_str(qstr), ==, value_s);
1029 qobject_unref(qstr);
1031 /* object */
1033 qobj = qobject_from_jsonf_nofail("%p", value_p);
1034 g_assert(qobj == value_p);
1037 static void interpolation_unknown(void)
1039 if (g_test_subprocess()) {
1040 qobject_from_jsonf_nofail("%x", 666);
1042 g_test_trap_subprocess(NULL, 0, 0);
1043 g_test_trap_assert_failed();
1044 g_test_trap_assert_stderr("*Unexpected error*"
1045 "invalid interpolation '%x'*");
1048 static void interpolation_string(void)
1050 if (g_test_subprocess()) {
1051 qobject_from_jsonf_nofail("['%s', %s]", "eins", "zwei");
1053 g_test_trap_subprocess(NULL, 0, 0);
1054 g_test_trap_assert_failed();
1055 g_test_trap_assert_stderr("*Unexpected error*"
1056 "can't interpolate into string*");
1059 static void simple_dict(void)
1061 int i;
1062 struct {
1063 const char *encoded;
1064 QLitObject decoded;
1065 } test_cases[] = {
1067 .encoded = "{\"foo\": 42, \"bar\": \"hello world\"}",
1068 .decoded = QLIT_QDICT(((QLitDictEntry[]){
1069 { "foo", QLIT_QNUM(42) },
1070 { "bar", QLIT_QSTR("hello world") },
1072 })),
1073 }, {
1074 .encoded = "{}",
1075 .decoded = QLIT_QDICT(((QLitDictEntry[]){
1077 })),
1078 }, {
1079 .encoded = "{\"foo\": 43}",
1080 .decoded = QLIT_QDICT(((QLitDictEntry[]){
1081 { "foo", QLIT_QNUM(43) },
1083 })),
1088 for (i = 0; test_cases[i].encoded; i++) {
1089 QObject *obj;
1090 QString *str;
1092 obj = qobject_from_json(test_cases[i].encoded, &error_abort);
1093 g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
1095 str = qobject_to_json(obj);
1096 qobject_unref(obj);
1098 obj = qobject_from_json(qstring_get_str(str), &error_abort);
1099 g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
1100 qobject_unref(obj);
1101 qobject_unref(str);
1106 * this generates json of the form:
1107 * a(0,m) = [0, 1, ..., m-1]
1108 * a(n,m) = {
1109 * 'key0': a(0,m),
1110 * 'key1': a(1,m),
1111 * ...
1112 * 'key(n-1)': a(n-1,m)
1115 static void gen_test_json(GString *gstr, int nest_level_max,
1116 int elem_count)
1118 int i;
1120 g_assert(gstr);
1121 if (nest_level_max == 0) {
1122 g_string_append(gstr, "[");
1123 for (i = 0; i < elem_count; i++) {
1124 g_string_append_printf(gstr, "%d", i);
1125 if (i < elem_count - 1) {
1126 g_string_append_printf(gstr, ", ");
1129 g_string_append(gstr, "]");
1130 return;
1133 g_string_append(gstr, "{");
1134 for (i = 0; i < nest_level_max; i++) {
1135 g_string_append_printf(gstr, "'key%d': ", i);
1136 gen_test_json(gstr, i, elem_count);
1137 if (i < nest_level_max - 1) {
1138 g_string_append(gstr, ",");
1141 g_string_append(gstr, "}");
1144 static void large_dict(void)
1146 GString *gstr = g_string_new("");
1147 QObject *obj;
1149 gen_test_json(gstr, 10, 100);
1150 obj = qobject_from_json(gstr->str, &error_abort);
1151 g_assert(obj != NULL);
1153 qobject_unref(obj);
1154 g_string_free(gstr, true);
1157 static void simple_list(void)
1159 int i;
1160 struct {
1161 const char *encoded;
1162 QLitObject decoded;
1163 } test_cases[] = {
1165 .encoded = "[43,42]",
1166 .decoded = QLIT_QLIST(((QLitObject[]){
1167 QLIT_QNUM(43),
1168 QLIT_QNUM(42),
1170 })),
1173 .encoded = "[43]",
1174 .decoded = QLIT_QLIST(((QLitObject[]){
1175 QLIT_QNUM(43),
1177 })),
1180 .encoded = "[]",
1181 .decoded = QLIT_QLIST(((QLitObject[]){
1183 })),
1186 .encoded = "[{}]",
1187 .decoded = QLIT_QLIST(((QLitObject[]){
1188 QLIT_QDICT(((QLitDictEntry[]){
1190 })),
1192 })),
1197 for (i = 0; test_cases[i].encoded; i++) {
1198 QObject *obj;
1199 QString *str;
1201 obj = qobject_from_json(test_cases[i].encoded, &error_abort);
1202 g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
1204 str = qobject_to_json(obj);
1205 qobject_unref(obj);
1207 obj = qobject_from_json(qstring_get_str(str), &error_abort);
1208 g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
1209 qobject_unref(obj);
1210 qobject_unref(str);
1214 static void simple_whitespace(void)
1216 int i;
1217 struct {
1218 const char *encoded;
1219 QLitObject decoded;
1220 } test_cases[] = {
1222 .encoded = " [ 43 , 42 ]",
1223 .decoded = QLIT_QLIST(((QLitObject[]){
1224 QLIT_QNUM(43),
1225 QLIT_QNUM(42),
1227 })),
1230 .encoded = "\t[ 43 , { 'h' : 'b' },\r\n\t[ ], 42 ]\n",
1231 .decoded = QLIT_QLIST(((QLitObject[]){
1232 QLIT_QNUM(43),
1233 QLIT_QDICT(((QLitDictEntry[]){
1234 { "h", QLIT_QSTR("b") },
1235 { }})),
1236 QLIT_QLIST(((QLitObject[]){
1237 { }})),
1238 QLIT_QNUM(42),
1240 })),
1243 .encoded = " [ 43 , { 'h' : 'b' , 'a' : 32 }, [ ], 42 ]",
1244 .decoded = QLIT_QLIST(((QLitObject[]){
1245 QLIT_QNUM(43),
1246 QLIT_QDICT(((QLitDictEntry[]){
1247 { "h", QLIT_QSTR("b") },
1248 { "a", QLIT_QNUM(32) },
1249 { }})),
1250 QLIT_QLIST(((QLitObject[]){
1251 { }})),
1252 QLIT_QNUM(42),
1254 })),
1259 for (i = 0; test_cases[i].encoded; i++) {
1260 QObject *obj;
1261 QString *str;
1263 obj = qobject_from_json(test_cases[i].encoded, &error_abort);
1264 g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
1266 str = qobject_to_json(obj);
1267 qobject_unref(obj);
1269 obj = qobject_from_json(qstring_get_str(str), &error_abort);
1270 g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
1272 qobject_unref(obj);
1273 qobject_unref(str);
1277 static void simple_interpolation(void)
1279 QObject *embedded_obj;
1280 QObject *obj;
1281 QLitObject decoded = QLIT_QLIST(((QLitObject[]){
1282 QLIT_QNUM(1),
1283 QLIT_QSTR("100%"),
1284 QLIT_QLIST(((QLitObject[]){
1285 QLIT_QNUM(32),
1286 QLIT_QNUM(42),
1287 {}})),
1288 {}}));
1290 embedded_obj = qobject_from_json("[32, 42]", &error_abort);
1291 g_assert(embedded_obj != NULL);
1293 obj = qobject_from_jsonf_nofail("[%d, '100%%', %p]", 1, embedded_obj);
1294 g_assert(qlit_equal_qobject(&decoded, obj));
1296 qobject_unref(obj);
1299 static void empty_input(void)
1301 Error *err = NULL;
1302 QObject *obj;
1304 obj = qobject_from_json("", &err);
1305 error_free_or_abort(&err);
1306 g_assert(obj == NULL);
1309 static void blank_input(void)
1311 Error *err = NULL;
1312 QObject *obj;
1314 obj = qobject_from_json("\n ", &err);
1315 error_free_or_abort(&err);
1316 g_assert(obj == NULL);
1319 static void junk_input(void)
1321 /* Note: junk within strings is covered elsewhere */
1322 Error *err = NULL;
1323 QObject *obj;
1325 obj = qobject_from_json("@", &err);
1326 error_free_or_abort(&err);
1327 g_assert(obj == NULL);
1329 obj = qobject_from_json("{\x01", &err);
1330 error_free_or_abort(&err);
1331 g_assert(obj == NULL);
1333 obj = qobject_from_json("[0\xFF]", &err);
1334 error_free_or_abort(&err);
1335 g_assert(obj == NULL);
1337 obj = qobject_from_json("00", &err);
1338 error_free_or_abort(&err);
1339 g_assert(obj == NULL);
1341 obj = qobject_from_json("[1e", &err);
1342 error_free_or_abort(&err);
1343 g_assert(obj == NULL);
1345 obj = qobject_from_json("truer", &err);
1346 error_free_or_abort(&err);
1347 g_assert(obj == NULL);
1350 static void unterminated_string(void)
1352 Error *err = NULL;
1353 QObject *obj = qobject_from_json("\"abc", &err);
1354 error_free_or_abort(&err);
1355 g_assert(obj == NULL);
1358 static void unterminated_sq_string(void)
1360 Error *err = NULL;
1361 QObject *obj = qobject_from_json("'abc", &err);
1362 error_free_or_abort(&err);
1363 g_assert(obj == NULL);
1366 static void unterminated_escape(void)
1368 Error *err = NULL;
1369 QObject *obj = qobject_from_json("\"abc\\\"", &err);
1370 error_free_or_abort(&err);
1371 g_assert(obj == NULL);
1374 static void unterminated_array(void)
1376 Error *err = NULL;
1377 QObject *obj = qobject_from_json("[32", &err);
1378 error_free_or_abort(&err);
1379 g_assert(obj == NULL);
1382 static void unterminated_array_comma(void)
1384 Error *err = NULL;
1385 QObject *obj = qobject_from_json("[32,", &err);
1386 error_free_or_abort(&err);
1387 g_assert(obj == NULL);
1390 static void invalid_array_comma(void)
1392 Error *err = NULL;
1393 QObject *obj = qobject_from_json("[32,}", &err);
1394 error_free_or_abort(&err);
1395 g_assert(obj == NULL);
1398 static void unterminated_dict(void)
1400 Error *err = NULL;
1401 QObject *obj = qobject_from_json("{'abc':32", &err);
1402 error_free_or_abort(&err);
1403 g_assert(obj == NULL);
1406 static void unterminated_dict_comma(void)
1408 Error *err = NULL;
1409 QObject *obj = qobject_from_json("{'abc':32,", &err);
1410 error_free_or_abort(&err);
1411 g_assert(obj == NULL);
1414 static void invalid_dict_comma(void)
1416 Error *err = NULL;
1417 QObject *obj = qobject_from_json("{'abc':32,}", &err);
1418 error_free_or_abort(&err);
1419 g_assert(obj == NULL);
1422 static void invalid_dict_key(void)
1424 Error *err = NULL;
1425 QObject *obj = qobject_from_json("{32:'abc'}", &err);
1426 error_free_or_abort(&err);
1427 g_assert(obj == NULL);
1430 static void unterminated_literal(void)
1432 Error *err = NULL;
1433 QObject *obj = qobject_from_json("nul", &err);
1434 error_free_or_abort(&err);
1435 g_assert(obj == NULL);
1438 static char *make_nest(char *buf, size_t cnt)
1440 memset(buf, '[', cnt - 1);
1441 buf[cnt - 1] = '{';
1442 buf[cnt] = '}';
1443 memset(buf + cnt + 1, ']', cnt - 1);
1444 buf[2 * cnt] = 0;
1445 return buf;
1448 static void limits_nesting(void)
1450 Error *err = NULL;
1451 enum { max_nesting = 1024 }; /* see qobject/json-streamer.c */
1452 char buf[2 * (max_nesting + 1) + 1];
1453 QObject *obj;
1455 obj = qobject_from_json(make_nest(buf, max_nesting), &error_abort);
1456 g_assert(obj != NULL);
1457 qobject_unref(obj);
1459 obj = qobject_from_json(make_nest(buf, max_nesting + 1), &err);
1460 error_free_or_abort(&err);
1461 g_assert(obj == NULL);
1464 static void multiple_values(void)
1466 Error *err = NULL;
1467 QObject *obj;
1469 obj = qobject_from_json("false true", &err);
1470 error_free_or_abort(&err);
1471 g_assert(obj == NULL);
1473 obj = qobject_from_json("} true", &err);
1474 error_free_or_abort(&err);
1475 g_assert(obj == NULL);
1478 int main(int argc, char **argv)
1480 g_test_init(&argc, &argv, NULL);
1482 g_test_add_func("/literals/string/escaped", escaped_string);
1483 g_test_add_func("/literals/string/quotes", string_with_quotes);
1484 g_test_add_func("/literals/string/utf8", utf8_string);
1486 g_test_add_func("/literals/number/int", int_number);
1487 g_test_add_func("/literals/number/uint", uint_number);
1488 g_test_add_func("/literals/number/float", float_number);
1490 g_test_add_func("/literals/keyword", keyword_literal);
1492 g_test_add_func("/literals/interpolation/valid", interpolation_valid);
1493 g_test_add_func("/literals/interpolation/unkown", interpolation_unknown);
1494 g_test_add_func("/literals/interpolation/string", interpolation_string);
1496 g_test_add_func("/dicts/simple_dict", simple_dict);
1497 g_test_add_func("/dicts/large_dict", large_dict);
1498 g_test_add_func("/lists/simple_list", simple_list);
1500 g_test_add_func("/mixed/simple_whitespace", simple_whitespace);
1501 g_test_add_func("/mixed/interpolation", simple_interpolation);
1503 g_test_add_func("/errors/empty", empty_input);
1504 g_test_add_func("/errors/blank", blank_input);
1505 g_test_add_func("/errors/junk", junk_input);
1506 g_test_add_func("/errors/unterminated/string", unterminated_string);
1507 g_test_add_func("/errors/unterminated/escape", unterminated_escape);
1508 g_test_add_func("/errors/unterminated/sq_string", unterminated_sq_string);
1509 g_test_add_func("/errors/unterminated/array", unterminated_array);
1510 g_test_add_func("/errors/unterminated/array_comma", unterminated_array_comma);
1511 g_test_add_func("/errors/unterminated/dict", unterminated_dict);
1512 g_test_add_func("/errors/unterminated/dict_comma", unterminated_dict_comma);
1513 g_test_add_func("/errors/invalid_array_comma", invalid_array_comma);
1514 g_test_add_func("/errors/invalid_dict_comma", invalid_dict_comma);
1515 g_test_add_func("/errors/invalid_dict_key", invalid_dict_key);
1516 g_test_add_func("/errors/unterminated/literal", unterminated_literal);
1517 g_test_add_func("/errors/limits/nesting", limits_nesting);
1518 g_test_add_func("/errors/multiple_values", multiple_values);
1520 return g_test_run();