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-types.h"
19 #include "test-qapi-visit.h"
20 #include "qapi/qmp/types.h"
21 #include "qapi/qmp/qjson.h"
23 typedef struct TestOutputVisitorData
{
26 } TestOutputVisitorData
;
28 static void visitor_output_setup(TestOutputVisitorData
*data
,
31 data
->ov
= qobject_output_visitor_new(&data
->obj
);
35 static void visitor_output_teardown(TestOutputVisitorData
*data
,
40 qobject_decref(data
->obj
);
44 static QObject
*visitor_get(TestOutputVisitorData
*data
)
46 visit_complete(data
->ov
, &data
->obj
);
51 static void visitor_reset(TestOutputVisitorData
*data
)
53 visitor_output_teardown(data
, NULL
);
54 visitor_output_setup(data
, NULL
);
57 static void test_visitor_out_int(TestOutputVisitorData
*data
,
64 visit_type_int(data
->ov
, NULL
, &value
, &error_abort
);
66 qnum
= qobject_to_qnum(visitor_get(data
));
68 g_assert(qnum_get_try_int(qnum
, &val
));
69 g_assert_cmpint(val
, ==, value
);
72 static void test_visitor_out_bool(TestOutputVisitorData
*data
,
78 visit_type_bool(data
->ov
, NULL
, &value
, &error_abort
);
80 qbool
= qobject_to_qbool(visitor_get(data
));
82 g_assert(qbool_get_bool(qbool
) == value
);
85 static void test_visitor_out_number(TestOutputVisitorData
*data
,
91 visit_type_number(data
->ov
, NULL
, &value
, &error_abort
);
93 qnum
= qobject_to_qnum(visitor_get(data
));
95 g_assert(qnum_get_double(qnum
) == value
);
98 static void test_visitor_out_string(TestOutputVisitorData
*data
,
101 char *string
= (char *) "Q E M U";
104 visit_type_str(data
->ov
, NULL
, &string
, &error_abort
);
106 qstr
= qobject_to_qstring(visitor_get(data
));
108 g_assert_cmpstr(qstring_get_str(qstr
), ==, string
);
111 static void test_visitor_out_no_string(TestOutputVisitorData
*data
,
117 /* A null string should return "" */
118 visit_type_str(data
->ov
, NULL
, &string
, &error_abort
);
120 qstr
= qobject_to_qstring(visitor_get(data
));
122 g_assert_cmpstr(qstring_get_str(qstr
), ==, "");
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 qstr
= qobject_to_qstring(visitor_get(data
));
136 g_assert_cmpstr(qstring_get_str(qstr
), ==, EnumOne_lookup
[i
]);
141 static void test_visitor_out_enum_errors(TestOutputVisitorData
*data
,
144 EnumOne i
, bad_values
[] = { ENUM_ONE__MAX
, -1 };
147 for (i
= 0; i
< ARRAY_SIZE(bad_values
) ; i
++) {
149 visit_type_EnumOne(data
->ov
, "unused", &bad_values
[i
], &err
);
150 error_free_or_abort(&err
);
156 static void test_visitor_out_struct(TestOutputVisitorData
*data
,
159 TestStruct test_struct
= { .integer
= 42,
161 .string
= (char *) "foo"};
162 TestStruct
*p
= &test_struct
;
165 visit_type_TestStruct(data
->ov
, NULL
, &p
, &error_abort
);
167 qdict
= qobject_to_qdict(visitor_get(data
));
169 g_assert_cmpint(qdict_size(qdict
), ==, 3);
170 g_assert_cmpint(qdict_get_int(qdict
, "integer"), ==, 42);
171 g_assert_cmpint(qdict_get_bool(qdict
, "boolean"), ==, false);
172 g_assert_cmpstr(qdict_get_str(qdict
, "string"), ==, "foo");
175 static void test_visitor_out_struct_nested(TestOutputVisitorData
*data
,
180 QDict
*qdict
, *dict1
, *dict2
, *dict3
, *userdef
;
181 const char *string
= "user def string";
182 const char *strings
[] = { "forty two", "forty three", "forty four",
185 ud2
= g_malloc0(sizeof(*ud2
));
186 ud2
->string0
= g_strdup(strings
[0]);
188 ud2
->dict1
= g_malloc0(sizeof(*ud2
->dict1
));
189 ud2
->dict1
->string1
= g_strdup(strings
[1]);
191 ud2
->dict1
->dict2
= g_malloc0(sizeof(*ud2
->dict1
->dict2
));
192 ud2
->dict1
->dict2
->userdef
= g_new0(UserDefOne
, 1);
193 ud2
->dict1
->dict2
->userdef
->string
= g_strdup(string
);
194 ud2
->dict1
->dict2
->userdef
->integer
= value
;
195 ud2
->dict1
->dict2
->string
= g_strdup(strings
[2]);
197 ud2
->dict1
->dict3
= g_malloc0(sizeof(*ud2
->dict1
->dict3
));
198 ud2
->dict1
->has_dict3
= true;
199 ud2
->dict1
->dict3
->userdef
= g_new0(UserDefOne
, 1);
200 ud2
->dict1
->dict3
->userdef
->string
= g_strdup(string
);
201 ud2
->dict1
->dict3
->userdef
->integer
= value
;
202 ud2
->dict1
->dict3
->string
= g_strdup(strings
[3]);
204 visit_type_UserDefTwo(data
->ov
, "unused", &ud2
, &error_abort
);
206 qdict
= qobject_to_qdict(visitor_get(data
));
208 g_assert_cmpint(qdict_size(qdict
), ==, 2);
209 g_assert_cmpstr(qdict_get_str(qdict
, "string0"), ==, strings
[0]);
211 dict1
= qdict_get_qdict(qdict
, "dict1");
212 g_assert_cmpint(qdict_size(dict1
), ==, 3);
213 g_assert_cmpstr(qdict_get_str(dict1
, "string1"), ==, strings
[1]);
215 dict2
= qdict_get_qdict(dict1
, "dict2");
216 g_assert_cmpint(qdict_size(dict2
), ==, 2);
217 g_assert_cmpstr(qdict_get_str(dict2
, "string"), ==, strings
[2]);
218 userdef
= qdict_get_qdict(dict2
, "userdef");
219 g_assert_cmpint(qdict_size(userdef
), ==, 2);
220 g_assert_cmpint(qdict_get_int(userdef
, "integer"), ==, value
);
221 g_assert_cmpstr(qdict_get_str(userdef
, "string"), ==, string
);
223 dict3
= qdict_get_qdict(dict1
, "dict3");
224 g_assert_cmpint(qdict_size(dict3
), ==, 2);
225 g_assert_cmpstr(qdict_get_str(dict3
, "string"), ==, strings
[3]);
226 userdef
= qdict_get_qdict(dict3
, "userdef");
227 g_assert_cmpint(qdict_size(userdef
), ==, 2);
228 g_assert_cmpint(qdict_get_int(userdef
, "integer"), ==, value
);
229 g_assert_cmpstr(qdict_get_str(userdef
, "string"), ==, string
);
231 qapi_free_UserDefTwo(ud2
);
234 static void test_visitor_out_struct_errors(TestOutputVisitorData
*data
,
237 EnumOne bad_values
[] = { ENUM_ONE__MAX
, -1 };
243 for (i
= 0; i
< ARRAY_SIZE(bad_values
) ; i
++) {
246 u
.enum1
= bad_values
[i
];
247 visit_type_UserDefOne(data
->ov
, "unused", &pu
, &err
);
248 error_free_or_abort(&err
);
254 static void test_visitor_out_list(TestOutputVisitorData
*data
,
257 const char *value_str
= "list value";
258 TestStructList
*p
, *head
= NULL
;
259 const int max_items
= 10;
260 bool value_bool
= true;
266 /* Build the list in reverse order... */
267 for (i
= 0; i
< max_items
; i
++) {
268 p
= g_malloc0(sizeof(*p
));
269 p
->value
= g_malloc0(sizeof(*p
->value
));
270 p
->value
->integer
= value_int
+ (max_items
- i
- 1);
271 p
->value
->boolean
= value_bool
;
272 p
->value
->string
= g_strdup(value_str
);
278 visit_type_TestStructList(data
->ov
, NULL
, &head
, &error_abort
);
280 qlist
= qobject_to_qlist(visitor_get(data
));
282 g_assert(!qlist_empty(qlist
));
284 /* ...and ensure that the visitor sees it in order */
286 QLIST_FOREACH_ENTRY(qlist
, entry
) {
289 qdict
= qobject_to_qdict(entry
->value
);
291 g_assert_cmpint(qdict_size(qdict
), ==, 3);
292 g_assert_cmpint(qdict_get_int(qdict
, "integer"), ==, value_int
+ i
);
293 g_assert_cmpint(qdict_get_bool(qdict
, "boolean"), ==, value_bool
);
294 g_assert_cmpstr(qdict_get_str(qdict
, "string"), ==, value_str
);
297 g_assert_cmpint(i
, ==, max_items
);
299 qapi_free_TestStructList(head
);
302 static void test_visitor_out_list_qapi_free(TestOutputVisitorData
*data
,
305 UserDefTwoList
*p
, *head
= NULL
;
306 const char string
[] = "foo bar";
307 int i
, max_count
= 1024;
309 for (i
= 0; i
< max_count
; i
++) {
310 p
= g_malloc0(sizeof(*p
));
311 p
->value
= g_malloc0(sizeof(*p
->value
));
313 p
->value
->string0
= g_strdup(string
);
314 p
->value
->dict1
= g_new0(UserDefTwoDict
, 1);
315 p
->value
->dict1
->string1
= g_strdup(string
);
316 p
->value
->dict1
->dict2
= g_new0(UserDefTwoDictDict
, 1);
317 p
->value
->dict1
->dict2
->userdef
= g_new0(UserDefOne
, 1);
318 p
->value
->dict1
->dict2
->userdef
->string
= g_strdup(string
);
319 p
->value
->dict1
->dict2
->userdef
->integer
= 42;
320 p
->value
->dict1
->dict2
->string
= g_strdup(string
);
321 p
->value
->dict1
->has_dict3
= false;
327 qapi_free_UserDefTwoList(head
);
330 static void test_visitor_out_any(TestOutputVisitorData
*data
,
340 qobj
= QOBJECT(qnum_from_int(-42));
341 visit_type_any(data
->ov
, NULL
, &qobj
, &error_abort
);
342 qnum
= qobject_to_qnum(visitor_get(data
));
344 g_assert(qnum_get_try_int(qnum
, &val
));
345 g_assert_cmpint(val
, ==, -42);
346 qobject_decref(qobj
);
350 qdict_put_int(qdict
, "integer", -42);
351 qdict_put_bool(qdict
, "boolean", true);
352 qdict_put_str(qdict
, "string", "foo");
353 qobj
= QOBJECT(qdict
);
354 visit_type_any(data
->ov
, NULL
, &qobj
, &error_abort
);
355 qobject_decref(qobj
);
356 qdict
= qobject_to_qdict(visitor_get(data
));
358 qnum
= qobject_to_qnum(qdict_get(qdict
, "integer"));
360 g_assert(qnum_get_try_int(qnum
, &val
));
361 g_assert_cmpint(val
, ==, -42);
362 qbool
= qobject_to_qbool(qdict_get(qdict
, "boolean"));
364 g_assert(qbool_get_bool(qbool
) == true);
365 qstring
= qobject_to_qstring(qdict_get(qdict
, "string"));
367 g_assert_cmpstr(qstring_get_str(qstring
), ==, "foo");
370 static void test_visitor_out_union_flat(TestOutputVisitorData
*data
,
375 UserDefFlatUnion
*tmp
= g_malloc0(sizeof(UserDefFlatUnion
));
376 tmp
->enum1
= ENUM_ONE_VALUE1
;
377 tmp
->string
= g_strdup("str");
379 tmp
->u
.value1
.boolean
= true;
381 visit_type_UserDefFlatUnion(data
->ov
, NULL
, &tmp
, &error_abort
);
382 qdict
= qobject_to_qdict(visitor_get(data
));
384 g_assert_cmpstr(qdict_get_str(qdict
, "enum1"), ==, "value1");
385 g_assert_cmpstr(qdict_get_str(qdict
, "string"), ==, "str");
386 g_assert_cmpint(qdict_get_int(qdict
, "integer"), ==, 41);
387 g_assert_cmpint(qdict_get_bool(qdict
, "boolean"), ==, true);
389 qapi_free_UserDefFlatUnion(tmp
);
392 static void test_visitor_out_alternate(TestOutputVisitorData
*data
,
395 UserDefAlternate
*tmp
;
401 tmp
= g_new0(UserDefAlternate
, 1);
402 tmp
->type
= QTYPE_QNUM
;
405 visit_type_UserDefAlternate(data
->ov
, NULL
, &tmp
, &error_abort
);
406 qnum
= qobject_to_qnum(visitor_get(data
));
408 g_assert(qnum_get_try_int(qnum
, &val
));
409 g_assert_cmpint(val
, ==, 42);
411 qapi_free_UserDefAlternate(tmp
);
414 tmp
= g_new0(UserDefAlternate
, 1);
415 tmp
->type
= QTYPE_QSTRING
;
416 tmp
->u
.e
= ENUM_ONE_VALUE1
;
418 visit_type_UserDefAlternate(data
->ov
, NULL
, &tmp
, &error_abort
);
419 qstr
= qobject_to_qstring(visitor_get(data
));
421 g_assert_cmpstr(qstring_get_str(qstr
), ==, "value1");
423 qapi_free_UserDefAlternate(tmp
);
426 tmp
= g_new0(UserDefAlternate
, 1);
427 tmp
->type
= QTYPE_QDICT
;
428 tmp
->u
.udfu
.integer
= 1;
429 tmp
->u
.udfu
.string
= g_strdup("str");
430 tmp
->u
.udfu
.enum1
= ENUM_ONE_VALUE1
;
431 tmp
->u
.udfu
.u
.value1
.boolean
= true;
433 visit_type_UserDefAlternate(data
->ov
, NULL
, &tmp
, &error_abort
);
434 qdict
= qobject_to_qdict(visitor_get(data
));
436 g_assert_cmpint(qdict_size(qdict
), ==, 4);
437 g_assert_cmpint(qdict_get_int(qdict
, "integer"), ==, 1);
438 g_assert_cmpstr(qdict_get_str(qdict
, "string"), ==, "str");
439 g_assert_cmpstr(qdict_get_str(qdict
, "enum1"), ==, "value1");
440 g_assert_cmpint(qdict_get_bool(qdict
, "boolean"), ==, true);
442 qapi_free_UserDefAlternate(tmp
);
445 static void test_visitor_out_null(TestOutputVisitorData
*data
,
451 visit_start_struct(data
->ov
, NULL
, NULL
, 0, &error_abort
);
452 visit_type_null(data
->ov
, "a", &error_abort
);
453 visit_check_struct(data
->ov
, &error_abort
);
454 visit_end_struct(data
->ov
, NULL
);
455 qdict
= qobject_to_qdict(visitor_get(data
));
457 g_assert_cmpint(qdict_size(qdict
), ==, 1);
458 nil
= qdict_get(qdict
, "a");
460 g_assert(qobject_type(nil
) == QTYPE_QNULL
);
463 static void init_native_list(UserDefNativeListUnion
*cvalue
)
466 switch (cvalue
->type
) {
467 case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER
: {
468 intList
**list
= &cvalue
->u
.integer
.data
;
469 for (i
= 0; i
< 32; i
++) {
470 *list
= g_new0(intList
, 1);
472 (*list
)->next
= NULL
;
473 list
= &(*list
)->next
;
477 case USER_DEF_NATIVE_LIST_UNION_KIND_S8
: {
478 int8List
**list
= &cvalue
->u
.s8
.data
;
479 for (i
= 0; i
< 32; i
++) {
480 *list
= g_new0(int8List
, 1);
482 (*list
)->next
= NULL
;
483 list
= &(*list
)->next
;
487 case USER_DEF_NATIVE_LIST_UNION_KIND_S16
: {
488 int16List
**list
= &cvalue
->u
.s16
.data
;
489 for (i
= 0; i
< 32; i
++) {
490 *list
= g_new0(int16List
, 1);
492 (*list
)->next
= NULL
;
493 list
= &(*list
)->next
;
497 case USER_DEF_NATIVE_LIST_UNION_KIND_S32
: {
498 int32List
**list
= &cvalue
->u
.s32
.data
;
499 for (i
= 0; i
< 32; i
++) {
500 *list
= g_new0(int32List
, 1);
502 (*list
)->next
= NULL
;
503 list
= &(*list
)->next
;
507 case USER_DEF_NATIVE_LIST_UNION_KIND_S64
: {
508 int64List
**list
= &cvalue
->u
.s64
.data
;
509 for (i
= 0; i
< 32; i
++) {
510 *list
= g_new0(int64List
, 1);
512 (*list
)->next
= NULL
;
513 list
= &(*list
)->next
;
517 case USER_DEF_NATIVE_LIST_UNION_KIND_U8
: {
518 uint8List
**list
= &cvalue
->u
.u8
.data
;
519 for (i
= 0; i
< 32; i
++) {
520 *list
= g_new0(uint8List
, 1);
522 (*list
)->next
= NULL
;
523 list
= &(*list
)->next
;
527 case USER_DEF_NATIVE_LIST_UNION_KIND_U16
: {
528 uint16List
**list
= &cvalue
->u
.u16
.data
;
529 for (i
= 0; i
< 32; i
++) {
530 *list
= g_new0(uint16List
, 1);
532 (*list
)->next
= NULL
;
533 list
= &(*list
)->next
;
537 case USER_DEF_NATIVE_LIST_UNION_KIND_U32
: {
538 uint32List
**list
= &cvalue
->u
.u32
.data
;
539 for (i
= 0; i
< 32; i
++) {
540 *list
= g_new0(uint32List
, 1);
542 (*list
)->next
= NULL
;
543 list
= &(*list
)->next
;
547 case USER_DEF_NATIVE_LIST_UNION_KIND_U64
: {
548 uint64List
**list
= &cvalue
->u
.u64
.data
;
549 for (i
= 0; i
< 32; i
++) {
550 *list
= g_new0(uint64List
, 1);
552 (*list
)->next
= NULL
;
553 list
= &(*list
)->next
;
557 case USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN
: {
558 boolList
**list
= &cvalue
->u
.boolean
.data
;
559 for (i
= 0; i
< 32; i
++) {
560 *list
= g_new0(boolList
, 1);
561 (*list
)->value
= (i
% 3 == 0);
562 (*list
)->next
= NULL
;
563 list
= &(*list
)->next
;
567 case USER_DEF_NATIVE_LIST_UNION_KIND_STRING
: {
568 strList
**list
= &cvalue
->u
.string
.data
;
569 for (i
= 0; i
< 32; i
++) {
570 *list
= g_new0(strList
, 1);
571 (*list
)->value
= g_strdup_printf("%d", i
);
572 (*list
)->next
= NULL
;
573 list
= &(*list
)->next
;
577 case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER
: {
578 numberList
**list
= &cvalue
->u
.number
.data
;
579 for (i
= 0; i
< 32; i
++) {
580 *list
= g_new0(numberList
, 1);
581 (*list
)->value
= (double)i
/ 3;
582 (*list
)->next
= NULL
;
583 list
= &(*list
)->next
;
588 g_assert_not_reached();
592 static void check_native_list(QObject
*qobj
,
593 UserDefNativeListUnionKind kind
)
599 qdict
= qobject_to_qdict(qobj
);
601 g_assert(qdict_haskey(qdict
, "data"));
602 qlist
= qlist_copy(qobject_to_qlist(qdict_get(qdict
, "data")));
605 case USER_DEF_NATIVE_LIST_UNION_KIND_U8
:
606 case USER_DEF_NATIVE_LIST_UNION_KIND_U16
:
607 case USER_DEF_NATIVE_LIST_UNION_KIND_U32
:
608 case USER_DEF_NATIVE_LIST_UNION_KIND_U64
:
609 for (i
= 0; i
< 32; i
++) {
614 tmp
= qlist_peek(qlist
);
616 qvalue
= qobject_to_qnum(tmp
);
617 g_assert(qnum_get_try_uint(qvalue
, &val
));
618 g_assert_cmpint(val
, ==, i
);
619 qobject_decref(qlist_pop(qlist
));
623 case USER_DEF_NATIVE_LIST_UNION_KIND_S8
:
624 case USER_DEF_NATIVE_LIST_UNION_KIND_S16
:
625 case USER_DEF_NATIVE_LIST_UNION_KIND_S32
:
626 case USER_DEF_NATIVE_LIST_UNION_KIND_S64
:
628 * All integer elements in JSON arrays get stored into QNums
629 * when we convert to QObjects, so we can check them all in
630 * the same fashion, so simply fall through here.
632 case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER
:
633 for (i
= 0; i
< 32; i
++) {
638 tmp
= qlist_peek(qlist
);
640 qvalue
= qobject_to_qnum(tmp
);
641 g_assert(qnum_get_try_int(qvalue
, &val
));
642 g_assert_cmpint(val
, ==, i
);
643 qobject_decref(qlist_pop(qlist
));
646 case USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN
:
647 for (i
= 0; i
< 32; i
++) {
650 tmp
= qlist_peek(qlist
);
652 qvalue
= qobject_to_qbool(tmp
);
653 g_assert_cmpint(qbool_get_bool(qvalue
), ==, i
% 3 == 0);
654 qobject_decref(qlist_pop(qlist
));
657 case USER_DEF_NATIVE_LIST_UNION_KIND_STRING
:
658 for (i
= 0; i
< 32; i
++) {
662 tmp
= qlist_peek(qlist
);
664 qvalue
= qobject_to_qstring(tmp
);
665 sprintf(str
, "%d", i
);
666 g_assert_cmpstr(qstring_get_str(qvalue
), ==, str
);
667 qobject_decref(qlist_pop(qlist
));
670 case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER
:
671 for (i
= 0; i
< 32; i
++) {
674 GString
*double_expected
= g_string_new("");
675 GString
*double_actual
= g_string_new("");
677 tmp
= qlist_peek(qlist
);
679 qvalue
= qobject_to_qnum(tmp
);
680 g_string_printf(double_expected
, "%.6f", (double)i
/ 3);
681 g_string_printf(double_actual
, "%.6f", qnum_get_double(qvalue
));
682 g_assert_cmpstr(double_actual
->str
, ==, double_expected
->str
);
684 qobject_decref(qlist_pop(qlist
));
685 g_string_free(double_expected
, true);
686 g_string_free(double_actual
, true);
690 g_assert_not_reached();
695 static void test_native_list(TestOutputVisitorData
*data
,
697 UserDefNativeListUnionKind kind
)
699 UserDefNativeListUnion
*cvalue
= g_new0(UserDefNativeListUnion
, 1);
703 init_native_list(cvalue
);
705 visit_type_UserDefNativeListUnion(data
->ov
, NULL
, &cvalue
, &error_abort
);
707 obj
= visitor_get(data
);
708 check_native_list(obj
, cvalue
->type
);
709 qapi_free_UserDefNativeListUnion(cvalue
);
712 static void test_visitor_out_native_list_int(TestOutputVisitorData
*data
,
715 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER
);
718 static void test_visitor_out_native_list_int8(TestOutputVisitorData
*data
,
721 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S8
);
724 static void test_visitor_out_native_list_int16(TestOutputVisitorData
*data
,
727 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S16
);
730 static void test_visitor_out_native_list_int32(TestOutputVisitorData
*data
,
733 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S32
);
736 static void test_visitor_out_native_list_int64(TestOutputVisitorData
*data
,
739 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S64
);
742 static void test_visitor_out_native_list_uint8(TestOutputVisitorData
*data
,
745 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U8
);
748 static void test_visitor_out_native_list_uint16(TestOutputVisitorData
*data
,
751 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U16
);
754 static void test_visitor_out_native_list_uint32(TestOutputVisitorData
*data
,
757 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U32
);
760 static void test_visitor_out_native_list_uint64(TestOutputVisitorData
*data
,
763 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U64
);
766 static void test_visitor_out_native_list_bool(TestOutputVisitorData
*data
,
769 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN
);
772 static void test_visitor_out_native_list_str(TestOutputVisitorData
*data
,
775 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_STRING
);
778 static void test_visitor_out_native_list_number(TestOutputVisitorData
*data
,
781 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER
);
784 static void output_visitor_test_add(const char *testpath
,
785 TestOutputVisitorData
*data
,
786 void (*test_func
)(TestOutputVisitorData
*data
, const void *user_data
))
788 g_test_add(testpath
, TestOutputVisitorData
, data
, visitor_output_setup
,
789 test_func
, visitor_output_teardown
);
792 int main(int argc
, char **argv
)
794 TestOutputVisitorData out_visitor_data
;
796 g_test_init(&argc
, &argv
, NULL
);
798 output_visitor_test_add("/visitor/output/int",
799 &out_visitor_data
, test_visitor_out_int
);
800 output_visitor_test_add("/visitor/output/bool",
801 &out_visitor_data
, test_visitor_out_bool
);
802 output_visitor_test_add("/visitor/output/number",
803 &out_visitor_data
, test_visitor_out_number
);
804 output_visitor_test_add("/visitor/output/string",
805 &out_visitor_data
, test_visitor_out_string
);
806 output_visitor_test_add("/visitor/output/no-string",
807 &out_visitor_data
, test_visitor_out_no_string
);
808 output_visitor_test_add("/visitor/output/enum",
809 &out_visitor_data
, test_visitor_out_enum
);
810 output_visitor_test_add("/visitor/output/enum-errors",
811 &out_visitor_data
, test_visitor_out_enum_errors
);
812 output_visitor_test_add("/visitor/output/struct",
813 &out_visitor_data
, test_visitor_out_struct
);
814 output_visitor_test_add("/visitor/output/struct-nested",
815 &out_visitor_data
, test_visitor_out_struct_nested
);
816 output_visitor_test_add("/visitor/output/struct-errors",
817 &out_visitor_data
, test_visitor_out_struct_errors
);
818 output_visitor_test_add("/visitor/output/list",
819 &out_visitor_data
, test_visitor_out_list
);
820 output_visitor_test_add("/visitor/output/any",
821 &out_visitor_data
, test_visitor_out_any
);
822 output_visitor_test_add("/visitor/output/list-qapi-free",
823 &out_visitor_data
, test_visitor_out_list_qapi_free
);
824 output_visitor_test_add("/visitor/output/union-flat",
825 &out_visitor_data
, test_visitor_out_union_flat
);
826 output_visitor_test_add("/visitor/output/alternate",
827 &out_visitor_data
, test_visitor_out_alternate
);
828 output_visitor_test_add("/visitor/output/null",
829 &out_visitor_data
, test_visitor_out_null
);
830 output_visitor_test_add("/visitor/output/native_list/int",
832 test_visitor_out_native_list_int
);
833 output_visitor_test_add("/visitor/output/native_list/int8",
835 test_visitor_out_native_list_int8
);
836 output_visitor_test_add("/visitor/output/native_list/int16",
838 test_visitor_out_native_list_int16
);
839 output_visitor_test_add("/visitor/output/native_list/int32",
841 test_visitor_out_native_list_int32
);
842 output_visitor_test_add("/visitor/output/native_list/int64",
844 test_visitor_out_native_list_int64
);
845 output_visitor_test_add("/visitor/output/native_list/uint8",
847 test_visitor_out_native_list_uint8
);
848 output_visitor_test_add("/visitor/output/native_list/uint16",
850 test_visitor_out_native_list_uint16
);
851 output_visitor_test_add("/visitor/output/native_list/uint32",
853 test_visitor_out_native_list_uint32
);
854 output_visitor_test_add("/visitor/output/native_list/uint64",
856 test_visitor_out_native_list_uint64
);
857 output_visitor_test_add("/visitor/output/native_list/bool",
859 test_visitor_out_native_list_bool
);
860 output_visitor_test_add("/visitor/output/native_list/string",
862 test_visitor_out_native_list_str
);
863 output_visitor_test_add("/visitor/output/native_list/number",
865 test_visitor_out_native_list_number
);