blob: 5418e085a49eb7884251c6afc19709334f664fcb [file] [log] [blame]
Paolo Bonzini2d7799f2012-02-09 11:21:03 +01001/*
2 * String Input Visitor unit-tests.
3 *
4 * Copyright (C) 2012 Red Hat Inc.
5 *
6 * Authors:
Daniel P. Berrangeb3db2112016-09-30 15:45:27 +01007 * Paolo Bonzini <pbonzini@redhat.com> (based on test-qobject-input-visitor)
Paolo Bonzini2d7799f2012-02-09 11:21:03 +01008 *
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.
11 */
12
Peter Maydell681c28a2016-02-08 18:08:51 +000013#include "qemu/osdep.h"
Paolo Bonzini2d7799f2012-02-09 11:21:03 +010014
Paolo Bonzini79ee7df2012-12-06 11:22:34 +010015#include "qemu-common.h"
Markus Armbrusterda34e652016-03-14 09:01:28 +010016#include "qapi/error.h"
Paolo Bonzini2d7799f2012-02-09 11:21:03 +010017#include "qapi/string-input-visitor.h"
Paolo Bonzini2d7799f2012-02-09 11:21:03 +010018#include "test-qapi-visit.h"
Paolo Bonzini2d7799f2012-02-09 11:21:03 +010019
20typedef struct TestInputVisitorData {
Eric Blake7a0525c2016-06-09 10:48:37 -060021 Visitor *v;
Paolo Bonzini2d7799f2012-02-09 11:21:03 +010022} TestInputVisitorData;
23
24static void visitor_input_teardown(TestInputVisitorData *data,
25 const void *unused)
26{
Eric Blake7a0525c2016-06-09 10:48:37 -060027 if (data->v) {
28 visit_free(data->v);
29 data->v = NULL;
Paolo Bonzini2d7799f2012-02-09 11:21:03 +010030 }
31}
32
33/* This is provided instead of a test setup function so that the JSON
34 string used by the tests are kept in the test functions (and not
35 int main()) */
36static
37Visitor *visitor_input_test_init(TestInputVisitorData *data,
38 const char *string)
39{
Markus Armbruster0f721d12017-03-03 13:32:41 +010040 visitor_input_teardown(data, NULL);
41
Eric Blake7a0525c2016-06-09 10:48:37 -060042 data->v = string_input_visitor_new(string);
43 g_assert(data->v);
44 return data->v;
Paolo Bonzini2d7799f2012-02-09 11:21:03 +010045}
46
47static void test_visitor_in_int(TestInputVisitorData *data,
48 const void *unused)
49{
50 int64_t res = 0, value = -42;
Markus Armbrustere940f542014-05-02 13:26:29 +020051 Error *err = NULL;
Paolo Bonzini2d7799f2012-02-09 11:21:03 +010052 Visitor *v;
53
54 v = visitor_input_test_init(data, "-42");
55
Eric Blake51e72bc2016-01-29 06:48:54 -070056 visit_type_int(v, NULL, &res, &err);
Markus Armbrustere940f542014-05-02 13:26:29 +020057 g_assert(!err);
Paolo Bonzini2d7799f2012-02-09 11:21:03 +010058 g_assert_cmpint(res, ==, value);
Markus Armbruster73374682016-04-28 15:45:29 -060059
Markus Armbruster73374682016-04-28 15:45:29 -060060 v = visitor_input_test_init(data, "not an int");
61
62 visit_type_int(v, NULL, &res, &err);
63 error_free_or_abort(&err);
Markus Armbrusterd2788222017-03-20 17:13:43 +010064
65 v = visitor_input_test_init(data, "");
66
67 visit_type_int(v, NULL, &res, &err);
68 error_free_or_abort(&err);
Paolo Bonzini2d7799f2012-02-09 11:21:03 +010069}
70
Markus Armbruster3d089ce2017-03-03 13:32:42 +010071static void check_ilist(Visitor *v, int64_t *expected, size_t n)
72{
73 int64List *res = NULL;
74 int64List *tail;
75 int i;
76
77 visit_type_int64List(v, NULL, &res, &error_abort);
78 tail = res;
79 for (i = 0; i < n; i++) {
80 g_assert(tail);
81 g_assert_cmpint(tail->value, ==, expected[i]);
82 tail = tail->next;
83 }
84 g_assert(!tail);
85
86 qapi_free_int64List(res);
87}
88
89static void check_ulist(Visitor *v, uint64_t *expected, size_t n)
90{
91 uint64List *res = NULL;
92 uint64List *tail;
93 int i;
94
Markus Armbruster3d089ce2017-03-03 13:32:42 +010095 visit_type_uint64List(v, NULL, &res, &error_abort);
96 tail = res;
97 for (i = 0; i < n; i++) {
98 g_assert(tail);
99 g_assert_cmpuint(tail->value, ==, expected[i]);
100 tail = tail->next;
101 }
102 g_assert(!tail);
103
104 qapi_free_uint64List(res);
105}
106
Hu Tao659268f2014-06-10 19:15:27 +0800107static void test_visitor_in_intList(TestInputVisitorData *data,
108 const void *unused)
109{
David Hildenbrandc9fba9d2018-11-21 17:44:18 +0100110 int64_t expect1[] = { 1, 2, 0, 2, 3, 4, 20, 5, 6, 7,
111 8, 9, 1, 2, 3, 4, 5, 6, 7, 8 };
Markus Armbruster3d089ce2017-03-03 13:32:42 +0100112 int64_t expect2[] = { 32767, -32768, -32767 };
David Hildenbrandc9fba9d2018-11-21 17:44:18 +0100113 int64_t expect3[] = { INT64_MIN, INT64_MAX };
David Hildenbrandeac47542018-11-21 17:44:17 +0100114 int64_t expect4[] = { 1 };
David Hildenbrand345e4012018-11-21 17:44:21 +0100115 int64_t expect5[] = { INT64_MAX - 2, INT64_MAX - 1, INT64_MAX };
Markus Armbruster73374682016-04-28 15:45:29 -0600116 Error *err = NULL;
Markus Armbruster3d089ce2017-03-03 13:32:42 +0100117 int64List *res = NULL;
Hu Tao659268f2014-06-10 19:15:27 +0800118 Visitor *v;
Markus Armbrustera9416dc2017-03-03 13:32:46 +0100119 int64_t val;
Markus Armbruster3d089ce2017-03-03 13:32:42 +0100120
121 /* Valid lists */
Hu Tao659268f2014-06-10 19:15:27 +0800122
123 v = visitor_input_test_init(data, "1,2,0,2-4,20,5-9,1-8");
Markus Armbruster3d089ce2017-03-03 13:32:42 +0100124 check_ilist(v, expect1, ARRAY_SIZE(expect1));
Hu Tao659268f2014-06-10 19:15:27 +0800125
Markus Armbruster3d089ce2017-03-03 13:32:42 +0100126 v = visitor_input_test_init(data, "32767,-32768--32767");
127 check_ilist(v, expect2, ARRAY_SIZE(expect2));
Hu Tao659268f2014-06-10 19:15:27 +0800128
Markus Armbruster3d089ce2017-03-03 13:32:42 +0100129 v = visitor_input_test_init(data,
130 "-9223372036854775808,9223372036854775807");
131 check_ilist(v, expect3, ARRAY_SIZE(expect3));
132
David Hildenbrandeac47542018-11-21 17:44:17 +0100133 v = visitor_input_test_init(data, "1-1");
134 check_ilist(v, expect4, ARRAY_SIZE(expect4));
135
David Hildenbrand345e4012018-11-21 17:44:21 +0100136 v = visitor_input_test_init(data,
137 "9223372036854775805-9223372036854775807");
138 check_ilist(v, expect5, ARRAY_SIZE(expect5));
139
David Hildenbrandeac47542018-11-21 17:44:17 +0100140 /* Value too large */
141
142 v = visitor_input_test_init(data, "9223372036854775808");
143 visit_type_int64List(v, NULL, &res, &err);
144 error_free_or_abort(&err);
145 g_assert(!res);
146
147 /* Value too small */
148
149 v = visitor_input_test_init(data, "-9223372036854775809");
150 visit_type_int64List(v, NULL, &res, &err);
151 error_free_or_abort(&err);
152 g_assert(!res);
153
154 /* Range not ascending */
155
156 v = visitor_input_test_init(data, "3-1");
157 visit_type_int64List(v, NULL, &res, &err);
158 error_free_or_abort(&err);
159 g_assert(!res);
160
161 v = visitor_input_test_init(data, "9223372036854775807-0");
162 visit_type_int64List(v, NULL, &res, &err);
163 error_free_or_abort(&err);
164 g_assert(!res);
165
166 /* Range too big (65536 is the limit against DOS attacks) */
167
168 v = visitor_input_test_init(data, "0-65536");
169 visit_type_int64List(v, NULL, &res, &err);
170 error_free_or_abort(&err);
171 g_assert(!res);
Markus Armbruster3d089ce2017-03-03 13:32:42 +0100172
Markus Armbrusterd2788222017-03-20 17:13:43 +0100173 /* Empty list */
Markus Armbruster3d089ce2017-03-03 13:32:42 +0100174
175 v = visitor_input_test_init(data, "");
Markus Armbrusterd2788222017-03-20 17:13:43 +0100176 visit_type_int64List(v, NULL, &res, &error_abort);
177 g_assert(!res);
Markus Armbruster3d089ce2017-03-03 13:32:42 +0100178
179 /* Not a list */
Markus Armbruster73374682016-04-28 15:45:29 -0600180
Markus Armbruster73374682016-04-28 15:45:29 -0600181 v = visitor_input_test_init(data, "not an int list");
182
Markus Armbruster3d089ce2017-03-03 13:32:42 +0100183 visit_type_int64List(v, NULL, &res, &err);
Eric Blake74f24cb2016-04-28 15:45:30 -0600184 error_free_or_abort(&err);
185 g_assert(!res);
Markus Armbruster9cb8ef32017-03-03 13:32:43 +0100186
187 /* Unvisited list tail */
188
189 v = visitor_input_test_init(data, "0,2-3");
190
David Hildenbrand13088592018-11-21 17:44:19 +0100191 visit_start_list(v, NULL, NULL, 0, &error_abort);
192 visit_type_int64(v, NULL, &val, &error_abort);
193 g_assert_cmpint(val, ==, 0);
194 visit_type_int64(v, NULL, &val, &error_abort);
195 g_assert_cmpint(val, ==, 2);
Markus Armbrustera4a1c702017-03-03 13:32:45 +0100196
197 visit_check_list(v, &err);
198 error_free_or_abort(&err);
David Hildenbrand13088592018-11-21 17:44:19 +0100199 visit_end_list(v, NULL);
Markus Armbrustera9416dc2017-03-03 13:32:46 +0100200
201 /* Visit beyond end of list */
David Hildenbrand13088592018-11-21 17:44:19 +0100202
Markus Armbrustera9416dc2017-03-03 13:32:46 +0100203 v = visitor_input_test_init(data, "0");
204
David Hildenbrand13088592018-11-21 17:44:19 +0100205 visit_start_list(v, NULL, NULL, 0, &error_abort);
206 visit_type_int64(v, NULL, &val, &err);
207 g_assert_cmpint(val, ==, 0);
Markus Armbrustera9416dc2017-03-03 13:32:46 +0100208 visit_type_int64(v, NULL, &val, &err);
David Hildenbrandc9fba9d2018-11-21 17:44:18 +0100209 error_free_or_abort(&err);
Markus Armbrustera9416dc2017-03-03 13:32:46 +0100210
David Hildenbrand13088592018-11-21 17:44:19 +0100211 visit_check_list(v, &error_abort);
212 visit_end_list(v, NULL);
Hu Tao659268f2014-06-10 19:15:27 +0800213}
214
David Hildenbrandcc871b12018-11-21 17:44:20 +0100215static void test_visitor_in_uintList(TestInputVisitorData *data,
216 const void *unused)
217{
218 uint64_t expect1[] = { 1, 2, 0, 2, 3, 4, 20, 5, 6, 7,
219 8, 9, 1, 2, 3, 4, 5, 6, 7, 8 };
220 uint64_t expect2[] = { 32767, -32768, -32767 };
221 uint64_t expect3[] = { INT64_MIN, INT64_MAX };
222 uint64_t expect4[] = { 1 };
223 uint64_t expect5[] = { UINT64_MAX };
David Hildenbrand345e4012018-11-21 17:44:21 +0100224 uint64_t expect6[] = { UINT64_MAX - 2, UINT64_MAX - 1, UINT64_MAX };
David Hildenbrandcc871b12018-11-21 17:44:20 +0100225 Error *err = NULL;
226 uint64List *res = NULL;
227 Visitor *v;
228 uint64_t val;
229
230 /* Valid lists */
231
232 v = visitor_input_test_init(data, "1,2,0,2-4,20,5-9,1-8");
233 check_ulist(v, expect1, ARRAY_SIZE(expect1));
234
235 v = visitor_input_test_init(data, "32767,-32768--32767");
236 check_ulist(v, expect2, ARRAY_SIZE(expect2));
237
238 v = visitor_input_test_init(data,
239 "-9223372036854775808,9223372036854775807");
240 check_ulist(v, expect3, ARRAY_SIZE(expect3));
241
242 v = visitor_input_test_init(data, "1-1");
243 check_ulist(v, expect4, ARRAY_SIZE(expect4));
244
245 v = visitor_input_test_init(data, "18446744073709551615");
246 check_ulist(v, expect5, ARRAY_SIZE(expect5));
247
David Hildenbrand345e4012018-11-21 17:44:21 +0100248 v = visitor_input_test_init(data,
249 "18446744073709551613-18446744073709551615");
250 check_ulist(v, expect6, ARRAY_SIZE(expect6));
251
David Hildenbrandcc871b12018-11-21 17:44:20 +0100252 /* Value too large */
253
254 v = visitor_input_test_init(data, "18446744073709551616");
255 visit_type_uint64List(v, NULL, &res, &err);
256 error_free_or_abort(&err);
257 g_assert(!res);
258
259 /* Value too small */
260
261 v = visitor_input_test_init(data, "-18446744073709551616");
262 visit_type_uint64List(v, NULL, &res, &err);
263 error_free_or_abort(&err);
264 g_assert(!res);
265
266 /* Range not ascending */
267
268 v = visitor_input_test_init(data, "3-1");
269 visit_type_uint64List(v, NULL, &res, &err);
270 error_free_or_abort(&err);
271 g_assert(!res);
272
273 v = visitor_input_test_init(data, "18446744073709551615-0");
274 visit_type_uint64List(v, NULL, &res, &err);
275 error_free_or_abort(&err);
276 g_assert(!res);
277
278 /* Range too big (65536 is the limit against DOS attacks) */
279
280 v = visitor_input_test_init(data, "0-65536");
281 visit_type_uint64List(v, NULL, &res, &err);
282 error_free_or_abort(&err);
283 g_assert(!res);
284
285 /* Empty list */
286
287 v = visitor_input_test_init(data, "");
288 visit_type_uint64List(v, NULL, &res, &error_abort);
289 g_assert(!res);
290
291 /* Not a list */
292
293 v = visitor_input_test_init(data, "not an uint list");
294
295 visit_type_uint64List(v, NULL, &res, &err);
296 error_free_or_abort(&err);
297 g_assert(!res);
298
299 /* Unvisited list tail */
300
301 v = visitor_input_test_init(data, "0,2-3");
302
303 visit_start_list(v, NULL, NULL, 0, &error_abort);
304 visit_type_uint64(v, NULL, &val, &error_abort);
305 g_assert_cmpuint(val, ==, 0);
306 visit_type_uint64(v, NULL, &val, &error_abort);
307 g_assert_cmpuint(val, ==, 2);
308
309 visit_check_list(v, &err);
310 error_free_or_abort(&err);
311 visit_end_list(v, NULL);
312
313 /* Visit beyond end of list */
314
315 v = visitor_input_test_init(data, "0");
316
317 visit_start_list(v, NULL, NULL, 0, &error_abort);
318 visit_type_uint64(v, NULL, &val, &err);
319 g_assert_cmpuint(val, ==, 0);
320 visit_type_uint64(v, NULL, &val, &err);
321 error_free_or_abort(&err);
322
323 visit_check_list(v, &error_abort);
324 visit_end_list(v, NULL);
325}
326
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100327static void test_visitor_in_bool(TestInputVisitorData *data,
328 const void *unused)
329{
Markus Armbrustere940f542014-05-02 13:26:29 +0200330 Error *err = NULL;
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100331 bool res = false;
332 Visitor *v;
333
334 v = visitor_input_test_init(data, "true");
335
Eric Blake51e72bc2016-01-29 06:48:54 -0700336 visit_type_bool(v, NULL, &res, &err);
Markus Armbrustere940f542014-05-02 13:26:29 +0200337 g_assert(!err);
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100338 g_assert_cmpint(res, ==, true);
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100339
340 v = visitor_input_test_init(data, "yes");
341
Eric Blake51e72bc2016-01-29 06:48:54 -0700342 visit_type_bool(v, NULL, &res, &err);
Markus Armbrustere940f542014-05-02 13:26:29 +0200343 g_assert(!err);
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100344 g_assert_cmpint(res, ==, true);
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100345
346 v = visitor_input_test_init(data, "on");
347
Eric Blake51e72bc2016-01-29 06:48:54 -0700348 visit_type_bool(v, NULL, &res, &err);
Markus Armbrustere940f542014-05-02 13:26:29 +0200349 g_assert(!err);
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100350 g_assert_cmpint(res, ==, true);
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100351
352 v = visitor_input_test_init(data, "false");
353
Eric Blake51e72bc2016-01-29 06:48:54 -0700354 visit_type_bool(v, NULL, &res, &err);
Markus Armbrustere940f542014-05-02 13:26:29 +0200355 g_assert(!err);
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100356 g_assert_cmpint(res, ==, false);
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100357
358 v = visitor_input_test_init(data, "no");
359
Eric Blake51e72bc2016-01-29 06:48:54 -0700360 visit_type_bool(v, NULL, &res, &err);
Markus Armbrustere940f542014-05-02 13:26:29 +0200361 g_assert(!err);
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100362 g_assert_cmpint(res, ==, false);
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100363
364 v = visitor_input_test_init(data, "off");
365
Eric Blake51e72bc2016-01-29 06:48:54 -0700366 visit_type_bool(v, NULL, &res, &err);
Markus Armbrustere940f542014-05-02 13:26:29 +0200367 g_assert(!err);
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100368 g_assert_cmpint(res, ==, false);
369}
370
371static void test_visitor_in_number(TestInputVisitorData *data,
372 const void *unused)
373{
374 double res = 0, value = 3.14;
Markus Armbrustere940f542014-05-02 13:26:29 +0200375 Error *err = NULL;
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100376 Visitor *v;
377
378 v = visitor_input_test_init(data, "3.14");
379
Eric Blake51e72bc2016-01-29 06:48:54 -0700380 visit_type_number(v, NULL, &res, &err);
Markus Armbrustere940f542014-05-02 13:26:29 +0200381 g_assert(!err);
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100382 g_assert_cmpfloat(res, ==, value);
David Hildenbrand4b69d4c2018-11-21 17:44:15 +0100383
384 /* NaN and infinity has to be rejected */
385
386 v = visitor_input_test_init(data, "NaN");
387
388 visit_type_number(v, NULL, &res, &err);
389 error_free_or_abort(&err);
390
391 v = visitor_input_test_init(data, "inf");
392
393 visit_type_number(v, NULL, &res, &err);
394 error_free_or_abort(&err);
395
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100396}
397
398static void test_visitor_in_string(TestInputVisitorData *data,
399 const void *unused)
400{
401 char *res = NULL, *value = (char *) "Q E M U";
Markus Armbrustere940f542014-05-02 13:26:29 +0200402 Error *err = NULL;
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100403 Visitor *v;
404
405 v = visitor_input_test_init(data, value);
406
Eric Blake51e72bc2016-01-29 06:48:54 -0700407 visit_type_str(v, NULL, &res, &err);
Markus Armbrustere940f542014-05-02 13:26:29 +0200408 g_assert(!err);
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100409 g_assert_cmpstr(res, ==, value);
410
411 g_free(res);
412}
413
414static void test_visitor_in_enum(TestInputVisitorData *data,
415 const void *unused)
416{
Markus Armbrustere940f542014-05-02 13:26:29 +0200417 Error *err = NULL;
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100418 Visitor *v;
419 EnumOne i;
420
Markus Armbruster1c236ba2017-08-24 10:46:06 +0200421 for (i = 0; i < ENUM_ONE__MAX; i++) {
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100422 EnumOne res = -1;
423
Markus Armbruster977c7362017-08-24 10:46:08 +0200424 v = visitor_input_test_init(data, EnumOne_str(i));
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100425
Eric Blake51e72bc2016-01-29 06:48:54 -0700426 visit_type_EnumOne(v, NULL, &res, &err);
Markus Armbrustere940f542014-05-02 13:26:29 +0200427 g_assert(!err);
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100428 g_assert_cmpint(i, ==, res);
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100429 }
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100430}
431
Blue Swirl3f0f31a2013-01-19 15:43:53 +0000432/* Try to crash the visitors */
433static void test_visitor_in_fuzz(TestInputVisitorData *data,
434 const void *unused)
435{
436 int64_t ires;
Hu Tao659268f2014-06-10 19:15:27 +0800437 intList *ilres;
Blue Swirl3f0f31a2013-01-19 15:43:53 +0000438 bool bres;
439 double nres;
440 char *sres;
441 EnumOne eres;
Blue Swirl3f0f31a2013-01-19 15:43:53 +0000442 Visitor *v;
443 unsigned int i;
444 char buf[10000];
445
446 for (i = 0; i < 100; i++) {
Andrey Shinkevichf6731742019-07-30 19:01:37 +0300447 unsigned int j, k;
Blue Swirl3f0f31a2013-01-19 15:43:53 +0000448
449 j = g_test_rand_int_range(0, sizeof(buf) - 1);
450
451 buf[j] = '\0';
452
Andrey Shinkevichf6731742019-07-30 19:01:37 +0300453 for (k = 0; k != j; k++) {
454 buf[k] = (char)g_test_rand_int_range(0, 256);
Blue Swirl3f0f31a2013-01-19 15:43:53 +0000455 }
456
457 v = visitor_input_test_init(data, buf);
Eric Blake51e72bc2016-01-29 06:48:54 -0700458 visit_type_int(v, NULL, &ires, NULL);
Blue Swirl3f0f31a2013-01-19 15:43:53 +0000459
460 v = visitor_input_test_init(data, buf);
Eric Blake51e72bc2016-01-29 06:48:54 -0700461 visit_type_intList(v, NULL, &ilres, NULL);
Marc-André Lureaubd794062016-07-12 16:08:47 +0200462 qapi_free_intList(ilres);
Hu Tao659268f2014-06-10 19:15:27 +0800463
464 v = visitor_input_test_init(data, buf);
Eric Blake51e72bc2016-01-29 06:48:54 -0700465 visit_type_bool(v, NULL, &bres, NULL);
Blue Swirl3f0f31a2013-01-19 15:43:53 +0000466
467 v = visitor_input_test_init(data, buf);
Eric Blake51e72bc2016-01-29 06:48:54 -0700468 visit_type_number(v, NULL, &nres, NULL);
Blue Swirl3f0f31a2013-01-19 15:43:53 +0000469
470 v = visitor_input_test_init(data, buf);
Peter Maydell01845432013-02-05 20:44:23 +0000471 sres = NULL;
Eric Blake51e72bc2016-01-29 06:48:54 -0700472 visit_type_str(v, NULL, &sres, NULL);
Blue Swirl3f0f31a2013-01-19 15:43:53 +0000473 g_free(sres);
474
475 v = visitor_input_test_init(data, buf);
Eric Blake51e72bc2016-01-29 06:48:54 -0700476 visit_type_EnumOne(v, NULL, &eres, NULL);
Blue Swirl3f0f31a2013-01-19 15:43:53 +0000477 }
478}
479
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100480static void input_visitor_test_add(const char *testpath,
481 TestInputVisitorData *data,
482 void (*test_func)(TestInputVisitorData *data, const void *user_data))
483{
484 g_test_add(testpath, TestInputVisitorData, data, NULL, test_func,
485 visitor_input_teardown);
486}
487
488int main(int argc, char **argv)
489{
490 TestInputVisitorData in_visitor_data;
491
492 g_test_init(&argc, &argv, NULL);
493
494 input_visitor_test_add("/string-visitor/input/int",
495 &in_visitor_data, test_visitor_in_int);
Hu Tao659268f2014-06-10 19:15:27 +0800496 input_visitor_test_add("/string-visitor/input/intList",
497 &in_visitor_data, test_visitor_in_intList);
David Hildenbrandcc871b12018-11-21 17:44:20 +0100498 input_visitor_test_add("/string-visitor/input/uintList",
499 &in_visitor_data, test_visitor_in_uintList);
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100500 input_visitor_test_add("/string-visitor/input/bool",
501 &in_visitor_data, test_visitor_in_bool);
502 input_visitor_test_add("/string-visitor/input/number",
503 &in_visitor_data, test_visitor_in_number);
504 input_visitor_test_add("/string-visitor/input/string",
505 &in_visitor_data, test_visitor_in_string);
506 input_visitor_test_add("/string-visitor/input/enum",
507 &in_visitor_data, test_visitor_in_enum);
Blue Swirl3f0f31a2013-01-19 15:43:53 +0000508 input_visitor_test_add("/string-visitor/input/fuzz",
509 &in_visitor_data, test_visitor_in_fuzz);
Paolo Bonzini2d7799f2012-02-09 11:21:03 +0100510
511 g_test_run();
512
513 return 0;
514}