2 * QMP Output Visitor unit-tests.
4 * Copyright (C) 2011, 2015 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
, &err
);
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
, &err
);
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_bool(qobject_to_qbool(obj
)) == value
);
80 static void test_visitor_out_number(TestOutputVisitorData
*data
,
87 visit_type_number(data
->ov
, &value
, NULL
, &err
);
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
, &err
);
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
, &err
);
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", &err
);
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", &err
);
169 typedef struct TestStruct
176 static void visit_type_TestStruct(Visitor
*v
, TestStruct
**obj
,
177 const char *name
, Error
**errp
)
181 visit_start_struct(v
, (void **)obj
, "TestStruct", name
, sizeof(TestStruct
),
187 visit_type_int(v
, &(*obj
)->integer
, "integer", &err
);
191 visit_type_bool(v
, &(*obj
)->boolean
, "boolean", &err
);
195 visit_type_str(v
, &(*obj
)->string
, "string", &err
);
198 error_propagate(errp
, err
);
200 visit_end_struct(v
, &err
);
202 error_propagate(errp
, err
);
205 static void test_visitor_out_struct(TestOutputVisitorData
*data
,
208 TestStruct test_struct
= { .integer
= 42,
210 .string
= (char *) "foo"};
211 TestStruct
*p
= &test_struct
;
216 visit_type_TestStruct(data
->ov
, &p
, NULL
, &err
);
219 obj
= qmp_output_get_qobject(data
->qov
);
220 g_assert(obj
!= NULL
);
221 g_assert(qobject_type(obj
) == QTYPE_QDICT
);
223 qdict
= qobject_to_qdict(obj
);
224 g_assert_cmpint(qdict_size(qdict
), ==, 3);
225 g_assert_cmpint(qdict_get_int(qdict
, "integer"), ==, 42);
226 g_assert_cmpint(qdict_get_bool(qdict
, "boolean"), ==, false);
227 g_assert_cmpstr(qdict_get_str(qdict
, "string"), ==, "foo");
232 static void test_visitor_out_struct_nested(TestOutputVisitorData
*data
,
239 QDict
*qdict
, *dict1
, *dict2
, *dict3
, *userdef
;
240 const char *string
= "user def string";
241 const char *strings
[] = { "forty two", "forty three", "forty four",
244 ud2
= g_malloc0(sizeof(*ud2
));
245 ud2
->string0
= g_strdup(strings
[0]);
247 ud2
->dict1
= g_malloc0(sizeof(*ud2
->dict1
));
248 ud2
->dict1
->string1
= g_strdup(strings
[1]);
250 ud2
->dict1
->dict2
= g_malloc0(sizeof(*ud2
->dict1
->dict2
));
251 ud2
->dict1
->dict2
->userdef
= g_new0(UserDefOne
, 1);
252 ud2
->dict1
->dict2
->userdef
->string
= g_strdup(string
);
253 ud2
->dict1
->dict2
->userdef
->base
= g_new0(UserDefZero
, 1);
254 ud2
->dict1
->dict2
->userdef
->base
->integer
= value
;
255 ud2
->dict1
->dict2
->string
= g_strdup(strings
[2]);
257 ud2
->dict1
->dict3
= g_malloc0(sizeof(*ud2
->dict1
->dict3
));
258 ud2
->dict1
->has_dict3
= true;
259 ud2
->dict1
->dict3
->userdef
= g_new0(UserDefOne
, 1);
260 ud2
->dict1
->dict3
->userdef
->string
= g_strdup(string
);
261 ud2
->dict1
->dict3
->userdef
->base
= g_new0(UserDefZero
, 1);
262 ud2
->dict1
->dict3
->userdef
->base
->integer
= value
;
263 ud2
->dict1
->dict3
->string
= g_strdup(strings
[3]);
265 visit_type_UserDefTwo(data
->ov
, &ud2
, "unused", &err
);
268 obj
= qmp_output_get_qobject(data
->qov
);
269 g_assert(obj
!= NULL
);
270 g_assert(qobject_type(obj
) == QTYPE_QDICT
);
272 qdict
= qobject_to_qdict(obj
);
273 g_assert_cmpint(qdict_size(qdict
), ==, 2);
274 g_assert_cmpstr(qdict_get_str(qdict
, "string0"), ==, strings
[0]);
276 dict1
= qdict_get_qdict(qdict
, "dict1");
277 g_assert_cmpint(qdict_size(dict1
), ==, 3);
278 g_assert_cmpstr(qdict_get_str(dict1
, "string1"), ==, strings
[1]);
280 dict2
= qdict_get_qdict(dict1
, "dict2");
281 g_assert_cmpint(qdict_size(dict2
), ==, 2);
282 g_assert_cmpstr(qdict_get_str(dict2
, "string"), ==, strings
[2]);
283 userdef
= qdict_get_qdict(dict2
, "userdef");
284 g_assert_cmpint(qdict_size(userdef
), ==, 2);
285 g_assert_cmpint(qdict_get_int(userdef
, "integer"), ==, value
);
286 g_assert_cmpstr(qdict_get_str(userdef
, "string"), ==, string
);
288 dict3
= qdict_get_qdict(dict1
, "dict3");
289 g_assert_cmpint(qdict_size(dict3
), ==, 2);
290 g_assert_cmpstr(qdict_get_str(dict3
, "string"), ==, strings
[3]);
291 userdef
= qdict_get_qdict(dict3
, "userdef");
292 g_assert_cmpint(qdict_size(userdef
), ==, 2);
293 g_assert_cmpint(qdict_get_int(userdef
, "integer"), ==, value
);
294 g_assert_cmpstr(qdict_get_str(userdef
, "string"), ==, string
);
297 qapi_free_UserDefTwo(ud2
);
300 static void test_visitor_out_struct_errors(TestOutputVisitorData
*data
,
303 EnumOne bad_values
[] = { ENUM_ONE_MAX
, -1 };
305 UserDefOne u
= { .base
= &b
}, *pu
= &u
;
309 for (i
= 0; i
< ARRAY_SIZE(bad_values
) ; i
++) {
312 u
.enum1
= bad_values
[i
];
313 visit_type_UserDefOne(data
->ov
, &pu
, "unused", &err
);
319 typedef struct TestStructList
325 struct TestStructList
*next
;
328 static void visit_type_TestStructList(Visitor
*v
, TestStructList
**obj
,
329 const char *name
, Error
**errp
)
331 GenericList
*i
, **head
= (GenericList
**)obj
;
333 visit_start_list(v
, name
, errp
);
335 for (*head
= i
= visit_next_list(v
, head
, errp
); i
; i
= visit_next_list(v
, &i
, errp
)) {
336 TestStructList
*native_i
= (TestStructList
*)i
;
337 visit_type_TestStruct(v
, &native_i
->value
, NULL
, errp
);
340 visit_end_list(v
, errp
);
343 static void test_visitor_out_list(TestOutputVisitorData
*data
,
346 char *value_str
= (char *) "list value";
347 TestStructList
*p
, *head
= NULL
;
348 const int max_items
= 10;
349 bool value_bool
= true;
357 for (i
= 0; i
< max_items
; i
++) {
358 p
= g_malloc0(sizeof(*p
));
359 p
->value
= g_malloc0(sizeof(*p
->value
));
360 p
->value
->integer
= value_int
;
361 p
->value
->boolean
= value_bool
;
362 p
->value
->string
= value_str
;
368 visit_type_TestStructList(data
->ov
, &head
, NULL
, &err
);
371 obj
= qmp_output_get_qobject(data
->qov
);
372 g_assert(obj
!= NULL
);
373 g_assert(qobject_type(obj
) == QTYPE_QLIST
);
375 qlist
= qobject_to_qlist(obj
);
376 g_assert(!qlist_empty(qlist
));
379 QLIST_FOREACH_ENTRY(qlist
, entry
) {
382 g_assert(qobject_type(entry
->value
) == QTYPE_QDICT
);
383 qdict
= qobject_to_qdict(entry
->value
);
384 g_assert_cmpint(qdict_size(qdict
), ==, 3);
385 g_assert_cmpint(qdict_get_int(qdict
, "integer"), ==, value_int
);
386 g_assert_cmpint(qdict_get_bool(qdict
, "boolean"), ==, value_bool
);
387 g_assert_cmpstr(qdict_get_str(qdict
, "string"), ==, value_str
);
390 g_assert_cmpint(i
, ==, max_items
);
395 TestStructList
*tmp
= p
->next
;
402 static void test_visitor_out_list_qapi_free(TestOutputVisitorData
*data
,
405 UserDefTwoList
*p
, *head
= NULL
;
406 const char string
[] = "foo bar";
407 int i
, max_count
= 1024;
409 for (i
= 0; i
< max_count
; i
++) {
410 p
= g_malloc0(sizeof(*p
));
411 p
->value
= g_malloc0(sizeof(*p
->value
));
413 p
->value
->string0
= g_strdup(string
);
414 p
->value
->dict1
= g_new0(UserDefTwoDict
, 1);
415 p
->value
->dict1
->string1
= g_strdup(string
);
416 p
->value
->dict1
->dict2
= g_new0(UserDefTwoDictDict
, 1);
417 p
->value
->dict1
->dict2
->userdef
= g_new0(UserDefOne
, 1);
418 p
->value
->dict1
->dict2
->userdef
->string
= g_strdup(string
);
419 p
->value
->dict1
->dict2
->userdef
->base
= g_new0(UserDefZero
, 1);
420 p
->value
->dict1
->dict2
->userdef
->base
->integer
= 42;
421 p
->value
->dict1
->dict2
->string
= g_strdup(string
);
422 p
->value
->dict1
->has_dict3
= false;
428 qapi_free_UserDefTwoList(head
);
431 static void test_visitor_out_any(TestOutputVisitorData
*data
,
442 qobj
= QOBJECT(qint_from_int(-42));
443 visit_type_any(data
->ov
, &qobj
, NULL
, &err
);
445 obj
= qmp_output_get_qobject(data
->qov
);
446 g_assert(obj
!= NULL
);
447 g_assert(qobject_type(obj
) == QTYPE_QINT
);
448 g_assert_cmpint(qint_get_int(qobject_to_qint(obj
)), ==, -42);
450 qobject_decref(qobj
);
453 qdict_put(qdict
, "integer", qint_from_int(-42));
454 qdict_put(qdict
, "boolean", qbool_from_bool(true));
455 qdict_put(qdict
, "string", qstring_from_str("foo"));
456 qobj
= QOBJECT(qdict
);
457 visit_type_any(data
->ov
, &qobj
, NULL
, &err
);
459 obj
= qmp_output_get_qobject(data
->qov
);
460 g_assert(obj
!= NULL
);
461 qdict
= qobject_to_qdict(obj
);
463 qobj
= qdict_get(qdict
, "integer");
465 qint
= qobject_to_qint(qobj
);
467 g_assert_cmpint(qint_get_int(qint
), ==, -42);
468 qobj
= qdict_get(qdict
, "boolean");
470 qbool
= qobject_to_qbool(qobj
);
472 g_assert(qbool_get_bool(qbool
) == true);
473 qobj
= qdict_get(qdict
, "string");
475 qstring
= qobject_to_qstring(qobj
);
477 g_assert_cmpstr(qstring_get_str(qstring
), ==, "foo");
479 qobject_decref(qobj
);
482 static void test_visitor_out_union_flat(TestOutputVisitorData
*data
,
490 UserDefFlatUnion
*tmp
= g_malloc0(sizeof(UserDefFlatUnion
));
491 tmp
->enum1
= ENUM_ONE_VALUE1
;
492 tmp
->string
= g_strdup("str");
493 tmp
->value1
= g_malloc0(sizeof(UserDefA
));
494 /* TODO when generator bug is fixed: tmp->integer = 41; */
495 tmp
->value1
->boolean
= true;
497 visit_type_UserDefFlatUnion(data
->ov
, &tmp
, NULL
, &err
);
498 g_assert(err
== NULL
);
499 arg
= qmp_output_get_qobject(data
->qov
);
501 g_assert(qobject_type(arg
) == QTYPE_QDICT
);
502 qdict
= qobject_to_qdict(arg
);
504 g_assert_cmpstr(qdict_get_str(qdict
, "enum1"), ==, "value1");
505 g_assert_cmpstr(qdict_get_str(qdict
, "string"), ==, "str");
506 /* TODO g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 41); */
507 g_assert_cmpint(qdict_get_bool(qdict
, "boolean"), ==, true);
509 qapi_free_UserDefFlatUnion(tmp
);
513 static void test_visitor_out_alternate(TestOutputVisitorData
*data
,
519 UserDefAlternate
*tmp
= g_malloc0(sizeof(UserDefAlternate
));
520 tmp
->kind
= USER_DEF_ALTERNATE_KIND_I
;
523 visit_type_UserDefAlternate(data
->ov
, &tmp
, NULL
, &err
);
524 g_assert(err
== NULL
);
525 arg
= qmp_output_get_qobject(data
->qov
);
527 g_assert(qobject_type(arg
) == QTYPE_QINT
);
528 g_assert_cmpint(qint_get_int(qobject_to_qint(arg
)), ==, 42);
530 qapi_free_UserDefAlternate(tmp
);
533 static void test_visitor_out_empty(TestOutputVisitorData
*data
,
538 arg
= qmp_output_get_qobject(data
->qov
);
539 g_assert(qobject_type(arg
) == QTYPE_QNULL
);
543 static void init_native_list(UserDefNativeListUnion
*cvalue
)
546 switch (cvalue
->kind
) {
547 case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER
: {
548 intList
**list
= &cvalue
->integer
;
549 for (i
= 0; i
< 32; i
++) {
550 *list
= g_new0(intList
, 1);
552 (*list
)->next
= NULL
;
553 list
= &(*list
)->next
;
557 case USER_DEF_NATIVE_LIST_UNION_KIND_S8
: {
558 int8List
**list
= &cvalue
->s8
;
559 for (i
= 0; i
< 32; i
++) {
560 *list
= g_new0(int8List
, 1);
562 (*list
)->next
= NULL
;
563 list
= &(*list
)->next
;
567 case USER_DEF_NATIVE_LIST_UNION_KIND_S16
: {
568 int16List
**list
= &cvalue
->s16
;
569 for (i
= 0; i
< 32; i
++) {
570 *list
= g_new0(int16List
, 1);
572 (*list
)->next
= NULL
;
573 list
= &(*list
)->next
;
577 case USER_DEF_NATIVE_LIST_UNION_KIND_S32
: {
578 int32List
**list
= &cvalue
->s32
;
579 for (i
= 0; i
< 32; i
++) {
580 *list
= g_new0(int32List
, 1);
582 (*list
)->next
= NULL
;
583 list
= &(*list
)->next
;
587 case USER_DEF_NATIVE_LIST_UNION_KIND_S64
: {
588 int64List
**list
= &cvalue
->s64
;
589 for (i
= 0; i
< 32; i
++) {
590 *list
= g_new0(int64List
, 1);
592 (*list
)->next
= NULL
;
593 list
= &(*list
)->next
;
597 case USER_DEF_NATIVE_LIST_UNION_KIND_U8
: {
598 uint8List
**list
= &cvalue
->u8
;
599 for (i
= 0; i
< 32; i
++) {
600 *list
= g_new0(uint8List
, 1);
602 (*list
)->next
= NULL
;
603 list
= &(*list
)->next
;
607 case USER_DEF_NATIVE_LIST_UNION_KIND_U16
: {
608 uint16List
**list
= &cvalue
->u16
;
609 for (i
= 0; i
< 32; i
++) {
610 *list
= g_new0(uint16List
, 1);
612 (*list
)->next
= NULL
;
613 list
= &(*list
)->next
;
617 case USER_DEF_NATIVE_LIST_UNION_KIND_U32
: {
618 uint32List
**list
= &cvalue
->u32
;
619 for (i
= 0; i
< 32; i
++) {
620 *list
= g_new0(uint32List
, 1);
622 (*list
)->next
= NULL
;
623 list
= &(*list
)->next
;
627 case USER_DEF_NATIVE_LIST_UNION_KIND_U64
: {
628 uint64List
**list
= &cvalue
->u64
;
629 for (i
= 0; i
< 32; i
++) {
630 *list
= g_new0(uint64List
, 1);
632 (*list
)->next
= NULL
;
633 list
= &(*list
)->next
;
637 case USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN
: {
638 boolList
**list
= &cvalue
->boolean
;
639 for (i
= 0; i
< 32; i
++) {
640 *list
= g_new0(boolList
, 1);
641 (*list
)->value
= (i
% 3 == 0);
642 (*list
)->next
= NULL
;
643 list
= &(*list
)->next
;
647 case USER_DEF_NATIVE_LIST_UNION_KIND_STRING
: {
648 strList
**list
= &cvalue
->string
;
649 for (i
= 0; i
< 32; i
++) {
650 *list
= g_new0(strList
, 1);
651 (*list
)->value
= g_strdup_printf("%d", i
);
652 (*list
)->next
= NULL
;
653 list
= &(*list
)->next
;
657 case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER
: {
658 numberList
**list
= &cvalue
->number
;
659 for (i
= 0; i
< 32; i
++) {
660 *list
= g_new0(numberList
, 1);
661 (*list
)->value
= (double)i
/ 3;
662 (*list
)->next
= NULL
;
663 list
= &(*list
)->next
;
668 g_assert_not_reached();
672 static void check_native_list(QObject
*qobj
,
673 UserDefNativeListUnionKind kind
)
680 g_assert(qobject_type(qobj
) == QTYPE_QDICT
);
681 qdict
= qobject_to_qdict(qobj
);
683 g_assert(qdict_haskey(qdict
, "data"));
684 qlist
= qlist_copy(qobject_to_qlist(qdict_get(qdict
, "data")));
687 case USER_DEF_NATIVE_LIST_UNION_KIND_S8
:
688 case USER_DEF_NATIVE_LIST_UNION_KIND_S16
:
689 case USER_DEF_NATIVE_LIST_UNION_KIND_S32
:
690 case USER_DEF_NATIVE_LIST_UNION_KIND_S64
:
691 case USER_DEF_NATIVE_LIST_UNION_KIND_U8
:
692 case USER_DEF_NATIVE_LIST_UNION_KIND_U16
:
693 case USER_DEF_NATIVE_LIST_UNION_KIND_U32
:
694 case USER_DEF_NATIVE_LIST_UNION_KIND_U64
:
695 /* all integer elements in JSON arrays get stored into QInts when
696 * we convert to QObjects, so we can check them all in the same
697 * fashion, so simply fall through here
699 case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER
:
700 for (i
= 0; i
< 32; i
++) {
703 tmp
= qlist_peek(qlist
);
705 qvalue
= qobject_to_qint(tmp
);
706 g_assert_cmpint(qint_get_int(qvalue
), ==, i
);
707 qobject_decref(qlist_pop(qlist
));
710 case USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN
:
711 for (i
= 0; i
< 32; i
++) {
714 tmp
= qlist_peek(qlist
);
716 qvalue
= qobject_to_qbool(tmp
);
717 g_assert_cmpint(qbool_get_bool(qvalue
), ==, i
% 3 == 0);
718 qobject_decref(qlist_pop(qlist
));
721 case USER_DEF_NATIVE_LIST_UNION_KIND_STRING
:
722 for (i
= 0; i
< 32; i
++) {
726 tmp
= qlist_peek(qlist
);
728 qvalue
= qobject_to_qstring(tmp
);
729 sprintf(str
, "%d", i
);
730 g_assert_cmpstr(qstring_get_str(qvalue
), ==, str
);
731 qobject_decref(qlist_pop(qlist
));
734 case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER
:
735 for (i
= 0; i
< 32; i
++) {
738 GString
*double_expected
= g_string_new("");
739 GString
*double_actual
= g_string_new("");
741 tmp
= qlist_peek(qlist
);
743 qvalue
= qobject_to_qfloat(tmp
);
744 g_string_printf(double_expected
, "%.6f", (double)i
/ 3);
745 g_string_printf(double_actual
, "%.6f", qfloat_get_double(qvalue
));
746 g_assert_cmpstr(double_actual
->str
, ==, double_expected
->str
);
748 qobject_decref(qlist_pop(qlist
));
749 g_string_free(double_expected
, true);
750 g_string_free(double_actual
, true);
754 g_assert_not_reached();
759 static void test_native_list(TestOutputVisitorData
*data
,
761 UserDefNativeListUnionKind kind
)
763 UserDefNativeListUnion
*cvalue
= g_new0(UserDefNativeListUnion
, 1);
768 init_native_list(cvalue
);
770 visit_type_UserDefNativeListUnion(data
->ov
, &cvalue
, NULL
, &err
);
771 g_assert(err
== NULL
);
773 obj
= qmp_output_get_qobject(data
->qov
);
774 check_native_list(obj
, cvalue
->kind
);
775 qapi_free_UserDefNativeListUnion(cvalue
);
779 static void test_visitor_out_native_list_int(TestOutputVisitorData
*data
,
782 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER
);
785 static void test_visitor_out_native_list_int8(TestOutputVisitorData
*data
,
788 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S8
);
791 static void test_visitor_out_native_list_int16(TestOutputVisitorData
*data
,
794 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S16
);
797 static void test_visitor_out_native_list_int32(TestOutputVisitorData
*data
,
800 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S32
);
803 static void test_visitor_out_native_list_int64(TestOutputVisitorData
*data
,
806 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S64
);
809 static void test_visitor_out_native_list_uint8(TestOutputVisitorData
*data
,
812 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U8
);
815 static void test_visitor_out_native_list_uint16(TestOutputVisitorData
*data
,
818 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U16
);
821 static void test_visitor_out_native_list_uint32(TestOutputVisitorData
*data
,
824 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U32
);
827 static void test_visitor_out_native_list_uint64(TestOutputVisitorData
*data
,
830 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U64
);
833 static void test_visitor_out_native_list_bool(TestOutputVisitorData
*data
,
836 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN
);
839 static void test_visitor_out_native_list_str(TestOutputVisitorData
*data
,
842 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_STRING
);
845 static void test_visitor_out_native_list_number(TestOutputVisitorData
*data
,
848 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER
);
851 static void output_visitor_test_add(const char *testpath
,
852 TestOutputVisitorData
*data
,
853 void (*test_func
)(TestOutputVisitorData
*data
, const void *user_data
))
855 g_test_add(testpath
, TestOutputVisitorData
, data
, visitor_output_setup
,
856 test_func
, visitor_output_teardown
);
859 int main(int argc
, char **argv
)
861 TestOutputVisitorData out_visitor_data
;
863 g_test_init(&argc
, &argv
, NULL
);
865 output_visitor_test_add("/visitor/output/int",
866 &out_visitor_data
, test_visitor_out_int
);
867 output_visitor_test_add("/visitor/output/bool",
868 &out_visitor_data
, test_visitor_out_bool
);
869 output_visitor_test_add("/visitor/output/number",
870 &out_visitor_data
, test_visitor_out_number
);
871 output_visitor_test_add("/visitor/output/string",
872 &out_visitor_data
, test_visitor_out_string
);
873 output_visitor_test_add("/visitor/output/no-string",
874 &out_visitor_data
, test_visitor_out_no_string
);
875 output_visitor_test_add("/visitor/output/enum",
876 &out_visitor_data
, test_visitor_out_enum
);
877 output_visitor_test_add("/visitor/output/enum-errors",
878 &out_visitor_data
, test_visitor_out_enum_errors
);
879 output_visitor_test_add("/visitor/output/struct",
880 &out_visitor_data
, test_visitor_out_struct
);
881 output_visitor_test_add("/visitor/output/struct-nested",
882 &out_visitor_data
, test_visitor_out_struct_nested
);
883 output_visitor_test_add("/visitor/output/struct-errors",
884 &out_visitor_data
, test_visitor_out_struct_errors
);
885 output_visitor_test_add("/visitor/output/list",
886 &out_visitor_data
, test_visitor_out_list
);
887 output_visitor_test_add("/visitor/output/any",
888 &out_visitor_data
, test_visitor_out_any
);
889 output_visitor_test_add("/visitor/output/list-qapi-free",
890 &out_visitor_data
, test_visitor_out_list_qapi_free
);
891 output_visitor_test_add("/visitor/output/union-flat",
892 &out_visitor_data
, test_visitor_out_union_flat
);
893 output_visitor_test_add("/visitor/output/alternate",
894 &out_visitor_data
, test_visitor_out_alternate
);
895 output_visitor_test_add("/visitor/output/empty",
896 &out_visitor_data
, test_visitor_out_empty
);
897 output_visitor_test_add("/visitor/output/native_list/int",
899 test_visitor_out_native_list_int
);
900 output_visitor_test_add("/visitor/output/native_list/int8",
902 test_visitor_out_native_list_int8
);
903 output_visitor_test_add("/visitor/output/native_list/int16",
905 test_visitor_out_native_list_int16
);
906 output_visitor_test_add("/visitor/output/native_list/int32",
908 test_visitor_out_native_list_int32
);
909 output_visitor_test_add("/visitor/output/native_list/int64",
911 test_visitor_out_native_list_int64
);
912 output_visitor_test_add("/visitor/output/native_list/uint8",
914 test_visitor_out_native_list_uint8
);
915 output_visitor_test_add("/visitor/output/native_list/uint16",
917 test_visitor_out_native_list_uint16
);
918 output_visitor_test_add("/visitor/output/native_list/uint32",
920 test_visitor_out_native_list_uint32
);
921 output_visitor_test_add("/visitor/output/native_list/uint64",
923 test_visitor_out_native_list_uint64
);
924 output_visitor_test_add("/visitor/output/native_list/bool",
926 test_visitor_out_native_list_bool
);
927 output_visitor_test_add("/visitor/output/native_list/string",
929 test_visitor_out_native_list_str
);
930 output_visitor_test_add("/visitor/output/native_list/number",
932 test_visitor_out_native_list_number
);