From: Markus Armbruster <armbru@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH 3/3] qapi-schema: test: add a unit test for parsing array alternates
Date: Tue, 22 Mar 2022 10:47:56 +0100 [thread overview]
Message-ID: <878rt2jp2r.fsf@pond.sub.org> (raw)
In-Reply-To: <20220321164243.200569-4-pbonzini@redhat.com> (Paolo Bonzini's message of "Mon, 21 Mar 2022 17:42:43 +0100")
Paolo Bonzini <pbonzini@redhat.com> writes:
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> tests/qapi-schema/qapi-schema-test.json | 1 +
> tests/qapi-schema/qapi-schema-test.out | 4 +++
> tests/unit/test-qobject-input-visitor.c | 43 +++++++++++++++++++++++++
> 3 files changed, 48 insertions(+)
>
> diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json
> index 43b8697002..ba7302f42b 100644
> --- a/tests/qapi-schema/qapi-schema-test.json
> +++ b/tests/qapi-schema/qapi-schema-test.json
> @@ -119,6 +119,7 @@
> { 'alternate': 'AltEnumNum', 'data': { 'e': 'EnumOne', 'n': 'number' } }
> { 'alternate': 'AltNumEnum', 'data': { 'n': 'number', 'e': 'EnumOne' } }
> { 'alternate': 'AltEnumInt', 'data': { 'e': 'EnumOne', 'i': 'int' } }
> +{ 'alternate': 'AltListInt', 'data': { 'l': ['int'], 'i': 'int' } }
>
> # for testing use of 'str' within alternates
> { 'alternate': 'AltStrObj', 'data': { 's': 'str', 'o': 'TestStruct' } }
> diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out
> index 1f9585fa9b..043d75c655 100644
> --- a/tests/qapi-schema/qapi-schema-test.out
> +++ b/tests/qapi-schema/qapi-schema-test.out
> @@ -121,6 +121,10 @@ alternate AltEnumInt
> tag type
> case e: EnumOne
> case i: int
> +alternate AltListInt
> + tag type
> + case l: intList
> + case i: int
> alternate AltStrObj
> tag type
> case s: str
> diff --git a/tests/unit/test-qobject-input-visitor.c b/tests/unit/test-qobject-input-visitor.c
> index 6f59a7f432..2af002dd82 100644
> --- a/tests/unit/test-qobject-input-visitor.c
> +++ b/tests/unit/test-qobject-input-visitor.c
> @@ -776,6 +776,7 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data,
> AltEnumNum *aen;
> AltNumEnum *ans;
> AltEnumInt *asi;
> + AltListInt *ali;
>
> /* Parsing an int */
>
> @@ -802,6 +803,12 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data,
> g_assert_cmpint(asi->u.i, ==, 42);
> qapi_free_AltEnumInt(asi);
>
> + v = visitor_input_test_init(data, "42");
> + visit_type_AltListInt(v, NULL, &ali, &error_abort);
> + g_assert_cmpint(ali->type, ==, QTYPE_QNUM);
> + g_assert_cmpint(ali->u.i, ==, 42);
> + qapi_free_AltListInt(ali);
> +
> /* Parsing a double */
>
> v = visitor_input_test_init(data, "42.5");
> @@ -827,6 +834,40 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data,
> qapi_free_AltEnumInt(asi);
> }
>
> +static void test_visitor_in_alternate_list(TestInputVisitorData *data,
> + const void *unused)
> +{
> + intList *item;
> + Visitor *v;
> + AltListInt *ali;
> + int i;
> +
> + v = visitor_input_test_init(data, "[ 42, 43, 44 ]");
> + visit_type_AltListInt(v, NULL, &ali, &error_abort);
> + g_assert(ali != NULL);
> +
> + g_assert_cmpint(ali->type, ==, QTYPE_QLIST);
> + for (i = 0, item = ali->u.l; item; item = item->next, i++) {
> + char string[12];
> +
> + snprintf(string, sizeof(string), "string%d", i);
This appears to be unused. Can drop in my tree.
> + g_assert_cmpint(item->value, ==, 42 + i);
> + }
> +
> + qapi_free_AltListInt(ali);
> + ali = NULL;
> +
> + /* An empty list is valid */
> + v = visitor_input_test_init(data, "[]");
> + visit_type_AltListInt(v, NULL, &ali, &error_abort);
> + g_assert(ali != NULL);
> +
> + g_assert_cmpint(ali->type, ==, QTYPE_QLIST);
> + g_assert(!ali->u.l);
> + qapi_free_AltListInt(ali);
> + ali = NULL;
> +}
> +
> static void input_visitor_test_add(const char *testpath,
> const void *user_data,
> void (*test_func)(TestInputVisitorData *data,
> @@ -1188,6 +1229,8 @@ int main(int argc, char **argv)
> NULL, test_visitor_in_wrong_type);
> input_visitor_test_add("/visitor/input/alternate-number",
> NULL, test_visitor_in_alternate_number);
> + input_visitor_test_add("/visitor/input/alternate-list",
> + NULL, test_visitor_in_alternate_list);
> input_visitor_test_add("/visitor/input/fail/struct",
> NULL, test_visitor_in_fail_struct);
> input_visitor_test_add("/visitor/input/fail/struct-nested",
Other than that:
Reviewed-by: Markus Armbruster <armbru@redhat.com>
next prev parent reply other threads:[~2022-03-22 9:51 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-21 16:42 [PATCH 0/3] qapi-schema: support alternates with array type Paolo Bonzini
2022-03-21 16:42 ` [PATCH 1/3] " Paolo Bonzini
2022-03-22 9:48 ` Markus Armbruster
2022-04-18 14:52 ` Paolo Bonzini
2022-03-21 16:42 ` [PATCH 2/3] qapi-schema: test: add a qapi-schema-test for array alternates Paolo Bonzini
2022-03-22 9:46 ` Markus Armbruster
2022-03-21 16:42 ` [PATCH 3/3] qapi-schema: test: add a unit test for parsing " Paolo Bonzini
2022-03-22 9:47 ` Markus Armbruster [this message]
2022-04-04 12:13 ` [PATCH 0/3] qapi-schema: support alternates with array type Markus Armbruster
2022-04-18 14:50 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878rt2jp2r.fsf@pond.sub.org \
--to=armbru@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.