aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/test-opts-visitor.c41
-rw-r--r--tests/test-qobject-input-visitor.c44
-rw-r--r--tests/test-string-input-visitor.c22
3 files changed, 107 insertions, 0 deletions
diff --git a/tests/test-opts-visitor.c b/tests/test-opts-visitor.c
index 0a9e75f1bb..d0f764699b 100644
--- a/tests/test-opts-visitor.c
+++ b/tests/test-opts-visitor.c
@@ -172,6 +172,44 @@ expect_u64_max(OptsVisitorFixture *f, gconstpointer test_data)
/* test cases */
+static void
+test_opts_range_unvisited(void)
+{
+ intList *list = NULL;
+ intList *tail;
+ QemuOpts *opts;
+ Visitor *v;
+
+ opts = qemu_opts_parse(qemu_find_opts("userdef"), "ilist=0-2", false,
+ &error_abort);
+
+ v = opts_visitor_new(opts);
+
+ visit_start_struct(v, NULL, NULL, 0, &error_abort);
+
+ /* Would be simpler if the visitor genuinely supported virtual walks */
+ visit_start_list(v, "ilist", (GenericList **)&list, sizeof(*list),
+ &error_abort);
+ tail = list;
+ visit_type_int(v, NULL, &tail->value, &error_abort);
+ g_assert_cmpint(tail->value, ==, 0);
+ tail = (intList *)visit_next_list(v, (GenericList *)tail, sizeof(*list));
+ g_assert(tail);
+ visit_type_int(v, NULL, &tail->value, &error_abort);
+ g_assert_cmpint(tail->value, ==, 1);
+ tail = (intList *)visit_next_list(v, (GenericList *)tail, sizeof(*list));
+ g_assert(tail);
+ visit_end_list(v, (void **)&list);
+ /* BUG: unvisited tail not reported; actually not reportable by design */
+
+ visit_check_struct(v, &error_abort);
+ visit_end_struct(v, NULL);
+
+ qapi_free_intList(list);
+ visit_free(v);
+ qemu_opts_del(opts);
+}
+
int
main(int argc, char **argv)
{
@@ -263,6 +301,9 @@ main(int argc, char **argv)
add_test("/visitor/opts/i64/range/2big/full", &expect_fail,
"i64=-0x8000000000000000-0x7fffffffffffffff");
+ g_test_add_func("/visitor/opts/range/unvisited",
+ test_opts_range_unvisited);
+
g_test_run();
return 0;
}
diff --git a/tests/test-qobject-input-visitor.c b/tests/test-qobject-input-visitor.c
index 32c6b3d689..10c15c46db 100644
--- a/tests/test-qobject-input-visitor.c
+++ b/tests/test-qobject-input-visitor.c
@@ -923,6 +923,46 @@ static void test_visitor_in_fail_struct_missing(TestInputVisitorData *data,
visit_end_struct(v, NULL);
}
+static void test_visitor_in_fail_list(TestInputVisitorData *data,
+ const void *unused)
+{
+ int64_t i64 = -1;
+ Visitor *v;
+
+ /* Unvisited list tail */
+
+ v = visitor_input_test_init(data, "[ 1, 2, 3 ]");
+
+ visit_start_list(v, NULL, NULL, 0, &error_abort);
+ visit_type_int(v, NULL, &i64, &error_abort);
+ g_assert_cmpint(i64, ==, 1);
+ visit_type_int(v, NULL, &i64, &error_abort);
+ g_assert_cmpint(i64, ==, 2);
+ visit_end_list(v, NULL);
+ /* BUG: unvisited tail not reported; actually not reportable by design */
+}
+
+static void test_visitor_in_fail_list_nested(TestInputVisitorData *data,
+ const void *unused)
+{
+ int64_t i64 = -1;
+ Visitor *v;
+
+ /* Unvisited nested list tail */
+
+ v = visitor_input_test_init(data, "[ 0, [ 1, 2, 3 ] ]");
+
+ visit_start_list(v, NULL, NULL, 0, &error_abort);
+ visit_type_int(v, NULL, &i64, &error_abort);
+ g_assert_cmpint(i64, ==, 0);
+ visit_start_list(v, NULL, NULL, 0, &error_abort);
+ visit_type_int(v, NULL, &i64, &error_abort);
+ g_assert_cmpint(i64, ==, 1);
+ visit_end_list(v, NULL);
+ /* BUG: unvisited tail not reported; actually not reportable by design */
+ visit_end_list(v, NULL);
+}
+
static void test_visitor_in_fail_union_native_list(TestInputVisitorData *data,
const void *unused)
{
@@ -1070,6 +1110,10 @@ int main(int argc, char **argv)
NULL, test_visitor_in_fail_struct_in_list);
input_visitor_test_add("/visitor/input/fail/struct-missing",
NULL, test_visitor_in_fail_struct_missing);
+ input_visitor_test_add("/visitor/input/fail/list",
+ NULL, test_visitor_in_fail_list);
+ input_visitor_test_add("/visitor/input/fail/list-nested",
+ NULL, test_visitor_in_fail_list_nested);
input_visitor_test_add("/visitor/input/fail/union-flat",
NULL, test_visitor_in_fail_union_flat);
input_visitor_test_add("/visitor/input/fail/union-flat-no-discriminator",
diff --git a/tests/test-string-input-visitor.c b/tests/test-string-input-visitor.c
index 72f8732f97..70cee65cd0 100644
--- a/tests/test-string-input-visitor.c
+++ b/tests/test-string-input-visitor.c
@@ -121,6 +121,7 @@ static void test_visitor_in_intList(TestInputVisitorData *data,
uint64_t expect4[] = { UINT64_MAX };
Error *err = NULL;
int64List *res = NULL;
+ int64List *tail;
Visitor *v;
/* Valid lists */
@@ -151,6 +152,27 @@ static void test_visitor_in_intList(TestInputVisitorData *data,
visit_type_int64List(v, NULL, &res, &err);
error_free_or_abort(&err);
g_assert(!res);
+
+ /* Unvisited list tail */
+
+ v = visitor_input_test_init(data, "0,2-3");
+
+ /* Would be simpler if the visitor genuinely supported virtual walks */
+ visit_start_list(v, NULL, (GenericList **)&res, sizeof(*res),
+ &error_abort);
+ tail = res;
+ visit_type_int64(v, NULL, &tail->value, &error_abort);
+ g_assert_cmpint(tail->value, ==, 0);
+ tail = (int64List *)visit_next_list(v, (GenericList *)tail, sizeof(*res));
+ g_assert(tail);
+ visit_type_int64(v, NULL, &tail->value, &error_abort);
+ g_assert_cmpint(tail->value, ==, 2);
+ tail = (int64List *)visit_next_list(v, (GenericList *)tail, sizeof(*res));
+ g_assert(tail);
+ visit_end_list(v, (void **)&res);
+ /* BUG: unvisited tail not reported; actually not reportable by design */
+
+ qapi_free_int64List(res);
}
static void test_visitor_in_bool(TestInputVisitorData *data,