aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/test-qobject-input-visitor.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2022-03-21 17:42:43 +0100
committerMarkus Armbruster <armbru@redhat.com>2022-04-21 10:11:25 +0200
commit79db994861daadeeb9e852fba3831e9f3d5554c8 (patch)
treeeb8033360427244ac300387d46ec1a559e513ac2 /tests/unit/test-qobject-input-visitor.c
parentb36dc5c279706e23ed75f0a90dfe7195340a73cb (diff)
qapi-schema: test: add a unit test for parsing array alternates
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <20220321164243.200569-4-pbonzini@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> [Dead code dropped in test_visitor_in_alternate_list()] Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'tests/unit/test-qobject-input-visitor.c')
-rw-r--r--tests/unit/test-qobject-input-visitor.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/unit/test-qobject-input-visitor.c b/tests/unit/test-qobject-input-visitor.c
index aed08eaebc..14329dabcf 100644
--- a/tests/unit/test-qobject-input-visitor.c
+++ b/tests/unit/test-qobject-input-visitor.c
@@ -775,6 +775,7 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data,
AltEnumNum *aen;
AltNumEnum *ans;
AltEnumInt *asi;
+ AltListInt *ali;
/* Parsing an int */
@@ -801,6 +802,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");
@@ -826,6 +833,37 @@ 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++) {
+ 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,
@@ -1187,6 +1225,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",