2 * QMP Input Visitor unit-tests.
4 * Copyright (C) 2011, 2015 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"
16 #include "qemu-common.h"
17 #include "qapi/qmp-input-visitor.h"
18 #include "test-qapi-types.h"
19 #include "test-qapi-visit.h"
20 #include "qapi/qmp/types.h"
22 typedef struct TestInputVisitorData
{
25 } TestInputVisitorData
;
27 static void visitor_input_teardown(TestInputVisitorData
*data
,
30 qobject_decref(data
->obj
);
34 qmp_input_visitor_cleanup(data
->qiv
);
39 /* The various test_init functions are provided instead of a test setup
40 function so that the JSON string used by the tests are kept in the test
41 functions (and not in main()). */
42 static Visitor
*visitor_input_test_init_internal(TestInputVisitorData
*data
,
43 const char *json_string
,
48 visitor_input_teardown(data
, NULL
);
50 data
->obj
= qobject_from_jsonv(json_string
, ap
);
53 data
->qiv
= qmp_input_visitor_new(data
->obj
);
56 v
= qmp_input_get_visitor(data
->qiv
);
62 static GCC_FMT_ATTR(2, 3)
63 Visitor
*visitor_input_test_init(TestInputVisitorData
*data
,
64 const char *json_string
, ...)
69 va_start(ap
, json_string
);
70 v
= visitor_input_test_init_internal(data
, json_string
, &ap
);
75 /* similar to visitor_input_test_init(), but does not expect a string
76 * literal/format json_string argument and so can be used for
77 * programatically generated strings (and we can't pass in programatically
78 * generated strings via %s format parameters since qobject_from_jsonv()
79 * will wrap those in double-quotes and treat the entire object as a
82 static Visitor
*visitor_input_test_init_raw(TestInputVisitorData
*data
,
83 const char *json_string
)
85 return visitor_input_test_init_internal(data
, json_string
, NULL
);
88 static void test_visitor_in_int(TestInputVisitorData
*data
,
91 int64_t res
= 0, value
= -42;
94 v
= visitor_input_test_init(data
, "%" PRId64
, value
);
96 visit_type_int(v
, NULL
, &res
, &error_abort
);
97 g_assert_cmpint(res
, ==, value
);
100 static void test_visitor_in_int_overflow(TestInputVisitorData
*data
,
107 /* this will overflow a Qint/int64, so should be deserialized into
108 * a QFloat/double field instead, leading to an error if we pass it
109 * to visit_type_int. confirm this.
111 v
= visitor_input_test_init(data
, "%f", DBL_MAX
);
113 visit_type_int(v
, NULL
, &res
, &err
);
114 error_free_or_abort(&err
);
117 static void test_visitor_in_bool(TestInputVisitorData
*data
,
123 v
= visitor_input_test_init(data
, "true");
125 visit_type_bool(v
, NULL
, &res
, &error_abort
);
126 g_assert_cmpint(res
, ==, true);
129 static void test_visitor_in_number(TestInputVisitorData
*data
,
132 double res
= 0, value
= 3.14;
135 v
= visitor_input_test_init(data
, "%f", value
);
137 visit_type_number(v
, NULL
, &res
, &error_abort
);
138 g_assert_cmpfloat(res
, ==, value
);
141 static void test_visitor_in_string(TestInputVisitorData
*data
,
144 char *res
= NULL
, *value
= (char *) "Q E M U";
147 v
= visitor_input_test_init(data
, "%s", value
);
149 visit_type_str(v
, NULL
, &res
, &error_abort
);
150 g_assert_cmpstr(res
, ==, value
);
155 static void test_visitor_in_enum(TestInputVisitorData
*data
,
161 for (i
= 0; EnumOne_lookup
[i
]; i
++) {
164 v
= visitor_input_test_init(data
, "%s", EnumOne_lookup
[i
]);
166 visit_type_EnumOne(v
, NULL
, &res
, &error_abort
);
167 g_assert_cmpint(i
, ==, res
);
172 static void test_visitor_in_struct(TestInputVisitorData
*data
,
175 TestStruct
*p
= NULL
;
178 v
= visitor_input_test_init(data
, "{ 'integer': -42, 'boolean': true, 'string': 'foo' }");
180 visit_type_TestStruct(v
, NULL
, &p
, &error_abort
);
181 g_assert_cmpint(p
->integer
, ==, -42);
182 g_assert(p
->boolean
== true);
183 g_assert_cmpstr(p
->string
, ==, "foo");
189 static void test_visitor_in_struct_nested(TestInputVisitorData
*data
,
192 UserDefTwo
*udp
= NULL
;
195 v
= visitor_input_test_init(data
, "{ 'string0': 'string0', "
196 "'dict1': { 'string1': 'string1', "
197 "'dict2': { 'userdef': { 'integer': 42, "
198 "'string': 'string' }, 'string': 'string2'}}}");
200 visit_type_UserDefTwo(v
, NULL
, &udp
, &error_abort
);
202 g_assert_cmpstr(udp
->string0
, ==, "string0");
203 g_assert_cmpstr(udp
->dict1
->string1
, ==, "string1");
204 g_assert_cmpint(udp
->dict1
->dict2
->userdef
->integer
, ==, 42);
205 g_assert_cmpstr(udp
->dict1
->dict2
->userdef
->string
, ==, "string");
206 g_assert_cmpstr(udp
->dict1
->dict2
->string
, ==, "string2");
207 g_assert(udp
->dict1
->has_dict3
== false);
209 qapi_free_UserDefTwo(udp
);
212 static void test_visitor_in_list(TestInputVisitorData
*data
,
215 UserDefOneList
*item
, *head
= NULL
;
219 v
= visitor_input_test_init(data
, "[ { 'string': 'string0', 'integer': 42 }, { 'string': 'string1', 'integer': 43 }, { 'string': 'string2', 'integer': 44 } ]");
221 visit_type_UserDefOneList(v
, NULL
, &head
, &error_abort
);
222 g_assert(head
!= NULL
);
224 for (i
= 0, item
= head
; item
; item
= item
->next
, i
++) {
227 snprintf(string
, sizeof(string
), "string%d", i
);
228 g_assert_cmpstr(item
->value
->string
, ==, string
);
229 g_assert_cmpint(item
->value
->integer
, ==, 42 + i
);
232 qapi_free_UserDefOneList(head
);
235 /* An empty list is valid */
236 v
= visitor_input_test_init(data
, "[]");
237 visit_type_UserDefOneList(v
, NULL
, &head
, &error_abort
);
241 static void test_visitor_in_any(TestInputVisitorData
*data
,
252 v
= visitor_input_test_init(data
, "-42");
253 visit_type_any(v
, NULL
, &res
, &error_abort
);
254 qint
= qobject_to_qint(res
);
256 g_assert_cmpint(qint_get_int(qint
), ==, -42);
259 v
= visitor_input_test_init(data
, "{ 'integer': -42, 'boolean': true, 'string': 'foo' }");
260 visit_type_any(v
, NULL
, &res
, &error_abort
);
261 qdict
= qobject_to_qdict(res
);
262 g_assert(qdict
&& qdict_size(qdict
) == 3);
263 qobj
= qdict_get(qdict
, "integer");
265 qint
= qobject_to_qint(qobj
);
267 g_assert_cmpint(qint_get_int(qint
), ==, -42);
268 qobj
= qdict_get(qdict
, "boolean");
270 qbool
= qobject_to_qbool(qobj
);
272 g_assert(qbool_get_bool(qbool
) == true);
273 qobj
= qdict_get(qdict
, "string");
275 qstring
= qobject_to_qstring(qobj
);
277 g_assert_cmpstr(qstring_get_str(qstring
), ==, "foo");
281 static void test_visitor_in_union_flat(TestInputVisitorData
*data
,
285 UserDefFlatUnion
*tmp
;
286 UserDefUnionBase
*base
;
288 v
= visitor_input_test_init(data
,
289 "{ 'enum1': 'value1', "
292 "'boolean': true }");
294 visit_type_UserDefFlatUnion(v
, NULL
, &tmp
, &error_abort
);
295 g_assert_cmpint(tmp
->enum1
, ==, ENUM_ONE_VALUE1
);
296 g_assert_cmpstr(tmp
->string
, ==, "str");
297 g_assert_cmpint(tmp
->integer
, ==, 41);
298 g_assert_cmpint(tmp
->u
.value1
->boolean
, ==, true);
300 base
= qapi_UserDefFlatUnion_base(tmp
);
301 g_assert(&base
->enum1
== &tmp
->enum1
);
303 qapi_free_UserDefFlatUnion(tmp
);
306 static void test_visitor_in_alternate(TestInputVisitorData
*data
,
311 UserDefAlternate
*tmp
;
313 v
= visitor_input_test_init(data
, "42");
314 visit_type_UserDefAlternate(v
, NULL
, &tmp
, &error_abort
);
315 g_assert_cmpint(tmp
->type
, ==, QTYPE_QINT
);
316 g_assert_cmpint(tmp
->u
.i
, ==, 42);
317 qapi_free_UserDefAlternate(tmp
);
319 v
= visitor_input_test_init(data
, "'string'");
320 visit_type_UserDefAlternate(v
, NULL
, &tmp
, &error_abort
);
321 g_assert_cmpint(tmp
->type
, ==, QTYPE_QSTRING
);
322 g_assert_cmpstr(tmp
->u
.s
, ==, "string");
323 qapi_free_UserDefAlternate(tmp
);
325 v
= visitor_input_test_init(data
, "false");
326 visit_type_UserDefAlternate(v
, NULL
, &tmp
, &err
);
327 error_free_or_abort(&err
);
328 qapi_free_UserDefAlternate(tmp
);
331 static void test_visitor_in_alternate_number(TestInputVisitorData
*data
,
345 v
= visitor_input_test_init(data
, "42");
346 visit_type_AltStrBool(v
, NULL
, &asb
, &err
);
347 error_free_or_abort(&err
);
348 qapi_free_AltStrBool(asb
);
350 v
= visitor_input_test_init(data
, "42");
351 visit_type_AltStrNum(v
, NULL
, &asn
, &error_abort
);
352 g_assert_cmpint(asn
->type
, ==, QTYPE_QFLOAT
);
353 g_assert_cmpfloat(asn
->u
.n
, ==, 42);
354 qapi_free_AltStrNum(asn
);
356 v
= visitor_input_test_init(data
, "42");
357 visit_type_AltNumStr(v
, NULL
, &ans
, &error_abort
);
358 g_assert_cmpint(ans
->type
, ==, QTYPE_QFLOAT
);
359 g_assert_cmpfloat(ans
->u
.n
, ==, 42);
360 qapi_free_AltNumStr(ans
);
362 v
= visitor_input_test_init(data
, "42");
363 visit_type_AltStrInt(v
, NULL
, &asi
, &error_abort
);
364 g_assert_cmpint(asi
->type
, ==, QTYPE_QINT
);
365 g_assert_cmpint(asi
->u
.i
, ==, 42);
366 qapi_free_AltStrInt(asi
);
368 v
= visitor_input_test_init(data
, "42");
369 visit_type_AltIntNum(v
, NULL
, &ain
, &error_abort
);
370 g_assert_cmpint(ain
->type
, ==, QTYPE_QINT
);
371 g_assert_cmpint(ain
->u
.i
, ==, 42);
372 qapi_free_AltIntNum(ain
);
374 v
= visitor_input_test_init(data
, "42");
375 visit_type_AltNumInt(v
, NULL
, &ani
, &error_abort
);
376 g_assert_cmpint(ani
->type
, ==, QTYPE_QINT
);
377 g_assert_cmpint(ani
->u
.i
, ==, 42);
378 qapi_free_AltNumInt(ani
);
380 /* Parsing a double */
382 v
= visitor_input_test_init(data
, "42.5");
383 visit_type_AltStrBool(v
, NULL
, &asb
, &err
);
384 error_free_or_abort(&err
);
385 qapi_free_AltStrBool(asb
);
387 v
= visitor_input_test_init(data
, "42.5");
388 visit_type_AltStrNum(v
, NULL
, &asn
, &error_abort
);
389 g_assert_cmpint(asn
->type
, ==, QTYPE_QFLOAT
);
390 g_assert_cmpfloat(asn
->u
.n
, ==, 42.5);
391 qapi_free_AltStrNum(asn
);
393 v
= visitor_input_test_init(data
, "42.5");
394 visit_type_AltNumStr(v
, NULL
, &ans
, &error_abort
);
395 g_assert_cmpint(ans
->type
, ==, QTYPE_QFLOAT
);
396 g_assert_cmpfloat(ans
->u
.n
, ==, 42.5);
397 qapi_free_AltNumStr(ans
);
399 v
= visitor_input_test_init(data
, "42.5");
400 visit_type_AltStrInt(v
, NULL
, &asi
, &err
);
401 error_free_or_abort(&err
);
402 qapi_free_AltStrInt(asi
);
404 v
= visitor_input_test_init(data
, "42.5");
405 visit_type_AltIntNum(v
, NULL
, &ain
, &error_abort
);
406 g_assert_cmpint(ain
->type
, ==, QTYPE_QFLOAT
);
407 g_assert_cmpfloat(ain
->u
.n
, ==, 42.5);
408 qapi_free_AltIntNum(ain
);
410 v
= visitor_input_test_init(data
, "42.5");
411 visit_type_AltNumInt(v
, NULL
, &ani
, &error_abort
);
412 g_assert_cmpint(ani
->type
, ==, QTYPE_QFLOAT
);
413 g_assert_cmpfloat(ani
->u
.n
, ==, 42.5);
414 qapi_free_AltNumInt(ani
);
417 static void test_native_list_integer_helper(TestInputVisitorData
*data
,
419 UserDefNativeListUnionKind kind
)
421 UserDefNativeListUnion
*cvalue
= NULL
;
423 GString
*gstr_list
= g_string_new("");
424 GString
*gstr_union
= g_string_new("");
427 for (i
= 0; i
< 32; i
++) {
428 g_string_append_printf(gstr_list
, "%d", i
);
430 g_string_append(gstr_list
, ", ");
433 g_string_append_printf(gstr_union
, "{ 'type': '%s', 'data': [ %s ] }",
434 UserDefNativeListUnionKind_lookup
[kind
],
436 v
= visitor_input_test_init_raw(data
, gstr_union
->str
);
438 visit_type_UserDefNativeListUnion(v
, NULL
, &cvalue
, &error_abort
);
439 g_assert(cvalue
!= NULL
);
440 g_assert_cmpint(cvalue
->type
, ==, kind
);
443 case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER
: {
444 intList
*elem
= NULL
;
445 for (i
= 0, elem
= cvalue
->u
.integer
; elem
; elem
= elem
->next
, i
++) {
446 g_assert_cmpint(elem
->value
, ==, i
);
450 case USER_DEF_NATIVE_LIST_UNION_KIND_S8
: {
451 int8List
*elem
= NULL
;
452 for (i
= 0, elem
= cvalue
->u
.s8
; elem
; elem
= elem
->next
, i
++) {
453 g_assert_cmpint(elem
->value
, ==, i
);
457 case USER_DEF_NATIVE_LIST_UNION_KIND_S16
: {
458 int16List
*elem
= NULL
;
459 for (i
= 0, elem
= cvalue
->u
.s16
; elem
; elem
= elem
->next
, i
++) {
460 g_assert_cmpint(elem
->value
, ==, i
);
464 case USER_DEF_NATIVE_LIST_UNION_KIND_S32
: {
465 int32List
*elem
= NULL
;
466 for (i
= 0, elem
= cvalue
->u
.s32
; elem
; elem
= elem
->next
, i
++) {
467 g_assert_cmpint(elem
->value
, ==, i
);
471 case USER_DEF_NATIVE_LIST_UNION_KIND_S64
: {
472 int64List
*elem
= NULL
;
473 for (i
= 0, elem
= cvalue
->u
.s64
; elem
; elem
= elem
->next
, i
++) {
474 g_assert_cmpint(elem
->value
, ==, i
);
478 case USER_DEF_NATIVE_LIST_UNION_KIND_U8
: {
479 uint8List
*elem
= NULL
;
480 for (i
= 0, elem
= cvalue
->u
.u8
; elem
; elem
= elem
->next
, i
++) {
481 g_assert_cmpint(elem
->value
, ==, i
);
485 case USER_DEF_NATIVE_LIST_UNION_KIND_U16
: {
486 uint16List
*elem
= NULL
;
487 for (i
= 0, elem
= cvalue
->u
.u16
; elem
; elem
= elem
->next
, i
++) {
488 g_assert_cmpint(elem
->value
, ==, i
);
492 case USER_DEF_NATIVE_LIST_UNION_KIND_U32
: {
493 uint32List
*elem
= NULL
;
494 for (i
= 0, elem
= cvalue
->u
.u32
; elem
; elem
= elem
->next
, i
++) {
495 g_assert_cmpint(elem
->value
, ==, i
);
499 case USER_DEF_NATIVE_LIST_UNION_KIND_U64
: {
500 uint64List
*elem
= NULL
;
501 for (i
= 0, elem
= cvalue
->u
.u64
; elem
; elem
= elem
->next
, i
++) {
502 g_assert_cmpint(elem
->value
, ==, i
);
507 g_assert_not_reached();
510 g_string_free(gstr_union
, true);
511 g_string_free(gstr_list
, true);
512 qapi_free_UserDefNativeListUnion(cvalue
);
515 static void test_visitor_in_native_list_int(TestInputVisitorData
*data
,
518 test_native_list_integer_helper(data
, unused
,
519 USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER
);
522 static void test_visitor_in_native_list_int8(TestInputVisitorData
*data
,
525 test_native_list_integer_helper(data
, unused
,
526 USER_DEF_NATIVE_LIST_UNION_KIND_S8
);
529 static void test_visitor_in_native_list_int16(TestInputVisitorData
*data
,
532 test_native_list_integer_helper(data
, unused
,
533 USER_DEF_NATIVE_LIST_UNION_KIND_S16
);
536 static void test_visitor_in_native_list_int32(TestInputVisitorData
*data
,
539 test_native_list_integer_helper(data
, unused
,
540 USER_DEF_NATIVE_LIST_UNION_KIND_S32
);
543 static void test_visitor_in_native_list_int64(TestInputVisitorData
*data
,
546 test_native_list_integer_helper(data
, unused
,
547 USER_DEF_NATIVE_LIST_UNION_KIND_S64
);
550 static void test_visitor_in_native_list_uint8(TestInputVisitorData
*data
,
553 test_native_list_integer_helper(data
, unused
,
554 USER_DEF_NATIVE_LIST_UNION_KIND_U8
);
557 static void test_visitor_in_native_list_uint16(TestInputVisitorData
*data
,
560 test_native_list_integer_helper(data
, unused
,
561 USER_DEF_NATIVE_LIST_UNION_KIND_U16
);
564 static void test_visitor_in_native_list_uint32(TestInputVisitorData
*data
,
567 test_native_list_integer_helper(data
, unused
,
568 USER_DEF_NATIVE_LIST_UNION_KIND_U32
);
571 static void test_visitor_in_native_list_uint64(TestInputVisitorData
*data
,
574 test_native_list_integer_helper(data
, unused
,
575 USER_DEF_NATIVE_LIST_UNION_KIND_U64
);
578 static void test_visitor_in_native_list_bool(TestInputVisitorData
*data
,
581 UserDefNativeListUnion
*cvalue
= NULL
;
582 boolList
*elem
= NULL
;
584 GString
*gstr_list
= g_string_new("");
585 GString
*gstr_union
= g_string_new("");
588 for (i
= 0; i
< 32; i
++) {
589 g_string_append_printf(gstr_list
, "%s",
590 (i
% 3 == 0) ? "true" : "false");
592 g_string_append(gstr_list
, ", ");
595 g_string_append_printf(gstr_union
, "{ 'type': 'boolean', 'data': [ %s ] }",
597 v
= visitor_input_test_init_raw(data
, gstr_union
->str
);
599 visit_type_UserDefNativeListUnion(v
, NULL
, &cvalue
, &error_abort
);
600 g_assert(cvalue
!= NULL
);
601 g_assert_cmpint(cvalue
->type
, ==, USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN
);
603 for (i
= 0, elem
= cvalue
->u
.boolean
; elem
; elem
= elem
->next
, i
++) {
604 g_assert_cmpint(elem
->value
, ==, (i
% 3 == 0) ? 1 : 0);
607 g_string_free(gstr_union
, true);
608 g_string_free(gstr_list
, true);
609 qapi_free_UserDefNativeListUnion(cvalue
);
612 static void test_visitor_in_native_list_string(TestInputVisitorData
*data
,
615 UserDefNativeListUnion
*cvalue
= NULL
;
616 strList
*elem
= NULL
;
618 GString
*gstr_list
= g_string_new("");
619 GString
*gstr_union
= g_string_new("");
622 for (i
= 0; i
< 32; i
++) {
623 g_string_append_printf(gstr_list
, "'%d'", i
);
625 g_string_append(gstr_list
, ", ");
628 g_string_append_printf(gstr_union
, "{ 'type': 'string', 'data': [ %s ] }",
630 v
= visitor_input_test_init_raw(data
, gstr_union
->str
);
632 visit_type_UserDefNativeListUnion(v
, NULL
, &cvalue
, &error_abort
);
633 g_assert(cvalue
!= NULL
);
634 g_assert_cmpint(cvalue
->type
, ==, USER_DEF_NATIVE_LIST_UNION_KIND_STRING
);
636 for (i
= 0, elem
= cvalue
->u
.string
; elem
; elem
= elem
->next
, i
++) {
638 sprintf(str
, "%d", i
);
639 g_assert_cmpstr(elem
->value
, ==, str
);
642 g_string_free(gstr_union
, true);
643 g_string_free(gstr_list
, true);
644 qapi_free_UserDefNativeListUnion(cvalue
);
647 #define DOUBLE_STR_MAX 16
649 static void test_visitor_in_native_list_number(TestInputVisitorData
*data
,
652 UserDefNativeListUnion
*cvalue
= NULL
;
653 numberList
*elem
= NULL
;
655 GString
*gstr_list
= g_string_new("");
656 GString
*gstr_union
= g_string_new("");
659 for (i
= 0; i
< 32; i
++) {
660 g_string_append_printf(gstr_list
, "%f", (double)i
/ 3);
662 g_string_append(gstr_list
, ", ");
665 g_string_append_printf(gstr_union
, "{ 'type': 'number', 'data': [ %s ] }",
667 v
= visitor_input_test_init_raw(data
, gstr_union
->str
);
669 visit_type_UserDefNativeListUnion(v
, NULL
, &cvalue
, &error_abort
);
670 g_assert(cvalue
!= NULL
);
671 g_assert_cmpint(cvalue
->type
, ==, USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER
);
673 for (i
= 0, elem
= cvalue
->u
.number
; elem
; elem
= elem
->next
, i
++) {
674 GString
*double_expected
= g_string_new("");
675 GString
*double_actual
= g_string_new("");
677 g_string_printf(double_expected
, "%.6f", (double)i
/ 3);
678 g_string_printf(double_actual
, "%.6f", elem
->value
);
679 g_assert_cmpstr(double_expected
->str
, ==, double_actual
->str
);
681 g_string_free(double_expected
, true);
682 g_string_free(double_actual
, true);
685 g_string_free(gstr_union
, true);
686 g_string_free(gstr_list
, true);
687 qapi_free_UserDefNativeListUnion(cvalue
);
690 static void input_visitor_test_add(const char *testpath
,
691 TestInputVisitorData
*data
,
692 void (*test_func
)(TestInputVisitorData
*data
, const void *user_data
))
694 g_test_add(testpath
, TestInputVisitorData
, data
, NULL
, test_func
,
695 visitor_input_teardown
);
698 static void test_visitor_in_errors(TestInputVisitorData
*data
,
701 TestStruct
*p
= NULL
;
706 v
= visitor_input_test_init(data
, "{ 'integer': false, 'boolean': 'foo', "
709 visit_type_TestStruct(v
, NULL
, &p
, &err
);
710 error_free_or_abort(&err
);
711 /* FIXME - a failed parse should not leave a partially-allocated p
712 * for us to clean up; this could cause callers to leak memory. */
713 g_assert(p
->string
== NULL
);
718 v
= visitor_input_test_init(data
, "[ '1', '2', false, '3' ]");
719 visit_type_strList(v
, NULL
, &q
, &err
);
720 error_free_or_abort(&err
);
722 qapi_free_strList(q
);
725 static void test_visitor_in_wrong_type(TestInputVisitorData
*data
,
728 TestStruct
*p
= NULL
;
734 /* Make sure arrays and structs cannot be confused */
736 v
= visitor_input_test_init(data
, "[]");
737 visit_type_TestStruct(v
, NULL
, &p
, &err
);
738 error_free_or_abort(&err
);
741 v
= visitor_input_test_init(data
, "{}");
742 visit_type_strList(v
, NULL
, &q
, &err
);
743 error_free_or_abort(&err
);
746 /* Make sure primitives and struct cannot be confused */
748 v
= visitor_input_test_init(data
, "1");
749 visit_type_TestStruct(v
, NULL
, &p
, &err
);
750 error_free_or_abort(&err
);
753 v
= visitor_input_test_init(data
, "{}");
754 visit_type_int(v
, NULL
, &i
, &err
);
755 error_free_or_abort(&err
);
757 /* Make sure primitives and arrays cannot be confused */
759 v
= visitor_input_test_init(data
, "1");
760 visit_type_strList(v
, NULL
, &q
, &err
);
761 error_free_or_abort(&err
);
764 v
= visitor_input_test_init(data
, "[]");
765 visit_type_int(v
, NULL
, &i
, &err
);
766 error_free_or_abort(&err
);
769 int main(int argc
, char **argv
)
771 TestInputVisitorData in_visitor_data
;
773 g_test_init(&argc
, &argv
, NULL
);
775 input_visitor_test_add("/visitor/input/int",
776 &in_visitor_data
, test_visitor_in_int
);
777 input_visitor_test_add("/visitor/input/int_overflow",
778 &in_visitor_data
, test_visitor_in_int_overflow
);
779 input_visitor_test_add("/visitor/input/bool",
780 &in_visitor_data
, test_visitor_in_bool
);
781 input_visitor_test_add("/visitor/input/number",
782 &in_visitor_data
, test_visitor_in_number
);
783 input_visitor_test_add("/visitor/input/string",
784 &in_visitor_data
, test_visitor_in_string
);
785 input_visitor_test_add("/visitor/input/enum",
786 &in_visitor_data
, test_visitor_in_enum
);
787 input_visitor_test_add("/visitor/input/struct",
788 &in_visitor_data
, test_visitor_in_struct
);
789 input_visitor_test_add("/visitor/input/struct-nested",
790 &in_visitor_data
, test_visitor_in_struct_nested
);
791 input_visitor_test_add("/visitor/input/list",
792 &in_visitor_data
, test_visitor_in_list
);
793 input_visitor_test_add("/visitor/input/any",
794 &in_visitor_data
, test_visitor_in_any
);
795 input_visitor_test_add("/visitor/input/union-flat",
796 &in_visitor_data
, test_visitor_in_union_flat
);
797 input_visitor_test_add("/visitor/input/alternate",
798 &in_visitor_data
, test_visitor_in_alternate
);
799 input_visitor_test_add("/visitor/input/errors",
800 &in_visitor_data
, test_visitor_in_errors
);
801 input_visitor_test_add("/visitor/input/wrong-type",
802 &in_visitor_data
, test_visitor_in_wrong_type
);
803 input_visitor_test_add("/visitor/input/alternate-number",
804 &in_visitor_data
, test_visitor_in_alternate_number
);
805 input_visitor_test_add("/visitor/input/native_list/int",
807 test_visitor_in_native_list_int
);
808 input_visitor_test_add("/visitor/input/native_list/int8",
810 test_visitor_in_native_list_int8
);
811 input_visitor_test_add("/visitor/input/native_list/int16",
813 test_visitor_in_native_list_int16
);
814 input_visitor_test_add("/visitor/input/native_list/int32",
816 test_visitor_in_native_list_int32
);
817 input_visitor_test_add("/visitor/input/native_list/int64",
819 test_visitor_in_native_list_int64
);
820 input_visitor_test_add("/visitor/input/native_list/uint8",
822 test_visitor_in_native_list_uint8
);
823 input_visitor_test_add("/visitor/input/native_list/uint16",
825 test_visitor_in_native_list_uint16
);
826 input_visitor_test_add("/visitor/input/native_list/uint32",
828 test_visitor_in_native_list_uint32
);
829 input_visitor_test_add("/visitor/input/native_list/uint64",
831 test_visitor_in_native_list_uint64
);
832 input_visitor_test_add("/visitor/input/native_list/bool",
833 &in_visitor_data
, test_visitor_in_native_list_bool
);
834 input_visitor_test_add("/visitor/input/native_list/str",
836 test_visitor_in_native_list_string
);
837 input_visitor_test_add("/visitor/input/native_list/number",
839 test_visitor_in_native_list_number
);