2 * QMP 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/qmp-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
= qmp_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 obj
= visitor_get(data
);
66 g_assert(qobject_type(obj
) == QTYPE_QINT
);
67 g_assert_cmpint(qint_get_int(qobject_to_qint(obj
)), ==, value
);
70 static void test_visitor_out_bool(TestOutputVisitorData
*data
,
76 visit_type_bool(data
->ov
, NULL
, &value
, &error_abort
);
78 obj
= visitor_get(data
);
79 g_assert(qobject_type(obj
) == QTYPE_QBOOL
);
80 g_assert(qbool_get_bool(qobject_to_qbool(obj
)) == value
);
83 static void test_visitor_out_number(TestOutputVisitorData
*data
,
89 visit_type_number(data
->ov
, NULL
, &value
, &error_abort
);
91 obj
= visitor_get(data
);
92 g_assert(qobject_type(obj
) == QTYPE_QFLOAT
);
93 g_assert(qfloat_get_double(qobject_to_qfloat(obj
)) == 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 obj
= visitor_get(data
);
105 g_assert(qobject_type(obj
) == QTYPE_QSTRING
);
106 g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj
)), ==, 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 obj
= visitor_get(data
);
119 g_assert(qobject_type(obj
) == QTYPE_QSTRING
);
120 g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj
)), ==, "");
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 obj
= visitor_get(data
);
133 g_assert(qobject_type(obj
) == QTYPE_QSTRING
);
134 g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj
)), ==,
140 static void test_visitor_out_enum_errors(TestOutputVisitorData
*data
,
143 EnumOne i
, bad_values
[] = { ENUM_ONE__MAX
, -1 };
146 for (i
= 0; i
< ARRAY_SIZE(bad_values
) ; i
++) {
148 visit_type_EnumOne(data
->ov
, "unused", &bad_values
[i
], &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
;
166 visit_type_TestStruct(data
->ov
, NULL
, &p
, &error_abort
);
168 obj
= visitor_get(data
);
169 g_assert(qobject_type(obj
) == QTYPE_QDICT
);
171 qdict
= qobject_to_qdict(obj
);
172 g_assert_cmpint(qdict_size(qdict
), ==, 3);
173 g_assert_cmpint(qdict_get_int(qdict
, "integer"), ==, 42);
174 g_assert_cmpint(qdict_get_bool(qdict
, "boolean"), ==, false);
175 g_assert_cmpstr(qdict_get_str(qdict
, "string"), ==, "foo");
178 static void test_visitor_out_struct_nested(TestOutputVisitorData
*data
,
184 QDict
*qdict
, *dict1
, *dict2
, *dict3
, *userdef
;
185 const char *string
= "user def string";
186 const char *strings
[] = { "forty two", "forty three", "forty four",
189 ud2
= g_malloc0(sizeof(*ud2
));
190 ud2
->string0
= g_strdup(strings
[0]);
192 ud2
->dict1
= g_malloc0(sizeof(*ud2
->dict1
));
193 ud2
->dict1
->string1
= g_strdup(strings
[1]);
195 ud2
->dict1
->dict2
= g_malloc0(sizeof(*ud2
->dict1
->dict2
));
196 ud2
->dict1
->dict2
->userdef
= g_new0(UserDefOne
, 1);
197 ud2
->dict1
->dict2
->userdef
->string
= g_strdup(string
);
198 ud2
->dict1
->dict2
->userdef
->integer
= value
;
199 ud2
->dict1
->dict2
->string
= g_strdup(strings
[2]);
201 ud2
->dict1
->dict3
= g_malloc0(sizeof(*ud2
->dict1
->dict3
));
202 ud2
->dict1
->has_dict3
= true;
203 ud2
->dict1
->dict3
->userdef
= g_new0(UserDefOne
, 1);
204 ud2
->dict1
->dict3
->userdef
->string
= g_strdup(string
);
205 ud2
->dict1
->dict3
->userdef
->integer
= value
;
206 ud2
->dict1
->dict3
->string
= g_strdup(strings
[3]);
208 visit_type_UserDefTwo(data
->ov
, "unused", &ud2
, &error_abort
);
210 obj
= visitor_get(data
);
211 g_assert(qobject_type(obj
) == QTYPE_QDICT
);
213 qdict
= qobject_to_qdict(obj
);
214 g_assert_cmpint(qdict_size(qdict
), ==, 2);
215 g_assert_cmpstr(qdict_get_str(qdict
, "string0"), ==, strings
[0]);
217 dict1
= qdict_get_qdict(qdict
, "dict1");
218 g_assert_cmpint(qdict_size(dict1
), ==, 3);
219 g_assert_cmpstr(qdict_get_str(dict1
, "string1"), ==, strings
[1]);
221 dict2
= qdict_get_qdict(dict1
, "dict2");
222 g_assert_cmpint(qdict_size(dict2
), ==, 2);
223 g_assert_cmpstr(qdict_get_str(dict2
, "string"), ==, strings
[2]);
224 userdef
= qdict_get_qdict(dict2
, "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 dict3
= qdict_get_qdict(dict1
, "dict3");
230 g_assert_cmpint(qdict_size(dict3
), ==, 2);
231 g_assert_cmpstr(qdict_get_str(dict3
, "string"), ==, strings
[3]);
232 userdef
= qdict_get_qdict(dict3
, "userdef");
233 g_assert_cmpint(qdict_size(userdef
), ==, 2);
234 g_assert_cmpint(qdict_get_int(userdef
, "integer"), ==, value
);
235 g_assert_cmpstr(qdict_get_str(userdef
, "string"), ==, string
);
237 qapi_free_UserDefTwo(ud2
);
240 static void test_visitor_out_struct_errors(TestOutputVisitorData
*data
,
243 EnumOne bad_values
[] = { ENUM_ONE__MAX
, -1 };
249 for (i
= 0; i
< ARRAY_SIZE(bad_values
) ; i
++) {
252 u
.enum1
= bad_values
[i
];
253 visit_type_UserDefOne(data
->ov
, "unused", &pu
, &err
);
261 static void test_visitor_out_list(TestOutputVisitorData
*data
,
264 const char *value_str
= "list value";
265 TestStructList
*p
, *head
= NULL
;
266 const int max_items
= 10;
267 bool value_bool
= true;
274 /* Build the list in reverse order... */
275 for (i
= 0; i
< max_items
; i
++) {
276 p
= g_malloc0(sizeof(*p
));
277 p
->value
= g_malloc0(sizeof(*p
->value
));
278 p
->value
->integer
= value_int
+ (max_items
- i
- 1);
279 p
->value
->boolean
= value_bool
;
280 p
->value
->string
= g_strdup(value_str
);
286 visit_type_TestStructList(data
->ov
, NULL
, &head
, &error_abort
);
288 obj
= visitor_get(data
);
289 g_assert(qobject_type(obj
) == QTYPE_QLIST
);
291 qlist
= qobject_to_qlist(obj
);
292 g_assert(!qlist_empty(qlist
));
294 /* ...and ensure that the visitor sees it in order */
296 QLIST_FOREACH_ENTRY(qlist
, entry
) {
299 g_assert(qobject_type(entry
->value
) == QTYPE_QDICT
);
300 qdict
= qobject_to_qdict(entry
->value
);
301 g_assert_cmpint(qdict_size(qdict
), ==, 3);
302 g_assert_cmpint(qdict_get_int(qdict
, "integer"), ==, value_int
+ i
);
303 g_assert_cmpint(qdict_get_bool(qdict
, "boolean"), ==, value_bool
);
304 g_assert_cmpstr(qdict_get_str(qdict
, "string"), ==, value_str
);
307 g_assert_cmpint(i
, ==, max_items
);
309 qapi_free_TestStructList(head
);
312 static void test_visitor_out_list_qapi_free(TestOutputVisitorData
*data
,
315 UserDefTwoList
*p
, *head
= NULL
;
316 const char string
[] = "foo bar";
317 int i
, max_count
= 1024;
319 for (i
= 0; i
< max_count
; i
++) {
320 p
= g_malloc0(sizeof(*p
));
321 p
->value
= g_malloc0(sizeof(*p
->value
));
323 p
->value
->string0
= g_strdup(string
);
324 p
->value
->dict1
= g_new0(UserDefTwoDict
, 1);
325 p
->value
->dict1
->string1
= g_strdup(string
);
326 p
->value
->dict1
->dict2
= g_new0(UserDefTwoDictDict
, 1);
327 p
->value
->dict1
->dict2
->userdef
= g_new0(UserDefOne
, 1);
328 p
->value
->dict1
->dict2
->userdef
->string
= g_strdup(string
);
329 p
->value
->dict1
->dict2
->userdef
->integer
= 42;
330 p
->value
->dict1
->dict2
->string
= g_strdup(string
);
331 p
->value
->dict1
->has_dict3
= false;
337 qapi_free_UserDefTwoList(head
);
340 static void test_visitor_out_any(TestOutputVisitorData
*data
,
350 qobj
= QOBJECT(qint_from_int(-42));
351 visit_type_any(data
->ov
, NULL
, &qobj
, &error_abort
);
352 obj
= visitor_get(data
);
353 g_assert(qobject_type(obj
) == QTYPE_QINT
);
354 g_assert_cmpint(qint_get_int(qobject_to_qint(obj
)), ==, -42);
355 qobject_decref(qobj
);
359 qdict_put(qdict
, "integer", qint_from_int(-42));
360 qdict_put(qdict
, "boolean", qbool_from_bool(true));
361 qdict_put(qdict
, "string", qstring_from_str("foo"));
362 qobj
= QOBJECT(qdict
);
363 visit_type_any(data
->ov
, NULL
, &qobj
, &error_abort
);
364 qobject_decref(qobj
);
365 obj
= visitor_get(data
);
366 qdict
= qobject_to_qdict(obj
);
368 qobj
= qdict_get(qdict
, "integer");
370 qint
= qobject_to_qint(qobj
);
372 g_assert_cmpint(qint_get_int(qint
), ==, -42);
373 qobj
= qdict_get(qdict
, "boolean");
375 qbool
= qobject_to_qbool(qobj
);
377 g_assert(qbool_get_bool(qbool
) == true);
378 qobj
= qdict_get(qdict
, "string");
380 qstring
= qobject_to_qstring(qobj
);
382 g_assert_cmpstr(qstring_get_str(qstring
), ==, "foo");
385 static void test_visitor_out_union_flat(TestOutputVisitorData
*data
,
391 UserDefFlatUnion
*tmp
= g_malloc0(sizeof(UserDefFlatUnion
));
392 tmp
->enum1
= ENUM_ONE_VALUE1
;
393 tmp
->string
= g_strdup("str");
395 tmp
->u
.value1
.boolean
= true;
397 visit_type_UserDefFlatUnion(data
->ov
, NULL
, &tmp
, &error_abort
);
398 arg
= visitor_get(data
);
400 g_assert(qobject_type(arg
) == QTYPE_QDICT
);
401 qdict
= qobject_to_qdict(arg
);
403 g_assert_cmpstr(qdict_get_str(qdict
, "enum1"), ==, "value1");
404 g_assert_cmpstr(qdict_get_str(qdict
, "string"), ==, "str");
405 g_assert_cmpint(qdict_get_int(qdict
, "integer"), ==, 41);
406 g_assert_cmpint(qdict_get_bool(qdict
, "boolean"), ==, true);
408 qapi_free_UserDefFlatUnion(tmp
);
411 static void test_visitor_out_alternate(TestOutputVisitorData
*data
,
415 UserDefAlternate
*tmp
;
418 tmp
= g_new0(UserDefAlternate
, 1);
419 tmp
->type
= QTYPE_QINT
;
422 visit_type_UserDefAlternate(data
->ov
, NULL
, &tmp
, &error_abort
);
423 arg
= visitor_get(data
);
425 g_assert(qobject_type(arg
) == QTYPE_QINT
);
426 g_assert_cmpint(qint_get_int(qobject_to_qint(arg
)), ==, 42);
428 qapi_free_UserDefAlternate(tmp
);
431 tmp
= g_new0(UserDefAlternate
, 1);
432 tmp
->type
= QTYPE_QSTRING
;
433 tmp
->u
.s
= g_strdup("hello");
435 visit_type_UserDefAlternate(data
->ov
, NULL
, &tmp
, &error_abort
);
436 arg
= visitor_get(data
);
438 g_assert(qobject_type(arg
) == QTYPE_QSTRING
);
439 g_assert_cmpstr(qstring_get_str(qobject_to_qstring(arg
)), ==, "hello");
441 qapi_free_UserDefAlternate(tmp
);
444 tmp
= g_new0(UserDefAlternate
, 1);
445 tmp
->type
= QTYPE_QDICT
;
446 tmp
->u
.udfu
.integer
= 1;
447 tmp
->u
.udfu
.string
= g_strdup("str");
448 tmp
->u
.udfu
.enum1
= ENUM_ONE_VALUE1
;
449 tmp
->u
.udfu
.u
.value1
.boolean
= true;
451 visit_type_UserDefAlternate(data
->ov
, NULL
, &tmp
, &error_abort
);
452 arg
= visitor_get(data
);
454 g_assert_cmpint(qobject_type(arg
), ==, QTYPE_QDICT
);
455 qdict
= qobject_to_qdict(arg
);
456 g_assert_cmpint(qdict_size(qdict
), ==, 4);
457 g_assert_cmpint(qdict_get_int(qdict
, "integer"), ==, 1);
458 g_assert_cmpstr(qdict_get_str(qdict
, "string"), ==, "str");
459 g_assert_cmpstr(qdict_get_str(qdict
, "enum1"), ==, "value1");
460 g_assert_cmpint(qdict_get_bool(qdict
, "boolean"), ==, true);
462 qapi_free_UserDefAlternate(tmp
);
465 static void test_visitor_out_null(TestOutputVisitorData
*data
,
472 visit_start_struct(data
->ov
, NULL
, NULL
, 0, &error_abort
);
473 visit_type_null(data
->ov
, "a", &error_abort
);
474 visit_check_struct(data
->ov
, &error_abort
);
475 visit_end_struct(data
->ov
, NULL
);
476 arg
= visitor_get(data
);
477 g_assert(qobject_type(arg
) == QTYPE_QDICT
);
478 qdict
= qobject_to_qdict(arg
);
479 g_assert_cmpint(qdict_size(qdict
), ==, 1);
480 nil
= qdict_get(qdict
, "a");
482 g_assert(qobject_type(nil
) == QTYPE_QNULL
);
485 static void init_native_list(UserDefNativeListUnion
*cvalue
)
488 switch (cvalue
->type
) {
489 case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER
: {
490 intList
**list
= &cvalue
->u
.integer
.data
;
491 for (i
= 0; i
< 32; i
++) {
492 *list
= g_new0(intList
, 1);
494 (*list
)->next
= NULL
;
495 list
= &(*list
)->next
;
499 case USER_DEF_NATIVE_LIST_UNION_KIND_S8
: {
500 int8List
**list
= &cvalue
->u
.s8
.data
;
501 for (i
= 0; i
< 32; i
++) {
502 *list
= g_new0(int8List
, 1);
504 (*list
)->next
= NULL
;
505 list
= &(*list
)->next
;
509 case USER_DEF_NATIVE_LIST_UNION_KIND_S16
: {
510 int16List
**list
= &cvalue
->u
.s16
.data
;
511 for (i
= 0; i
< 32; i
++) {
512 *list
= g_new0(int16List
, 1);
514 (*list
)->next
= NULL
;
515 list
= &(*list
)->next
;
519 case USER_DEF_NATIVE_LIST_UNION_KIND_S32
: {
520 int32List
**list
= &cvalue
->u
.s32
.data
;
521 for (i
= 0; i
< 32; i
++) {
522 *list
= g_new0(int32List
, 1);
524 (*list
)->next
= NULL
;
525 list
= &(*list
)->next
;
529 case USER_DEF_NATIVE_LIST_UNION_KIND_S64
: {
530 int64List
**list
= &cvalue
->u
.s64
.data
;
531 for (i
= 0; i
< 32; i
++) {
532 *list
= g_new0(int64List
, 1);
534 (*list
)->next
= NULL
;
535 list
= &(*list
)->next
;
539 case USER_DEF_NATIVE_LIST_UNION_KIND_U8
: {
540 uint8List
**list
= &cvalue
->u
.u8
.data
;
541 for (i
= 0; i
< 32; i
++) {
542 *list
= g_new0(uint8List
, 1);
544 (*list
)->next
= NULL
;
545 list
= &(*list
)->next
;
549 case USER_DEF_NATIVE_LIST_UNION_KIND_U16
: {
550 uint16List
**list
= &cvalue
->u
.u16
.data
;
551 for (i
= 0; i
< 32; i
++) {
552 *list
= g_new0(uint16List
, 1);
554 (*list
)->next
= NULL
;
555 list
= &(*list
)->next
;
559 case USER_DEF_NATIVE_LIST_UNION_KIND_U32
: {
560 uint32List
**list
= &cvalue
->u
.u32
.data
;
561 for (i
= 0; i
< 32; i
++) {
562 *list
= g_new0(uint32List
, 1);
564 (*list
)->next
= NULL
;
565 list
= &(*list
)->next
;
569 case USER_DEF_NATIVE_LIST_UNION_KIND_U64
: {
570 uint64List
**list
= &cvalue
->u
.u64
.data
;
571 for (i
= 0; i
< 32; i
++) {
572 *list
= g_new0(uint64List
, 1);
574 (*list
)->next
= NULL
;
575 list
= &(*list
)->next
;
579 case USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN
: {
580 boolList
**list
= &cvalue
->u
.boolean
.data
;
581 for (i
= 0; i
< 32; i
++) {
582 *list
= g_new0(boolList
, 1);
583 (*list
)->value
= (i
% 3 == 0);
584 (*list
)->next
= NULL
;
585 list
= &(*list
)->next
;
589 case USER_DEF_NATIVE_LIST_UNION_KIND_STRING
: {
590 strList
**list
= &cvalue
->u
.string
.data
;
591 for (i
= 0; i
< 32; i
++) {
592 *list
= g_new0(strList
, 1);
593 (*list
)->value
= g_strdup_printf("%d", i
);
594 (*list
)->next
= NULL
;
595 list
= &(*list
)->next
;
599 case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER
: {
600 numberList
**list
= &cvalue
->u
.number
.data
;
601 for (i
= 0; i
< 32; i
++) {
602 *list
= g_new0(numberList
, 1);
603 (*list
)->value
= (double)i
/ 3;
604 (*list
)->next
= NULL
;
605 list
= &(*list
)->next
;
610 g_assert_not_reached();
614 static void check_native_list(QObject
*qobj
,
615 UserDefNativeListUnionKind kind
)
622 g_assert(qobject_type(qobj
) == QTYPE_QDICT
);
623 qdict
= qobject_to_qdict(qobj
);
625 g_assert(qdict_haskey(qdict
, "data"));
626 qlist
= qlist_copy(qobject_to_qlist(qdict_get(qdict
, "data")));
629 case USER_DEF_NATIVE_LIST_UNION_KIND_S8
:
630 case USER_DEF_NATIVE_LIST_UNION_KIND_S16
:
631 case USER_DEF_NATIVE_LIST_UNION_KIND_S32
:
632 case USER_DEF_NATIVE_LIST_UNION_KIND_S64
:
633 case USER_DEF_NATIVE_LIST_UNION_KIND_U8
:
634 case USER_DEF_NATIVE_LIST_UNION_KIND_U16
:
635 case USER_DEF_NATIVE_LIST_UNION_KIND_U32
:
636 case USER_DEF_NATIVE_LIST_UNION_KIND_U64
:
637 /* all integer elements in JSON arrays get stored into QInts when
638 * we convert to QObjects, so we can check them all in the same
639 * fashion, so simply fall through here
641 case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER
:
642 for (i
= 0; i
< 32; i
++) {
645 tmp
= qlist_peek(qlist
);
647 qvalue
= qobject_to_qint(tmp
);
648 g_assert_cmpint(qint_get_int(qvalue
), ==, i
);
649 qobject_decref(qlist_pop(qlist
));
652 case USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN
:
653 for (i
= 0; i
< 32; i
++) {
656 tmp
= qlist_peek(qlist
);
658 qvalue
= qobject_to_qbool(tmp
);
659 g_assert_cmpint(qbool_get_bool(qvalue
), ==, i
% 3 == 0);
660 qobject_decref(qlist_pop(qlist
));
663 case USER_DEF_NATIVE_LIST_UNION_KIND_STRING
:
664 for (i
= 0; i
< 32; i
++) {
668 tmp
= qlist_peek(qlist
);
670 qvalue
= qobject_to_qstring(tmp
);
671 sprintf(str
, "%d", i
);
672 g_assert_cmpstr(qstring_get_str(qvalue
), ==, str
);
673 qobject_decref(qlist_pop(qlist
));
676 case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER
:
677 for (i
= 0; i
< 32; i
++) {
680 GString
*double_expected
= g_string_new("");
681 GString
*double_actual
= g_string_new("");
683 tmp
= qlist_peek(qlist
);
685 qvalue
= qobject_to_qfloat(tmp
);
686 g_string_printf(double_expected
, "%.6f", (double)i
/ 3);
687 g_string_printf(double_actual
, "%.6f", qfloat_get_double(qvalue
));
688 g_assert_cmpstr(double_actual
->str
, ==, double_expected
->str
);
690 qobject_decref(qlist_pop(qlist
));
691 g_string_free(double_expected
, true);
692 g_string_free(double_actual
, true);
696 g_assert_not_reached();
701 static void test_native_list(TestOutputVisitorData
*data
,
703 UserDefNativeListUnionKind kind
)
705 UserDefNativeListUnion
*cvalue
= g_new0(UserDefNativeListUnion
, 1);
709 init_native_list(cvalue
);
711 visit_type_UserDefNativeListUnion(data
->ov
, NULL
, &cvalue
, &error_abort
);
713 obj
= visitor_get(data
);
714 check_native_list(obj
, cvalue
->type
);
715 qapi_free_UserDefNativeListUnion(cvalue
);
718 static void test_visitor_out_native_list_int(TestOutputVisitorData
*data
,
721 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER
);
724 static void test_visitor_out_native_list_int8(TestOutputVisitorData
*data
,
727 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S8
);
730 static void test_visitor_out_native_list_int16(TestOutputVisitorData
*data
,
733 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S16
);
736 static void test_visitor_out_native_list_int32(TestOutputVisitorData
*data
,
739 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S32
);
742 static void test_visitor_out_native_list_int64(TestOutputVisitorData
*data
,
745 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_S64
);
748 static void test_visitor_out_native_list_uint8(TestOutputVisitorData
*data
,
751 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U8
);
754 static void test_visitor_out_native_list_uint16(TestOutputVisitorData
*data
,
757 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U16
);
760 static void test_visitor_out_native_list_uint32(TestOutputVisitorData
*data
,
763 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U32
);
766 static void test_visitor_out_native_list_uint64(TestOutputVisitorData
*data
,
769 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_U64
);
772 static void test_visitor_out_native_list_bool(TestOutputVisitorData
*data
,
775 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN
);
778 static void test_visitor_out_native_list_str(TestOutputVisitorData
*data
,
781 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_STRING
);
784 static void test_visitor_out_native_list_number(TestOutputVisitorData
*data
,
787 test_native_list(data
, unused
, USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER
);
790 static void output_visitor_test_add(const char *testpath
,
791 TestOutputVisitorData
*data
,
792 void (*test_func
)(TestOutputVisitorData
*data
, const void *user_data
))
794 g_test_add(testpath
, TestOutputVisitorData
, data
, visitor_output_setup
,
795 test_func
, visitor_output_teardown
);
798 int main(int argc
, char **argv
)
800 TestOutputVisitorData out_visitor_data
;
802 g_test_init(&argc
, &argv
, NULL
);
804 output_visitor_test_add("/visitor/output/int",
805 &out_visitor_data
, test_visitor_out_int
);
806 output_visitor_test_add("/visitor/output/bool",
807 &out_visitor_data
, test_visitor_out_bool
);
808 output_visitor_test_add("/visitor/output/number",
809 &out_visitor_data
, test_visitor_out_number
);
810 output_visitor_test_add("/visitor/output/string",
811 &out_visitor_data
, test_visitor_out_string
);
812 output_visitor_test_add("/visitor/output/no-string",
813 &out_visitor_data
, test_visitor_out_no_string
);
814 output_visitor_test_add("/visitor/output/enum",
815 &out_visitor_data
, test_visitor_out_enum
);
816 output_visitor_test_add("/visitor/output/enum-errors",
817 &out_visitor_data
, test_visitor_out_enum_errors
);
818 output_visitor_test_add("/visitor/output/struct",
819 &out_visitor_data
, test_visitor_out_struct
);
820 output_visitor_test_add("/visitor/output/struct-nested",
821 &out_visitor_data
, test_visitor_out_struct_nested
);
822 output_visitor_test_add("/visitor/output/struct-errors",
823 &out_visitor_data
, test_visitor_out_struct_errors
);
824 output_visitor_test_add("/visitor/output/list",
825 &out_visitor_data
, test_visitor_out_list
);
826 output_visitor_test_add("/visitor/output/any",
827 &out_visitor_data
, test_visitor_out_any
);
828 output_visitor_test_add("/visitor/output/list-qapi-free",
829 &out_visitor_data
, test_visitor_out_list_qapi_free
);
830 output_visitor_test_add("/visitor/output/union-flat",
831 &out_visitor_data
, test_visitor_out_union_flat
);
832 output_visitor_test_add("/visitor/output/alternate",
833 &out_visitor_data
, test_visitor_out_alternate
);
834 output_visitor_test_add("/visitor/output/null",
835 &out_visitor_data
, test_visitor_out_null
);
836 output_visitor_test_add("/visitor/output/native_list/int",
838 test_visitor_out_native_list_int
);
839 output_visitor_test_add("/visitor/output/native_list/int8",
841 test_visitor_out_native_list_int8
);
842 output_visitor_test_add("/visitor/output/native_list/int16",
844 test_visitor_out_native_list_int16
);
845 output_visitor_test_add("/visitor/output/native_list/int32",
847 test_visitor_out_native_list_int32
);
848 output_visitor_test_add("/visitor/output/native_list/int64",
850 test_visitor_out_native_list_int64
);
851 output_visitor_test_add("/visitor/output/native_list/uint8",
853 test_visitor_out_native_list_uint8
);
854 output_visitor_test_add("/visitor/output/native_list/uint16",
856 test_visitor_out_native_list_uint16
);
857 output_visitor_test_add("/visitor/output/native_list/uint32",
859 test_visitor_out_native_list_uint32
);
860 output_visitor_test_add("/visitor/output/native_list/uint64",
862 test_visitor_out_native_list_uint64
);
863 output_visitor_test_add("/visitor/output/native_list/bool",
865 test_visitor_out_native_list_bool
);
866 output_visitor_test_add("/visitor/output/native_list/string",
868 test_visitor_out_native_list_str
);
869 output_visitor_test_add("/visitor/output/native_list/number",
871 test_visitor_out_native_list_number
);