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
, NULL
, &value
, &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
, NULL
, &value
, &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
, NULL
, &value
, &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
, NULL
, &string
, &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
, NULL
, &string
, &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
, "unused", &i
, &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
, "unused", &bad_values
[i
], &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
, NULL
, &p
, &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
, "unused", &ud2
, &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
, "unused", &pu
, &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
, NULL
, &head
, &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
, NULL
, &qobj
, &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
, NULL
, &qobj
, &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
, NULL
, &tmp
, &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
, NULL
, &tmp
, &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
, NULL
, &tmp
, &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
);
464 /* Check that qnull reference counting is sane */
465 g_assert(arg
->refcnt
== 2);
469 static void init_native_list(UserDefNativeListUnion
*cvalue
)
472 switch (cvalue
->type
) {
473 case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER
: {
474 intList
**list
= &cvalue
->u
.integer
;
475 for (i
= 0; i
< 32; i
++) {
476 *list
= g_new0(intList
, 1);
478 (*list
)->next
= NULL
;
479 list
= &(*list
)->next
;
483 case USER_DEF_NATIVE_LIST_UNION_KIND_S8
: {
484 int8List
**list
= &cvalue
->u
.s8
;
485 for (i
= 0; i
< 32; i
++) {
486 *list
= g_new0(int8List
, 1);
488 (*list
)->next
= NULL
;
489 list
= &(*list
)->next
;
493 case USER_DEF_NATIVE_LIST_UNION_KIND_S16
: {
494 int16List
**list
= &cvalue
->u
.s16
;
495 for (i
= 0; i
< 32; i
++) {
496 *list
= g_new0(int16List
, 1);
498 (*list
)->next
= NULL
;
499 list
= &(*list
)->next
;
503 case USER_DEF_NATIVE_LIST_UNION_KIND_S32
: {
504 int32List
**list
= &cvalue
->u
.s32
;
505 for (i
= 0; i
< 32; i
++) {
506 *list
= g_new0(int32List
, 1);
508 (*list
)->next
= NULL
;
509 list
= &(*list
)->next
;
513 case USER_DEF_NATIVE_LIST_UNION_KIND_S64
: {
514 int64List
**list
= &cvalue
->u
.s64
;
515 for (i
= 0; i
< 32; i
++) {
516 *list
= g_new0(int64List
, 1);
518 (*list
)->next
= NULL
;
519 list
= &(*list
)->next
;
523 case USER_DEF_NATIVE_LIST_UNION_KIND_U8
: {
524 uint8List
**list
= &cvalue
->u
.u8
;
525 for (i
= 0; i
< 32; i
++) {
526 *list
= g_new0(uint8List
, 1);
528 (*list
)->next
= NULL
;
529 list
= &(*list
)->next
;
533 case USER_DEF_NATIVE_LIST_UNION_KIND_U16
: {
534 uint16List
**list
= &cvalue
->u
.u16
;
535 for (i
= 0; i
< 32; i
++) {
536 *list
= g_new0(uint16List
, 1);
538 (*list
)->next
= NULL
;
539 list
= &(*list
)->next
;
543 case USER_DEF_NATIVE_LIST_UNION_KIND_U32
: {
544 uint32List
**list
= &cvalue
->u
.u32
;
545 for (i
= 0; i
< 32; i
++) {
546 *list
= g_new0(uint32List
, 1);
548 (*list
)->next
= NULL
;
549 list
= &(*list
)->next
;
553 case USER_DEF_NATIVE_LIST_UNION_KIND_U64
: {
554 uint64List
**list
= &cvalue
->u
.u64
;
555 for (i
= 0; i
< 32; i
++) {
556 *list
= g_new0(uint64List
, 1);
558 (*list
)->next
= NULL
;
559 list
= &(*list
)->next
;
563 case USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN
: {
564 boolList
**list
= &cvalue
->u
.boolean
;
565 for (i
= 0; i
< 32; i
++) {
566 *list
= g_new0(boolList
, 1);
567 (*list
)->value
= (i
% 3 == 0);
568 (*list
)->next
= NULL
;
569 list
= &(*list
)->next
;
573 case USER_DEF_NATIVE_LIST_UNION_KIND_STRING
: {
574 strList
**list
= &cvalue
->u
.string
;
575 for (i
= 0; i
< 32; i
++) {
576 *list
= g_new0(strList
, 1);
577 (*list
)->value
= g_strdup_printf("%d", i
);
578 (*list
)->next
= NULL
;
579 list
= &(*list
)->next
;
583 case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER
: {
584 numberList
**list
= &cvalue
->u
.number
;
585 for (i
= 0; i
< 32; i
++) {
586 *list
= g_new0(numberList
, 1);
587 (*list
)->value
= (double)i
/ 3;
588 (*list
)->next
= NULL
;
589 list
= &(*list
)->next
;
594 g_assert_not_reached();
598 static void check_native_list(QObject
*qobj
,
599 UserDefNativeListUnionKind kind
)
606 g_assert(qobject_type(qobj
) == QTYPE_QDICT
);
607 qdict
= qobject_to_qdict(qobj
);
609 g_assert(qdict_haskey(qdict
, "data"));
610 qlist
= qlist_copy(qobject_to_qlist(qdict_get(qdict
, "data")));
613 case USER_DEF_NATIVE_LIST_UNION_KIND_S8
:
614 case USER_DEF_NATIVE_LIST_UNION_KIND_S16
:
615 case USER_DEF_NATIVE_LIST_UNION_KIND_S32
:
616 case USER_DEF_NATIVE_LIST_UNION_KIND_S64
:
617 case USER_DEF_NATIVE_LIST_UNION_KIND_U8
:
618 case USER_DEF_NATIVE_LIST_UNION_KIND_U16
:
619 case USER_DEF_NATIVE_LIST_UNION_KIND_U32
:
620 case USER_DEF_NATIVE_LIST_UNION_KIND_U64
:
621 /* all integer elements in JSON arrays get stored into QInts when
622 * we convert to QObjects, so we can check them all in the same
623 * fashion, so simply fall through here
625 case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER
:
626 for (i
= 0; i
< 32; i
++) {
629 tmp
= qlist_peek(qlist
);
631 qvalue
= qobject_to_qint(tmp
);
632 g_assert_cmpint(qint_get_int(qvalue
), ==, i
);
633 qobject_decref(qlist_pop(qlist
));
636 case USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN
:
637 for (i
= 0; i
< 32; i
++) {
640 tmp
= qlist_peek(qlist
);
642 qvalue
= qobject_to_qbool(tmp
);
643 g_assert_cmpint(qbool_get_bool(qvalue
), ==, i
% 3 == 0);
644 qobject_decref(qlist_pop(qlist
));
647 case USER_DEF_NATIVE_LIST_UNION_KIND_STRING
:
648 for (i
= 0; i
< 32; i
++) {
652 tmp
= qlist_peek(qlist
);
654 qvalue
= qobject_to_qstring(tmp
);
655 sprintf(str
, "%d", i
);
656 g_assert_cmpstr(qstring_get_str(qvalue
), ==, str
);
657 qobject_decref(qlist_pop(qlist
));
660 case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER
:
661 for (i
= 0; i
< 32; i
++) {
664 GString
*double_expected
= g_string_new("");
665 GString
*double_actual
= g_string_new("");
667 tmp
= qlist_peek(qlist
);
669 qvalue
= qobject_to_qfloat(tmp
);
670 g_string_printf(double_expected
, "%.6f", (double)i
/ 3);
671 g_string_printf(double_actual
, "%.6f", qfloat_get_double(qvalue
));
672 g_assert_cmpstr(double_actual
->str
, ==, double_expected
->str
);
674 qobject_decref(qlist_pop(qlist
));
675 g_string_free(double_expected
, true);
676 g_string_free(double_actual
, true);
680 g_assert_not_reached();
685 static void test_native_list(TestOutputVisitorData
*data
,
687 UserDefNativeListUnionKind kind
)
689 UserDefNativeListUnion
*cvalue
= g_new0(UserDefNativeListUnion
, 1);
693 init_native_list(cvalue
);
695 visit_type_UserDefNativeListUnion(data
->ov
, NULL
, &cvalue
, &error_abort
);
697 obj
= qmp_output_get_qobject(data
->qov
);
698 check_native_list(obj
, cvalue
->type
);
699 qapi_free_UserDefNativeListUnion(cvalue
);
703 static void test_visitor_out_native_list_int(TestOutputVisitorData
*data
,
706 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER
);
709 static void test_visitor_out_native_list_int8(TestOutputVisitorData
*data
,
712 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S8
);
715 static void test_visitor_out_native_list_int16(TestOutputVisitorData
*data
,
718 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S16
);
721 static void test_visitor_out_native_list_int32(TestOutputVisitorData
*data
,
724 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S32
);
727 static void test_visitor_out_native_list_int64(TestOutputVisitorData
*data
,
730 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S64
);
733 static void test_visitor_out_native_list_uint8(TestOutputVisitorData
*data
,
736 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U8
);
739 static void test_visitor_out_native_list_uint16(TestOutputVisitorData
*data
,
742 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U16
);
745 static void test_visitor_out_native_list_uint32(TestOutputVisitorData
*data
,
748 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U32
);
751 static void test_visitor_out_native_list_uint64(TestOutputVisitorData
*data
,
754 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U64
);
757 static void test_visitor_out_native_list_bool(TestOutputVisitorData
*data
,
760 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN
);
763 static void test_visitor_out_native_list_str(TestOutputVisitorData
*data
,
766 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_STRING
);
769 static void test_visitor_out_native_list_number(TestOutputVisitorData
*data
,
772 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER
);
775 static void output_visitor_test_add(const char *testpath
,
776 TestOutputVisitorData
*data
,
777 void (*test_func
)(TestOutputVisitorData
*data
, const void *user_data
))
779 g_test_add(testpath
, TestOutputVisitorData
, data
, visitor_output_setup
,
780 test_func
, visitor_output_teardown
);
783 int main(int argc
, char **argv
)
785 TestOutputVisitorData out_visitor_data
;
787 g_test_init(&argc
, &argv
, NULL
);
789 output_visitor_test_add("/visitor/output/int",
790 &out_visitor_data
, test_visitor_out_int
);
791 output_visitor_test_add("/visitor/output/bool",
792 &out_visitor_data
, test_visitor_out_bool
);
793 output_visitor_test_add("/visitor/output/number",
794 &out_visitor_data
, test_visitor_out_number
);
795 output_visitor_test_add("/visitor/output/string",
796 &out_visitor_data
, test_visitor_out_string
);
797 output_visitor_test_add("/visitor/output/no-string",
798 &out_visitor_data
, test_visitor_out_no_string
);
799 output_visitor_test_add("/visitor/output/enum",
800 &out_visitor_data
, test_visitor_out_enum
);
801 output_visitor_test_add("/visitor/output/enum-errors",
802 &out_visitor_data
, test_visitor_out_enum_errors
);
803 output_visitor_test_add("/visitor/output/struct",
804 &out_visitor_data
, test_visitor_out_struct
);
805 output_visitor_test_add("/visitor/output/struct-nested",
806 &out_visitor_data
, test_visitor_out_struct_nested
);
807 output_visitor_test_add("/visitor/output/struct-errors",
808 &out_visitor_data
, test_visitor_out_struct_errors
);
809 output_visitor_test_add("/visitor/output/list",
810 &out_visitor_data
, test_visitor_out_list
);
811 output_visitor_test_add("/visitor/output/any",
812 &out_visitor_data
, test_visitor_out_any
);
813 output_visitor_test_add("/visitor/output/list-qapi-free",
814 &out_visitor_data
, test_visitor_out_list_qapi_free
);
815 output_visitor_test_add("/visitor/output/union-flat",
816 &out_visitor_data
, test_visitor_out_union_flat
);
817 output_visitor_test_add("/visitor/output/alternate",
818 &out_visitor_data
, test_visitor_out_alternate
);
819 output_visitor_test_add("/visitor/output/empty",
820 &out_visitor_data
, test_visitor_out_empty
);
821 output_visitor_test_add("/visitor/output/native_list/int",
823 test_visitor_out_native_list_int
);
824 output_visitor_test_add("/visitor/output/native_list/int8",
826 test_visitor_out_native_list_int8
);
827 output_visitor_test_add("/visitor/output/native_list/int16",
829 test_visitor_out_native_list_int16
);
830 output_visitor_test_add("/visitor/output/native_list/int32",
832 test_visitor_out_native_list_int32
);
833 output_visitor_test_add("/visitor/output/native_list/int64",
835 test_visitor_out_native_list_int64
);
836 output_visitor_test_add("/visitor/output/native_list/uint8",
838 test_visitor_out_native_list_uint8
);
839 output_visitor_test_add("/visitor/output/native_list/uint16",
841 test_visitor_out_native_list_uint16
);
842 output_visitor_test_add("/visitor/output/native_list/uint32",
844 test_visitor_out_native_list_uint32
);
845 output_visitor_test_add("/visitor/output/native_list/uint64",
847 test_visitor_out_native_list_uint64
);
848 output_visitor_test_add("/visitor/output/native_list/bool",
850 test_visitor_out_native_list_bool
);
851 output_visitor_test_add("/visitor/output/native_list/string",
853 test_visitor_out_native_list_str
);
854 output_visitor_test_add("/visitor/output/native_list/number",
856 test_visitor_out_native_list_number
);