ppc/pnv: Add support for POWER8+ LPC Controller
[qemu.git] / tests / test-qobject-input-visitor.c
1 /*
2 * QObject Input Visitor unit-tests.
3 *
4 * Copyright (C) 2011-2016 Red Hat Inc.
5 *
6 * Authors:
7 * Luiz Capitulino <lcapitulino@redhat.com>
8 * Paolo Bonzini <pbonzini@redhat.com>
9 *
10 * This work is licensed under the terms of the GNU GPL, version 2 or later.
11 * See the COPYING file in the top-level directory.
12 */
13
14 #include "qemu/osdep.h"
15
16 #include "qemu-common.h"
17 #include "qapi/error.h"
18 #include "qapi/qobject-input-visitor.h"
19 #include "test-qapi-types.h"
20 #include "test-qapi-visit.h"
21 #include "qapi/qmp/types.h"
22 #include "qapi/qmp/qjson.h"
23 #include "test-qmp-introspect.h"
24 #include "qmp-introspect.h"
25 #include "qapi-visit.h"
26
27 typedef struct TestInputVisitorData {
28 QObject *obj;
29 Visitor *qiv;
30 } TestInputVisitorData;
31
32 static void visitor_input_teardown(TestInputVisitorData *data,
33 const void *unused)
34 {
35 qobject_decref(data->obj);
36 data->obj = NULL;
37
38 if (data->qiv) {
39 visit_free(data->qiv);
40 data->qiv = NULL;
41 }
42 }
43
44 /* The various test_init functions are provided instead of a test setup
45 function so that the JSON string used by the tests are kept in the test
46 functions (and not in main()). */
47 static Visitor *visitor_input_test_init_internal(TestInputVisitorData *data,
48 bool keyval,
49 const char *json_string,
50 va_list *ap)
51 {
52 visitor_input_teardown(data, NULL);
53
54 data->obj = qobject_from_jsonv(json_string, ap, &error_abort);
55 g_assert(data->obj);
56
57 if (keyval) {
58 data->qiv = qobject_input_visitor_new_keyval(data->obj);
59 } else {
60 data->qiv = qobject_input_visitor_new(data->obj);
61 }
62 g_assert(data->qiv);
63 return data->qiv;
64 }
65
66 static GCC_FMT_ATTR(3, 4)
67 Visitor *visitor_input_test_init_full(TestInputVisitorData *data,
68 bool keyval,
69 const char *json_string, ...)
70 {
71 Visitor *v;
72 va_list ap;
73
74 va_start(ap, json_string);
75 v = visitor_input_test_init_internal(data, keyval, json_string, &ap);
76 va_end(ap);
77 return v;
78 }
79
80 static GCC_FMT_ATTR(2, 3)
81 Visitor *visitor_input_test_init(TestInputVisitorData *data,
82 const char *json_string, ...)
83 {
84 Visitor *v;
85 va_list ap;
86
87 va_start(ap, json_string);
88 v = visitor_input_test_init_internal(data, false, json_string, &ap);
89 va_end(ap);
90 return v;
91 }
92
93 /* similar to visitor_input_test_init(), but does not expect a string
94 * literal/format json_string argument and so can be used for
95 * programatically generated strings (and we can't pass in programatically
96 * generated strings via %s format parameters since qobject_from_jsonv()
97 * will wrap those in double-quotes and treat the entire object as a
98 * string)
99 */
100 static Visitor *visitor_input_test_init_raw(TestInputVisitorData *data,
101 const char *json_string)
102 {
103 return visitor_input_test_init_internal(data, false, json_string, NULL);
104 }
105
106 static void test_visitor_in_int(TestInputVisitorData *data,
107 const void *unused)
108 {
109 int64_t res = 0;
110 int value = -42;
111 Visitor *v;
112
113 v = visitor_input_test_init(data, "%d", value);
114
115 visit_type_int(v, NULL, &res, &error_abort);
116 g_assert_cmpint(res, ==, value);
117 }
118
119 static void test_visitor_in_uint(TestInputVisitorData *data,
120 const void *unused)
121 {
122 Error *err = NULL;
123 uint64_t res = 0;
124 int value = 42;
125 Visitor *v;
126
127 v = visitor_input_test_init(data, "%d", value);
128
129 visit_type_uint64(v, NULL, &res, &error_abort);
130 g_assert_cmpuint(res, ==, (uint64_t)value);
131
132 /* BUG: value between INT64_MIN and -1 accepted modulo 2^64 */
133
134 v = visitor_input_test_init(data, "%d", -value);
135
136 visit_type_uint64(v, NULL, &res, &error_abort);
137 g_assert_cmpuint(res, ==, (uint64_t)-value);
138
139 /* BUG: value between INT64_MAX+1 and UINT64_MAX rejected */
140
141 v = visitor_input_test_init(data, "18446744073709551574");
142
143 visit_type_uint64(v, NULL, &res, &err);
144 error_free_or_abort(&err);
145 }
146
147 static void test_visitor_in_int_overflow(TestInputVisitorData *data,
148 const void *unused)
149 {
150 int64_t res = 0;
151 Error *err = NULL;
152 Visitor *v;
153
154 /* this will overflow a Qint/int64, so should be deserialized into
155 * a QFloat/double field instead, leading to an error if we pass it
156 * to visit_type_int. confirm this.
157 */
158 v = visitor_input_test_init(data, "%f", DBL_MAX);
159
160 visit_type_int(v, NULL, &res, &err);
161 error_free_or_abort(&err);
162 }
163
164 static void test_visitor_in_int_keyval(TestInputVisitorData *data,
165 const void *unused)
166 {
167 int64_t res = 0, value = -42;
168 Error *err = NULL;
169 Visitor *v;
170
171 v = visitor_input_test_init_full(data, true, "%" PRId64, value);
172 visit_type_int(v, NULL, &res, &err);
173 error_free_or_abort(&err);
174 }
175
176 static void test_visitor_in_int_str_keyval(TestInputVisitorData *data,
177 const void *unused)
178 {
179 int64_t res = 0, value = -42;
180 Visitor *v;
181
182 v = visitor_input_test_init_full(data, true, "\"-42\"");
183
184 visit_type_int(v, NULL, &res, &error_abort);
185 g_assert_cmpint(res, ==, value);
186 }
187
188 static void test_visitor_in_int_str_fail(TestInputVisitorData *data,
189 const void *unused)
190 {
191 int64_t res = 0;
192 Visitor *v;
193 Error *err = NULL;
194
195 v = visitor_input_test_init(data, "\"-42\"");
196
197 visit_type_int(v, NULL, &res, &err);
198 error_free_or_abort(&err);
199 }
200
201 static void test_visitor_in_bool(TestInputVisitorData *data,
202 const void *unused)
203 {
204 bool res = false;
205 Visitor *v;
206
207 v = visitor_input_test_init(data, "true");
208
209 visit_type_bool(v, NULL, &res, &error_abort);
210 g_assert_cmpint(res, ==, true);
211 }
212
213 static void test_visitor_in_bool_keyval(TestInputVisitorData *data,
214 const void *unused)
215 {
216 bool res = false;
217 Error *err = NULL;
218 Visitor *v;
219
220 v = visitor_input_test_init_full(data, true, "true");
221
222 visit_type_bool(v, NULL, &res, &err);
223 error_free_or_abort(&err);
224 }
225
226 static void test_visitor_in_bool_str_keyval(TestInputVisitorData *data,
227 const void *unused)
228 {
229 bool res = false;
230 Visitor *v;
231
232 v = visitor_input_test_init_full(data, true, "\"on\"");
233
234 visit_type_bool(v, NULL, &res, &error_abort);
235 g_assert_cmpint(res, ==, true);
236 }
237
238 static void test_visitor_in_bool_str_fail(TestInputVisitorData *data,
239 const void *unused)
240 {
241 bool res = false;
242 Visitor *v;
243 Error *err = NULL;
244
245 v = visitor_input_test_init(data, "\"true\"");
246
247 visit_type_bool(v, NULL, &res, &err);
248 error_free_or_abort(&err);
249 }
250
251 static void test_visitor_in_number(TestInputVisitorData *data,
252 const void *unused)
253 {
254 double res = 0, value = 3.14;
255 Visitor *v;
256
257 v = visitor_input_test_init(data, "%f", value);
258
259 visit_type_number(v, NULL, &res, &error_abort);
260 g_assert_cmpfloat(res, ==, value);
261 }
262
263 static void test_visitor_in_number_keyval(TestInputVisitorData *data,
264 const void *unused)
265 {
266 double res = 0, value = 3.14;
267 Error *err = NULL;
268 Visitor *v;
269
270 v = visitor_input_test_init_full(data, true, "%f", value);
271
272 visit_type_number(v, NULL, &res, &err);
273 error_free_or_abort(&err);
274 }
275
276 static void test_visitor_in_number_str_keyval(TestInputVisitorData *data,
277 const void *unused)
278 {
279 double res = 0, value = 3.14;
280 Visitor *v;
281
282 v = visitor_input_test_init_full(data, true, "\"3.14\"");
283
284 visit_type_number(v, NULL, &res, &error_abort);
285 g_assert_cmpfloat(res, ==, value);
286 }
287
288 static void test_visitor_in_number_str_fail(TestInputVisitorData *data,
289 const void *unused)
290 {
291 double res = 0;
292 Visitor *v;
293 Error *err = NULL;
294
295 v = visitor_input_test_init(data, "\"3.14\"");
296
297 visit_type_number(v, NULL, &res, &err);
298 error_free_or_abort(&err);
299 }
300
301 static void test_visitor_in_size_str_keyval(TestInputVisitorData *data,
302 const void *unused)
303 {
304 uint64_t res, value = 500 * 1024 * 1024;
305 Visitor *v;
306
307 v = visitor_input_test_init_full(data, true, "\"500M\"");
308
309 visit_type_size(v, NULL, &res, &error_abort);
310 g_assert_cmpfloat(res, ==, value);
311 }
312
313 static void test_visitor_in_size_str_fail(TestInputVisitorData *data,
314 const void *unused)
315 {
316 uint64_t res = 0;
317 Visitor *v;
318 Error *err = NULL;
319
320 v = visitor_input_test_init(data, "\"500M\"");
321
322 visit_type_size(v, NULL, &res, &err);
323 error_free_or_abort(&err);
324 }
325
326 static void test_visitor_in_string(TestInputVisitorData *data,
327 const void *unused)
328 {
329 char *res = NULL, *value = (char *) "Q E M U";
330 Visitor *v;
331
332 v = visitor_input_test_init(data, "%s", value);
333
334 visit_type_str(v, NULL, &res, &error_abort);
335 g_assert_cmpstr(res, ==, value);
336
337 g_free(res);
338 }
339
340 static void test_visitor_in_enum(TestInputVisitorData *data,
341 const void *unused)
342 {
343 Visitor *v;
344 EnumOne i;
345
346 for (i = 0; EnumOne_lookup[i]; i++) {
347 EnumOne res = -1;
348
349 v = visitor_input_test_init(data, "%s", EnumOne_lookup[i]);
350
351 visit_type_EnumOne(v, NULL, &res, &error_abort);
352 g_assert_cmpint(i, ==, res);
353 }
354 }
355
356
357 static void test_visitor_in_struct(TestInputVisitorData *data,
358 const void *unused)
359 {
360 TestStruct *p = NULL;
361 Visitor *v;
362
363 v = visitor_input_test_init(data, "{ 'integer': -42, 'boolean': true, 'string': 'foo' }");
364
365 visit_type_TestStruct(v, NULL, &p, &error_abort);
366 g_assert_cmpint(p->integer, ==, -42);
367 g_assert(p->boolean == true);
368 g_assert_cmpstr(p->string, ==, "foo");
369
370 g_free(p->string);
371 g_free(p);
372 }
373
374 static void test_visitor_in_struct_nested(TestInputVisitorData *data,
375 const void *unused)
376 {
377 UserDefTwo *udp = NULL;
378 Visitor *v;
379
380 v = visitor_input_test_init(data, "{ 'string0': 'string0', "
381 "'dict1': { 'string1': 'string1', "
382 "'dict2': { 'userdef': { 'integer': 42, "
383 "'string': 'string' }, 'string': 'string2'}}}");
384
385 visit_type_UserDefTwo(v, NULL, &udp, &error_abort);
386
387 g_assert_cmpstr(udp->string0, ==, "string0");
388 g_assert_cmpstr(udp->dict1->string1, ==, "string1");
389 g_assert_cmpint(udp->dict1->dict2->userdef->integer, ==, 42);
390 g_assert_cmpstr(udp->dict1->dict2->userdef->string, ==, "string");
391 g_assert_cmpstr(udp->dict1->dict2->string, ==, "string2");
392 g_assert(udp->dict1->has_dict3 == false);
393
394 qapi_free_UserDefTwo(udp);
395 }
396
397 static void test_visitor_in_list(TestInputVisitorData *data,
398 const void *unused)
399 {
400 UserDefOneList *item, *head = NULL;
401 Visitor *v;
402 int i;
403
404 v = visitor_input_test_init(data, "[ { 'string': 'string0', 'integer': 42 }, { 'string': 'string1', 'integer': 43 }, { 'string': 'string2', 'integer': 44 } ]");
405
406 visit_type_UserDefOneList(v, NULL, &head, &error_abort);
407 g_assert(head != NULL);
408
409 for (i = 0, item = head; item; item = item->next, i++) {
410 char string[12];
411
412 snprintf(string, sizeof(string), "string%d", i);
413 g_assert_cmpstr(item->value->string, ==, string);
414 g_assert_cmpint(item->value->integer, ==, 42 + i);
415 }
416
417 qapi_free_UserDefOneList(head);
418 head = NULL;
419
420 /* An empty list is valid */
421 v = visitor_input_test_init(data, "[]");
422 visit_type_UserDefOneList(v, NULL, &head, &error_abort);
423 g_assert(!head);
424 }
425
426 static void test_visitor_in_any(TestInputVisitorData *data,
427 const void *unused)
428 {
429 QObject *res = NULL;
430 Visitor *v;
431 QInt *qint;
432 QBool *qbool;
433 QString *qstring;
434 QDict *qdict;
435 QObject *qobj;
436
437 v = visitor_input_test_init(data, "-42");
438 visit_type_any(v, NULL, &res, &error_abort);
439 qint = qobject_to_qint(res);
440 g_assert(qint);
441 g_assert_cmpint(qint_get_int(qint), ==, -42);
442 qobject_decref(res);
443
444 v = visitor_input_test_init(data, "{ 'integer': -42, 'boolean': true, 'string': 'foo' }");
445 visit_type_any(v, NULL, &res, &error_abort);
446 qdict = qobject_to_qdict(res);
447 g_assert(qdict && qdict_size(qdict) == 3);
448 qobj = qdict_get(qdict, "integer");
449 g_assert(qobj);
450 qint = qobject_to_qint(qobj);
451 g_assert(qint);
452 g_assert_cmpint(qint_get_int(qint), ==, -42);
453 qobj = qdict_get(qdict, "boolean");
454 g_assert(qobj);
455 qbool = qobject_to_qbool(qobj);
456 g_assert(qbool);
457 g_assert(qbool_get_bool(qbool) == true);
458 qobj = qdict_get(qdict, "string");
459 g_assert(qobj);
460 qstring = qobject_to_qstring(qobj);
461 g_assert(qstring);
462 g_assert_cmpstr(qstring_get_str(qstring), ==, "foo");
463 qobject_decref(res);
464 }
465
466 static void test_visitor_in_null(TestInputVisitorData *data,
467 const void *unused)
468 {
469 Visitor *v;
470 Error *err = NULL;
471 char *tmp;
472
473 /*
474 * FIXME: Since QAPI doesn't know the 'null' type yet, we can't
475 * test visit_type_null() by reading into a QAPI struct then
476 * checking that it was populated correctly. The best we can do
477 * for now is ensure that we consumed null from the input, proven
478 * by the fact that we can't re-read the key; and that we detect
479 * when input is not null.
480 */
481
482 v = visitor_input_test_init_full(data, false,
483 "{ 'a': null, 'b': '' }");
484 visit_start_struct(v, NULL, NULL, 0, &error_abort);
485 visit_type_null(v, "a", &error_abort);
486 visit_type_null(v, "b", &err);
487 error_free_or_abort(&err);
488 visit_type_str(v, "c", &tmp, &err);
489 g_assert(!tmp);
490 error_free_or_abort(&err);
491 visit_check_struct(v, &error_abort);
492 visit_end_struct(v, NULL);
493 }
494
495 static void test_visitor_in_union_flat(TestInputVisitorData *data,
496 const void *unused)
497 {
498 Visitor *v;
499 UserDefFlatUnion *tmp;
500 UserDefUnionBase *base;
501
502 v = visitor_input_test_init(data,
503 "{ 'enum1': 'value1', "
504 "'integer': 41, "
505 "'string': 'str', "
506 "'boolean': true }");
507
508 visit_type_UserDefFlatUnion(v, NULL, &tmp, &error_abort);
509 g_assert_cmpint(tmp->enum1, ==, ENUM_ONE_VALUE1);
510 g_assert_cmpstr(tmp->string, ==, "str");
511 g_assert_cmpint(tmp->integer, ==, 41);
512 g_assert_cmpint(tmp->u.value1.boolean, ==, true);
513
514 base = qapi_UserDefFlatUnion_base(tmp);
515 g_assert(&base->enum1 == &tmp->enum1);
516
517 qapi_free_UserDefFlatUnion(tmp);
518 }
519
520 static void test_visitor_in_alternate(TestInputVisitorData *data,
521 const void *unused)
522 {
523 Visitor *v;
524 Error *err = NULL;
525 UserDefAlternate *tmp;
526 WrapAlternate *wrap;
527
528 v = visitor_input_test_init(data, "42");
529 visit_type_UserDefAlternate(v, NULL, &tmp, &error_abort);
530 g_assert_cmpint(tmp->type, ==, QTYPE_QINT);
531 g_assert_cmpint(tmp->u.i, ==, 42);
532 qapi_free_UserDefAlternate(tmp);
533
534 v = visitor_input_test_init(data, "'string'");
535 visit_type_UserDefAlternate(v, NULL, &tmp, &error_abort);
536 g_assert_cmpint(tmp->type, ==, QTYPE_QSTRING);
537 g_assert_cmpstr(tmp->u.s, ==, "string");
538 qapi_free_UserDefAlternate(tmp);
539
540 v = visitor_input_test_init(data, "{'integer':1, 'string':'str', "
541 "'enum1':'value1', 'boolean':true}");
542 visit_type_UserDefAlternate(v, NULL, &tmp, &error_abort);
543 g_assert_cmpint(tmp->type, ==, QTYPE_QDICT);
544 g_assert_cmpint(tmp->u.udfu.integer, ==, 1);
545 g_assert_cmpstr(tmp->u.udfu.string, ==, "str");
546 g_assert_cmpint(tmp->u.udfu.enum1, ==, ENUM_ONE_VALUE1);
547 g_assert_cmpint(tmp->u.udfu.u.value1.boolean, ==, true);
548 g_assert_cmpint(tmp->u.udfu.u.value1.has_a_b, ==, false);
549 qapi_free_UserDefAlternate(tmp);
550
551 v = visitor_input_test_init(data, "false");
552 visit_type_UserDefAlternate(v, NULL, &tmp, &err);
553 error_free_or_abort(&err);
554 qapi_free_UserDefAlternate(tmp);
555
556 v = visitor_input_test_init(data, "{ 'alt': 42 }");
557 visit_type_WrapAlternate(v, NULL, &wrap, &error_abort);
558 g_assert_cmpint(wrap->alt->type, ==, QTYPE_QINT);
559 g_assert_cmpint(wrap->alt->u.i, ==, 42);
560 qapi_free_WrapAlternate(wrap);
561
562 v = visitor_input_test_init(data, "{ 'alt': 'string' }");
563 visit_type_WrapAlternate(v, NULL, &wrap, &error_abort);
564 g_assert_cmpint(wrap->alt->type, ==, QTYPE_QSTRING);
565 g_assert_cmpstr(wrap->alt->u.s, ==, "string");
566 qapi_free_WrapAlternate(wrap);
567
568 v = visitor_input_test_init(data, "{ 'alt': {'integer':1, 'string':'str', "
569 "'enum1':'value1', 'boolean':true} }");
570 visit_type_WrapAlternate(v, NULL, &wrap, &error_abort);
571 g_assert_cmpint(wrap->alt->type, ==, QTYPE_QDICT);
572 g_assert_cmpint(wrap->alt->u.udfu.integer, ==, 1);
573 g_assert_cmpstr(wrap->alt->u.udfu.string, ==, "str");
574 g_assert_cmpint(wrap->alt->u.udfu.enum1, ==, ENUM_ONE_VALUE1);
575 g_assert_cmpint(wrap->alt->u.udfu.u.value1.boolean, ==, true);
576 g_assert_cmpint(wrap->alt->u.udfu.u.value1.has_a_b, ==, false);
577 qapi_free_WrapAlternate(wrap);
578 }
579
580 static void test_visitor_in_alternate_number(TestInputVisitorData *data,
581 const void *unused)
582 {
583 Visitor *v;
584 Error *err = NULL;
585 AltStrBool *asb;
586 AltStrNum *asn;
587 AltNumStr *ans;
588 AltStrInt *asi;
589 AltIntNum *ain;
590 AltNumInt *ani;
591
592 /* Parsing an int */
593
594 v = visitor_input_test_init(data, "42");
595 visit_type_AltStrBool(v, NULL, &asb, &err);
596 error_free_or_abort(&err);
597 qapi_free_AltStrBool(asb);
598
599 v = visitor_input_test_init(data, "42");
600 visit_type_AltStrNum(v, NULL, &asn, &error_abort);
601 g_assert_cmpint(asn->type, ==, QTYPE_QFLOAT);
602 g_assert_cmpfloat(asn->u.n, ==, 42);
603 qapi_free_AltStrNum(asn);
604
605 v = visitor_input_test_init(data, "42");
606 visit_type_AltNumStr(v, NULL, &ans, &error_abort);
607 g_assert_cmpint(ans->type, ==, QTYPE_QFLOAT);
608 g_assert_cmpfloat(ans->u.n, ==, 42);
609 qapi_free_AltNumStr(ans);
610
611 v = visitor_input_test_init(data, "42");
612 visit_type_AltStrInt(v, NULL, &asi, &error_abort);
613 g_assert_cmpint(asi->type, ==, QTYPE_QINT);
614 g_assert_cmpint(asi->u.i, ==, 42);
615 qapi_free_AltStrInt(asi);
616
617 v = visitor_input_test_init(data, "42");
618 visit_type_AltIntNum(v, NULL, &ain, &error_abort);
619 g_assert_cmpint(ain->type, ==, QTYPE_QINT);
620 g_assert_cmpint(ain->u.i, ==, 42);
621 qapi_free_AltIntNum(ain);
622
623 v = visitor_input_test_init(data, "42");
624 visit_type_AltNumInt(v, NULL, &ani, &error_abort);
625 g_assert_cmpint(ani->type, ==, QTYPE_QINT);
626 g_assert_cmpint(ani->u.i, ==, 42);
627 qapi_free_AltNumInt(ani);
628
629 /* Parsing a double */
630
631 v = visitor_input_test_init(data, "42.5");
632 visit_type_AltStrBool(v, NULL, &asb, &err);
633 error_free_or_abort(&err);
634 qapi_free_AltStrBool(asb);
635
636 v = visitor_input_test_init(data, "42.5");
637 visit_type_AltStrNum(v, NULL, &asn, &error_abort);
638 g_assert_cmpint(asn->type, ==, QTYPE_QFLOAT);
639 g_assert_cmpfloat(asn->u.n, ==, 42.5);
640 qapi_free_AltStrNum(asn);
641
642 v = visitor_input_test_init(data, "42.5");
643 visit_type_AltNumStr(v, NULL, &ans, &error_abort);
644 g_assert_cmpint(ans->type, ==, QTYPE_QFLOAT);
645 g_assert_cmpfloat(ans->u.n, ==, 42.5);
646 qapi_free_AltNumStr(ans);
647
648 v = visitor_input_test_init(data, "42.5");
649 visit_type_AltStrInt(v, NULL, &asi, &err);
650 error_free_or_abort(&err);
651 qapi_free_AltStrInt(asi);
652
653 v = visitor_input_test_init(data, "42.5");
654 visit_type_AltIntNum(v, NULL, &ain, &error_abort);
655 g_assert_cmpint(ain->type, ==, QTYPE_QFLOAT);
656 g_assert_cmpfloat(ain->u.n, ==, 42.5);
657 qapi_free_AltIntNum(ain);
658
659 v = visitor_input_test_init(data, "42.5");
660 visit_type_AltNumInt(v, NULL, &ani, &error_abort);
661 g_assert_cmpint(ani->type, ==, QTYPE_QFLOAT);
662 g_assert_cmpfloat(ani->u.n, ==, 42.5);
663 qapi_free_AltNumInt(ani);
664 }
665
666 static void test_native_list_integer_helper(TestInputVisitorData *data,
667 const void *unused,
668 UserDefNativeListUnionKind kind)
669 {
670 UserDefNativeListUnion *cvalue = NULL;
671 Visitor *v;
672 GString *gstr_list = g_string_new("");
673 GString *gstr_union = g_string_new("");
674 int i;
675
676 for (i = 0; i < 32; i++) {
677 g_string_append_printf(gstr_list, "%d", i);
678 if (i != 31) {
679 g_string_append(gstr_list, ", ");
680 }
681 }
682 g_string_append_printf(gstr_union, "{ 'type': '%s', 'data': [ %s ] }",
683 UserDefNativeListUnionKind_lookup[kind],
684 gstr_list->str);
685 v = visitor_input_test_init_raw(data, gstr_union->str);
686
687 visit_type_UserDefNativeListUnion(v, NULL, &cvalue, &error_abort);
688 g_assert(cvalue != NULL);
689 g_assert_cmpint(cvalue->type, ==, kind);
690
691 switch (kind) {
692 case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER: {
693 intList *elem = NULL;
694 for (i = 0, elem = cvalue->u.integer.data;
695 elem; elem = elem->next, i++) {
696 g_assert_cmpint(elem->value, ==, i);
697 }
698 break;
699 }
700 case USER_DEF_NATIVE_LIST_UNION_KIND_S8: {
701 int8List *elem = NULL;
702 for (i = 0, elem = cvalue->u.s8.data; elem; elem = elem->next, i++) {
703 g_assert_cmpint(elem->value, ==, i);
704 }
705 break;
706 }
707 case USER_DEF_NATIVE_LIST_UNION_KIND_S16: {
708 int16List *elem = NULL;
709 for (i = 0, elem = cvalue->u.s16.data; elem; elem = elem->next, i++) {
710 g_assert_cmpint(elem->value, ==, i);
711 }
712 break;
713 }
714 case USER_DEF_NATIVE_LIST_UNION_KIND_S32: {
715 int32List *elem = NULL;
716 for (i = 0, elem = cvalue->u.s32.data; elem; elem = elem->next, i++) {
717 g_assert_cmpint(elem->value, ==, i);
718 }
719 break;
720 }
721 case USER_DEF_NATIVE_LIST_UNION_KIND_S64: {
722 int64List *elem = NULL;
723 for (i = 0, elem = cvalue->u.s64.data; elem; elem = elem->next, i++) {
724 g_assert_cmpint(elem->value, ==, i);
725 }
726 break;
727 }
728 case USER_DEF_NATIVE_LIST_UNION_KIND_U8: {
729 uint8List *elem = NULL;
730 for (i = 0, elem = cvalue->u.u8.data; elem; elem = elem->next, i++) {
731 g_assert_cmpint(elem->value, ==, i);
732 }
733 break;
734 }
735 case USER_DEF_NATIVE_LIST_UNION_KIND_U16: {
736 uint16List *elem = NULL;
737 for (i = 0, elem = cvalue->u.u16.data; elem; elem = elem->next, i++) {
738 g_assert_cmpint(elem->value, ==, i);
739 }
740 break;
741 }
742 case USER_DEF_NATIVE_LIST_UNION_KIND_U32: {
743 uint32List *elem = NULL;
744 for (i = 0, elem = cvalue->u.u32.data; elem; elem = elem->next, i++) {
745 g_assert_cmpint(elem->value, ==, i);
746 }
747 break;
748 }
749 case USER_DEF_NATIVE_LIST_UNION_KIND_U64: {
750 uint64List *elem = NULL;
751 for (i = 0, elem = cvalue->u.u64.data; elem; elem = elem->next, i++) {
752 g_assert_cmpint(elem->value, ==, i);
753 }
754 break;
755 }
756 default:
757 g_assert_not_reached();
758 }
759
760 g_string_free(gstr_union, true);
761 g_string_free(gstr_list, true);
762 qapi_free_UserDefNativeListUnion(cvalue);
763 }
764
765 static void test_visitor_in_native_list_int(TestInputVisitorData *data,
766 const void *unused)
767 {
768 test_native_list_integer_helper(data, unused,
769 USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER);
770 }
771
772 static void test_visitor_in_native_list_int8(TestInputVisitorData *data,
773 const void *unused)
774 {
775 test_native_list_integer_helper(data, unused,
776 USER_DEF_NATIVE_LIST_UNION_KIND_S8);
777 }
778
779 static void test_visitor_in_native_list_int16(TestInputVisitorData *data,
780 const void *unused)
781 {
782 test_native_list_integer_helper(data, unused,
783 USER_DEF_NATIVE_LIST_UNION_KIND_S16);
784 }
785
786 static void test_visitor_in_native_list_int32(TestInputVisitorData *data,
787 const void *unused)
788 {
789 test_native_list_integer_helper(data, unused,
790 USER_DEF_NATIVE_LIST_UNION_KIND_S32);
791 }
792
793 static void test_visitor_in_native_list_int64(TestInputVisitorData *data,
794 const void *unused)
795 {
796 test_native_list_integer_helper(data, unused,
797 USER_DEF_NATIVE_LIST_UNION_KIND_S64);
798 }
799
800 static void test_visitor_in_native_list_uint8(TestInputVisitorData *data,
801 const void *unused)
802 {
803 test_native_list_integer_helper(data, unused,
804 USER_DEF_NATIVE_LIST_UNION_KIND_U8);
805 }
806
807 static void test_visitor_in_native_list_uint16(TestInputVisitorData *data,
808 const void *unused)
809 {
810 test_native_list_integer_helper(data, unused,
811 USER_DEF_NATIVE_LIST_UNION_KIND_U16);
812 }
813
814 static void test_visitor_in_native_list_uint32(TestInputVisitorData *data,
815 const void *unused)
816 {
817 test_native_list_integer_helper(data, unused,
818 USER_DEF_NATIVE_LIST_UNION_KIND_U32);
819 }
820
821 static void test_visitor_in_native_list_uint64(TestInputVisitorData *data,
822 const void *unused)
823 {
824 test_native_list_integer_helper(data, unused,
825 USER_DEF_NATIVE_LIST_UNION_KIND_U64);
826 }
827
828 static void test_visitor_in_native_list_bool(TestInputVisitorData *data,
829 const void *unused)
830 {
831 UserDefNativeListUnion *cvalue = NULL;
832 boolList *elem = NULL;
833 Visitor *v;
834 GString *gstr_list = g_string_new("");
835 GString *gstr_union = g_string_new("");
836 int i;
837
838 for (i = 0; i < 32; i++) {
839 g_string_append_printf(gstr_list, "%s",
840 (i % 3 == 0) ? "true" : "false");
841 if (i != 31) {
842 g_string_append(gstr_list, ", ");
843 }
844 }
845 g_string_append_printf(gstr_union, "{ 'type': 'boolean', 'data': [ %s ] }",
846 gstr_list->str);
847 v = visitor_input_test_init_raw(data, gstr_union->str);
848
849 visit_type_UserDefNativeListUnion(v, NULL, &cvalue, &error_abort);
850 g_assert(cvalue != NULL);
851 g_assert_cmpint(cvalue->type, ==, USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN);
852
853 for (i = 0, elem = cvalue->u.boolean.data; elem; elem = elem->next, i++) {
854 g_assert_cmpint(elem->value, ==, (i % 3 == 0) ? 1 : 0);
855 }
856
857 g_string_free(gstr_union, true);
858 g_string_free(gstr_list, true);
859 qapi_free_UserDefNativeListUnion(cvalue);
860 }
861
862 static void test_visitor_in_native_list_string(TestInputVisitorData *data,
863 const void *unused)
864 {
865 UserDefNativeListUnion *cvalue = NULL;
866 strList *elem = NULL;
867 Visitor *v;
868 GString *gstr_list = g_string_new("");
869 GString *gstr_union = g_string_new("");
870 int i;
871
872 for (i = 0; i < 32; i++) {
873 g_string_append_printf(gstr_list, "'%d'", i);
874 if (i != 31) {
875 g_string_append(gstr_list, ", ");
876 }
877 }
878 g_string_append_printf(gstr_union, "{ 'type': 'string', 'data': [ %s ] }",
879 gstr_list->str);
880 v = visitor_input_test_init_raw(data, gstr_union->str);
881
882 visit_type_UserDefNativeListUnion(v, NULL, &cvalue, &error_abort);
883 g_assert(cvalue != NULL);
884 g_assert_cmpint(cvalue->type, ==, USER_DEF_NATIVE_LIST_UNION_KIND_STRING);
885
886 for (i = 0, elem = cvalue->u.string.data; elem; elem = elem->next, i++) {
887 gchar str[8];
888 sprintf(str, "%d", i);
889 g_assert_cmpstr(elem->value, ==, str);
890 }
891
892 g_string_free(gstr_union, true);
893 g_string_free(gstr_list, true);
894 qapi_free_UserDefNativeListUnion(cvalue);
895 }
896
897 #define DOUBLE_STR_MAX 16
898
899 static void test_visitor_in_native_list_number(TestInputVisitorData *data,
900 const void *unused)
901 {
902 UserDefNativeListUnion *cvalue = NULL;
903 numberList *elem = NULL;
904 Visitor *v;
905 GString *gstr_list = g_string_new("");
906 GString *gstr_union = g_string_new("");
907 int i;
908
909 for (i = 0; i < 32; i++) {
910 g_string_append_printf(gstr_list, "%f", (double)i / 3);
911 if (i != 31) {
912 g_string_append(gstr_list, ", ");
913 }
914 }
915 g_string_append_printf(gstr_union, "{ 'type': 'number', 'data': [ %s ] }",
916 gstr_list->str);
917 v = visitor_input_test_init_raw(data, gstr_union->str);
918
919 visit_type_UserDefNativeListUnion(v, NULL, &cvalue, &error_abort);
920 g_assert(cvalue != NULL);
921 g_assert_cmpint(cvalue->type, ==, USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER);
922
923 for (i = 0, elem = cvalue->u.number.data; elem; elem = elem->next, i++) {
924 GString *double_expected = g_string_new("");
925 GString *double_actual = g_string_new("");
926
927 g_string_printf(double_expected, "%.6f", (double)i / 3);
928 g_string_printf(double_actual, "%.6f", elem->value);
929 g_assert_cmpstr(double_expected->str, ==, double_actual->str);
930
931 g_string_free(double_expected, true);
932 g_string_free(double_actual, true);
933 }
934
935 g_string_free(gstr_union, true);
936 g_string_free(gstr_list, true);
937 qapi_free_UserDefNativeListUnion(cvalue);
938 }
939
940 static void input_visitor_test_add(const char *testpath,
941 const void *user_data,
942 void (*test_func)(TestInputVisitorData *data,
943 const void *user_data))
944 {
945 g_test_add(testpath, TestInputVisitorData, user_data, NULL, test_func,
946 visitor_input_teardown);
947 }
948
949 static void test_visitor_in_errors(TestInputVisitorData *data,
950 const void *unused)
951 {
952 TestStruct *p = NULL;
953 Error *err = NULL;
954 Visitor *v;
955 strList *q = NULL;
956 UserDefTwo *r = NULL;
957 WrapAlternate *s = NULL;
958
959 v = visitor_input_test_init(data, "{ 'integer': false, 'boolean': 'foo', "
960 "'string': -42 }");
961
962 visit_type_TestStruct(v, NULL, &p, &err);
963 error_free_or_abort(&err);
964 g_assert(!p);
965
966 v = visitor_input_test_init(data, "[ '1', '2', false, '3' ]");
967 visit_type_strList(v, NULL, &q, &err);
968 error_free_or_abort(&err);
969 assert(!q);
970
971 v = visitor_input_test_init(data, "{ 'str':'hi' }");
972 visit_type_UserDefTwo(v, NULL, &r, &err);
973 error_free_or_abort(&err);
974 assert(!r);
975
976 v = visitor_input_test_init(data, "{ }");
977 visit_type_WrapAlternate(v, NULL, &s, &err);
978 error_free_or_abort(&err);
979 assert(!s);
980 }
981
982 static void test_visitor_in_wrong_type(TestInputVisitorData *data,
983 const void *unused)
984 {
985 TestStruct *p = NULL;
986 Visitor *v;
987 strList *q = NULL;
988 int64_t i;
989 Error *err = NULL;
990
991 /* Make sure arrays and structs cannot be confused */
992
993 v = visitor_input_test_init(data, "[]");
994 visit_type_TestStruct(v, NULL, &p, &err);
995 error_free_or_abort(&err);
996 g_assert(!p);
997
998 v = visitor_input_test_init(data, "{}");
999 visit_type_strList(v, NULL, &q, &err);
1000 error_free_or_abort(&err);
1001 assert(!q);
1002
1003 /* Make sure primitives and struct cannot be confused */
1004
1005 v = visitor_input_test_init(data, "1");
1006 visit_type_TestStruct(v, NULL, &p, &err);
1007 error_free_or_abort(&err);
1008 g_assert(!p);
1009
1010 v = visitor_input_test_init(data, "{}");
1011 visit_type_int(v, NULL, &i, &err);
1012 error_free_or_abort(&err);
1013
1014 /* Make sure primitives and arrays cannot be confused */
1015
1016 v = visitor_input_test_init(data, "1");
1017 visit_type_strList(v, NULL, &q, &err);
1018 error_free_or_abort(&err);
1019 assert(!q);
1020
1021 v = visitor_input_test_init(data, "[]");
1022 visit_type_int(v, NULL, &i, &err);
1023 error_free_or_abort(&err);
1024 }
1025
1026 static void test_visitor_in_fail_struct(TestInputVisitorData *data,
1027 const void *unused)
1028 {
1029 TestStruct *p = NULL;
1030 Error *err = NULL;
1031 Visitor *v;
1032
1033 v = visitor_input_test_init(data, "{ 'integer': -42, 'boolean': true, 'string': 'foo', 'extra': 42 }");
1034
1035 visit_type_TestStruct(v, NULL, &p, &err);
1036 error_free_or_abort(&err);
1037 g_assert(!p);
1038 }
1039
1040 static void test_visitor_in_fail_struct_nested(TestInputVisitorData *data,
1041 const void *unused)
1042 {
1043 UserDefTwo *udp = NULL;
1044 Error *err = NULL;
1045 Visitor *v;
1046
1047 v = visitor_input_test_init(data, "{ 'string0': 'string0', 'dict1': { 'string1': 'string1', 'dict2': { 'userdef1': { 'integer': 42, 'string': 'string', 'extra': [42, 23, {'foo':'bar'}] }, 'string2': 'string2'}}}");
1048
1049 visit_type_UserDefTwo(v, NULL, &udp, &err);
1050 error_free_or_abort(&err);
1051 g_assert(!udp);
1052 }
1053
1054 static void test_visitor_in_fail_struct_in_list(TestInputVisitorData *data,
1055 const void *unused)
1056 {
1057 UserDefOneList *head = NULL;
1058 Error *err = NULL;
1059 Visitor *v;
1060
1061 v = visitor_input_test_init(data, "[ { 'string': 'string0', 'integer': 42 }, { 'string': 'string1', 'integer': 43 }, { 'string': 'string2', 'integer': 44, 'extra': 'ggg' } ]");
1062
1063 visit_type_UserDefOneList(v, NULL, &head, &err);
1064 error_free_or_abort(&err);
1065 g_assert(!head);
1066 }
1067
1068 static void test_visitor_in_fail_struct_missing(TestInputVisitorData *data,
1069 const void *unused)
1070 {
1071 Error *err = NULL;
1072 Visitor *v;
1073 QObject *any;
1074 GenericAlternate *alt;
1075 bool present;
1076 int en;
1077 int64_t i64;
1078 uint32_t u32;
1079 int8_t i8;
1080 char *str;
1081 double dbl;
1082
1083 v = visitor_input_test_init(data, "{ 'sub': [ {} ] }");
1084 visit_start_struct(v, NULL, NULL, 0, &error_abort);
1085 visit_start_struct(v, "struct", NULL, 0, &err);
1086 error_free_or_abort(&err);
1087 visit_start_list(v, "list", NULL, 0, &err);
1088 error_free_or_abort(&err);
1089 visit_start_alternate(v, "alternate", &alt, sizeof(*alt), false, &err);
1090 error_free_or_abort(&err);
1091 visit_optional(v, "optional", &present);
1092 g_assert(!present);
1093 visit_type_enum(v, "enum", &en, EnumOne_lookup, &err);
1094 error_free_or_abort(&err);
1095 visit_type_int(v, "i64", &i64, &err);
1096 error_free_or_abort(&err);
1097 visit_type_uint32(v, "u32", &u32, &err);
1098 error_free_or_abort(&err);
1099 visit_type_int8(v, "i8", &i8, &err);
1100 error_free_or_abort(&err);
1101 visit_type_str(v, "i8", &str, &err);
1102 error_free_or_abort(&err);
1103 visit_type_number(v, "dbl", &dbl, &err);
1104 error_free_or_abort(&err);
1105 visit_type_any(v, "any", &any, &err);
1106 error_free_or_abort(&err);
1107 visit_type_null(v, "null", &err);
1108 error_free_or_abort(&err);
1109 visit_start_list(v, "sub", NULL, 0, &error_abort);
1110 visit_start_struct(v, NULL, NULL, 0, &error_abort);
1111 visit_type_int(v, "i64", &i64, &err);
1112 error_free_or_abort(&err);
1113 visit_end_struct(v, NULL);
1114 visit_end_list(v, NULL);
1115 visit_end_struct(v, NULL);
1116 }
1117
1118 static void test_visitor_in_fail_list(TestInputVisitorData *data,
1119 const void *unused)
1120 {
1121 int64_t i64 = -1;
1122 Error *err = NULL;
1123 Visitor *v;
1124
1125 /* Unvisited list tail */
1126
1127 v = visitor_input_test_init(data, "[ 1, 2, 3 ]");
1128
1129 visit_start_list(v, NULL, NULL, 0, &error_abort);
1130 visit_type_int(v, NULL, &i64, &error_abort);
1131 g_assert_cmpint(i64, ==, 1);
1132 visit_type_int(v, NULL, &i64, &error_abort);
1133 g_assert_cmpint(i64, ==, 2);
1134 visit_check_list(v, &err);
1135 error_free_or_abort(&err);
1136 visit_end_list(v, NULL);
1137
1138 /* Visit beyond end of list */
1139 v = visitor_input_test_init(data, "[]");
1140
1141 visit_start_list(v, NULL, NULL, 0, &error_abort);
1142 visit_type_int(v, NULL, &i64, &err);
1143 error_free_or_abort(&err);
1144 visit_end_list(v, NULL);
1145 }
1146
1147 static void test_visitor_in_fail_list_nested(TestInputVisitorData *data,
1148 const void *unused)
1149 {
1150 int64_t i64 = -1;
1151 Error *err = NULL;
1152 Visitor *v;
1153
1154 /* Unvisited nested list tail */
1155
1156 v = visitor_input_test_init(data, "[ 0, [ 1, 2, 3 ] ]");
1157
1158 visit_start_list(v, NULL, NULL, 0, &error_abort);
1159 visit_type_int(v, NULL, &i64, &error_abort);
1160 g_assert_cmpint(i64, ==, 0);
1161 visit_start_list(v, NULL, NULL, 0, &error_abort);
1162 visit_type_int(v, NULL, &i64, &error_abort);
1163 g_assert_cmpint(i64, ==, 1);
1164 visit_check_list(v, &err);
1165 error_free_or_abort(&err);
1166 visit_end_list(v, NULL);
1167 visit_check_list(v, &error_abort);
1168 visit_end_list(v, NULL);
1169 }
1170
1171 static void test_visitor_in_fail_union_native_list(TestInputVisitorData *data,
1172 const void *unused)
1173 {
1174 UserDefNativeListUnion *tmp = NULL;
1175 Error *err = NULL;
1176 Visitor *v;
1177
1178 v = visitor_input_test_init(data,
1179 "{ 'type': 'integer', 'data' : [ 'string' ] }");
1180
1181 visit_type_UserDefNativeListUnion(v, NULL, &tmp, &err);
1182 error_free_or_abort(&err);
1183 g_assert(!tmp);
1184 }
1185
1186 static void test_visitor_in_fail_union_flat(TestInputVisitorData *data,
1187 const void *unused)
1188 {
1189 UserDefFlatUnion *tmp = NULL;
1190 Error *err = NULL;
1191 Visitor *v;
1192
1193 v = visitor_input_test_init(data, "{ 'string': 'c', 'integer': 41, 'boolean': true }");
1194
1195 visit_type_UserDefFlatUnion(v, NULL, &tmp, &err);
1196 error_free_or_abort(&err);
1197 g_assert(!tmp);
1198 }
1199
1200 static void test_visitor_in_fail_union_flat_no_discrim(TestInputVisitorData *data,
1201 const void *unused)
1202 {
1203 UserDefFlatUnion2 *tmp = NULL;
1204 Error *err = NULL;
1205 Visitor *v;
1206
1207 /* test situation where discriminator field ('enum1' here) is missing */
1208 v = visitor_input_test_init(data, "{ 'integer': 42, 'string': 'c', 'string1': 'd', 'string2': 'e' }");
1209
1210 visit_type_UserDefFlatUnion2(v, NULL, &tmp, &err);
1211 error_free_or_abort(&err);
1212 g_assert(!tmp);
1213 }
1214
1215 static void test_visitor_in_fail_alternate(TestInputVisitorData *data,
1216 const void *unused)
1217 {
1218 UserDefAlternate *tmp;
1219 Visitor *v;
1220 Error *err = NULL;
1221
1222 v = visitor_input_test_init(data, "3.14");
1223
1224 visit_type_UserDefAlternate(v, NULL, &tmp, &err);
1225 error_free_or_abort(&err);
1226 g_assert(!tmp);
1227 }
1228
1229 static void do_test_visitor_in_qmp_introspect(TestInputVisitorData *data,
1230 const char *schema_json)
1231 {
1232 SchemaInfoList *schema = NULL;
1233 Visitor *v;
1234
1235 v = visitor_input_test_init_raw(data, schema_json);
1236
1237 visit_type_SchemaInfoList(v, NULL, &schema, &error_abort);
1238 g_assert(schema);
1239
1240 qapi_free_SchemaInfoList(schema);
1241 }
1242
1243 static void test_visitor_in_qmp_introspect(TestInputVisitorData *data,
1244 const void *unused)
1245 {
1246 do_test_visitor_in_qmp_introspect(data, test_qmp_schema_json);
1247 do_test_visitor_in_qmp_introspect(data, qmp_schema_json);
1248 }
1249
1250 int main(int argc, char **argv)
1251 {
1252 g_test_init(&argc, &argv, NULL);
1253
1254 input_visitor_test_add("/visitor/input/int",
1255 NULL, test_visitor_in_int);
1256 input_visitor_test_add("/visitor/input/uint",
1257 NULL, test_visitor_in_uint);
1258 input_visitor_test_add("/visitor/input/int_overflow",
1259 NULL, test_visitor_in_int_overflow);
1260 input_visitor_test_add("/visitor/input/int_keyval",
1261 NULL, test_visitor_in_int_keyval);
1262 input_visitor_test_add("/visitor/input/int_str_keyval",
1263 NULL, test_visitor_in_int_str_keyval);
1264 input_visitor_test_add("/visitor/input/int_str_fail",
1265 NULL, test_visitor_in_int_str_fail);
1266 input_visitor_test_add("/visitor/input/bool",
1267 NULL, test_visitor_in_bool);
1268 input_visitor_test_add("/visitor/input/bool_keyval",
1269 NULL, test_visitor_in_bool_keyval);
1270 input_visitor_test_add("/visitor/input/bool_str_keyval",
1271 NULL, test_visitor_in_bool_str_keyval);
1272 input_visitor_test_add("/visitor/input/bool_str_fail",
1273 NULL, test_visitor_in_bool_str_fail);
1274 input_visitor_test_add("/visitor/input/number",
1275 NULL, test_visitor_in_number);
1276 input_visitor_test_add("/visitor/input/number_keyval",
1277 NULL, test_visitor_in_number_keyval);
1278 input_visitor_test_add("/visitor/input/number_str_keyval",
1279 NULL, test_visitor_in_number_str_keyval);
1280 input_visitor_test_add("/visitor/input/number_str_fail",
1281 NULL, test_visitor_in_number_str_fail);
1282 input_visitor_test_add("/visitor/input/size_str_keyval",
1283 NULL, test_visitor_in_size_str_keyval);
1284 input_visitor_test_add("/visitor/input/size_str_fail",
1285 NULL, test_visitor_in_size_str_fail);
1286 input_visitor_test_add("/visitor/input/string",
1287 NULL, test_visitor_in_string);
1288 input_visitor_test_add("/visitor/input/enum",
1289 NULL, test_visitor_in_enum);
1290 input_visitor_test_add("/visitor/input/struct",
1291 NULL, test_visitor_in_struct);
1292 input_visitor_test_add("/visitor/input/struct-nested",
1293 NULL, test_visitor_in_struct_nested);
1294 input_visitor_test_add("/visitor/input/list",
1295 NULL, test_visitor_in_list);
1296 input_visitor_test_add("/visitor/input/any",
1297 NULL, test_visitor_in_any);
1298 input_visitor_test_add("/visitor/input/null",
1299 NULL, test_visitor_in_null);
1300 input_visitor_test_add("/visitor/input/union-flat",
1301 NULL, test_visitor_in_union_flat);
1302 input_visitor_test_add("/visitor/input/alternate",
1303 NULL, test_visitor_in_alternate);
1304 input_visitor_test_add("/visitor/input/errors",
1305 NULL, test_visitor_in_errors);
1306 input_visitor_test_add("/visitor/input/wrong-type",
1307 NULL, test_visitor_in_wrong_type);
1308 input_visitor_test_add("/visitor/input/alternate-number",
1309 NULL, test_visitor_in_alternate_number);
1310 input_visitor_test_add("/visitor/input/native_list/int",
1311 NULL, test_visitor_in_native_list_int);
1312 input_visitor_test_add("/visitor/input/native_list/int8",
1313 NULL, test_visitor_in_native_list_int8);
1314 input_visitor_test_add("/visitor/input/native_list/int16",
1315 NULL, test_visitor_in_native_list_int16);
1316 input_visitor_test_add("/visitor/input/native_list/int32",
1317 NULL, test_visitor_in_native_list_int32);
1318 input_visitor_test_add("/visitor/input/native_list/int64",
1319 NULL, test_visitor_in_native_list_int64);
1320 input_visitor_test_add("/visitor/input/native_list/uint8",
1321 NULL, test_visitor_in_native_list_uint8);
1322 input_visitor_test_add("/visitor/input/native_list/uint16",
1323 NULL, test_visitor_in_native_list_uint16);
1324 input_visitor_test_add("/visitor/input/native_list/uint32",
1325 NULL, test_visitor_in_native_list_uint32);
1326 input_visitor_test_add("/visitor/input/native_list/uint64",
1327 NULL, test_visitor_in_native_list_uint64);
1328 input_visitor_test_add("/visitor/input/native_list/bool",
1329 NULL, test_visitor_in_native_list_bool);
1330 input_visitor_test_add("/visitor/input/native_list/str",
1331 NULL, test_visitor_in_native_list_string);
1332 input_visitor_test_add("/visitor/input/native_list/number",
1333 NULL, test_visitor_in_native_list_number);
1334 input_visitor_test_add("/visitor/input/fail/struct",
1335 NULL, test_visitor_in_fail_struct);
1336 input_visitor_test_add("/visitor/input/fail/struct-nested",
1337 NULL, test_visitor_in_fail_struct_nested);
1338 input_visitor_test_add("/visitor/input/fail/struct-in-list",
1339 NULL, test_visitor_in_fail_struct_in_list);
1340 input_visitor_test_add("/visitor/input/fail/struct-missing",
1341 NULL, test_visitor_in_fail_struct_missing);
1342 input_visitor_test_add("/visitor/input/fail/list",
1343 NULL, test_visitor_in_fail_list);
1344 input_visitor_test_add("/visitor/input/fail/list-nested",
1345 NULL, test_visitor_in_fail_list_nested);
1346 input_visitor_test_add("/visitor/input/fail/union-flat",
1347 NULL, test_visitor_in_fail_union_flat);
1348 input_visitor_test_add("/visitor/input/fail/union-flat-no-discriminator",
1349 NULL, test_visitor_in_fail_union_flat_no_discrim);
1350 input_visitor_test_add("/visitor/input/fail/alternate",
1351 NULL, test_visitor_in_fail_alternate);
1352 input_visitor_test_add("/visitor/input/fail/union-native-list",
1353 NULL, test_visitor_in_fail_union_native_list);
1354 input_visitor_test_add("/visitor/input/qmp-introspect",
1355 NULL, test_visitor_in_qmp_introspect);
1356
1357 g_test_run();
1358
1359 return 0;
1360 }