gitlab: add a CI job to validate the DCO sign off
[qemu/ar7.git] / tests / test-qobject-output-visitor.c
blob1c856d9bd20a788edad897207e1d33ea4cccd8e9
1 /*
2 * QObject Output Visitor unit-tests.
4 * Copyright (C) 2011-2016 Red Hat Inc.
6 * Authors:
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-visit.h"
19 #include "qapi/qmp/qbool.h"
20 #include "qapi/qmp/qdict.h"
21 #include "qapi/qmp/qlist.h"
22 #include "qapi/qmp/qnull.h"
23 #include "qapi/qmp/qnum.h"
24 #include "qapi/qmp/qstring.h"
26 typedef struct TestOutputVisitorData {
27 Visitor *ov;
28 QObject *obj;
29 } TestOutputVisitorData;
31 static void visitor_output_setup(TestOutputVisitorData *data,
32 const void *unused)
34 data->ov = qobject_output_visitor_new(&data->obj);
35 g_assert(data->ov);
38 static void visitor_output_teardown(TestOutputVisitorData *data,
39 const void *unused)
41 visit_free(data->ov);
42 data->ov = NULL;
43 qobject_unref(data->obj);
44 data->obj = NULL;
47 static QObject *visitor_get(TestOutputVisitorData *data)
49 visit_complete(data->ov, &data->obj);
50 g_assert(data->obj);
51 return data->obj;
54 static void visitor_reset(TestOutputVisitorData *data)
56 visitor_output_teardown(data, NULL);
57 visitor_output_setup(data, NULL);
60 static void test_visitor_out_int(TestOutputVisitorData *data,
61 const void *unused)
63 int64_t value = -42;
64 int64_t val;
65 QNum *qnum;
67 visit_type_int(data->ov, NULL, &value, &error_abort);
69 qnum = qobject_to(QNum, visitor_get(data));
70 g_assert(qnum);
71 g_assert(qnum_get_try_int(qnum, &val));
72 g_assert_cmpint(val, ==, value);
75 static void test_visitor_out_bool(TestOutputVisitorData *data,
76 const void *unused)
78 bool value = true;
79 QBool *qbool;
81 visit_type_bool(data->ov, NULL, &value, &error_abort);
83 qbool = qobject_to(QBool, visitor_get(data));
84 g_assert(qbool);
85 g_assert(qbool_get_bool(qbool) == value);
88 static void test_visitor_out_number(TestOutputVisitorData *data,
89 const void *unused)
91 double value = 3.14;
92 QNum *qnum;
94 visit_type_number(data->ov, NULL, &value, &error_abort);
96 qnum = qobject_to(QNum, visitor_get(data));
97 g_assert(qnum);
98 g_assert(qnum_get_double(qnum) == value);
101 static void test_visitor_out_string(TestOutputVisitorData *data,
102 const void *unused)
104 char *string = (char *) "Q E M U";
105 QString *qstr;
107 visit_type_str(data->ov, NULL, &string, &error_abort);
109 qstr = qobject_to(QString, visitor_get(data));
110 g_assert(qstr);
111 g_assert_cmpstr(qstring_get_str(qstr), ==, string);
114 static void test_visitor_out_no_string(TestOutputVisitorData *data,
115 const void *unused)
117 char *string = NULL;
118 QString *qstr;
120 /* A null string should return "" */
121 visit_type_str(data->ov, NULL, &string, &error_abort);
123 qstr = qobject_to(QString, visitor_get(data));
124 g_assert(qstr);
125 g_assert_cmpstr(qstring_get_str(qstr), ==, "");
128 static void test_visitor_out_enum(TestOutputVisitorData *data,
129 const void *unused)
131 EnumOne i;
132 QString *qstr;
134 for (i = 0; i < ENUM_ONE__MAX; i++) {
135 visit_type_EnumOne(data->ov, "unused", &i, &error_abort);
137 qstr = qobject_to(QString, visitor_get(data));
138 g_assert(qstr);
139 g_assert_cmpstr(qstring_get_str(qstr), ==, EnumOne_str(i));
140 visitor_reset(data);
144 static void test_visitor_out_struct(TestOutputVisitorData *data,
145 const void *unused)
147 TestStruct test_struct = { .integer = 42,
148 .boolean = false,
149 .string = (char *) "foo"};
150 TestStruct *p = &test_struct;
151 QDict *qdict;
153 visit_type_TestStruct(data->ov, NULL, &p, &error_abort);
155 qdict = qobject_to(QDict, visitor_get(data));
156 g_assert(qdict);
157 g_assert_cmpint(qdict_size(qdict), ==, 3);
158 g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 42);
159 g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, false);
160 g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, "foo");
163 static void test_visitor_out_struct_nested(TestOutputVisitorData *data,
164 const void *unused)
166 int64_t value = 42;
167 UserDefTwo *ud2;
168 QDict *qdict, *dict1, *dict2, *dict3, *userdef;
169 const char *string = "user def string";
170 const char *strings[] = { "forty two", "forty three", "forty four",
171 "forty five" };
173 ud2 = g_malloc0(sizeof(*ud2));
174 ud2->string0 = g_strdup(strings[0]);
176 ud2->dict1 = g_malloc0(sizeof(*ud2->dict1));
177 ud2->dict1->string1 = g_strdup(strings[1]);
179 ud2->dict1->dict2 = g_malloc0(sizeof(*ud2->dict1->dict2));
180 ud2->dict1->dict2->userdef = g_new0(UserDefOne, 1);
181 ud2->dict1->dict2->userdef->string = g_strdup(string);
182 ud2->dict1->dict2->userdef->integer = value;
183 ud2->dict1->dict2->string = g_strdup(strings[2]);
185 ud2->dict1->dict3 = g_malloc0(sizeof(*ud2->dict1->dict3));
186 ud2->dict1->has_dict3 = true;
187 ud2->dict1->dict3->userdef = g_new0(UserDefOne, 1);
188 ud2->dict1->dict3->userdef->string = g_strdup(string);
189 ud2->dict1->dict3->userdef->integer = value;
190 ud2->dict1->dict3->string = g_strdup(strings[3]);
192 visit_type_UserDefTwo(data->ov, "unused", &ud2, &error_abort);
194 qdict = qobject_to(QDict, visitor_get(data));
195 g_assert(qdict);
196 g_assert_cmpint(qdict_size(qdict), ==, 2);
197 g_assert_cmpstr(qdict_get_str(qdict, "string0"), ==, strings[0]);
199 dict1 = qdict_get_qdict(qdict, "dict1");
200 g_assert_cmpint(qdict_size(dict1), ==, 3);
201 g_assert_cmpstr(qdict_get_str(dict1, "string1"), ==, strings[1]);
203 dict2 = qdict_get_qdict(dict1, "dict2");
204 g_assert_cmpint(qdict_size(dict2), ==, 2);
205 g_assert_cmpstr(qdict_get_str(dict2, "string"), ==, strings[2]);
206 userdef = qdict_get_qdict(dict2, "userdef");
207 g_assert_cmpint(qdict_size(userdef), ==, 2);
208 g_assert_cmpint(qdict_get_int(userdef, "integer"), ==, value);
209 g_assert_cmpstr(qdict_get_str(userdef, "string"), ==, string);
211 dict3 = qdict_get_qdict(dict1, "dict3");
212 g_assert_cmpint(qdict_size(dict3), ==, 2);
213 g_assert_cmpstr(qdict_get_str(dict3, "string"), ==, strings[3]);
214 userdef = qdict_get_qdict(dict3, "userdef");
215 g_assert_cmpint(qdict_size(userdef), ==, 2);
216 g_assert_cmpint(qdict_get_int(userdef, "integer"), ==, value);
217 g_assert_cmpstr(qdict_get_str(userdef, "string"), ==, string);
219 qapi_free_UserDefTwo(ud2);
222 static void test_visitor_out_list(TestOutputVisitorData *data,
223 const void *unused)
225 const char *value_str = "list value";
226 TestStructList *p, *head = NULL;
227 const int max_items = 10;
228 bool value_bool = true;
229 int value_int = 10;
230 QListEntry *entry;
231 QList *qlist;
232 int i;
234 /* Build the list in reverse order... */
235 for (i = 0; i < max_items; i++) {
236 p = g_malloc0(sizeof(*p));
237 p->value = g_malloc0(sizeof(*p->value));
238 p->value->integer = value_int + (max_items - i - 1);
239 p->value->boolean = value_bool;
240 p->value->string = g_strdup(value_str);
242 p->next = head;
243 head = p;
246 visit_type_TestStructList(data->ov, NULL, &head, &error_abort);
248 qlist = qobject_to(QList, visitor_get(data));
249 g_assert(qlist);
250 g_assert(!qlist_empty(qlist));
252 /* ...and ensure that the visitor sees it in order */
253 i = 0;
254 QLIST_FOREACH_ENTRY(qlist, entry) {
255 QDict *qdict;
257 qdict = qobject_to(QDict, entry->value);
258 g_assert(qdict);
259 g_assert_cmpint(qdict_size(qdict), ==, 3);
260 g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, value_int + i);
261 g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, value_bool);
262 g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, value_str);
263 i++;
265 g_assert_cmpint(i, ==, max_items);
267 qapi_free_TestStructList(head);
270 static void test_visitor_out_list_qapi_free(TestOutputVisitorData *data,
271 const void *unused)
273 UserDefTwoList *p, *head = NULL;
274 const char string[] = "foo bar";
275 int i, max_count = 1024;
277 for (i = 0; i < max_count; i++) {
278 p = g_malloc0(sizeof(*p));
279 p->value = g_malloc0(sizeof(*p->value));
281 p->value->string0 = g_strdup(string);
282 p->value->dict1 = g_new0(UserDefTwoDict, 1);
283 p->value->dict1->string1 = g_strdup(string);
284 p->value->dict1->dict2 = g_new0(UserDefTwoDictDict, 1);
285 p->value->dict1->dict2->userdef = g_new0(UserDefOne, 1);
286 p->value->dict1->dict2->userdef->string = g_strdup(string);
287 p->value->dict1->dict2->userdef->integer = 42;
288 p->value->dict1->dict2->string = g_strdup(string);
289 p->value->dict1->has_dict3 = false;
291 p->next = head;
292 head = p;
295 qapi_free_UserDefTwoList(head);
298 static void test_visitor_out_any(TestOutputVisitorData *data,
299 const void *unused)
301 QObject *qobj;
302 QNum *qnum;
303 QBool *qbool;
304 QString *qstring;
305 QDict *qdict;
306 int64_t val;
308 qobj = QOBJECT(qnum_from_int(-42));
309 visit_type_any(data->ov, NULL, &qobj, &error_abort);
310 qnum = qobject_to(QNum, visitor_get(data));
311 g_assert(qnum);
312 g_assert(qnum_get_try_int(qnum, &val));
313 g_assert_cmpint(val, ==, -42);
314 qobject_unref(qobj);
316 visitor_reset(data);
317 qdict = qdict_new();
318 qdict_put_int(qdict, "integer", -42);
319 qdict_put_bool(qdict, "boolean", true);
320 qdict_put_str(qdict, "string", "foo");
321 qobj = QOBJECT(qdict);
322 visit_type_any(data->ov, NULL, &qobj, &error_abort);
323 qobject_unref(qobj);
324 qdict = qobject_to(QDict, visitor_get(data));
325 g_assert(qdict);
326 qnum = qobject_to(QNum, qdict_get(qdict, "integer"));
327 g_assert(qnum);
328 g_assert(qnum_get_try_int(qnum, &val));
329 g_assert_cmpint(val, ==, -42);
330 qbool = qobject_to(QBool, qdict_get(qdict, "boolean"));
331 g_assert(qbool);
332 g_assert(qbool_get_bool(qbool) == true);
333 qstring = qobject_to(QString, qdict_get(qdict, "string"));
334 g_assert(qstring);
335 g_assert_cmpstr(qstring_get_str(qstring), ==, "foo");
338 static void test_visitor_out_union_flat(TestOutputVisitorData *data,
339 const void *unused)
341 QDict *qdict;
343 UserDefFlatUnion *tmp = g_malloc0(sizeof(UserDefFlatUnion));
344 tmp->enum1 = ENUM_ONE_VALUE1;
345 tmp->string = g_strdup("str");
346 tmp->integer = 41;
347 tmp->u.value1.boolean = true;
349 visit_type_UserDefFlatUnion(data->ov, NULL, &tmp, &error_abort);
350 qdict = qobject_to(QDict, visitor_get(data));
351 g_assert(qdict);
352 g_assert_cmpstr(qdict_get_str(qdict, "enum1"), ==, "value1");
353 g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, "str");
354 g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 41);
355 g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, true);
357 qapi_free_UserDefFlatUnion(tmp);
360 static void test_visitor_out_alternate(TestOutputVisitorData *data,
361 const void *unused)
363 UserDefAlternate *tmp;
364 QNum *qnum;
365 QString *qstr;
366 QDict *qdict;
367 int64_t val;
369 tmp = g_new0(UserDefAlternate, 1);
370 tmp->type = QTYPE_QNUM;
371 tmp->u.i = 42;
373 visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort);
374 qnum = qobject_to(QNum, visitor_get(data));
375 g_assert(qnum);
376 g_assert(qnum_get_try_int(qnum, &val));
377 g_assert_cmpint(val, ==, 42);
379 qapi_free_UserDefAlternate(tmp);
381 visitor_reset(data);
382 tmp = g_new0(UserDefAlternate, 1);
383 tmp->type = QTYPE_QSTRING;
384 tmp->u.e = ENUM_ONE_VALUE1;
386 visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort);
387 qstr = qobject_to(QString, visitor_get(data));
388 g_assert(qstr);
389 g_assert_cmpstr(qstring_get_str(qstr), ==, "value1");
391 qapi_free_UserDefAlternate(tmp);
393 visitor_reset(data);
394 tmp = g_new0(UserDefAlternate, 1);
395 tmp->type = QTYPE_QNULL;
396 tmp->u.n = qnull();
398 visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort);
399 g_assert_cmpint(qobject_type(visitor_get(data)), ==, QTYPE_QNULL);
401 qapi_free_UserDefAlternate(tmp);
403 visitor_reset(data);
404 tmp = g_new0(UserDefAlternate, 1);
405 tmp->type = QTYPE_QDICT;
406 tmp->u.udfu.integer = 1;
407 tmp->u.udfu.string = g_strdup("str");
408 tmp->u.udfu.enum1 = ENUM_ONE_VALUE1;
409 tmp->u.udfu.u.value1.boolean = true;
411 visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort);
412 qdict = qobject_to(QDict, visitor_get(data));
413 g_assert(qdict);
414 g_assert_cmpint(qdict_size(qdict), ==, 4);
415 g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 1);
416 g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, "str");
417 g_assert_cmpstr(qdict_get_str(qdict, "enum1"), ==, "value1");
418 g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, true);
420 qapi_free_UserDefAlternate(tmp);
423 static void test_visitor_out_null(TestOutputVisitorData *data,
424 const void *unused)
426 QNull *null = NULL;
427 QDict *qdict;
428 QObject *nil;
430 visit_start_struct(data->ov, NULL, NULL, 0, &error_abort);
431 visit_type_null(data->ov, "a", &null, &error_abort);
432 visit_check_struct(data->ov, &error_abort);
433 visit_end_struct(data->ov, NULL);
434 qdict = qobject_to(QDict, visitor_get(data));
435 g_assert(qdict);
436 g_assert_cmpint(qdict_size(qdict), ==, 1);
437 nil = qdict_get(qdict, "a");
438 g_assert(nil);
439 g_assert(qobject_type(nil) == QTYPE_QNULL);
442 static void init_list_union(UserDefListUnion *cvalue)
444 int i;
445 switch (cvalue->type) {
446 case USER_DEF_LIST_UNION_KIND_INTEGER: {
447 intList **list = &cvalue->u.integer.data;
448 for (i = 0; i < 32; i++) {
449 *list = g_new0(intList, 1);
450 (*list)->value = i;
451 (*list)->next = NULL;
452 list = &(*list)->next;
454 break;
456 case USER_DEF_LIST_UNION_KIND_S8: {
457 int8List **list = &cvalue->u.s8.data;
458 for (i = 0; i < 32; i++) {
459 *list = g_new0(int8List, 1);
460 (*list)->value = i;
461 (*list)->next = NULL;
462 list = &(*list)->next;
464 break;
466 case USER_DEF_LIST_UNION_KIND_S16: {
467 int16List **list = &cvalue->u.s16.data;
468 for (i = 0; i < 32; i++) {
469 *list = g_new0(int16List, 1);
470 (*list)->value = i;
471 (*list)->next = NULL;
472 list = &(*list)->next;
474 break;
476 case USER_DEF_LIST_UNION_KIND_S32: {
477 int32List **list = &cvalue->u.s32.data;
478 for (i = 0; i < 32; i++) {
479 *list = g_new0(int32List, 1);
480 (*list)->value = i;
481 (*list)->next = NULL;
482 list = &(*list)->next;
484 break;
486 case USER_DEF_LIST_UNION_KIND_S64: {
487 int64List **list = &cvalue->u.s64.data;
488 for (i = 0; i < 32; i++) {
489 *list = g_new0(int64List, 1);
490 (*list)->value = i;
491 (*list)->next = NULL;
492 list = &(*list)->next;
494 break;
496 case USER_DEF_LIST_UNION_KIND_U8: {
497 uint8List **list = &cvalue->u.u8.data;
498 for (i = 0; i < 32; i++) {
499 *list = g_new0(uint8List, 1);
500 (*list)->value = i;
501 (*list)->next = NULL;
502 list = &(*list)->next;
504 break;
506 case USER_DEF_LIST_UNION_KIND_U16: {
507 uint16List **list = &cvalue->u.u16.data;
508 for (i = 0; i < 32; i++) {
509 *list = g_new0(uint16List, 1);
510 (*list)->value = i;
511 (*list)->next = NULL;
512 list = &(*list)->next;
514 break;
516 case USER_DEF_LIST_UNION_KIND_U32: {
517 uint32List **list = &cvalue->u.u32.data;
518 for (i = 0; i < 32; i++) {
519 *list = g_new0(uint32List, 1);
520 (*list)->value = i;
521 (*list)->next = NULL;
522 list = &(*list)->next;
524 break;
526 case USER_DEF_LIST_UNION_KIND_U64: {
527 uint64List **list = &cvalue->u.u64.data;
528 for (i = 0; i < 32; i++) {
529 *list = g_new0(uint64List, 1);
530 (*list)->value = i;
531 (*list)->next = NULL;
532 list = &(*list)->next;
534 break;
536 case USER_DEF_LIST_UNION_KIND_BOOLEAN: {
537 boolList **list = &cvalue->u.boolean.data;
538 for (i = 0; i < 32; i++) {
539 *list = g_new0(boolList, 1);
540 (*list)->value = QEMU_IS_ALIGNED(i, 3);
541 (*list)->next = NULL;
542 list = &(*list)->next;
544 break;
546 case USER_DEF_LIST_UNION_KIND_STRING: {
547 strList **list = &cvalue->u.string.data;
548 for (i = 0; i < 32; i++) {
549 *list = g_new0(strList, 1);
550 (*list)->value = g_strdup_printf("%d", i);
551 (*list)->next = NULL;
552 list = &(*list)->next;
554 break;
556 case USER_DEF_LIST_UNION_KIND_NUMBER: {
557 numberList **list = &cvalue->u.number.data;
558 for (i = 0; i < 32; i++) {
559 *list = g_new0(numberList, 1);
560 (*list)->value = (double)i / 3;
561 (*list)->next = NULL;
562 list = &(*list)->next;
564 break;
566 default:
567 g_assert_not_reached();
571 static void check_list_union(QObject *qobj,
572 UserDefListUnionKind kind)
574 QDict *qdict;
575 QList *qlist;
576 int i;
578 qdict = qobject_to(QDict, qobj);
579 g_assert(qdict);
580 g_assert(qdict_haskey(qdict, "data"));
581 qlist = qlist_copy(qobject_to(QList, qdict_get(qdict, "data")));
583 switch (kind) {
584 case USER_DEF_LIST_UNION_KIND_U8:
585 case USER_DEF_LIST_UNION_KIND_U16:
586 case USER_DEF_LIST_UNION_KIND_U32:
587 case USER_DEF_LIST_UNION_KIND_U64:
588 for (i = 0; i < 32; i++) {
589 QObject *tmp;
590 QNum *qvalue;
591 uint64_t val;
593 tmp = qlist_peek(qlist);
594 g_assert(tmp);
595 qvalue = qobject_to(QNum, tmp);
596 g_assert(qnum_get_try_uint(qvalue, &val));
597 g_assert_cmpint(val, ==, i);
598 qobject_unref(qlist_pop(qlist));
600 break;
602 case USER_DEF_LIST_UNION_KIND_S8:
603 case USER_DEF_LIST_UNION_KIND_S16:
604 case USER_DEF_LIST_UNION_KIND_S32:
605 case USER_DEF_LIST_UNION_KIND_S64:
607 * All integer elements in JSON arrays get stored into QNums
608 * when we convert to QObjects, so we can check them all in
609 * the same fashion, so simply fall through here.
611 case USER_DEF_LIST_UNION_KIND_INTEGER:
612 for (i = 0; i < 32; i++) {
613 QObject *tmp;
614 QNum *qvalue;
615 int64_t val;
617 tmp = qlist_peek(qlist);
618 g_assert(tmp);
619 qvalue = qobject_to(QNum, tmp);
620 g_assert(qnum_get_try_int(qvalue, &val));
621 g_assert_cmpint(val, ==, i);
622 qobject_unref(qlist_pop(qlist));
624 break;
625 case USER_DEF_LIST_UNION_KIND_BOOLEAN:
626 for (i = 0; i < 32; i++) {
627 QObject *tmp;
628 QBool *qvalue;
629 tmp = qlist_peek(qlist);
630 g_assert(tmp);
631 qvalue = qobject_to(QBool, tmp);
632 g_assert_cmpint(qbool_get_bool(qvalue), ==, i % 3 == 0);
633 qobject_unref(qlist_pop(qlist));
635 break;
636 case USER_DEF_LIST_UNION_KIND_STRING:
637 for (i = 0; i < 32; i++) {
638 QObject *tmp;
639 QString *qvalue;
640 gchar str[8];
641 tmp = qlist_peek(qlist);
642 g_assert(tmp);
643 qvalue = qobject_to(QString, tmp);
644 sprintf(str, "%d", i);
645 g_assert_cmpstr(qstring_get_str(qvalue), ==, str);
646 qobject_unref(qlist_pop(qlist));
648 break;
649 case USER_DEF_LIST_UNION_KIND_NUMBER:
650 for (i = 0; i < 32; i++) {
651 QObject *tmp;
652 QNum *qvalue;
653 GString *double_expected = g_string_new("");
654 GString *double_actual = g_string_new("");
656 tmp = qlist_peek(qlist);
657 g_assert(tmp);
658 qvalue = qobject_to(QNum, tmp);
659 g_string_printf(double_expected, "%.6f", (double)i / 3);
660 g_string_printf(double_actual, "%.6f", qnum_get_double(qvalue));
661 g_assert_cmpstr(double_actual->str, ==, double_expected->str);
663 qobject_unref(qlist_pop(qlist));
664 g_string_free(double_expected, true);
665 g_string_free(double_actual, true);
667 break;
668 default:
669 g_assert_not_reached();
671 qobject_unref(qlist);
674 static void test_list_union(TestOutputVisitorData *data,
675 const void *unused,
676 UserDefListUnionKind kind)
678 UserDefListUnion *cvalue = g_new0(UserDefListUnion, 1);
679 QObject *obj;
681 cvalue->type = kind;
682 init_list_union(cvalue);
684 visit_type_UserDefListUnion(data->ov, NULL, &cvalue, &error_abort);
686 obj = visitor_get(data);
687 check_list_union(obj, cvalue->type);
688 qapi_free_UserDefListUnion(cvalue);
691 static void test_visitor_out_list_union_int(TestOutputVisitorData *data,
692 const void *unused)
694 test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_INTEGER);
697 static void test_visitor_out_list_union_int8(TestOutputVisitorData *data,
698 const void *unused)
700 test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_S8);
703 static void test_visitor_out_list_union_int16(TestOutputVisitorData *data,
704 const void *unused)
706 test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_S16);
709 static void test_visitor_out_list_union_int32(TestOutputVisitorData *data,
710 const void *unused)
712 test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_S32);
715 static void test_visitor_out_list_union_int64(TestOutputVisitorData *data,
716 const void *unused)
718 test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_S64);
721 static void test_visitor_out_list_union_uint8(TestOutputVisitorData *data,
722 const void *unused)
724 test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_U8);
727 static void test_visitor_out_list_union_uint16(TestOutputVisitorData *data,
728 const void *unused)
730 test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_U16);
733 static void test_visitor_out_list_union_uint32(TestOutputVisitorData *data,
734 const void *unused)
736 test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_U32);
739 static void test_visitor_out_list_union_uint64(TestOutputVisitorData *data,
740 const void *unused)
742 test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_U64);
745 static void test_visitor_out_list_union_bool(TestOutputVisitorData *data,
746 const void *unused)
748 test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_BOOLEAN);
751 static void test_visitor_out_list_union_str(TestOutputVisitorData *data,
752 const void *unused)
754 test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_STRING);
757 static void test_visitor_out_list_union_number(TestOutputVisitorData *data,
758 const void *unused)
760 test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_NUMBER);
763 static void output_visitor_test_add(const char *testpath,
764 TestOutputVisitorData *data,
765 void (*test_func)(TestOutputVisitorData *data, const void *user_data))
767 g_test_add(testpath, TestOutputVisitorData, data, visitor_output_setup,
768 test_func, visitor_output_teardown);
771 int main(int argc, char **argv)
773 TestOutputVisitorData out_visitor_data;
775 g_test_init(&argc, &argv, NULL);
777 output_visitor_test_add("/visitor/output/int",
778 &out_visitor_data, test_visitor_out_int);
779 output_visitor_test_add("/visitor/output/bool",
780 &out_visitor_data, test_visitor_out_bool);
781 output_visitor_test_add("/visitor/output/number",
782 &out_visitor_data, test_visitor_out_number);
783 output_visitor_test_add("/visitor/output/string",
784 &out_visitor_data, test_visitor_out_string);
785 output_visitor_test_add("/visitor/output/no-string",
786 &out_visitor_data, test_visitor_out_no_string);
787 output_visitor_test_add("/visitor/output/enum",
788 &out_visitor_data, test_visitor_out_enum);
789 output_visitor_test_add("/visitor/output/struct",
790 &out_visitor_data, test_visitor_out_struct);
791 output_visitor_test_add("/visitor/output/struct-nested",
792 &out_visitor_data, test_visitor_out_struct_nested);
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/list_union/int",
806 &out_visitor_data,
807 test_visitor_out_list_union_int);
808 output_visitor_test_add("/visitor/output/list_union/int8",
809 &out_visitor_data,
810 test_visitor_out_list_union_int8);
811 output_visitor_test_add("/visitor/output/list_union/int16",
812 &out_visitor_data,
813 test_visitor_out_list_union_int16);
814 output_visitor_test_add("/visitor/output/list_union/int32",
815 &out_visitor_data,
816 test_visitor_out_list_union_int32);
817 output_visitor_test_add("/visitor/output/list_union/int64",
818 &out_visitor_data,
819 test_visitor_out_list_union_int64);
820 output_visitor_test_add("/visitor/output/list_union/uint8",
821 &out_visitor_data,
822 test_visitor_out_list_union_uint8);
823 output_visitor_test_add("/visitor/output/list_union/uint16",
824 &out_visitor_data,
825 test_visitor_out_list_union_uint16);
826 output_visitor_test_add("/visitor/output/list_union/uint32",
827 &out_visitor_data,
828 test_visitor_out_list_union_uint32);
829 output_visitor_test_add("/visitor/output/list_union/uint64",
830 &out_visitor_data,
831 test_visitor_out_list_union_uint64);
832 output_visitor_test_add("/visitor/output/list_union/bool",
833 &out_visitor_data,
834 test_visitor_out_list_union_bool);
835 output_visitor_test_add("/visitor/output/list_union/string",
836 &out_visitor_data,
837 test_visitor_out_list_union_str);
838 output_visitor_test_add("/visitor/output/list_union/number",
839 &out_visitor_data,
840 test_visitor_out_list_union_number);
842 g_test_run();
844 return 0;