Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging
[qemu.git] / tests / test-qobject-output-visitor.c
blobc213fceeb30d52aa7f3b249a1598cd2b50174054
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-types.h"
19 #include "test-qapi-visit.h"
20 #include "qapi/qmp/types.h"
21 #include "qapi/qmp/qjson.h"
23 typedef struct TestOutputVisitorData {
24 Visitor *ov;
25 QObject *obj;
26 } TestOutputVisitorData;
28 static void visitor_output_setup(TestOutputVisitorData *data,
29 const void *unused)
31 data->ov = qobject_output_visitor_new(&data->obj);
32 g_assert(data->ov);
35 static void visitor_output_teardown(TestOutputVisitorData *data,
36 const void *unused)
38 visit_free(data->ov);
39 data->ov = NULL;
40 qobject_decref(data->obj);
41 data->obj = NULL;
44 static QObject *visitor_get(TestOutputVisitorData *data)
46 visit_complete(data->ov, &data->obj);
47 g_assert(data->obj);
48 return 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,
58 const void *unused)
60 int64_t value = -42;
61 QInt *qint;
63 visit_type_int(data->ov, NULL, &value, &error_abort);
65 qint = qobject_to_qint(visitor_get(data));
66 g_assert(qint);
67 g_assert_cmpint(qint_get_int(qint), ==, value);
70 static void test_visitor_out_bool(TestOutputVisitorData *data,
71 const void *unused)
73 bool value = true;
74 QBool *qbool;
76 visit_type_bool(data->ov, NULL, &value, &error_abort);
78 qbool = qobject_to_qbool(visitor_get(data));
79 g_assert(qbool);
80 g_assert(qbool_get_bool(qbool) == value);
83 static void test_visitor_out_number(TestOutputVisitorData *data,
84 const void *unused)
86 double value = 3.14;
87 QFloat *qfloat;
89 visit_type_number(data->ov, NULL, &value, &error_abort);
91 qfloat = qobject_to_qfloat(visitor_get(data));
92 g_assert(qfloat);
93 g_assert(qfloat_get_double(qfloat) == value);
96 static void test_visitor_out_string(TestOutputVisitorData *data,
97 const void *unused)
99 char *string = (char *) "Q E M U";
100 QString *qstr;
102 visit_type_str(data->ov, NULL, &string, &error_abort);
104 qstr = qobject_to_qstring(visitor_get(data));
105 g_assert(qstr);
106 g_assert_cmpstr(qstring_get_str(qstr), ==, string);
109 static void test_visitor_out_no_string(TestOutputVisitorData *data,
110 const void *unused)
112 char *string = NULL;
113 QString *qstr;
115 /* A null string should return "" */
116 visit_type_str(data->ov, NULL, &string, &error_abort);
118 qstr = qobject_to_qstring(visitor_get(data));
119 g_assert(qstr);
120 g_assert_cmpstr(qstring_get_str(qstr), ==, "");
123 static void test_visitor_out_enum(TestOutputVisitorData *data,
124 const void *unused)
126 EnumOne i;
127 QString *qstr;
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));
133 g_assert(qstr);
134 g_assert_cmpstr(qstring_get_str(qstr), ==, EnumOne_lookup[i]);
135 visitor_reset(data);
139 static void test_visitor_out_enum_errors(TestOutputVisitorData *data,
140 const void *unused)
142 EnumOne i, bad_values[] = { ENUM_ONE__MAX, -1 };
143 Error *err;
145 for (i = 0; i < ARRAY_SIZE(bad_values) ; i++) {
146 err = NULL;
147 visit_type_EnumOne(data->ov, "unused", &bad_values[i], &err);
148 error_free_or_abort(&err);
149 visitor_reset(data);
154 static void test_visitor_out_struct(TestOutputVisitorData *data,
155 const void *unused)
157 TestStruct test_struct = { .integer = 42,
158 .boolean = false,
159 .string = (char *) "foo"};
160 TestStruct *p = &test_struct;
161 QDict *qdict;
163 visit_type_TestStruct(data->ov, NULL, &p, &error_abort);
165 qdict = qobject_to_qdict(visitor_get(data));
166 g_assert(qdict);
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,
174 const void *unused)
176 int64_t value = 42;
177 UserDefTwo *ud2;
178 QDict *qdict, *dict1, *dict2, *dict3, *userdef;
179 const char *string = "user def string";
180 const char *strings[] = { "forty two", "forty three", "forty four",
181 "forty five" };
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));
205 g_assert(qdict);
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,
233 const void *unused)
235 EnumOne bad_values[] = { ENUM_ONE__MAX, -1 };
236 UserDefOne u = {0};
237 UserDefOne *pu = &u;
238 Error *err;
239 int i;
241 for (i = 0; i < ARRAY_SIZE(bad_values) ; i++) {
242 err = NULL;
243 u.has_enum1 = true;
244 u.enum1 = bad_values[i];
245 visit_type_UserDefOne(data->ov, "unused", &pu, &err);
246 error_free_or_abort(&err);
247 visitor_reset(data);
252 static void test_visitor_out_list(TestOutputVisitorData *data,
253 const void *unused)
255 const char *value_str = "list value";
256 TestStructList *p, *head = NULL;
257 const int max_items = 10;
258 bool value_bool = true;
259 int value_int = 10;
260 QListEntry *entry;
261 QList *qlist;
262 int i;
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);
272 p->next = head;
273 head = p;
276 visit_type_TestStructList(data->ov, NULL, &head, &error_abort);
278 qlist = qobject_to_qlist(visitor_get(data));
279 g_assert(qlist);
280 g_assert(!qlist_empty(qlist));
282 /* ...and ensure that the visitor sees it in order */
283 i = 0;
284 QLIST_FOREACH_ENTRY(qlist, entry) {
285 QDict *qdict;
287 qdict = qobject_to_qdict(entry->value);
288 g_assert(qdict);
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);
293 i++;
295 g_assert_cmpint(i, ==, max_items);
297 qapi_free_TestStructList(head);
300 static void test_visitor_out_list_qapi_free(TestOutputVisitorData *data,
301 const void *unused)
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;
321 p->next = head;
322 head = p;
325 qapi_free_UserDefTwoList(head);
328 static void test_visitor_out_any(TestOutputVisitorData *data,
329 const void *unused)
331 QObject *qobj;
332 QInt *qint;
333 QBool *qbool;
334 QString *qstring;
335 QDict *qdict;
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));
340 g_assert(qint);
341 g_assert_cmpint(qint_get_int(qint), ==, -42);
342 qobject_decref(qobj);
344 visitor_reset(data);
345 qdict = qdict_new();
346 qdict_put(qdict, "integer", qint_from_int(-42));
347 qdict_put(qdict, "boolean", qbool_from_bool(true));
348 qdict_put(qdict, "string", qstring_from_str("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));
353 g_assert(qdict);
354 qint = qobject_to_qint(qdict_get(qdict, "integer"));
355 g_assert(qint);
356 g_assert_cmpint(qint_get_int(qint), ==, -42);
357 qbool = qobject_to_qbool(qdict_get(qdict, "boolean"));
358 g_assert(qbool);
359 g_assert(qbool_get_bool(qbool) == true);
360 qstring = qobject_to_qstring(qdict_get(qdict, "string"));
361 g_assert(qstring);
362 g_assert_cmpstr(qstring_get_str(qstring), ==, "foo");
365 static void test_visitor_out_union_flat(TestOutputVisitorData *data,
366 const void *unused)
368 QDict *qdict;
370 UserDefFlatUnion *tmp = g_malloc0(sizeof(UserDefFlatUnion));
371 tmp->enum1 = ENUM_ONE_VALUE1;
372 tmp->string = g_strdup("str");
373 tmp->integer = 41;
374 tmp->u.value1.boolean = true;
376 visit_type_UserDefFlatUnion(data->ov, NULL, &tmp, &error_abort);
377 qdict = qobject_to_qdict(visitor_get(data));
378 g_assert(qdict);
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,
388 const void *unused)
390 UserDefAlternate *tmp;
391 QInt *qint;
392 QString *qstr;
393 QDict *qdict;
395 tmp = g_new0(UserDefAlternate, 1);
396 tmp->type = QTYPE_QINT;
397 tmp->u.i = 42;
399 visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort);
400 qint = qobject_to_qint(visitor_get(data));
401 g_assert(qint);
402 g_assert_cmpint(qint_get_int(qint), ==, 42);
404 qapi_free_UserDefAlternate(tmp);
406 visitor_reset(data);
407 tmp = g_new0(UserDefAlternate, 1);
408 tmp->type = QTYPE_QSTRING;
409 tmp->u.s = g_strdup("hello");
411 visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort);
412 qstr = qobject_to_qstring(visitor_get(data));
413 g_assert(qstr);
414 g_assert_cmpstr(qstring_get_str(qstr), ==, "hello");
416 qapi_free_UserDefAlternate(tmp);
418 visitor_reset(data);
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));
428 g_assert(qdict);
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,
439 const void *unused)
441 QDict *qdict;
442 QObject *nil;
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));
449 g_assert(qdict);
450 g_assert_cmpint(qdict_size(qdict), ==, 1);
451 nil = qdict_get(qdict, "a");
452 g_assert(nil);
453 g_assert(qobject_type(nil) == QTYPE_QNULL);
456 static void init_native_list(UserDefNativeListUnion *cvalue)
458 int i;
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);
464 (*list)->value = i;
465 (*list)->next = NULL;
466 list = &(*list)->next;
468 break;
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);
474 (*list)->value = i;
475 (*list)->next = NULL;
476 list = &(*list)->next;
478 break;
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);
484 (*list)->value = i;
485 (*list)->next = NULL;
486 list = &(*list)->next;
488 break;
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);
494 (*list)->value = i;
495 (*list)->next = NULL;
496 list = &(*list)->next;
498 break;
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);
504 (*list)->value = i;
505 (*list)->next = NULL;
506 list = &(*list)->next;
508 break;
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);
514 (*list)->value = i;
515 (*list)->next = NULL;
516 list = &(*list)->next;
518 break;
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);
524 (*list)->value = i;
525 (*list)->next = NULL;
526 list = &(*list)->next;
528 break;
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);
534 (*list)->value = i;
535 (*list)->next = NULL;
536 list = &(*list)->next;
538 break;
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);
544 (*list)->value = i;
545 (*list)->next = NULL;
546 list = &(*list)->next;
548 break;
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;
558 break;
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;
568 break;
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;
578 break;
580 default:
581 g_assert_not_reached();
585 static void check_native_list(QObject *qobj,
586 UserDefNativeListUnionKind kind)
588 QDict *qdict;
589 QList *qlist;
590 int i;
592 qdict = qobject_to_qdict(qobj);
593 g_assert(qdict);
594 g_assert(qdict_haskey(qdict, "data"));
595 qlist = qlist_copy(qobject_to_qlist(qdict_get(qdict, "data")));
597 switch (kind) {
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++) {
612 QObject *tmp;
613 QInt *qvalue;
614 tmp = qlist_peek(qlist);
615 g_assert(tmp);
616 qvalue = qobject_to_qint(tmp);
617 g_assert_cmpint(qint_get_int(qvalue), ==, i);
618 qobject_decref(qlist_pop(qlist));
620 break;
621 case USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN:
622 for (i = 0; i < 32; i++) {
623 QObject *tmp;
624 QBool *qvalue;
625 tmp = qlist_peek(qlist);
626 g_assert(tmp);
627 qvalue = qobject_to_qbool(tmp);
628 g_assert_cmpint(qbool_get_bool(qvalue), ==, i % 3 == 0);
629 qobject_decref(qlist_pop(qlist));
631 break;
632 case USER_DEF_NATIVE_LIST_UNION_KIND_STRING:
633 for (i = 0; i < 32; i++) {
634 QObject *tmp;
635 QString *qvalue;
636 gchar str[8];
637 tmp = qlist_peek(qlist);
638 g_assert(tmp);
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));
644 break;
645 case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER:
646 for (i = 0; i < 32; i++) {
647 QObject *tmp;
648 QFloat *qvalue;
649 GString *double_expected = g_string_new("");
650 GString *double_actual = g_string_new("");
652 tmp = qlist_peek(qlist);
653 g_assert(tmp);
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);
663 break;
664 default:
665 g_assert_not_reached();
667 QDECREF(qlist);
670 static void test_native_list(TestOutputVisitorData *data,
671 const void *unused,
672 UserDefNativeListUnionKind kind)
674 UserDefNativeListUnion *cvalue = g_new0(UserDefNativeListUnion, 1);
675 QObject *obj;
677 cvalue->type = kind;
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,
688 const void *unused)
690 test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER);
693 static void test_visitor_out_native_list_int8(TestOutputVisitorData *data,
694 const void *unused)
696 test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_S8);
699 static void test_visitor_out_native_list_int16(TestOutputVisitorData *data,
700 const void *unused)
702 test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_S16);
705 static void test_visitor_out_native_list_int32(TestOutputVisitorData *data,
706 const void *unused)
708 test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_S32);
711 static void test_visitor_out_native_list_int64(TestOutputVisitorData *data,
712 const void *unused)
714 test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_S64);
717 static void test_visitor_out_native_list_uint8(TestOutputVisitorData *data,
718 const void *unused)
720 test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_U8);
723 static void test_visitor_out_native_list_uint16(TestOutputVisitorData *data,
724 const void *unused)
726 test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_U16);
729 static void test_visitor_out_native_list_uint32(TestOutputVisitorData *data,
730 const void *unused)
732 test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_U32);
735 static void test_visitor_out_native_list_uint64(TestOutputVisitorData *data,
736 const void *unused)
738 test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_U64);
741 static void test_visitor_out_native_list_bool(TestOutputVisitorData *data,
742 const void *unused)
744 test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN);
747 static void test_visitor_out_native_list_str(TestOutputVisitorData *data,
748 const void *unused)
750 test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_STRING);
753 static void test_visitor_out_native_list_number(TestOutputVisitorData *data,
754 const void *unused)
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",
806 &out_visitor_data,
807 test_visitor_out_native_list_int);
808 output_visitor_test_add("/visitor/output/native_list/int8",
809 &out_visitor_data,
810 test_visitor_out_native_list_int8);
811 output_visitor_test_add("/visitor/output/native_list/int16",
812 &out_visitor_data,
813 test_visitor_out_native_list_int16);
814 output_visitor_test_add("/visitor/output/native_list/int32",
815 &out_visitor_data,
816 test_visitor_out_native_list_int32);
817 output_visitor_test_add("/visitor/output/native_list/int64",
818 &out_visitor_data,
819 test_visitor_out_native_list_int64);
820 output_visitor_test_add("/visitor/output/native_list/uint8",
821 &out_visitor_data,
822 test_visitor_out_native_list_uint8);
823 output_visitor_test_add("/visitor/output/native_list/uint16",
824 &out_visitor_data,
825 test_visitor_out_native_list_uint16);
826 output_visitor_test_add("/visitor/output/native_list/uint32",
827 &out_visitor_data,
828 test_visitor_out_native_list_uint32);
829 output_visitor_test_add("/visitor/output/native_list/uint64",
830 &out_visitor_data,
831 test_visitor_out_native_list_uint64);
832 output_visitor_test_add("/visitor/output/native_list/bool",
833 &out_visitor_data,
834 test_visitor_out_native_list_bool);
835 output_visitor_test_add("/visitor/output/native_list/string",
836 &out_visitor_data,
837 test_visitor_out_native_list_str);
838 output_visitor_test_add("/visitor/output/native_list/number",
839 &out_visitor_data,
840 test_visitor_out_native_list_number);
842 g_test_run();
844 return 0;