2 * QObject Output Visitor unit-tests.
4 * Copyright (C) 2011-2016 Red Hat Inc.
7 * Luiz Capitulino <lcapitulino@redhat.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
13 #include "qemu/osdep.h"
15 #include "qemu-common.h"
16 #include "qapi/error.h"
17 #include "qapi/qobject-output-visitor.h"
18 #include "test-qapi-visit.h"
19 #include "qapi/qmp/qbool.h"
20 #include "qapi/qmp/qdict.h"
21 #include "qapi/qmp/qlist.h"
22 #include "qapi/qmp/qnull.h"
23 #include "qapi/qmp/qnum.h"
24 #include "qapi/qmp/qstring.h"
26 typedef struct TestOutputVisitorData
{
29 } TestOutputVisitorData
;
31 static void visitor_output_setup(TestOutputVisitorData
*data
,
34 data
->ov
= qobject_output_visitor_new(&data
->obj
);
38 static void visitor_output_teardown(TestOutputVisitorData
*data
,
43 qobject_unref(data
->obj
);
47 static QObject
*visitor_get(TestOutputVisitorData
*data
)
49 visit_complete(data
->ov
, &data
->obj
);
54 static void visitor_reset(TestOutputVisitorData
*data
)
56 visitor_output_teardown(data
, NULL
);
57 visitor_output_setup(data
, NULL
);
60 static void test_visitor_out_int(TestOutputVisitorData
*data
,
67 visit_type_int(data
->ov
, NULL
, &value
, &error_abort
);
69 qnum
= qobject_to(QNum
, visitor_get(data
));
71 g_assert(qnum_get_try_int(qnum
, &val
));
72 g_assert_cmpint(val
, ==, value
);
75 static void test_visitor_out_bool(TestOutputVisitorData
*data
,
81 visit_type_bool(data
->ov
, NULL
, &value
, &error_abort
);
83 qbool
= qobject_to(QBool
, visitor_get(data
));
85 g_assert(qbool_get_bool(qbool
) == value
);
88 static void test_visitor_out_number(TestOutputVisitorData
*data
,
94 visit_type_number(data
->ov
, NULL
, &value
, &error_abort
);
96 qnum
= qobject_to(QNum
, visitor_get(data
));
98 g_assert(qnum_get_double(qnum
) == value
);
101 static void test_visitor_out_string(TestOutputVisitorData
*data
,
104 char *string
= (char *) "Q E M U";
107 visit_type_str(data
->ov
, NULL
, &string
, &error_abort
);
109 qstr
= qobject_to(QString
, visitor_get(data
));
111 g_assert_cmpstr(qstring_get_str(qstr
), ==, string
);
114 static void test_visitor_out_no_string(TestOutputVisitorData
*data
,
120 /* A null string should return "" */
121 visit_type_str(data
->ov
, NULL
, &string
, &error_abort
);
123 qstr
= qobject_to(QString
, visitor_get(data
));
125 g_assert_cmpstr(qstring_get_str(qstr
), ==, "");
128 static void test_visitor_out_enum(TestOutputVisitorData
*data
,
134 for (i
= 0; i
< ENUM_ONE__MAX
; i
++) {
135 visit_type_EnumOne(data
->ov
, "unused", &i
, &error_abort
);
137 qstr
= qobject_to(QString
, visitor_get(data
));
139 g_assert_cmpstr(qstring_get_str(qstr
), ==, EnumOne_str(i
));
144 static void test_visitor_out_struct(TestOutputVisitorData
*data
,
147 TestStruct test_struct
= { .integer
= 42,
149 .string
= (char *) "foo"};
150 TestStruct
*p
= &test_struct
;
153 visit_type_TestStruct(data
->ov
, NULL
, &p
, &error_abort
);
155 qdict
= qobject_to(QDict
, visitor_get(data
));
157 g_assert_cmpint(qdict_size(qdict
), ==, 3);
158 g_assert_cmpint(qdict_get_int(qdict
, "integer"), ==, 42);
159 g_assert_cmpint(qdict_get_bool(qdict
, "boolean"), ==, false);
160 g_assert_cmpstr(qdict_get_str(qdict
, "string"), ==, "foo");
163 static void test_visitor_out_struct_nested(TestOutputVisitorData
*data
,
168 QDict
*qdict
, *dict1
, *dict2
, *dict3
, *userdef
;
169 const char *string
= "user def string";
170 const char *strings
[] = { "forty two", "forty three", "forty four",
173 ud2
= g_malloc0(sizeof(*ud2
));
174 ud2
->string0
= g_strdup(strings
[0]);
176 ud2
->dict1
= g_malloc0(sizeof(*ud2
->dict1
));
177 ud2
->dict1
->string1
= g_strdup(strings
[1]);
179 ud2
->dict1
->dict2
= g_malloc0(sizeof(*ud2
->dict1
->dict2
));
180 ud2
->dict1
->dict2
->userdef
= g_new0(UserDefOne
, 1);
181 ud2
->dict1
->dict2
->userdef
->string
= g_strdup(string
);
182 ud2
->dict1
->dict2
->userdef
->integer
= value
;
183 ud2
->dict1
->dict2
->string
= g_strdup(strings
[2]);
185 ud2
->dict1
->dict3
= g_malloc0(sizeof(*ud2
->dict1
->dict3
));
186 ud2
->dict1
->has_dict3
= true;
187 ud2
->dict1
->dict3
->userdef
= g_new0(UserDefOne
, 1);
188 ud2
->dict1
->dict3
->userdef
->string
= g_strdup(string
);
189 ud2
->dict1
->dict3
->userdef
->integer
= value
;
190 ud2
->dict1
->dict3
->string
= g_strdup(strings
[3]);
192 visit_type_UserDefTwo(data
->ov
, "unused", &ud2
, &error_abort
);
194 qdict
= qobject_to(QDict
, visitor_get(data
));
196 g_assert_cmpint(qdict_size(qdict
), ==, 2);
197 g_assert_cmpstr(qdict_get_str(qdict
, "string0"), ==, strings
[0]);
199 dict1
= qdict_get_qdict(qdict
, "dict1");
200 g_assert_cmpint(qdict_size(dict1
), ==, 3);
201 g_assert_cmpstr(qdict_get_str(dict1
, "string1"), ==, strings
[1]);
203 dict2
= qdict_get_qdict(dict1
, "dict2");
204 g_assert_cmpint(qdict_size(dict2
), ==, 2);
205 g_assert_cmpstr(qdict_get_str(dict2
, "string"), ==, strings
[2]);
206 userdef
= qdict_get_qdict(dict2
, "userdef");
207 g_assert_cmpint(qdict_size(userdef
), ==, 2);
208 g_assert_cmpint(qdict_get_int(userdef
, "integer"), ==, value
);
209 g_assert_cmpstr(qdict_get_str(userdef
, "string"), ==, string
);
211 dict3
= qdict_get_qdict(dict1
, "dict3");
212 g_assert_cmpint(qdict_size(dict3
), ==, 2);
213 g_assert_cmpstr(qdict_get_str(dict3
, "string"), ==, strings
[3]);
214 userdef
= qdict_get_qdict(dict3
, "userdef");
215 g_assert_cmpint(qdict_size(userdef
), ==, 2);
216 g_assert_cmpint(qdict_get_int(userdef
, "integer"), ==, value
);
217 g_assert_cmpstr(qdict_get_str(userdef
, "string"), ==, string
);
219 qapi_free_UserDefTwo(ud2
);
222 static void test_visitor_out_list(TestOutputVisitorData
*data
,
225 const char *value_str
= "list value";
226 TestStructList
*p
, *head
= NULL
;
227 const int max_items
= 10;
228 bool value_bool
= true;
234 /* Build the list in reverse order... */
235 for (i
= 0; i
< max_items
; i
++) {
236 p
= g_malloc0(sizeof(*p
));
237 p
->value
= g_malloc0(sizeof(*p
->value
));
238 p
->value
->integer
= value_int
+ (max_items
- i
- 1);
239 p
->value
->boolean
= value_bool
;
240 p
->value
->string
= g_strdup(value_str
);
246 visit_type_TestStructList(data
->ov
, NULL
, &head
, &error_abort
);
248 qlist
= qobject_to(QList
, visitor_get(data
));
250 g_assert(!qlist_empty(qlist
));
252 /* ...and ensure that the visitor sees it in order */
254 QLIST_FOREACH_ENTRY(qlist
, entry
) {
257 qdict
= qobject_to(QDict
, entry
->value
);
259 g_assert_cmpint(qdict_size(qdict
), ==, 3);
260 g_assert_cmpint(qdict_get_int(qdict
, "integer"), ==, value_int
+ i
);
261 g_assert_cmpint(qdict_get_bool(qdict
, "boolean"), ==, value_bool
);
262 g_assert_cmpstr(qdict_get_str(qdict
, "string"), ==, value_str
);
265 g_assert_cmpint(i
, ==, max_items
);
267 qapi_free_TestStructList(head
);
270 static void test_visitor_out_list_qapi_free(TestOutputVisitorData
*data
,
273 UserDefTwoList
*p
, *head
= NULL
;
274 const char string
[] = "foo bar";
275 int i
, max_count
= 1024;
277 for (i
= 0; i
< max_count
; i
++) {
278 p
= g_malloc0(sizeof(*p
));
279 p
->value
= g_malloc0(sizeof(*p
->value
));
281 p
->value
->string0
= g_strdup(string
);
282 p
->value
->dict1
= g_new0(UserDefTwoDict
, 1);
283 p
->value
->dict1
->string1
= g_strdup(string
);
284 p
->value
->dict1
->dict2
= g_new0(UserDefTwoDictDict
, 1);
285 p
->value
->dict1
->dict2
->userdef
= g_new0(UserDefOne
, 1);
286 p
->value
->dict1
->dict2
->userdef
->string
= g_strdup(string
);
287 p
->value
->dict1
->dict2
->userdef
->integer
= 42;
288 p
->value
->dict1
->dict2
->string
= g_strdup(string
);
289 p
->value
->dict1
->has_dict3
= false;
295 qapi_free_UserDefTwoList(head
);
298 static void test_visitor_out_any(TestOutputVisitorData
*data
,
308 qobj
= QOBJECT(qnum_from_int(-42));
309 visit_type_any(data
->ov
, NULL
, &qobj
, &error_abort
);
310 qnum
= qobject_to(QNum
, visitor_get(data
));
312 g_assert(qnum_get_try_int(qnum
, &val
));
313 g_assert_cmpint(val
, ==, -42);
318 qdict_put_int(qdict
, "integer", -42);
319 qdict_put_bool(qdict
, "boolean", true);
320 qdict_put_str(qdict
, "string", "foo");
321 qobj
= QOBJECT(qdict
);
322 visit_type_any(data
->ov
, NULL
, &qobj
, &error_abort
);
324 qdict
= qobject_to(QDict
, visitor_get(data
));
326 qnum
= qobject_to(QNum
, qdict_get(qdict
, "integer"));
328 g_assert(qnum_get_try_int(qnum
, &val
));
329 g_assert_cmpint(val
, ==, -42);
330 qbool
= qobject_to(QBool
, qdict_get(qdict
, "boolean"));
332 g_assert(qbool_get_bool(qbool
) == true);
333 qstring
= qobject_to(QString
, qdict_get(qdict
, "string"));
335 g_assert_cmpstr(qstring_get_str(qstring
), ==, "foo");
338 static void test_visitor_out_union_flat(TestOutputVisitorData
*data
,
343 UserDefFlatUnion
*tmp
= g_malloc0(sizeof(UserDefFlatUnion
));
344 tmp
->enum1
= ENUM_ONE_VALUE1
;
345 tmp
->string
= g_strdup("str");
347 tmp
->u
.value1
.boolean
= true;
349 visit_type_UserDefFlatUnion(data
->ov
, NULL
, &tmp
, &error_abort
);
350 qdict
= qobject_to(QDict
, visitor_get(data
));
352 g_assert_cmpstr(qdict_get_str(qdict
, "enum1"), ==, "value1");
353 g_assert_cmpstr(qdict_get_str(qdict
, "string"), ==, "str");
354 g_assert_cmpint(qdict_get_int(qdict
, "integer"), ==, 41);
355 g_assert_cmpint(qdict_get_bool(qdict
, "boolean"), ==, true);
357 qapi_free_UserDefFlatUnion(tmp
);
360 static void test_visitor_out_alternate(TestOutputVisitorData
*data
,
363 UserDefAlternate
*tmp
;
369 tmp
= g_new0(UserDefAlternate
, 1);
370 tmp
->type
= QTYPE_QNUM
;
373 visit_type_UserDefAlternate(data
->ov
, NULL
, &tmp
, &error_abort
);
374 qnum
= qobject_to(QNum
, visitor_get(data
));
376 g_assert(qnum_get_try_int(qnum
, &val
));
377 g_assert_cmpint(val
, ==, 42);
379 qapi_free_UserDefAlternate(tmp
);
382 tmp
= g_new0(UserDefAlternate
, 1);
383 tmp
->type
= QTYPE_QSTRING
;
384 tmp
->u
.e
= ENUM_ONE_VALUE1
;
386 visit_type_UserDefAlternate(data
->ov
, NULL
, &tmp
, &error_abort
);
387 qstr
= qobject_to(QString
, visitor_get(data
));
389 g_assert_cmpstr(qstring_get_str(qstr
), ==, "value1");
391 qapi_free_UserDefAlternate(tmp
);
394 tmp
= g_new0(UserDefAlternate
, 1);
395 tmp
->type
= QTYPE_QNULL
;
398 visit_type_UserDefAlternate(data
->ov
, NULL
, &tmp
, &error_abort
);
399 g_assert_cmpint(qobject_type(visitor_get(data
)), ==, QTYPE_QNULL
);
401 qapi_free_UserDefAlternate(tmp
);
404 tmp
= g_new0(UserDefAlternate
, 1);
405 tmp
->type
= QTYPE_QDICT
;
406 tmp
->u
.udfu
.integer
= 1;
407 tmp
->u
.udfu
.string
= g_strdup("str");
408 tmp
->u
.udfu
.enum1
= ENUM_ONE_VALUE1
;
409 tmp
->u
.udfu
.u
.value1
.boolean
= true;
411 visit_type_UserDefAlternate(data
->ov
, NULL
, &tmp
, &error_abort
);
412 qdict
= qobject_to(QDict
, visitor_get(data
));
414 g_assert_cmpint(qdict_size(qdict
), ==, 4);
415 g_assert_cmpint(qdict_get_int(qdict
, "integer"), ==, 1);
416 g_assert_cmpstr(qdict_get_str(qdict
, "string"), ==, "str");
417 g_assert_cmpstr(qdict_get_str(qdict
, "enum1"), ==, "value1");
418 g_assert_cmpint(qdict_get_bool(qdict
, "boolean"), ==, true);
420 qapi_free_UserDefAlternate(tmp
);
423 static void test_visitor_out_null(TestOutputVisitorData
*data
,
430 visit_start_struct(data
->ov
, NULL
, NULL
, 0, &error_abort
);
431 visit_type_null(data
->ov
, "a", &null
, &error_abort
);
432 visit_check_struct(data
->ov
, &error_abort
);
433 visit_end_struct(data
->ov
, NULL
);
434 qdict
= qobject_to(QDict
, visitor_get(data
));
436 g_assert_cmpint(qdict_size(qdict
), ==, 1);
437 nil
= qdict_get(qdict
, "a");
439 g_assert(qobject_type(nil
) == QTYPE_QNULL
);
442 static void init_list_union(UserDefListUnion
*cvalue
)
445 switch (cvalue
->type
) {
446 case USER_DEF_LIST_UNION_KIND_INTEGER
: {
447 intList
**list
= &cvalue
->u
.integer
.data
;
448 for (i
= 0; i
< 32; i
++) {
449 *list
= g_new0(intList
, 1);
451 (*list
)->next
= NULL
;
452 list
= &(*list
)->next
;
456 case USER_DEF_LIST_UNION_KIND_S8
: {
457 int8List
**list
= &cvalue
->u
.s8
.data
;
458 for (i
= 0; i
< 32; i
++) {
459 *list
= g_new0(int8List
, 1);
461 (*list
)->next
= NULL
;
462 list
= &(*list
)->next
;
466 case USER_DEF_LIST_UNION_KIND_S16
: {
467 int16List
**list
= &cvalue
->u
.s16
.data
;
468 for (i
= 0; i
< 32; i
++) {
469 *list
= g_new0(int16List
, 1);
471 (*list
)->next
= NULL
;
472 list
= &(*list
)->next
;
476 case USER_DEF_LIST_UNION_KIND_S32
: {
477 int32List
**list
= &cvalue
->u
.s32
.data
;
478 for (i
= 0; i
< 32; i
++) {
479 *list
= g_new0(int32List
, 1);
481 (*list
)->next
= NULL
;
482 list
= &(*list
)->next
;
486 case USER_DEF_LIST_UNION_KIND_S64
: {
487 int64List
**list
= &cvalue
->u
.s64
.data
;
488 for (i
= 0; i
< 32; i
++) {
489 *list
= g_new0(int64List
, 1);
491 (*list
)->next
= NULL
;
492 list
= &(*list
)->next
;
496 case USER_DEF_LIST_UNION_KIND_U8
: {
497 uint8List
**list
= &cvalue
->u
.u8
.data
;
498 for (i
= 0; i
< 32; i
++) {
499 *list
= g_new0(uint8List
, 1);
501 (*list
)->next
= NULL
;
502 list
= &(*list
)->next
;
506 case USER_DEF_LIST_UNION_KIND_U16
: {
507 uint16List
**list
= &cvalue
->u
.u16
.data
;
508 for (i
= 0; i
< 32; i
++) {
509 *list
= g_new0(uint16List
, 1);
511 (*list
)->next
= NULL
;
512 list
= &(*list
)->next
;
516 case USER_DEF_LIST_UNION_KIND_U32
: {
517 uint32List
**list
= &cvalue
->u
.u32
.data
;
518 for (i
= 0; i
< 32; i
++) {
519 *list
= g_new0(uint32List
, 1);
521 (*list
)->next
= NULL
;
522 list
= &(*list
)->next
;
526 case USER_DEF_LIST_UNION_KIND_U64
: {
527 uint64List
**list
= &cvalue
->u
.u64
.data
;
528 for (i
= 0; i
< 32; i
++) {
529 *list
= g_new0(uint64List
, 1);
531 (*list
)->next
= NULL
;
532 list
= &(*list
)->next
;
536 case USER_DEF_LIST_UNION_KIND_BOOLEAN
: {
537 boolList
**list
= &cvalue
->u
.boolean
.data
;
538 for (i
= 0; i
< 32; i
++) {
539 *list
= g_new0(boolList
, 1);
540 (*list
)->value
= QEMU_IS_ALIGNED(i
, 3);
541 (*list
)->next
= NULL
;
542 list
= &(*list
)->next
;
546 case USER_DEF_LIST_UNION_KIND_STRING
: {
547 strList
**list
= &cvalue
->u
.string
.data
;
548 for (i
= 0; i
< 32; i
++) {
549 *list
= g_new0(strList
, 1);
550 (*list
)->value
= g_strdup_printf("%d", i
);
551 (*list
)->next
= NULL
;
552 list
= &(*list
)->next
;
556 case USER_DEF_LIST_UNION_KIND_NUMBER
: {
557 numberList
**list
= &cvalue
->u
.number
.data
;
558 for (i
= 0; i
< 32; i
++) {
559 *list
= g_new0(numberList
, 1);
560 (*list
)->value
= (double)i
/ 3;
561 (*list
)->next
= NULL
;
562 list
= &(*list
)->next
;
567 g_assert_not_reached();
571 static void check_list_union(QObject
*qobj
,
572 UserDefListUnionKind kind
)
578 qdict
= qobject_to(QDict
, qobj
);
580 g_assert(qdict_haskey(qdict
, "data"));
581 qlist
= qlist_copy(qobject_to(QList
, qdict_get(qdict
, "data")));
584 case USER_DEF_LIST_UNION_KIND_U8
:
585 case USER_DEF_LIST_UNION_KIND_U16
:
586 case USER_DEF_LIST_UNION_KIND_U32
:
587 case USER_DEF_LIST_UNION_KIND_U64
:
588 for (i
= 0; i
< 32; i
++) {
593 tmp
= qlist_peek(qlist
);
595 qvalue
= qobject_to(QNum
, tmp
);
596 g_assert(qnum_get_try_uint(qvalue
, &val
));
597 g_assert_cmpint(val
, ==, i
);
598 qobject_unref(qlist_pop(qlist
));
602 case USER_DEF_LIST_UNION_KIND_S8
:
603 case USER_DEF_LIST_UNION_KIND_S16
:
604 case USER_DEF_LIST_UNION_KIND_S32
:
605 case USER_DEF_LIST_UNION_KIND_S64
:
607 * All integer elements in JSON arrays get stored into QNums
608 * when we convert to QObjects, so we can check them all in
609 * the same fashion, so simply fall through here.
611 case USER_DEF_LIST_UNION_KIND_INTEGER
:
612 for (i
= 0; i
< 32; i
++) {
617 tmp
= qlist_peek(qlist
);
619 qvalue
= qobject_to(QNum
, tmp
);
620 g_assert(qnum_get_try_int(qvalue
, &val
));
621 g_assert_cmpint(val
, ==, i
);
622 qobject_unref(qlist_pop(qlist
));
625 case USER_DEF_LIST_UNION_KIND_BOOLEAN
:
626 for (i
= 0; i
< 32; i
++) {
629 tmp
= qlist_peek(qlist
);
631 qvalue
= qobject_to(QBool
, tmp
);
632 g_assert_cmpint(qbool_get_bool(qvalue
), ==, i
% 3 == 0);
633 qobject_unref(qlist_pop(qlist
));
636 case USER_DEF_LIST_UNION_KIND_STRING
:
637 for (i
= 0; i
< 32; i
++) {
641 tmp
= qlist_peek(qlist
);
643 qvalue
= qobject_to(QString
, tmp
);
644 sprintf(str
, "%d", i
);
645 g_assert_cmpstr(qstring_get_str(qvalue
), ==, str
);
646 qobject_unref(qlist_pop(qlist
));
649 case USER_DEF_LIST_UNION_KIND_NUMBER
:
650 for (i
= 0; i
< 32; i
++) {
653 GString
*double_expected
= g_string_new("");
654 GString
*double_actual
= g_string_new("");
656 tmp
= qlist_peek(qlist
);
658 qvalue
= qobject_to(QNum
, tmp
);
659 g_string_printf(double_expected
, "%.6f", (double)i
/ 3);
660 g_string_printf(double_actual
, "%.6f", qnum_get_double(qvalue
));
661 g_assert_cmpstr(double_actual
->str
, ==, double_expected
->str
);
663 qobject_unref(qlist_pop(qlist
));
664 g_string_free(double_expected
, true);
665 g_string_free(double_actual
, true);
669 g_assert_not_reached();
671 qobject_unref(qlist
);
674 static void test_list_union(TestOutputVisitorData
*data
,
676 UserDefListUnionKind kind
)
678 UserDefListUnion
*cvalue
= g_new0(UserDefListUnion
, 1);
682 init_list_union(cvalue
);
684 visit_type_UserDefListUnion(data
->ov
, NULL
, &cvalue
, &error_abort
);
686 obj
= visitor_get(data
);
687 check_list_union(obj
, cvalue
->type
);
688 qapi_free_UserDefListUnion(cvalue
);
691 static void test_visitor_out_list_union_int(TestOutputVisitorData
*data
,
694 test_list_union(data
, unused
, USER_DEF_LIST_UNION_KIND_INTEGER
);
697 static void test_visitor_out_list_union_int8(TestOutputVisitorData
*data
,
700 test_list_union(data
, unused
, USER_DEF_LIST_UNION_KIND_S8
);
703 static void test_visitor_out_list_union_int16(TestOutputVisitorData
*data
,
706 test_list_union(data
, unused
, USER_DEF_LIST_UNION_KIND_S16
);
709 static void test_visitor_out_list_union_int32(TestOutputVisitorData
*data
,
712 test_list_union(data
, unused
, USER_DEF_LIST_UNION_KIND_S32
);
715 static void test_visitor_out_list_union_int64(TestOutputVisitorData
*data
,
718 test_list_union(data
, unused
, USER_DEF_LIST_UNION_KIND_S64
);
721 static void test_visitor_out_list_union_uint8(TestOutputVisitorData
*data
,
724 test_list_union(data
, unused
, USER_DEF_LIST_UNION_KIND_U8
);
727 static void test_visitor_out_list_union_uint16(TestOutputVisitorData
*data
,
730 test_list_union(data
, unused
, USER_DEF_LIST_UNION_KIND_U16
);
733 static void test_visitor_out_list_union_uint32(TestOutputVisitorData
*data
,
736 test_list_union(data
, unused
, USER_DEF_LIST_UNION_KIND_U32
);
739 static void test_visitor_out_list_union_uint64(TestOutputVisitorData
*data
,
742 test_list_union(data
, unused
, USER_DEF_LIST_UNION_KIND_U64
);
745 static void test_visitor_out_list_union_bool(TestOutputVisitorData
*data
,
748 test_list_union(data
, unused
, USER_DEF_LIST_UNION_KIND_BOOLEAN
);
751 static void test_visitor_out_list_union_str(TestOutputVisitorData
*data
,
754 test_list_union(data
, unused
, USER_DEF_LIST_UNION_KIND_STRING
);
757 static void test_visitor_out_list_union_number(TestOutputVisitorData
*data
,
760 test_list_union(data
, unused
, USER_DEF_LIST_UNION_KIND_NUMBER
);
763 static void output_visitor_test_add(const char *testpath
,
764 TestOutputVisitorData
*data
,
765 void (*test_func
)(TestOutputVisitorData
*data
, const void *user_data
))
767 g_test_add(testpath
, TestOutputVisitorData
, data
, visitor_output_setup
,
768 test_func
, visitor_output_teardown
);
771 int main(int argc
, char **argv
)
773 TestOutputVisitorData out_visitor_data
;
775 g_test_init(&argc
, &argv
, NULL
);
777 output_visitor_test_add("/visitor/output/int",
778 &out_visitor_data
, test_visitor_out_int
);
779 output_visitor_test_add("/visitor/output/bool",
780 &out_visitor_data
, test_visitor_out_bool
);
781 output_visitor_test_add("/visitor/output/number",
782 &out_visitor_data
, test_visitor_out_number
);
783 output_visitor_test_add("/visitor/output/string",
784 &out_visitor_data
, test_visitor_out_string
);
785 output_visitor_test_add("/visitor/output/no-string",
786 &out_visitor_data
, test_visitor_out_no_string
);
787 output_visitor_test_add("/visitor/output/enum",
788 &out_visitor_data
, test_visitor_out_enum
);
789 output_visitor_test_add("/visitor/output/struct",
790 &out_visitor_data
, test_visitor_out_struct
);
791 output_visitor_test_add("/visitor/output/struct-nested",
792 &out_visitor_data
, test_visitor_out_struct_nested
);
793 output_visitor_test_add("/visitor/output/list",
794 &out_visitor_data
, test_visitor_out_list
);
795 output_visitor_test_add("/visitor/output/any",
796 &out_visitor_data
, test_visitor_out_any
);
797 output_visitor_test_add("/visitor/output/list-qapi-free",
798 &out_visitor_data
, test_visitor_out_list_qapi_free
);
799 output_visitor_test_add("/visitor/output/union-flat",
800 &out_visitor_data
, test_visitor_out_union_flat
);
801 output_visitor_test_add("/visitor/output/alternate",
802 &out_visitor_data
, test_visitor_out_alternate
);
803 output_visitor_test_add("/visitor/output/null",
804 &out_visitor_data
, test_visitor_out_null
);
805 output_visitor_test_add("/visitor/output/list_union/int",
807 test_visitor_out_list_union_int
);
808 output_visitor_test_add("/visitor/output/list_union/int8",
810 test_visitor_out_list_union_int8
);
811 output_visitor_test_add("/visitor/output/list_union/int16",
813 test_visitor_out_list_union_int16
);
814 output_visitor_test_add("/visitor/output/list_union/int32",
816 test_visitor_out_list_union_int32
);
817 output_visitor_test_add("/visitor/output/list_union/int64",
819 test_visitor_out_list_union_int64
);
820 output_visitor_test_add("/visitor/output/list_union/uint8",
822 test_visitor_out_list_union_uint8
);
823 output_visitor_test_add("/visitor/output/list_union/uint16",
825 test_visitor_out_list_union_uint16
);
826 output_visitor_test_add("/visitor/output/list_union/uint32",
828 test_visitor_out_list_union_uint32
);
829 output_visitor_test_add("/visitor/output/list_union/uint64",
831 test_visitor_out_list_union_uint64
);
832 output_visitor_test_add("/visitor/output/list_union/bool",
834 test_visitor_out_list_union_bool
);
835 output_visitor_test_add("/visitor/output/list_union/string",
837 test_visitor_out_list_union_str
);
838 output_visitor_test_add("/visitor/output/list_union/number",
840 test_visitor_out_list_union_number
);