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