2 * QMP Output Visitor unit-tests.
4 * Copyright (C) 2011 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.
15 #include "qemu-common.h"
16 #include "qapi/qmp-output-visitor.h"
17 #include "test-qapi-types.h"
18 #include "test-qapi-visit.h"
19 #include "qapi/qmp/types.h"
21 typedef struct TestOutputVisitorData
{
22 QmpOutputVisitor
*qov
;
24 } TestOutputVisitorData
;
26 static void visitor_output_setup(TestOutputVisitorData
*data
,
29 data
->qov
= qmp_output_visitor_new();
30 g_assert(data
->qov
!= NULL
);
32 data
->ov
= qmp_output_get_visitor(data
->qov
);
33 g_assert(data
->ov
!= NULL
);
36 static void visitor_output_teardown(TestOutputVisitorData
*data
,
39 qmp_output_visitor_cleanup(data
->qov
);
44 static void test_visitor_out_int(TestOutputVisitorData
*data
,
51 visit_type_int(data
->ov
, &value
, NULL
, &errp
);
54 obj
= qmp_output_get_qobject(data
->qov
);
55 g_assert(obj
!= NULL
);
56 g_assert(qobject_type(obj
) == QTYPE_QINT
);
57 g_assert_cmpint(qint_get_int(qobject_to_qint(obj
)), ==, value
);
62 static void test_visitor_out_bool(TestOutputVisitorData
*data
,
69 visit_type_bool(data
->ov
, &value
, NULL
, &errp
);
72 obj
= qmp_output_get_qobject(data
->qov
);
73 g_assert(obj
!= NULL
);
74 g_assert(qobject_type(obj
) == QTYPE_QBOOL
);
75 g_assert(qbool_get_int(qobject_to_qbool(obj
)) == value
);
80 static void test_visitor_out_number(TestOutputVisitorData
*data
,
87 visit_type_number(data
->ov
, &value
, NULL
, &errp
);
90 obj
= qmp_output_get_qobject(data
->qov
);
91 g_assert(obj
!= NULL
);
92 g_assert(qobject_type(obj
) == QTYPE_QFLOAT
);
93 g_assert(qfloat_get_double(qobject_to_qfloat(obj
)) == value
);
98 static void test_visitor_out_string(TestOutputVisitorData
*data
,
101 char *string
= (char *) "Q E M U";
105 visit_type_str(data
->ov
, &string
, NULL
, &errp
);
108 obj
= qmp_output_get_qobject(data
->qov
);
109 g_assert(obj
!= NULL
);
110 g_assert(qobject_type(obj
) == QTYPE_QSTRING
);
111 g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj
)), ==, string
);
116 static void test_visitor_out_no_string(TestOutputVisitorData
*data
,
123 /* A null string should return "" */
124 visit_type_str(data
->ov
, &string
, NULL
, &errp
);
127 obj
= qmp_output_get_qobject(data
->qov
);
128 g_assert(obj
!= NULL
);
129 g_assert(qobject_type(obj
) == QTYPE_QSTRING
);
130 g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj
)), ==, "");
135 static void test_visitor_out_enum(TestOutputVisitorData
*data
,
142 for (i
= 0; i
< ENUM_ONE_MAX
; i
++) {
143 visit_type_EnumOne(data
->ov
, &i
, "unused", &errp
);
146 obj
= qmp_output_get_qobject(data
->qov
);
147 g_assert(obj
!= NULL
);
148 g_assert(qobject_type(obj
) == QTYPE_QSTRING
);
149 g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj
)), ==,
155 static void test_visitor_out_enum_errors(TestOutputVisitorData
*data
,
158 EnumOne i
, bad_values
[] = { ENUM_ONE_MAX
, -1 };
161 for (i
= 0; i
< ARRAY_SIZE(bad_values
) ; i
++) {
163 visit_type_EnumOne(data
->ov
, &bad_values
[i
], "unused", &errp
);
169 typedef struct TestStruct
176 static void visit_type_TestStruct(Visitor
*v
, TestStruct
**obj
,
177 const char *name
, Error
**errp
)
179 visit_start_struct(v
, (void **)obj
, "TestStruct", name
, sizeof(TestStruct
),
182 visit_type_int(v
, &(*obj
)->integer
, "integer", errp
);
183 visit_type_bool(v
, &(*obj
)->boolean
, "boolean", errp
);
184 visit_type_str(v
, &(*obj
)->string
, "string", errp
);
186 visit_end_struct(v
, errp
);
189 static void test_visitor_out_struct(TestOutputVisitorData
*data
,
192 TestStruct test_struct
= { .integer
= 42,
194 .string
= (char *) "foo"};
195 TestStruct
*p
= &test_struct
;
200 visit_type_TestStruct(data
->ov
, &p
, NULL
, &errp
);
203 obj
= qmp_output_get_qobject(data
->qov
);
204 g_assert(obj
!= NULL
);
205 g_assert(qobject_type(obj
) == QTYPE_QDICT
);
207 qdict
= qobject_to_qdict(obj
);
208 g_assert_cmpint(qdict_size(qdict
), ==, 3);
209 g_assert_cmpint(qdict_get_int(qdict
, "integer"), ==, 42);
210 g_assert_cmpint(qdict_get_bool(qdict
, "boolean"), ==, 0);
211 g_assert_cmpstr(qdict_get_str(qdict
, "string"), ==, "foo");
216 static void test_visitor_out_struct_nested(TestOutputVisitorData
*data
,
223 QDict
*qdict
, *dict1
, *dict2
, *dict3
, *userdef
;
224 const char *string
= "user def string";
225 const char *strings
[] = { "forty two", "forty three", "forty four",
228 ud2
= g_malloc0(sizeof(*ud2
));
229 ud2
->string0
= g_strdup(strings
[0]);
231 ud2
->dict1
.string1
= g_strdup(strings
[1]);
232 ud2
->dict1
.dict2
.userdef1
= g_malloc0(sizeof(UserDefOne
));
233 ud2
->dict1
.dict2
.userdef1
->string
= g_strdup(string
);
234 ud2
->dict1
.dict2
.userdef1
->base
= g_new0(UserDefZero
, 1);
235 ud2
->dict1
.dict2
.userdef1
->base
->integer
= value
;
236 ud2
->dict1
.dict2
.string2
= g_strdup(strings
[2]);
238 ud2
->dict1
.has_dict3
= true;
239 ud2
->dict1
.dict3
.userdef2
= g_malloc0(sizeof(UserDefOne
));
240 ud2
->dict1
.dict3
.userdef2
->string
= g_strdup(string
);
241 ud2
->dict1
.dict3
.userdef2
->base
= g_new0(UserDefZero
, 1);
242 ud2
->dict1
.dict3
.userdef2
->base
->integer
= value
;
243 ud2
->dict1
.dict3
.string3
= g_strdup(strings
[3]);
245 visit_type_UserDefNested(data
->ov
, &ud2
, "unused", &errp
);
248 obj
= qmp_output_get_qobject(data
->qov
);
249 g_assert(obj
!= NULL
);
250 g_assert(qobject_type(obj
) == QTYPE_QDICT
);
252 qdict
= qobject_to_qdict(obj
);
253 g_assert_cmpint(qdict_size(qdict
), ==, 2);
254 g_assert_cmpstr(qdict_get_str(qdict
, "string0"), ==, strings
[0]);
256 dict1
= qdict_get_qdict(qdict
, "dict1");
257 g_assert_cmpint(qdict_size(dict1
), ==, 3);
258 g_assert_cmpstr(qdict_get_str(dict1
, "string1"), ==, strings
[1]);
260 dict2
= qdict_get_qdict(dict1
, "dict2");
261 g_assert_cmpint(qdict_size(dict2
), ==, 2);
262 g_assert_cmpstr(qdict_get_str(dict2
, "string2"), ==, strings
[2]);
263 userdef
= qdict_get_qdict(dict2
, "userdef1");
264 g_assert_cmpint(qdict_size(userdef
), ==, 2);
265 g_assert_cmpint(qdict_get_int(userdef
, "integer"), ==, value
);
266 g_assert_cmpstr(qdict_get_str(userdef
, "string"), ==, string
);
268 dict3
= qdict_get_qdict(dict1
, "dict3");
269 g_assert_cmpint(qdict_size(dict3
), ==, 2);
270 g_assert_cmpstr(qdict_get_str(dict3
, "string3"), ==, strings
[3]);
271 userdef
= qdict_get_qdict(dict3
, "userdef2");
272 g_assert_cmpint(qdict_size(userdef
), ==, 2);
273 g_assert_cmpint(qdict_get_int(userdef
, "integer"), ==, value
);
274 g_assert_cmpstr(qdict_get_str(userdef
, "string"), ==, string
);
277 qapi_free_UserDefNested(ud2
);
280 static void test_visitor_out_struct_errors(TestOutputVisitorData
*data
,
283 EnumOne bad_values
[] = { ENUM_ONE_MAX
, -1 };
285 UserDefOne u
= { .base
= &b
}, *pu
= &u
;
289 for (i
= 0; i
< ARRAY_SIZE(bad_values
) ; i
++) {
292 u
.enum1
= bad_values
[i
];
293 visit_type_UserDefOne(data
->ov
, &pu
, "unused", &errp
);
299 typedef struct TestStructList
305 struct TestStructList
*next
;
308 static void visit_type_TestStructList(Visitor
*v
, TestStructList
**obj
,
309 const char *name
, Error
**errp
)
311 GenericList
*i
, **head
= (GenericList
**)obj
;
313 visit_start_list(v
, name
, errp
);
315 for (*head
= i
= visit_next_list(v
, head
, errp
); i
; i
= visit_next_list(v
, &i
, errp
)) {
316 TestStructList
*native_i
= (TestStructList
*)i
;
317 visit_type_TestStruct(v
, &native_i
->value
, NULL
, errp
);
320 visit_end_list(v
, errp
);
323 static void test_visitor_out_list(TestOutputVisitorData
*data
,
326 char *value_str
= (char *) "list value";
327 TestStructList
*p
, *head
= NULL
;
328 const int max_items
= 10;
329 bool value_bool
= true;
337 for (i
= 0; i
< max_items
; i
++) {
338 p
= g_malloc0(sizeof(*p
));
339 p
->value
= g_malloc0(sizeof(*p
->value
));
340 p
->value
->integer
= value_int
;
341 p
->value
->boolean
= value_bool
;
342 p
->value
->string
= value_str
;
348 visit_type_TestStructList(data
->ov
, &head
, NULL
, &errp
);
351 obj
= qmp_output_get_qobject(data
->qov
);
352 g_assert(obj
!= NULL
);
353 g_assert(qobject_type(obj
) == QTYPE_QLIST
);
355 qlist
= qobject_to_qlist(obj
);
356 g_assert(!qlist_empty(qlist
));
359 QLIST_FOREACH_ENTRY(qlist
, entry
) {
362 g_assert(qobject_type(entry
->value
) == QTYPE_QDICT
);
363 qdict
= qobject_to_qdict(entry
->value
);
364 g_assert_cmpint(qdict_size(qdict
), ==, 3);
365 g_assert_cmpint(qdict_get_int(qdict
, "integer"), ==, value_int
);
366 g_assert_cmpint(qdict_get_bool(qdict
, "boolean"), ==, value_bool
);
367 g_assert_cmpstr(qdict_get_str(qdict
, "string"), ==, value_str
);
370 g_assert_cmpint(i
, ==, max_items
);
375 TestStructList
*tmp
= p
->next
;
382 static void test_visitor_out_list_qapi_free(TestOutputVisitorData
*data
,
385 UserDefNestedList
*p
, *head
= NULL
;
386 const char string
[] = "foo bar";
387 int i
, max_count
= 1024;
389 for (i
= 0; i
< max_count
; i
++) {
390 p
= g_malloc0(sizeof(*p
));
391 p
->value
= g_malloc0(sizeof(*p
->value
));
393 p
->value
->string0
= g_strdup(string
);
394 p
->value
->dict1
.string1
= g_strdup(string
);
395 p
->value
->dict1
.dict2
.userdef1
= g_malloc0(sizeof(UserDefOne
));
396 p
->value
->dict1
.dict2
.userdef1
->string
= g_strdup(string
);
397 p
->value
->dict1
.dict2
.userdef1
->base
= g_new0(UserDefZero
, 1);
398 p
->value
->dict1
.dict2
.userdef1
->base
->integer
= 42;
399 p
->value
->dict1
.dict2
.string2
= g_strdup(string
);
400 p
->value
->dict1
.has_dict3
= false;
406 qapi_free_UserDefNestedList(head
);
409 static void test_visitor_out_union(TestOutputVisitorData
*data
,
412 QObject
*arg
, *qvalue
;
413 QDict
*qdict
, *value
;
417 UserDefUnion
*tmp
= g_malloc0(sizeof(UserDefUnion
));
418 tmp
->kind
= USER_DEF_UNION_KIND_A
;
420 tmp
->a
= g_malloc0(sizeof(UserDefA
));
421 tmp
->a
->boolean
= true;
423 visit_type_UserDefUnion(data
->ov
, &tmp
, NULL
, &err
);
424 g_assert(err
== NULL
);
425 arg
= qmp_output_get_qobject(data
->qov
);
427 g_assert(qobject_type(arg
) == QTYPE_QDICT
);
428 qdict
= qobject_to_qdict(arg
);
430 g_assert_cmpstr(qdict_get_str(qdict
, "type"), ==, "a");
431 g_assert_cmpint(qdict_get_int(qdict
, "integer"), ==, 41);
433 qvalue
= qdict_get(qdict
, "data");
434 g_assert(data
!= NULL
);
435 g_assert(qobject_type(qvalue
) == QTYPE_QDICT
);
436 value
= qobject_to_qdict(qvalue
);
437 g_assert_cmpint(qdict_get_bool(value
, "boolean"), ==, true);
439 qapi_free_UserDefUnion(tmp
);
443 static void test_visitor_out_union_flat(TestOutputVisitorData
*data
,
451 UserDefFlatUnion
*tmp
= g_malloc0(sizeof(UserDefFlatUnion
));
452 tmp
->kind
= USER_DEF_UNION_KIND_A
;
453 tmp
->a
= g_malloc0(sizeof(UserDefA
));
454 /* TODO when generator bug is fixed: tmp->integer = 41; */
455 tmp
->a
->boolean
= true;
457 visit_type_UserDefFlatUnion(data
->ov
, &tmp
, NULL
, &err
);
458 g_assert(err
== NULL
);
459 arg
= qmp_output_get_qobject(data
->qov
);
461 g_assert(qobject_type(arg
) == QTYPE_QDICT
);
462 qdict
= qobject_to_qdict(arg
);
464 g_assert_cmpstr(qdict_get_str(qdict
, "string"), ==, "a");
465 /* TODO g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 41); */
466 g_assert_cmpint(qdict_get_bool(qdict
, "boolean"), ==, true);
468 qapi_free_UserDefFlatUnion(tmp
);
472 static void test_visitor_out_union_anon(TestOutputVisitorData
*data
,
478 UserDefAnonUnion
*tmp
= g_malloc0(sizeof(UserDefAnonUnion
));
479 tmp
->kind
= USER_DEF_ANON_UNION_KIND_I
;
482 visit_type_UserDefAnonUnion(data
->ov
, &tmp
, NULL
, &err
);
483 g_assert(err
== NULL
);
484 arg
= qmp_output_get_qobject(data
->qov
);
486 g_assert(qobject_type(arg
) == QTYPE_QINT
);
487 g_assert_cmpint(qint_get_int(qobject_to_qint(arg
)), ==, 42);
489 qapi_free_UserDefAnonUnion(tmp
);
492 static void init_native_list(UserDefNativeListUnion
*cvalue
)
495 switch (cvalue
->kind
) {
496 case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER
: {
497 intList
**list
= &cvalue
->integer
;
498 for (i
= 0; i
< 32; i
++) {
499 *list
= g_new0(intList
, 1);
501 (*list
)->next
= NULL
;
502 list
= &(*list
)->next
;
506 case USER_DEF_NATIVE_LIST_UNION_KIND_S8
: {
507 int8List
**list
= &cvalue
->s8
;
508 for (i
= 0; i
< 32; i
++) {
509 *list
= g_new0(int8List
, 1);
511 (*list
)->next
= NULL
;
512 list
= &(*list
)->next
;
516 case USER_DEF_NATIVE_LIST_UNION_KIND_S16
: {
517 int16List
**list
= &cvalue
->s16
;
518 for (i
= 0; i
< 32; i
++) {
519 *list
= g_new0(int16List
, 1);
521 (*list
)->next
= NULL
;
522 list
= &(*list
)->next
;
526 case USER_DEF_NATIVE_LIST_UNION_KIND_S32
: {
527 int32List
**list
= &cvalue
->s32
;
528 for (i
= 0; i
< 32; i
++) {
529 *list
= g_new0(int32List
, 1);
531 (*list
)->next
= NULL
;
532 list
= &(*list
)->next
;
536 case USER_DEF_NATIVE_LIST_UNION_KIND_S64
: {
537 int64List
**list
= &cvalue
->s64
;
538 for (i
= 0; i
< 32; i
++) {
539 *list
= g_new0(int64List
, 1);
541 (*list
)->next
= NULL
;
542 list
= &(*list
)->next
;
546 case USER_DEF_NATIVE_LIST_UNION_KIND_U8
: {
547 uint8List
**list
= &cvalue
->u8
;
548 for (i
= 0; i
< 32; i
++) {
549 *list
= g_new0(uint8List
, 1);
551 (*list
)->next
= NULL
;
552 list
= &(*list
)->next
;
556 case USER_DEF_NATIVE_LIST_UNION_KIND_U16
: {
557 uint16List
**list
= &cvalue
->u16
;
558 for (i
= 0; i
< 32; i
++) {
559 *list
= g_new0(uint16List
, 1);
561 (*list
)->next
= NULL
;
562 list
= &(*list
)->next
;
566 case USER_DEF_NATIVE_LIST_UNION_KIND_U32
: {
567 uint32List
**list
= &cvalue
->u32
;
568 for (i
= 0; i
< 32; i
++) {
569 *list
= g_new0(uint32List
, 1);
571 (*list
)->next
= NULL
;
572 list
= &(*list
)->next
;
576 case USER_DEF_NATIVE_LIST_UNION_KIND_U64
: {
577 uint64List
**list
= &cvalue
->u64
;
578 for (i
= 0; i
< 32; i
++) {
579 *list
= g_new0(uint64List
, 1);
581 (*list
)->next
= NULL
;
582 list
= &(*list
)->next
;
586 case USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN
: {
587 boolList
**list
= &cvalue
->boolean
;
588 for (i
= 0; i
< 32; i
++) {
589 *list
= g_new0(boolList
, 1);
590 (*list
)->value
= (i
% 3 == 0);
591 (*list
)->next
= NULL
;
592 list
= &(*list
)->next
;
596 case USER_DEF_NATIVE_LIST_UNION_KIND_STRING
: {
597 strList
**list
= &cvalue
->string
;
598 for (i
= 0; i
< 32; i
++) {
599 *list
= g_new0(strList
, 1);
600 (*list
)->value
= g_strdup_printf("%d", i
);
601 (*list
)->next
= NULL
;
602 list
= &(*list
)->next
;
606 case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER
: {
607 numberList
**list
= &cvalue
->number
;
608 for (i
= 0; i
< 32; i
++) {
609 *list
= g_new0(numberList
, 1);
610 (*list
)->value
= (double)i
/ 3;
611 (*list
)->next
= NULL
;
612 list
= &(*list
)->next
;
617 g_assert_not_reached();
621 static void check_native_list(QObject
*qobj
,
622 UserDefNativeListUnionKind kind
)
629 g_assert(qobject_type(qobj
) == QTYPE_QDICT
);
630 qdict
= qobject_to_qdict(qobj
);
632 g_assert(qdict_haskey(qdict
, "data"));
633 qlist
= qlist_copy(qobject_to_qlist(qdict_get(qdict
, "data")));
636 case USER_DEF_NATIVE_LIST_UNION_KIND_S8
:
637 case USER_DEF_NATIVE_LIST_UNION_KIND_S16
:
638 case USER_DEF_NATIVE_LIST_UNION_KIND_S32
:
639 case USER_DEF_NATIVE_LIST_UNION_KIND_S64
:
640 case USER_DEF_NATIVE_LIST_UNION_KIND_U8
:
641 case USER_DEF_NATIVE_LIST_UNION_KIND_U16
:
642 case USER_DEF_NATIVE_LIST_UNION_KIND_U32
:
643 case USER_DEF_NATIVE_LIST_UNION_KIND_U64
:
644 /* all integer elements in JSON arrays get stored into QInts when
645 * we convert to QObjects, so we can check them all in the same
646 * fashion, so simply fall through here
648 case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER
:
649 for (i
= 0; i
< 32; i
++) {
652 tmp
= qlist_peek(qlist
);
654 qvalue
= qobject_to_qint(tmp
);
655 g_assert_cmpint(qint_get_int(qvalue
), ==, i
);
656 qobject_decref(qlist_pop(qlist
));
659 case USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN
:
660 for (i
= 0; i
< 32; i
++) {
663 tmp
= qlist_peek(qlist
);
665 qvalue
= qobject_to_qbool(tmp
);
666 g_assert_cmpint(qbool_get_int(qvalue
), ==, (i
% 3 == 0) ? 1 : 0);
667 qobject_decref(qlist_pop(qlist
));
670 case USER_DEF_NATIVE_LIST_UNION_KIND_STRING
:
671 for (i
= 0; i
< 32; i
++) {
675 tmp
= qlist_peek(qlist
);
677 qvalue
= qobject_to_qstring(tmp
);
678 sprintf(str
, "%d", i
);
679 g_assert_cmpstr(qstring_get_str(qvalue
), ==, str
);
680 qobject_decref(qlist_pop(qlist
));
683 case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER
:
684 for (i
= 0; i
< 32; i
++) {
687 GString
*double_expected
= g_string_new("");
688 GString
*double_actual
= g_string_new("");
690 tmp
= qlist_peek(qlist
);
692 qvalue
= qobject_to_qfloat(tmp
);
693 g_string_printf(double_expected
, "%.6f", (double)i
/ 3);
694 g_string_printf(double_actual
, "%.6f", qfloat_get_double(qvalue
));
695 g_assert_cmpstr(double_actual
->str
, ==, double_expected
->str
);
697 qobject_decref(qlist_pop(qlist
));
698 g_string_free(double_expected
, true);
699 g_string_free(double_actual
, true);
703 g_assert_not_reached();
708 static void test_native_list(TestOutputVisitorData
*data
,
710 UserDefNativeListUnionKind kind
)
712 UserDefNativeListUnion
*cvalue
= g_new0(UserDefNativeListUnion
, 1);
717 init_native_list(cvalue
);
719 visit_type_UserDefNativeListUnion(data
->ov
, &cvalue
, NULL
, &err
);
720 g_assert(err
== NULL
);
722 obj
= qmp_output_get_qobject(data
->qov
);
723 check_native_list(obj
, cvalue
->kind
);
724 qapi_free_UserDefNativeListUnion(cvalue
);
728 static void test_visitor_out_native_list_int(TestOutputVisitorData
*data
,
731 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER
);
734 static void test_visitor_out_native_list_int8(TestOutputVisitorData
*data
,
737 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S8
);
740 static void test_visitor_out_native_list_int16(TestOutputVisitorData
*data
,
743 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S16
);
746 static void test_visitor_out_native_list_int32(TestOutputVisitorData
*data
,
749 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S32
);
752 static void test_visitor_out_native_list_int64(TestOutputVisitorData
*data
,
755 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S64
);
758 static void test_visitor_out_native_list_uint8(TestOutputVisitorData
*data
,
761 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U8
);
764 static void test_visitor_out_native_list_uint16(TestOutputVisitorData
*data
,
767 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U16
);
770 static void test_visitor_out_native_list_uint32(TestOutputVisitorData
*data
,
773 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U32
);
776 static void test_visitor_out_native_list_uint64(TestOutputVisitorData
*data
,
779 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U64
);
782 static void test_visitor_out_native_list_bool(TestOutputVisitorData
*data
,
785 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN
);
788 static void test_visitor_out_native_list_str(TestOutputVisitorData
*data
,
791 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_STRING
);
794 static void test_visitor_out_native_list_number(TestOutputVisitorData
*data
,
797 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER
);
800 static void output_visitor_test_add(const char *testpath
,
801 TestOutputVisitorData
*data
,
802 void (*test_func
)(TestOutputVisitorData
*data
, const void *user_data
))
804 g_test_add(testpath
, TestOutputVisitorData
, data
, visitor_output_setup
,
805 test_func
, visitor_output_teardown
);
808 int main(int argc
, char **argv
)
810 TestOutputVisitorData out_visitor_data
;
812 g_test_init(&argc
, &argv
, NULL
);
814 output_visitor_test_add("/visitor/output/int",
815 &out_visitor_data
, test_visitor_out_int
);
816 output_visitor_test_add("/visitor/output/bool",
817 &out_visitor_data
, test_visitor_out_bool
);
818 output_visitor_test_add("/visitor/output/number",
819 &out_visitor_data
, test_visitor_out_number
);
820 output_visitor_test_add("/visitor/output/string",
821 &out_visitor_data
, test_visitor_out_string
);
822 output_visitor_test_add("/visitor/output/no-string",
823 &out_visitor_data
, test_visitor_out_no_string
);
824 output_visitor_test_add("/visitor/output/enum",
825 &out_visitor_data
, test_visitor_out_enum
);
826 output_visitor_test_add("/visitor/output/enum-errors",
827 &out_visitor_data
, test_visitor_out_enum_errors
);
828 output_visitor_test_add("/visitor/output/struct",
829 &out_visitor_data
, test_visitor_out_struct
);
830 output_visitor_test_add("/visitor/output/struct-nested",
831 &out_visitor_data
, test_visitor_out_struct_nested
);
832 output_visitor_test_add("/visitor/output/struct-errors",
833 &out_visitor_data
, test_visitor_out_struct_errors
);
834 output_visitor_test_add("/visitor/output/list",
835 &out_visitor_data
, test_visitor_out_list
);
836 output_visitor_test_add("/visitor/output/list-qapi-free",
837 &out_visitor_data
, test_visitor_out_list_qapi_free
);
838 output_visitor_test_add("/visitor/output/union",
839 &out_visitor_data
, test_visitor_out_union
);
840 output_visitor_test_add("/visitor/output/union-flat",
841 &out_visitor_data
, test_visitor_out_union_flat
);
842 output_visitor_test_add("/visitor/output/union-anon",
843 &out_visitor_data
, test_visitor_out_union_anon
);
844 output_visitor_test_add("/visitor/output/native_list/int",
845 &out_visitor_data
, test_visitor_out_native_list_int
);
846 output_visitor_test_add("/visitor/output/native_list/int8",
847 &out_visitor_data
, test_visitor_out_native_list_int8
);
848 output_visitor_test_add("/visitor/output/native_list/int16",
849 &out_visitor_data
, test_visitor_out_native_list_int16
);
850 output_visitor_test_add("/visitor/output/native_list/int32",
851 &out_visitor_data
, test_visitor_out_native_list_int32
);
852 output_visitor_test_add("/visitor/output/native_list/int64",
853 &out_visitor_data
, test_visitor_out_native_list_int64
);
854 output_visitor_test_add("/visitor/output/native_list/uint8",
855 &out_visitor_data
, test_visitor_out_native_list_uint8
);
856 output_visitor_test_add("/visitor/output/native_list/uint16",
857 &out_visitor_data
, test_visitor_out_native_list_uint16
);
858 output_visitor_test_add("/visitor/output/native_list/uint32",
859 &out_visitor_data
, test_visitor_out_native_list_uint32
);
860 output_visitor_test_add("/visitor/output/native_list/uint64",
861 &out_visitor_data
, test_visitor_out_native_list_uint64
);
862 output_visitor_test_add("/visitor/output/native_list/bool",
863 &out_visitor_data
, test_visitor_out_native_list_bool
);
864 output_visitor_test_add("/visitor/output/native_list/string",
865 &out_visitor_data
, test_visitor_out_native_list_str
);
866 output_visitor_test_add("/visitor/output/native_list/number",
867 &out_visitor_data
, test_visitor_out_native_list_number
);