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
,
50 visit_type_int(data
->ov
, &value
, NULL
, &error_abort
);
52 obj
= qmp_output_get_qobject(data
->qov
);
53 g_assert(obj
!= NULL
);
54 g_assert(qobject_type(obj
) == QTYPE_QINT
);
55 g_assert_cmpint(qint_get_int(qobject_to_qint(obj
)), ==, value
);
60 static void test_visitor_out_bool(TestOutputVisitorData
*data
,
66 visit_type_bool(data
->ov
, &value
, NULL
, &error_abort
);
68 obj
= qmp_output_get_qobject(data
->qov
);
69 g_assert(obj
!= NULL
);
70 g_assert(qobject_type(obj
) == QTYPE_QBOOL
);
71 g_assert(qbool_get_bool(qobject_to_qbool(obj
)) == value
);
76 static void test_visitor_out_number(TestOutputVisitorData
*data
,
82 visit_type_number(data
->ov
, &value
, NULL
, &error_abort
);
84 obj
= qmp_output_get_qobject(data
->qov
);
85 g_assert(obj
!= NULL
);
86 g_assert(qobject_type(obj
) == QTYPE_QFLOAT
);
87 g_assert(qfloat_get_double(qobject_to_qfloat(obj
)) == value
);
92 static void test_visitor_out_string(TestOutputVisitorData
*data
,
95 char *string
= (char *) "Q E M U";
98 visit_type_str(data
->ov
, &string
, NULL
, &error_abort
);
100 obj
= qmp_output_get_qobject(data
->qov
);
101 g_assert(obj
!= NULL
);
102 g_assert(qobject_type(obj
) == QTYPE_QSTRING
);
103 g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj
)), ==, string
);
108 static void test_visitor_out_no_string(TestOutputVisitorData
*data
,
114 /* A null string should return "" */
115 visit_type_str(data
->ov
, &string
, NULL
, &error_abort
);
117 obj
= qmp_output_get_qobject(data
->qov
);
118 g_assert(obj
!= NULL
);
119 g_assert(qobject_type(obj
) == QTYPE_QSTRING
);
120 g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj
)), ==, "");
125 static void test_visitor_out_enum(TestOutputVisitorData
*data
,
131 for (i
= 0; i
< ENUM_ONE__MAX
; i
++) {
132 visit_type_EnumOne(data
->ov
, &i
, "unused", &error_abort
);
134 obj
= qmp_output_get_qobject(data
->qov
);
135 g_assert(obj
!= NULL
);
136 g_assert(qobject_type(obj
) == QTYPE_QSTRING
);
137 g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj
)), ==,
143 static void test_visitor_out_enum_errors(TestOutputVisitorData
*data
,
146 EnumOne i
, bad_values
[] = { ENUM_ONE__MAX
, -1 };
149 for (i
= 0; i
< ARRAY_SIZE(bad_values
) ; i
++) {
151 visit_type_EnumOne(data
->ov
, &bad_values
[i
], "unused", &err
);
158 static void test_visitor_out_struct(TestOutputVisitorData
*data
,
161 TestStruct test_struct
= { .integer
= 42,
163 .string
= (char *) "foo"};
164 TestStruct
*p
= &test_struct
;
168 visit_type_TestStruct(data
->ov
, &p
, NULL
, &error_abort
);
170 obj
= qmp_output_get_qobject(data
->qov
);
171 g_assert(obj
!= NULL
);
172 g_assert(qobject_type(obj
) == QTYPE_QDICT
);
174 qdict
= qobject_to_qdict(obj
);
175 g_assert_cmpint(qdict_size(qdict
), ==, 3);
176 g_assert_cmpint(qdict_get_int(qdict
, "integer"), ==, 42);
177 g_assert_cmpint(qdict_get_bool(qdict
, "boolean"), ==, false);
178 g_assert_cmpstr(qdict_get_str(qdict
, "string"), ==, "foo");
183 static void test_visitor_out_struct_nested(TestOutputVisitorData
*data
,
189 QDict
*qdict
, *dict1
, *dict2
, *dict3
, *userdef
;
190 const char *string
= "user def string";
191 const char *strings
[] = { "forty two", "forty three", "forty four",
194 ud2
= g_malloc0(sizeof(*ud2
));
195 ud2
->string0
= g_strdup(strings
[0]);
197 ud2
->dict1
= g_malloc0(sizeof(*ud2
->dict1
));
198 ud2
->dict1
->string1
= g_strdup(strings
[1]);
200 ud2
->dict1
->dict2
= g_malloc0(sizeof(*ud2
->dict1
->dict2
));
201 ud2
->dict1
->dict2
->userdef
= g_new0(UserDefOne
, 1);
202 ud2
->dict1
->dict2
->userdef
->string
= g_strdup(string
);
203 ud2
->dict1
->dict2
->userdef
->integer
= value
;
204 ud2
->dict1
->dict2
->string
= g_strdup(strings
[2]);
206 ud2
->dict1
->dict3
= g_malloc0(sizeof(*ud2
->dict1
->dict3
));
207 ud2
->dict1
->has_dict3
= true;
208 ud2
->dict1
->dict3
->userdef
= g_new0(UserDefOne
, 1);
209 ud2
->dict1
->dict3
->userdef
->string
= g_strdup(string
);
210 ud2
->dict1
->dict3
->userdef
->integer
= value
;
211 ud2
->dict1
->dict3
->string
= g_strdup(strings
[3]);
213 visit_type_UserDefTwo(data
->ov
, &ud2
, "unused", &error_abort
);
215 obj
= qmp_output_get_qobject(data
->qov
);
216 g_assert(obj
!= NULL
);
217 g_assert(qobject_type(obj
) == QTYPE_QDICT
);
219 qdict
= qobject_to_qdict(obj
);
220 g_assert_cmpint(qdict_size(qdict
), ==, 2);
221 g_assert_cmpstr(qdict_get_str(qdict
, "string0"), ==, strings
[0]);
223 dict1
= qdict_get_qdict(qdict
, "dict1");
224 g_assert_cmpint(qdict_size(dict1
), ==, 3);
225 g_assert_cmpstr(qdict_get_str(dict1
, "string1"), ==, strings
[1]);
227 dict2
= qdict_get_qdict(dict1
, "dict2");
228 g_assert_cmpint(qdict_size(dict2
), ==, 2);
229 g_assert_cmpstr(qdict_get_str(dict2
, "string"), ==, strings
[2]);
230 userdef
= qdict_get_qdict(dict2
, "userdef");
231 g_assert_cmpint(qdict_size(userdef
), ==, 2);
232 g_assert_cmpint(qdict_get_int(userdef
, "integer"), ==, value
);
233 g_assert_cmpstr(qdict_get_str(userdef
, "string"), ==, string
);
235 dict3
= qdict_get_qdict(dict1
, "dict3");
236 g_assert_cmpint(qdict_size(dict3
), ==, 2);
237 g_assert_cmpstr(qdict_get_str(dict3
, "string"), ==, strings
[3]);
238 userdef
= qdict_get_qdict(dict3
, "userdef");
239 g_assert_cmpint(qdict_size(userdef
), ==, 2);
240 g_assert_cmpint(qdict_get_int(userdef
, "integer"), ==, value
);
241 g_assert_cmpstr(qdict_get_str(userdef
, "string"), ==, string
);
244 qapi_free_UserDefTwo(ud2
);
247 static void test_visitor_out_struct_errors(TestOutputVisitorData
*data
,
250 EnumOne bad_values
[] = { ENUM_ONE__MAX
, -1 };
256 for (i
= 0; i
< ARRAY_SIZE(bad_values
) ; i
++) {
259 u
.enum1
= bad_values
[i
];
260 visit_type_UserDefOne(data
->ov
, &pu
, "unused", &err
);
267 static void test_visitor_out_list(TestOutputVisitorData
*data
,
270 const char *value_str
= "list value";
271 TestStructList
*p
, *head
= NULL
;
272 const int max_items
= 10;
273 bool value_bool
= true;
280 /* Build the list in reverse order... */
281 for (i
= 0; i
< max_items
; i
++) {
282 p
= g_malloc0(sizeof(*p
));
283 p
->value
= g_malloc0(sizeof(*p
->value
));
284 p
->value
->integer
= value_int
+ (max_items
- i
- 1);
285 p
->value
->boolean
= value_bool
;
286 p
->value
->string
= g_strdup(value_str
);
292 visit_type_TestStructList(data
->ov
, &head
, NULL
, &error_abort
);
294 obj
= qmp_output_get_qobject(data
->qov
);
295 g_assert(obj
!= NULL
);
296 g_assert(qobject_type(obj
) == QTYPE_QLIST
);
298 qlist
= qobject_to_qlist(obj
);
299 g_assert(!qlist_empty(qlist
));
301 /* ...and ensure that the visitor sees it in order */
303 QLIST_FOREACH_ENTRY(qlist
, entry
) {
306 g_assert(qobject_type(entry
->value
) == QTYPE_QDICT
);
307 qdict
= qobject_to_qdict(entry
->value
);
308 g_assert_cmpint(qdict_size(qdict
), ==, 3);
309 g_assert_cmpint(qdict_get_int(qdict
, "integer"), ==, value_int
+ i
);
310 g_assert_cmpint(qdict_get_bool(qdict
, "boolean"), ==, value_bool
);
311 g_assert_cmpstr(qdict_get_str(qdict
, "string"), ==, value_str
);
314 g_assert_cmpint(i
, ==, max_items
);
317 qapi_free_TestStructList(head
);
320 static void test_visitor_out_list_qapi_free(TestOutputVisitorData
*data
,
323 UserDefTwoList
*p
, *head
= NULL
;
324 const char string
[] = "foo bar";
325 int i
, max_count
= 1024;
327 for (i
= 0; i
< max_count
; i
++) {
328 p
= g_malloc0(sizeof(*p
));
329 p
->value
= g_malloc0(sizeof(*p
->value
));
331 p
->value
->string0
= g_strdup(string
);
332 p
->value
->dict1
= g_new0(UserDefTwoDict
, 1);
333 p
->value
->dict1
->string1
= g_strdup(string
);
334 p
->value
->dict1
->dict2
= g_new0(UserDefTwoDictDict
, 1);
335 p
->value
->dict1
->dict2
->userdef
= g_new0(UserDefOne
, 1);
336 p
->value
->dict1
->dict2
->userdef
->string
= g_strdup(string
);
337 p
->value
->dict1
->dict2
->userdef
->integer
= 42;
338 p
->value
->dict1
->dict2
->string
= g_strdup(string
);
339 p
->value
->dict1
->has_dict3
= false;
345 qapi_free_UserDefTwoList(head
);
348 static void test_visitor_out_any(TestOutputVisitorData
*data
,
358 qobj
= QOBJECT(qint_from_int(-42));
359 visit_type_any(data
->ov
, &qobj
, NULL
, &error_abort
);
360 obj
= qmp_output_get_qobject(data
->qov
);
361 g_assert(obj
!= NULL
);
362 g_assert(qobject_type(obj
) == QTYPE_QINT
);
363 g_assert_cmpint(qint_get_int(qobject_to_qint(obj
)), ==, -42);
365 qobject_decref(qobj
);
368 qdict_put(qdict
, "integer", qint_from_int(-42));
369 qdict_put(qdict
, "boolean", qbool_from_bool(true));
370 qdict_put(qdict
, "string", qstring_from_str("foo"));
371 qobj
= QOBJECT(qdict
);
372 visit_type_any(data
->ov
, &qobj
, NULL
, &error_abort
);
373 qobject_decref(qobj
);
374 obj
= qmp_output_get_qobject(data
->qov
);
375 g_assert(obj
!= NULL
);
376 qdict
= qobject_to_qdict(obj
);
378 qobj
= qdict_get(qdict
, "integer");
380 qint
= qobject_to_qint(qobj
);
382 g_assert_cmpint(qint_get_int(qint
), ==, -42);
383 qobj
= qdict_get(qdict
, "boolean");
385 qbool
= qobject_to_qbool(qobj
);
387 g_assert(qbool_get_bool(qbool
) == true);
388 qobj
= qdict_get(qdict
, "string");
390 qstring
= qobject_to_qstring(qobj
);
392 g_assert_cmpstr(qstring_get_str(qstring
), ==, "foo");
396 static void test_visitor_out_union_flat(TestOutputVisitorData
*data
,
402 UserDefFlatUnion
*tmp
= g_malloc0(sizeof(UserDefFlatUnion
));
403 tmp
->enum1
= ENUM_ONE_VALUE1
;
404 tmp
->string
= g_strdup("str");
405 tmp
->u
.value1
= g_malloc0(sizeof(UserDefA
));
407 tmp
->u
.value1
->boolean
= true;
409 visit_type_UserDefFlatUnion(data
->ov
, &tmp
, NULL
, &error_abort
);
410 arg
= qmp_output_get_qobject(data
->qov
);
412 g_assert(qobject_type(arg
) == QTYPE_QDICT
);
413 qdict
= qobject_to_qdict(arg
);
415 g_assert_cmpstr(qdict_get_str(qdict
, "enum1"), ==, "value1");
416 g_assert_cmpstr(qdict_get_str(qdict
, "string"), ==, "str");
417 g_assert_cmpint(qdict_get_int(qdict
, "integer"), ==, 41);
418 g_assert_cmpint(qdict_get_bool(qdict
, "boolean"), ==, true);
420 qapi_free_UserDefFlatUnion(tmp
);
424 static void test_visitor_out_alternate(TestOutputVisitorData
*data
,
428 UserDefAlternate
*tmp
;
430 tmp
= g_new0(UserDefAlternate
, 1);
431 tmp
->type
= QTYPE_QINT
;
434 visit_type_UserDefAlternate(data
->ov
, &tmp
, NULL
, &error_abort
);
435 arg
= qmp_output_get_qobject(data
->qov
);
437 g_assert(qobject_type(arg
) == QTYPE_QINT
);
438 g_assert_cmpint(qint_get_int(qobject_to_qint(arg
)), ==, 42);
440 qapi_free_UserDefAlternate(tmp
);
443 tmp
= g_new0(UserDefAlternate
, 1);
444 tmp
->type
= QTYPE_QSTRING
;
445 tmp
->u
.s
= g_strdup("hello");
447 visit_type_UserDefAlternate(data
->ov
, &tmp
, NULL
, &error_abort
);
448 arg
= qmp_output_get_qobject(data
->qov
);
450 g_assert(qobject_type(arg
) == QTYPE_QSTRING
);
451 g_assert_cmpstr(qstring_get_str(qobject_to_qstring(arg
)), ==, "hello");
453 qapi_free_UserDefAlternate(tmp
);
457 static void test_visitor_out_empty(TestOutputVisitorData
*data
,
462 arg
= qmp_output_get_qobject(data
->qov
);
463 g_assert(qobject_type(arg
) == QTYPE_QNULL
);
467 static void init_native_list(UserDefNativeListUnion
*cvalue
)
470 switch (cvalue
->type
) {
471 case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER
: {
472 intList
**list
= &cvalue
->u
.integer
;
473 for (i
= 0; i
< 32; i
++) {
474 *list
= g_new0(intList
, 1);
476 (*list
)->next
= NULL
;
477 list
= &(*list
)->next
;
481 case USER_DEF_NATIVE_LIST_UNION_KIND_S8
: {
482 int8List
**list
= &cvalue
->u
.s8
;
483 for (i
= 0; i
< 32; i
++) {
484 *list
= g_new0(int8List
, 1);
486 (*list
)->next
= NULL
;
487 list
= &(*list
)->next
;
491 case USER_DEF_NATIVE_LIST_UNION_KIND_S16
: {
492 int16List
**list
= &cvalue
->u
.s16
;
493 for (i
= 0; i
< 32; i
++) {
494 *list
= g_new0(int16List
, 1);
496 (*list
)->next
= NULL
;
497 list
= &(*list
)->next
;
501 case USER_DEF_NATIVE_LIST_UNION_KIND_S32
: {
502 int32List
**list
= &cvalue
->u
.s32
;
503 for (i
= 0; i
< 32; i
++) {
504 *list
= g_new0(int32List
, 1);
506 (*list
)->next
= NULL
;
507 list
= &(*list
)->next
;
511 case USER_DEF_NATIVE_LIST_UNION_KIND_S64
: {
512 int64List
**list
= &cvalue
->u
.s64
;
513 for (i
= 0; i
< 32; i
++) {
514 *list
= g_new0(int64List
, 1);
516 (*list
)->next
= NULL
;
517 list
= &(*list
)->next
;
521 case USER_DEF_NATIVE_LIST_UNION_KIND_U8
: {
522 uint8List
**list
= &cvalue
->u
.u8
;
523 for (i
= 0; i
< 32; i
++) {
524 *list
= g_new0(uint8List
, 1);
526 (*list
)->next
= NULL
;
527 list
= &(*list
)->next
;
531 case USER_DEF_NATIVE_LIST_UNION_KIND_U16
: {
532 uint16List
**list
= &cvalue
->u
.u16
;
533 for (i
= 0; i
< 32; i
++) {
534 *list
= g_new0(uint16List
, 1);
536 (*list
)->next
= NULL
;
537 list
= &(*list
)->next
;
541 case USER_DEF_NATIVE_LIST_UNION_KIND_U32
: {
542 uint32List
**list
= &cvalue
->u
.u32
;
543 for (i
= 0; i
< 32; i
++) {
544 *list
= g_new0(uint32List
, 1);
546 (*list
)->next
= NULL
;
547 list
= &(*list
)->next
;
551 case USER_DEF_NATIVE_LIST_UNION_KIND_U64
: {
552 uint64List
**list
= &cvalue
->u
.u64
;
553 for (i
= 0; i
< 32; i
++) {
554 *list
= g_new0(uint64List
, 1);
556 (*list
)->next
= NULL
;
557 list
= &(*list
)->next
;
561 case USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN
: {
562 boolList
**list
= &cvalue
->u
.boolean
;
563 for (i
= 0; i
< 32; i
++) {
564 *list
= g_new0(boolList
, 1);
565 (*list
)->value
= (i
% 3 == 0);
566 (*list
)->next
= NULL
;
567 list
= &(*list
)->next
;
571 case USER_DEF_NATIVE_LIST_UNION_KIND_STRING
: {
572 strList
**list
= &cvalue
->u
.string
;
573 for (i
= 0; i
< 32; i
++) {
574 *list
= g_new0(strList
, 1);
575 (*list
)->value
= g_strdup_printf("%d", i
);
576 (*list
)->next
= NULL
;
577 list
= &(*list
)->next
;
581 case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER
: {
582 numberList
**list
= &cvalue
->u
.number
;
583 for (i
= 0; i
< 32; i
++) {
584 *list
= g_new0(numberList
, 1);
585 (*list
)->value
= (double)i
/ 3;
586 (*list
)->next
= NULL
;
587 list
= &(*list
)->next
;
592 g_assert_not_reached();
596 static void check_native_list(QObject
*qobj
,
597 UserDefNativeListUnionKind kind
)
604 g_assert(qobject_type(qobj
) == QTYPE_QDICT
);
605 qdict
= qobject_to_qdict(qobj
);
607 g_assert(qdict_haskey(qdict
, "data"));
608 qlist
= qlist_copy(qobject_to_qlist(qdict_get(qdict
, "data")));
611 case USER_DEF_NATIVE_LIST_UNION_KIND_S8
:
612 case USER_DEF_NATIVE_LIST_UNION_KIND_S16
:
613 case USER_DEF_NATIVE_LIST_UNION_KIND_S32
:
614 case USER_DEF_NATIVE_LIST_UNION_KIND_S64
:
615 case USER_DEF_NATIVE_LIST_UNION_KIND_U8
:
616 case USER_DEF_NATIVE_LIST_UNION_KIND_U16
:
617 case USER_DEF_NATIVE_LIST_UNION_KIND_U32
:
618 case USER_DEF_NATIVE_LIST_UNION_KIND_U64
:
619 /* all integer elements in JSON arrays get stored into QInts when
620 * we convert to QObjects, so we can check them all in the same
621 * fashion, so simply fall through here
623 case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER
:
624 for (i
= 0; i
< 32; i
++) {
627 tmp
= qlist_peek(qlist
);
629 qvalue
= qobject_to_qint(tmp
);
630 g_assert_cmpint(qint_get_int(qvalue
), ==, i
);
631 qobject_decref(qlist_pop(qlist
));
634 case USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN
:
635 for (i
= 0; i
< 32; i
++) {
638 tmp
= qlist_peek(qlist
);
640 qvalue
= qobject_to_qbool(tmp
);
641 g_assert_cmpint(qbool_get_bool(qvalue
), ==, i
% 3 == 0);
642 qobject_decref(qlist_pop(qlist
));
645 case USER_DEF_NATIVE_LIST_UNION_KIND_STRING
:
646 for (i
= 0; i
< 32; i
++) {
650 tmp
= qlist_peek(qlist
);
652 qvalue
= qobject_to_qstring(tmp
);
653 sprintf(str
, "%d", i
);
654 g_assert_cmpstr(qstring_get_str(qvalue
), ==, str
);
655 qobject_decref(qlist_pop(qlist
));
658 case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER
:
659 for (i
= 0; i
< 32; i
++) {
662 GString
*double_expected
= g_string_new("");
663 GString
*double_actual
= g_string_new("");
665 tmp
= qlist_peek(qlist
);
667 qvalue
= qobject_to_qfloat(tmp
);
668 g_string_printf(double_expected
, "%.6f", (double)i
/ 3);
669 g_string_printf(double_actual
, "%.6f", qfloat_get_double(qvalue
));
670 g_assert_cmpstr(double_actual
->str
, ==, double_expected
->str
);
672 qobject_decref(qlist_pop(qlist
));
673 g_string_free(double_expected
, true);
674 g_string_free(double_actual
, true);
678 g_assert_not_reached();
683 static void test_native_list(TestOutputVisitorData
*data
,
685 UserDefNativeListUnionKind kind
)
687 UserDefNativeListUnion
*cvalue
= g_new0(UserDefNativeListUnion
, 1);
691 init_native_list(cvalue
);
693 visit_type_UserDefNativeListUnion(data
->ov
, &cvalue
, NULL
, &error_abort
);
695 obj
= qmp_output_get_qobject(data
->qov
);
696 check_native_list(obj
, cvalue
->type
);
697 qapi_free_UserDefNativeListUnion(cvalue
);
701 static void test_visitor_out_native_list_int(TestOutputVisitorData
*data
,
704 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER
);
707 static void test_visitor_out_native_list_int8(TestOutputVisitorData
*data
,
710 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S8
);
713 static void test_visitor_out_native_list_int16(TestOutputVisitorData
*data
,
716 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S16
);
719 static void test_visitor_out_native_list_int32(TestOutputVisitorData
*data
,
722 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S32
);
725 static void test_visitor_out_native_list_int64(TestOutputVisitorData
*data
,
728 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S64
);
731 static void test_visitor_out_native_list_uint8(TestOutputVisitorData
*data
,
734 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U8
);
737 static void test_visitor_out_native_list_uint16(TestOutputVisitorData
*data
,
740 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U16
);
743 static void test_visitor_out_native_list_uint32(TestOutputVisitorData
*data
,
746 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U32
);
749 static void test_visitor_out_native_list_uint64(TestOutputVisitorData
*data
,
752 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U64
);
755 static void test_visitor_out_native_list_bool(TestOutputVisitorData
*data
,
758 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN
);
761 static void test_visitor_out_native_list_str(TestOutputVisitorData
*data
,
764 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_STRING
);
767 static void test_visitor_out_native_list_number(TestOutputVisitorData
*data
,
770 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER
);
773 static void output_visitor_test_add(const char *testpath
,
774 TestOutputVisitorData
*data
,
775 void (*test_func
)(TestOutputVisitorData
*data
, const void *user_data
))
777 g_test_add(testpath
, TestOutputVisitorData
, data
, visitor_output_setup
,
778 test_func
, visitor_output_teardown
);
781 int main(int argc
, char **argv
)
783 TestOutputVisitorData out_visitor_data
;
785 g_test_init(&argc
, &argv
, NULL
);
787 output_visitor_test_add("/visitor/output/int",
788 &out_visitor_data
, test_visitor_out_int
);
789 output_visitor_test_add("/visitor/output/bool",
790 &out_visitor_data
, test_visitor_out_bool
);
791 output_visitor_test_add("/visitor/output/number",
792 &out_visitor_data
, test_visitor_out_number
);
793 output_visitor_test_add("/visitor/output/string",
794 &out_visitor_data
, test_visitor_out_string
);
795 output_visitor_test_add("/visitor/output/no-string",
796 &out_visitor_data
, test_visitor_out_no_string
);
797 output_visitor_test_add("/visitor/output/enum",
798 &out_visitor_data
, test_visitor_out_enum
);
799 output_visitor_test_add("/visitor/output/enum-errors",
800 &out_visitor_data
, test_visitor_out_enum_errors
);
801 output_visitor_test_add("/visitor/output/struct",
802 &out_visitor_data
, test_visitor_out_struct
);
803 output_visitor_test_add("/visitor/output/struct-nested",
804 &out_visitor_data
, test_visitor_out_struct_nested
);
805 output_visitor_test_add("/visitor/output/struct-errors",
806 &out_visitor_data
, test_visitor_out_struct_errors
);
807 output_visitor_test_add("/visitor/output/list",
808 &out_visitor_data
, test_visitor_out_list
);
809 output_visitor_test_add("/visitor/output/any",
810 &out_visitor_data
, test_visitor_out_any
);
811 output_visitor_test_add("/visitor/output/list-qapi-free",
812 &out_visitor_data
, test_visitor_out_list_qapi_free
);
813 output_visitor_test_add("/visitor/output/union-flat",
814 &out_visitor_data
, test_visitor_out_union_flat
);
815 output_visitor_test_add("/visitor/output/alternate",
816 &out_visitor_data
, test_visitor_out_alternate
);
817 output_visitor_test_add("/visitor/output/empty",
818 &out_visitor_data
, test_visitor_out_empty
);
819 output_visitor_test_add("/visitor/output/native_list/int",
821 test_visitor_out_native_list_int
);
822 output_visitor_test_add("/visitor/output/native_list/int8",
824 test_visitor_out_native_list_int8
);
825 output_visitor_test_add("/visitor/output/native_list/int16",
827 test_visitor_out_native_list_int16
);
828 output_visitor_test_add("/visitor/output/native_list/int32",
830 test_visitor_out_native_list_int32
);
831 output_visitor_test_add("/visitor/output/native_list/int64",
833 test_visitor_out_native_list_int64
);
834 output_visitor_test_add("/visitor/output/native_list/uint8",
836 test_visitor_out_native_list_uint8
);
837 output_visitor_test_add("/visitor/output/native_list/uint16",
839 test_visitor_out_native_list_uint16
);
840 output_visitor_test_add("/visitor/output/native_list/uint32",
842 test_visitor_out_native_list_uint32
);
843 output_visitor_test_add("/visitor/output/native_list/uint64",
845 test_visitor_out_native_list_uint64
);
846 output_visitor_test_add("/visitor/output/native_list/bool",
848 test_visitor_out_native_list_bool
);
849 output_visitor_test_add("/visitor/output/native_list/string",
851 test_visitor_out_native_list_str
);
852 output_visitor_test_add("/visitor/output/native_list/number",
854 test_visitor_out_native_list_number
);