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
,
63 visit_type_int(data
->ov
, NULL
, &value
, &error_abort
);
65 qint
= qobject_to_qint(visitor_get(data
));
67 g_assert_cmpint(qint_get_int(qint
), ==, value
);
70 static void test_visitor_out_bool(TestOutputVisitorData
*data
,
76 visit_type_bool(data
->ov
, NULL
, &value
, &error_abort
);
78 qbool
= qobject_to_qbool(visitor_get(data
));
80 g_assert(qbool_get_bool(qbool
) == value
);
83 static void test_visitor_out_number(TestOutputVisitorData
*data
,
89 visit_type_number(data
->ov
, NULL
, &value
, &error_abort
);
91 qfloat
= qobject_to_qfloat(visitor_get(data
));
93 g_assert(qfloat_get_double(qfloat
) == value
);
96 static void test_visitor_out_string(TestOutputVisitorData
*data
,
99 char *string
= (char *) "Q E M U";
102 visit_type_str(data
->ov
, NULL
, &string
, &error_abort
);
104 qstr
= qobject_to_qstring(visitor_get(data
));
106 g_assert_cmpstr(qstring_get_str(qstr
), ==, string
);
109 static void test_visitor_out_no_string(TestOutputVisitorData
*data
,
115 /* A null string should return "" */
116 visit_type_str(data
->ov
, NULL
, &string
, &error_abort
);
118 qstr
= qobject_to_qstring(visitor_get(data
));
120 g_assert_cmpstr(qstring_get_str(qstr
), ==, "");
123 static void test_visitor_out_enum(TestOutputVisitorData
*data
,
129 for (i
= 0; i
< ENUM_ONE__MAX
; i
++) {
130 visit_type_EnumOne(data
->ov
, "unused", &i
, &error_abort
);
132 qstr
= qobject_to_qstring(visitor_get(data
));
134 g_assert_cmpstr(qstring_get_str(qstr
), ==, EnumOne_lookup
[i
]);
139 static void test_visitor_out_enum_errors(TestOutputVisitorData
*data
,
142 EnumOne i
, bad_values
[] = { ENUM_ONE__MAX
, -1 };
145 for (i
= 0; i
< ARRAY_SIZE(bad_values
) ; i
++) {
147 visit_type_EnumOne(data
->ov
, "unused", &bad_values
[i
], &err
);
148 error_free_or_abort(&err
);
154 static void test_visitor_out_struct(TestOutputVisitorData
*data
,
157 TestStruct test_struct
= { .integer
= 42,
159 .string
= (char *) "foo"};
160 TestStruct
*p
= &test_struct
;
163 visit_type_TestStruct(data
->ov
, NULL
, &p
, &error_abort
);
165 qdict
= qobject_to_qdict(visitor_get(data
));
167 g_assert_cmpint(qdict_size(qdict
), ==, 3);
168 g_assert_cmpint(qdict_get_int(qdict
, "integer"), ==, 42);
169 g_assert_cmpint(qdict_get_bool(qdict
, "boolean"), ==, false);
170 g_assert_cmpstr(qdict_get_str(qdict
, "string"), ==, "foo");
173 static void test_visitor_out_struct_nested(TestOutputVisitorData
*data
,
178 QDict
*qdict
, *dict1
, *dict2
, *dict3
, *userdef
;
179 const char *string
= "user def string";
180 const char *strings
[] = { "forty two", "forty three", "forty four",
183 ud2
= g_malloc0(sizeof(*ud2
));
184 ud2
->string0
= g_strdup(strings
[0]);
186 ud2
->dict1
= g_malloc0(sizeof(*ud2
->dict1
));
187 ud2
->dict1
->string1
= g_strdup(strings
[1]);
189 ud2
->dict1
->dict2
= g_malloc0(sizeof(*ud2
->dict1
->dict2
));
190 ud2
->dict1
->dict2
->userdef
= g_new0(UserDefOne
, 1);
191 ud2
->dict1
->dict2
->userdef
->string
= g_strdup(string
);
192 ud2
->dict1
->dict2
->userdef
->integer
= value
;
193 ud2
->dict1
->dict2
->string
= g_strdup(strings
[2]);
195 ud2
->dict1
->dict3
= g_malloc0(sizeof(*ud2
->dict1
->dict3
));
196 ud2
->dict1
->has_dict3
= true;
197 ud2
->dict1
->dict3
->userdef
= g_new0(UserDefOne
, 1);
198 ud2
->dict1
->dict3
->userdef
->string
= g_strdup(string
);
199 ud2
->dict1
->dict3
->userdef
->integer
= value
;
200 ud2
->dict1
->dict3
->string
= g_strdup(strings
[3]);
202 visit_type_UserDefTwo(data
->ov
, "unused", &ud2
, &error_abort
);
204 qdict
= qobject_to_qdict(visitor_get(data
));
206 g_assert_cmpint(qdict_size(qdict
), ==, 2);
207 g_assert_cmpstr(qdict_get_str(qdict
, "string0"), ==, strings
[0]);
209 dict1
= qdict_get_qdict(qdict
, "dict1");
210 g_assert_cmpint(qdict_size(dict1
), ==, 3);
211 g_assert_cmpstr(qdict_get_str(dict1
, "string1"), ==, strings
[1]);
213 dict2
= qdict_get_qdict(dict1
, "dict2");
214 g_assert_cmpint(qdict_size(dict2
), ==, 2);
215 g_assert_cmpstr(qdict_get_str(dict2
, "string"), ==, strings
[2]);
216 userdef
= qdict_get_qdict(dict2
, "userdef");
217 g_assert_cmpint(qdict_size(userdef
), ==, 2);
218 g_assert_cmpint(qdict_get_int(userdef
, "integer"), ==, value
);
219 g_assert_cmpstr(qdict_get_str(userdef
, "string"), ==, string
);
221 dict3
= qdict_get_qdict(dict1
, "dict3");
222 g_assert_cmpint(qdict_size(dict3
), ==, 2);
223 g_assert_cmpstr(qdict_get_str(dict3
, "string"), ==, strings
[3]);
224 userdef
= qdict_get_qdict(dict3
, "userdef");
225 g_assert_cmpint(qdict_size(userdef
), ==, 2);
226 g_assert_cmpint(qdict_get_int(userdef
, "integer"), ==, value
);
227 g_assert_cmpstr(qdict_get_str(userdef
, "string"), ==, string
);
229 qapi_free_UserDefTwo(ud2
);
232 static void test_visitor_out_struct_errors(TestOutputVisitorData
*data
,
235 EnumOne bad_values
[] = { ENUM_ONE__MAX
, -1 };
241 for (i
= 0; i
< ARRAY_SIZE(bad_values
) ; i
++) {
244 u
.enum1
= bad_values
[i
];
245 visit_type_UserDefOne(data
->ov
, "unused", &pu
, &err
);
246 error_free_or_abort(&err
);
252 static void test_visitor_out_list(TestOutputVisitorData
*data
,
255 const char *value_str
= "list value";
256 TestStructList
*p
, *head
= NULL
;
257 const int max_items
= 10;
258 bool value_bool
= true;
264 /* Build the list in reverse order... */
265 for (i
= 0; i
< max_items
; i
++) {
266 p
= g_malloc0(sizeof(*p
));
267 p
->value
= g_malloc0(sizeof(*p
->value
));
268 p
->value
->integer
= value_int
+ (max_items
- i
- 1);
269 p
->value
->boolean
= value_bool
;
270 p
->value
->string
= g_strdup(value_str
);
276 visit_type_TestStructList(data
->ov
, NULL
, &head
, &error_abort
);
278 qlist
= qobject_to_qlist(visitor_get(data
));
280 g_assert(!qlist_empty(qlist
));
282 /* ...and ensure that the visitor sees it in order */
284 QLIST_FOREACH_ENTRY(qlist
, entry
) {
287 qdict
= qobject_to_qdict(entry
->value
);
289 g_assert_cmpint(qdict_size(qdict
), ==, 3);
290 g_assert_cmpint(qdict_get_int(qdict
, "integer"), ==, value_int
+ i
);
291 g_assert_cmpint(qdict_get_bool(qdict
, "boolean"), ==, value_bool
);
292 g_assert_cmpstr(qdict_get_str(qdict
, "string"), ==, value_str
);
295 g_assert_cmpint(i
, ==, max_items
);
297 qapi_free_TestStructList(head
);
300 static void test_visitor_out_list_qapi_free(TestOutputVisitorData
*data
,
303 UserDefTwoList
*p
, *head
= NULL
;
304 const char string
[] = "foo bar";
305 int i
, max_count
= 1024;
307 for (i
= 0; i
< max_count
; i
++) {
308 p
= g_malloc0(sizeof(*p
));
309 p
->value
= g_malloc0(sizeof(*p
->value
));
311 p
->value
->string0
= g_strdup(string
);
312 p
->value
->dict1
= g_new0(UserDefTwoDict
, 1);
313 p
->value
->dict1
->string1
= g_strdup(string
);
314 p
->value
->dict1
->dict2
= g_new0(UserDefTwoDictDict
, 1);
315 p
->value
->dict1
->dict2
->userdef
= g_new0(UserDefOne
, 1);
316 p
->value
->dict1
->dict2
->userdef
->string
= g_strdup(string
);
317 p
->value
->dict1
->dict2
->userdef
->integer
= 42;
318 p
->value
->dict1
->dict2
->string
= g_strdup(string
);
319 p
->value
->dict1
->has_dict3
= false;
325 qapi_free_UserDefTwoList(head
);
328 static void test_visitor_out_any(TestOutputVisitorData
*data
,
337 qobj
= QOBJECT(qint_from_int(-42));
338 visit_type_any(data
->ov
, NULL
, &qobj
, &error_abort
);
339 qint
= qobject_to_qint(visitor_get(data
));
341 g_assert_cmpint(qint_get_int(qint
), ==, -42);
342 qobject_decref(qobj
);
346 qdict_put_int(qdict
, "integer", -42);
347 qdict_put_bool(qdict
, "boolean", true);
348 qdict_put_str(qdict
, "string", "foo");
349 qobj
= QOBJECT(qdict
);
350 visit_type_any(data
->ov
, NULL
, &qobj
, &error_abort
);
351 qobject_decref(qobj
);
352 qdict
= qobject_to_qdict(visitor_get(data
));
354 qint
= qobject_to_qint(qdict_get(qdict
, "integer"));
356 g_assert_cmpint(qint_get_int(qint
), ==, -42);
357 qbool
= qobject_to_qbool(qdict_get(qdict
, "boolean"));
359 g_assert(qbool_get_bool(qbool
) == true);
360 qstring
= qobject_to_qstring(qdict_get(qdict
, "string"));
362 g_assert_cmpstr(qstring_get_str(qstring
), ==, "foo");
365 static void test_visitor_out_union_flat(TestOutputVisitorData
*data
,
370 UserDefFlatUnion
*tmp
= g_malloc0(sizeof(UserDefFlatUnion
));
371 tmp
->enum1
= ENUM_ONE_VALUE1
;
372 tmp
->string
= g_strdup("str");
374 tmp
->u
.value1
.boolean
= true;
376 visit_type_UserDefFlatUnion(data
->ov
, NULL
, &tmp
, &error_abort
);
377 qdict
= qobject_to_qdict(visitor_get(data
));
379 g_assert_cmpstr(qdict_get_str(qdict
, "enum1"), ==, "value1");
380 g_assert_cmpstr(qdict_get_str(qdict
, "string"), ==, "str");
381 g_assert_cmpint(qdict_get_int(qdict
, "integer"), ==, 41);
382 g_assert_cmpint(qdict_get_bool(qdict
, "boolean"), ==, true);
384 qapi_free_UserDefFlatUnion(tmp
);
387 static void test_visitor_out_alternate(TestOutputVisitorData
*data
,
390 UserDefAlternate
*tmp
;
395 tmp
= g_new0(UserDefAlternate
, 1);
396 tmp
->type
= QTYPE_QINT
;
399 visit_type_UserDefAlternate(data
->ov
, NULL
, &tmp
, &error_abort
);
400 qint
= qobject_to_qint(visitor_get(data
));
402 g_assert_cmpint(qint_get_int(qint
), ==, 42);
404 qapi_free_UserDefAlternate(tmp
);
407 tmp
= g_new0(UserDefAlternate
, 1);
408 tmp
->type
= QTYPE_QSTRING
;
409 tmp
->u
.e
= ENUM_ONE_VALUE1
;
411 visit_type_UserDefAlternate(data
->ov
, NULL
, &tmp
, &error_abort
);
412 qstr
= qobject_to_qstring(visitor_get(data
));
414 g_assert_cmpstr(qstring_get_str(qstr
), ==, "value1");
416 qapi_free_UserDefAlternate(tmp
);
419 tmp
= g_new0(UserDefAlternate
, 1);
420 tmp
->type
= QTYPE_QDICT
;
421 tmp
->u
.udfu
.integer
= 1;
422 tmp
->u
.udfu
.string
= g_strdup("str");
423 tmp
->u
.udfu
.enum1
= ENUM_ONE_VALUE1
;
424 tmp
->u
.udfu
.u
.value1
.boolean
= true;
426 visit_type_UserDefAlternate(data
->ov
, NULL
, &tmp
, &error_abort
);
427 qdict
= qobject_to_qdict(visitor_get(data
));
429 g_assert_cmpint(qdict_size(qdict
), ==, 4);
430 g_assert_cmpint(qdict_get_int(qdict
, "integer"), ==, 1);
431 g_assert_cmpstr(qdict_get_str(qdict
, "string"), ==, "str");
432 g_assert_cmpstr(qdict_get_str(qdict
, "enum1"), ==, "value1");
433 g_assert_cmpint(qdict_get_bool(qdict
, "boolean"), ==, true);
435 qapi_free_UserDefAlternate(tmp
);
438 static void test_visitor_out_null(TestOutputVisitorData
*data
,
444 visit_start_struct(data
->ov
, NULL
, NULL
, 0, &error_abort
);
445 visit_type_null(data
->ov
, "a", &error_abort
);
446 visit_check_struct(data
->ov
, &error_abort
);
447 visit_end_struct(data
->ov
, NULL
);
448 qdict
= qobject_to_qdict(visitor_get(data
));
450 g_assert_cmpint(qdict_size(qdict
), ==, 1);
451 nil
= qdict_get(qdict
, "a");
453 g_assert(qobject_type(nil
) == QTYPE_QNULL
);
456 static void init_native_list(UserDefNativeListUnion
*cvalue
)
459 switch (cvalue
->type
) {
460 case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER
: {
461 intList
**list
= &cvalue
->u
.integer
.data
;
462 for (i
= 0; i
< 32; i
++) {
463 *list
= g_new0(intList
, 1);
465 (*list
)->next
= NULL
;
466 list
= &(*list
)->next
;
470 case USER_DEF_NATIVE_LIST_UNION_KIND_S8
: {
471 int8List
**list
= &cvalue
->u
.s8
.data
;
472 for (i
= 0; i
< 32; i
++) {
473 *list
= g_new0(int8List
, 1);
475 (*list
)->next
= NULL
;
476 list
= &(*list
)->next
;
480 case USER_DEF_NATIVE_LIST_UNION_KIND_S16
: {
481 int16List
**list
= &cvalue
->u
.s16
.data
;
482 for (i
= 0; i
< 32; i
++) {
483 *list
= g_new0(int16List
, 1);
485 (*list
)->next
= NULL
;
486 list
= &(*list
)->next
;
490 case USER_DEF_NATIVE_LIST_UNION_KIND_S32
: {
491 int32List
**list
= &cvalue
->u
.s32
.data
;
492 for (i
= 0; i
< 32; i
++) {
493 *list
= g_new0(int32List
, 1);
495 (*list
)->next
= NULL
;
496 list
= &(*list
)->next
;
500 case USER_DEF_NATIVE_LIST_UNION_KIND_S64
: {
501 int64List
**list
= &cvalue
->u
.s64
.data
;
502 for (i
= 0; i
< 32; i
++) {
503 *list
= g_new0(int64List
, 1);
505 (*list
)->next
= NULL
;
506 list
= &(*list
)->next
;
510 case USER_DEF_NATIVE_LIST_UNION_KIND_U8
: {
511 uint8List
**list
= &cvalue
->u
.u8
.data
;
512 for (i
= 0; i
< 32; i
++) {
513 *list
= g_new0(uint8List
, 1);
515 (*list
)->next
= NULL
;
516 list
= &(*list
)->next
;
520 case USER_DEF_NATIVE_LIST_UNION_KIND_U16
: {
521 uint16List
**list
= &cvalue
->u
.u16
.data
;
522 for (i
= 0; i
< 32; i
++) {
523 *list
= g_new0(uint16List
, 1);
525 (*list
)->next
= NULL
;
526 list
= &(*list
)->next
;
530 case USER_DEF_NATIVE_LIST_UNION_KIND_U32
: {
531 uint32List
**list
= &cvalue
->u
.u32
.data
;
532 for (i
= 0; i
< 32; i
++) {
533 *list
= g_new0(uint32List
, 1);
535 (*list
)->next
= NULL
;
536 list
= &(*list
)->next
;
540 case USER_DEF_NATIVE_LIST_UNION_KIND_U64
: {
541 uint64List
**list
= &cvalue
->u
.u64
.data
;
542 for (i
= 0; i
< 32; i
++) {
543 *list
= g_new0(uint64List
, 1);
545 (*list
)->next
= NULL
;
546 list
= &(*list
)->next
;
550 case USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN
: {
551 boolList
**list
= &cvalue
->u
.boolean
.data
;
552 for (i
= 0; i
< 32; i
++) {
553 *list
= g_new0(boolList
, 1);
554 (*list
)->value
= (i
% 3 == 0);
555 (*list
)->next
= NULL
;
556 list
= &(*list
)->next
;
560 case USER_DEF_NATIVE_LIST_UNION_KIND_STRING
: {
561 strList
**list
= &cvalue
->u
.string
.data
;
562 for (i
= 0; i
< 32; i
++) {
563 *list
= g_new0(strList
, 1);
564 (*list
)->value
= g_strdup_printf("%d", i
);
565 (*list
)->next
= NULL
;
566 list
= &(*list
)->next
;
570 case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER
: {
571 numberList
**list
= &cvalue
->u
.number
.data
;
572 for (i
= 0; i
< 32; i
++) {
573 *list
= g_new0(numberList
, 1);
574 (*list
)->value
= (double)i
/ 3;
575 (*list
)->next
= NULL
;
576 list
= &(*list
)->next
;
581 g_assert_not_reached();
585 static void check_native_list(QObject
*qobj
,
586 UserDefNativeListUnionKind kind
)
592 qdict
= qobject_to_qdict(qobj
);
594 g_assert(qdict_haskey(qdict
, "data"));
595 qlist
= qlist_copy(qobject_to_qlist(qdict_get(qdict
, "data")));
598 case USER_DEF_NATIVE_LIST_UNION_KIND_S8
:
599 case USER_DEF_NATIVE_LIST_UNION_KIND_S16
:
600 case USER_DEF_NATIVE_LIST_UNION_KIND_S32
:
601 case USER_DEF_NATIVE_LIST_UNION_KIND_S64
:
602 case USER_DEF_NATIVE_LIST_UNION_KIND_U8
:
603 case USER_DEF_NATIVE_LIST_UNION_KIND_U16
:
604 case USER_DEF_NATIVE_LIST_UNION_KIND_U32
:
605 case USER_DEF_NATIVE_LIST_UNION_KIND_U64
:
606 /* all integer elements in JSON arrays get stored into QInts when
607 * we convert to QObjects, so we can check them all in the same
608 * fashion, so simply fall through here
610 case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER
:
611 for (i
= 0; i
< 32; i
++) {
614 tmp
= qlist_peek(qlist
);
616 qvalue
= qobject_to_qint(tmp
);
617 g_assert_cmpint(qint_get_int(qvalue
), ==, i
);
618 qobject_decref(qlist_pop(qlist
));
621 case USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN
:
622 for (i
= 0; i
< 32; i
++) {
625 tmp
= qlist_peek(qlist
);
627 qvalue
= qobject_to_qbool(tmp
);
628 g_assert_cmpint(qbool_get_bool(qvalue
), ==, i
% 3 == 0);
629 qobject_decref(qlist_pop(qlist
));
632 case USER_DEF_NATIVE_LIST_UNION_KIND_STRING
:
633 for (i
= 0; i
< 32; i
++) {
637 tmp
= qlist_peek(qlist
);
639 qvalue
= qobject_to_qstring(tmp
);
640 sprintf(str
, "%d", i
);
641 g_assert_cmpstr(qstring_get_str(qvalue
), ==, str
);
642 qobject_decref(qlist_pop(qlist
));
645 case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER
:
646 for (i
= 0; i
< 32; i
++) {
649 GString
*double_expected
= g_string_new("");
650 GString
*double_actual
= g_string_new("");
652 tmp
= qlist_peek(qlist
);
654 qvalue
= qobject_to_qfloat(tmp
);
655 g_string_printf(double_expected
, "%.6f", (double)i
/ 3);
656 g_string_printf(double_actual
, "%.6f", qfloat_get_double(qvalue
));
657 g_assert_cmpstr(double_actual
->str
, ==, double_expected
->str
);
659 qobject_decref(qlist_pop(qlist
));
660 g_string_free(double_expected
, true);
661 g_string_free(double_actual
, true);
665 g_assert_not_reached();
670 static void test_native_list(TestOutputVisitorData
*data
,
672 UserDefNativeListUnionKind kind
)
674 UserDefNativeListUnion
*cvalue
= g_new0(UserDefNativeListUnion
, 1);
678 init_native_list(cvalue
);
680 visit_type_UserDefNativeListUnion(data
->ov
, NULL
, &cvalue
, &error_abort
);
682 obj
= visitor_get(data
);
683 check_native_list(obj
, cvalue
->type
);
684 qapi_free_UserDefNativeListUnion(cvalue
);
687 static void test_visitor_out_native_list_int(TestOutputVisitorData
*data
,
690 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER
);
693 static void test_visitor_out_native_list_int8(TestOutputVisitorData
*data
,
696 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S8
);
699 static void test_visitor_out_native_list_int16(TestOutputVisitorData
*data
,
702 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S16
);
705 static void test_visitor_out_native_list_int32(TestOutputVisitorData
*data
,
708 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S32
);
711 static void test_visitor_out_native_list_int64(TestOutputVisitorData
*data
,
714 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S64
);
717 static void test_visitor_out_native_list_uint8(TestOutputVisitorData
*data
,
720 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U8
);
723 static void test_visitor_out_native_list_uint16(TestOutputVisitorData
*data
,
726 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U16
);
729 static void test_visitor_out_native_list_uint32(TestOutputVisitorData
*data
,
732 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U32
);
735 static void test_visitor_out_native_list_uint64(TestOutputVisitorData
*data
,
738 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U64
);
741 static void test_visitor_out_native_list_bool(TestOutputVisitorData
*data
,
744 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN
);
747 static void test_visitor_out_native_list_str(TestOutputVisitorData
*data
,
750 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_STRING
);
753 static void test_visitor_out_native_list_number(TestOutputVisitorData
*data
,
756 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER
);
759 static void output_visitor_test_add(const char *testpath
,
760 TestOutputVisitorData
*data
,
761 void (*test_func
)(TestOutputVisitorData
*data
, const void *user_data
))
763 g_test_add(testpath
, TestOutputVisitorData
, data
, visitor_output_setup
,
764 test_func
, visitor_output_teardown
);
767 int main(int argc
, char **argv
)
769 TestOutputVisitorData out_visitor_data
;
771 g_test_init(&argc
, &argv
, NULL
);
773 output_visitor_test_add("/visitor/output/int",
774 &out_visitor_data
, test_visitor_out_int
);
775 output_visitor_test_add("/visitor/output/bool",
776 &out_visitor_data
, test_visitor_out_bool
);
777 output_visitor_test_add("/visitor/output/number",
778 &out_visitor_data
, test_visitor_out_number
);
779 output_visitor_test_add("/visitor/output/string",
780 &out_visitor_data
, test_visitor_out_string
);
781 output_visitor_test_add("/visitor/output/no-string",
782 &out_visitor_data
, test_visitor_out_no_string
);
783 output_visitor_test_add("/visitor/output/enum",
784 &out_visitor_data
, test_visitor_out_enum
);
785 output_visitor_test_add("/visitor/output/enum-errors",
786 &out_visitor_data
, test_visitor_out_enum_errors
);
787 output_visitor_test_add("/visitor/output/struct",
788 &out_visitor_data
, test_visitor_out_struct
);
789 output_visitor_test_add("/visitor/output/struct-nested",
790 &out_visitor_data
, test_visitor_out_struct_nested
);
791 output_visitor_test_add("/visitor/output/struct-errors",
792 &out_visitor_data
, test_visitor_out_struct_errors
);
793 output_visitor_test_add("/visitor/output/list",
794 &out_visitor_data
, test_visitor_out_list
);
795 output_visitor_test_add("/visitor/output/any",
796 &out_visitor_data
, test_visitor_out_any
);
797 output_visitor_test_add("/visitor/output/list-qapi-free",
798 &out_visitor_data
, test_visitor_out_list_qapi_free
);
799 output_visitor_test_add("/visitor/output/union-flat",
800 &out_visitor_data
, test_visitor_out_union_flat
);
801 output_visitor_test_add("/visitor/output/alternate",
802 &out_visitor_data
, test_visitor_out_alternate
);
803 output_visitor_test_add("/visitor/output/null",
804 &out_visitor_data
, test_visitor_out_null
);
805 output_visitor_test_add("/visitor/output/native_list/int",
807 test_visitor_out_native_list_int
);
808 output_visitor_test_add("/visitor/output/native_list/int8",
810 test_visitor_out_native_list_int8
);
811 output_visitor_test_add("/visitor/output/native_list/int16",
813 test_visitor_out_native_list_int16
);
814 output_visitor_test_add("/visitor/output/native_list/int32",
816 test_visitor_out_native_list_int32
);
817 output_visitor_test_add("/visitor/output/native_list/int64",
819 test_visitor_out_native_list_int64
);
820 output_visitor_test_add("/visitor/output/native_list/uint8",
822 test_visitor_out_native_list_uint8
);
823 output_visitor_test_add("/visitor/output/native_list/uint16",
825 test_visitor_out_native_list_uint16
);
826 output_visitor_test_add("/visitor/output/native_list/uint32",
828 test_visitor_out_native_list_uint32
);
829 output_visitor_test_add("/visitor/output/native_list/uint64",
831 test_visitor_out_native_list_uint64
);
832 output_visitor_test_add("/visitor/output/native_list/bool",
834 test_visitor_out_native_list_bool
);
835 output_visitor_test_add("/visitor/output/native_list/string",
837 test_visitor_out_native_list_str
);
838 output_visitor_test_add("/visitor/output/native_list/number",
840 test_visitor_out_native_list_number
);