On 02/26/2017 03:43 PM, Markus Armbruster wrote: > 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 <[email protected]> > --- > tests/test-opts-visitor.c | 41 +++++++++++++++++++++++++++++++++++ > tests/test-qobject-input-visitor.c | 44 > ++++++++++++++++++++++++++++++++++++++ > tests/test-string-input-visitor.c | 22 +++++++++++++++++++ > 3 files changed, 107 insertions(+) >
>
> +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);
Although the complexity of adding virtual walks to the string visitor
may not be worth the effort.
> +++ 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 */
Indeed - the virtual walk is easier. At any rate, good testsuite
addition, and sets the stage for why the next patches fix the design flaw.
> +}
> +
> +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 ] ]");
In fact, QAPI does not (currently) allow the creation of one list nested
inside another (at least, not without an intervening struct), so this
particular input can only be walked virtually.
Reviewed-by: Eric Blake <[email protected]>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
