aboutsummaryrefslogtreecommitdiff
path: root/tests/test-opts-visitor.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2017-03-03 13:32:43 +0100
committerMarkus Armbruster <armbru@redhat.com>2017-03-05 09:14:20 +0100
commit9cb8ef36681b9645af1f7bd8fb64656e65de8a03 (patch)
tree8e5703f5c7fb6821eeb5496406cedf4e5e2a3e28 /tests/test-opts-visitor.c
parent3d089cea0d32e2cb63604a98f4aa2028860502f0 (diff)
downloadqemu-9cb8ef36681b9645af1f7bd8fb64656e65de8a03.zip
qemu-9cb8ef36681b9645af1f7bd8fb64656e65de8a03.tar.gz
qemu-9cb8ef36681b9645af1f7bd8fb64656e65de8a03.tar.bz2
tests: Cover partial input visit of list
Demonstrates a design flaw: there is no way to for input visitors to report that a list visit didn't visit the complete input list. The generated list visits always do, but manual visits needn't. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <1488544368-30622-24-git-send-email-armbru@redhat.com>
Diffstat (limited to 'tests/test-opts-visitor.c')
-rw-r--r--tests/test-opts-visitor.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/test-opts-visitor.c b/tests/test-opts-visitor.c
index 0a9e75f..d0f7646 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;
}