summary refs log tree commit diff stats
path: root/tests/unit/test-qobject-input-visitor.c
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2022-04-21 10:49:40 -0700
committerRichard Henderson <richard.henderson@linaro.org>2022-04-21 10:49:40 -0700
commit378f973a6ce89de16496bc6007f4dffa2f881dbc (patch)
treed7a32ed7bf0094b9a620cc127a88977925de2623 /tests/unit/test-qobject-input-visitor.c
parent28298069afff3eb696e4995e63b2579b27adf378 (diff)
parentde7371bc7c39ccacb963acb5129b261087967070 (diff)
downloadfocaccia-qemu-378f973a6ce89de16496bc6007f4dffa2f881dbc.tar.gz
focaccia-qemu-378f973a6ce89de16496bc6007f4dffa2f881dbc.zip
Merge tag 'pull-qapi-2022-04-21' of git://repo.or.cz/qemu/armbru into staging
QAPI patches patches for 2022-04-21

# -----BEGIN PGP SIGNATURE-----
#
# iQJGBAABCAAwFiEENUvIs9frKmtoZ05fOHC0AOuRhlMFAmJhZgISHGFybWJydUBy
# ZWRoYXQuY29tAAoJEDhwtADrkYZTuZQP/iesk/r4ytyk+q+ksNCQHTZl4B4uZcbI
# TgbA1dwbwkKOfNaqByKZzXvbymL9Y4RpZavZ0i1qa3hK5orKHThLK4omRaFD+SPp
# sH53TeTgkG/UNUQk00dim1BzuWJefqFo1rYSqvTzaXVPyx1Q9Gk9193q5zDTlMJs
# w6UKD+q+Yxne9aoi1IH2NzzEKElHz7MMFeBDsnxDbkedzBxY1Ka05IOI2ucXhJ7X
# mYTZxHsrjncW4qJNkf57u9y4faNDIBeT3vkFqBaIeTXSSqm+xO1rkLanGOLQKtIM
# zD6JDMcqsIkZttEy0QCOrjKvMueWaOTZsS0sbdCC+JpBAbyVeS83kmRyYwEhyGre
# FJzf81zcEH6FtnDYudWWUT7hKV6sHWbw+4ho5WTkCYnr/Cfqr3TyDbSW+f/eIxUK
# vaujP/8MTypS4p0mx4QfM2/eO05oZHwEaslOn0gkg7siAJWuC7KUkkWSwz6ZNZCp
# qj/+jtDRGhvB4bGFusciqwtbnLNtVPX2meUuVxK74lmKa00+zXraNFfvGIxfzzC0
# pJ6weJj2jMLo5OEsZ2xWfNqhDigFQYxbGR8X3N2hg5GZTx1k5WXx7mRz3GlAwd8Q
# /4hcTBXKTFxDNxXqzL2eHBtaruKHjnHoVo2eAodyF+9FqErInjr/wisVm6I+R8NR
# Z94UBs8lvMIC
# =a3AD
# -----END PGP SIGNATURE-----
# gpg: Signature made Thu 21 Apr 2022 07:11:14 AM PDT
# gpg:                using RSA key 354BC8B3D7EB2A6B68674E5F3870B400EB918653
# gpg:                issuer "armbru@redhat.com"
# gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" [undefined]
# gpg:                 aka "Markus Armbruster <armbru@pond.sub.org>" [undefined]
# gpg: WARNING: This key is not certified with a trusted signature!
# gpg:          There is no indication that the signature belongs to the owner.
# Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867  4E5F 3870 B400 EB91 8653

* tag 'pull-qapi-2022-04-21' of git://repo.or.cz/qemu/armbru:
  qapi: Fix version of cpu0-id field
  qapi: Fix typo
  qapi: Fix documentation for query-xen-replication-status
  docs: qapi: Remove outdated reference to simple unions
  qapi-schema: test: add a unit test for parsing array alternates
  qapi-schema: test: add a qapi-schema-test for array alternates
  qapi-schema: support alternates with array type

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
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",