aboutsummaryrefslogtreecommitdiff
path: root/tests/test-qmp-output-visitor.c
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2016-02-17 23:48:18 -0700
committerMarkus Armbruster <armbru@redhat.com>2016-02-19 11:08:57 +0100
commit68d078395d8233ca8455a95f05e5c23e367777c2 (patch)
treef1e769c6df0b7d5e1d93828a634ae31db5276c2e /tests/test-qmp-output-visitor.c
parent46534309e667fd860720f983c2c9aefe0354340d (diff)
qapi: Add tests of complex objects within alternate
Upcoming patches will adjust how we visit an object branch of an alternate; but we were completely lacking testsuite coverage. Rectify this, so that the future patches will be able to highlight the changes and still prove that we avoided regressions. In particular, the use of a flat union UserDefFlatUnion rather than a simple struct UserDefA as the branch will give us coverage of an object with variants. And visiting an alternate as both the top level and as a nested member gives confidence in correct memory allocation handling, especially if the test is run under valgrind. Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <1455778109-6278-5-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'tests/test-qmp-output-visitor.c')
-rw-r--r--tests/test-qmp-output-visitor.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/tests/test-qmp-output-visitor.c b/tests/test-qmp-output-visitor.c
index 965f298e11..2b0f7e9c53 100644
--- a/tests/test-qmp-output-visitor.c
+++ b/tests/test-qmp-output-visitor.c
@@ -1,7 +1,7 @@
/*
* QMP Output Visitor unit-tests.
*
- * Copyright (C) 2011, 2015 Red Hat Inc.
+ * Copyright (C) 2011-2016 Red Hat Inc.
*
* Authors:
* Luiz Capitulino <lcapitulino@redhat.com>
@@ -427,6 +427,7 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data,
{
QObject *arg;
UserDefAlternate *tmp;
+ QDict *qdict;
tmp = g_new0(UserDefAlternate, 1);
tmp->type = QTYPE_QINT;
@@ -453,6 +454,29 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data,
qapi_free_UserDefAlternate(tmp);
qobject_decref(arg);
+
+ tmp = g_new0(UserDefAlternate, 1);
+ tmp->type = QTYPE_QDICT;
+ tmp->u.udfu = g_new0(UserDefFlatUnion, 1);
+ tmp->u.udfu->integer = 1;
+ tmp->u.udfu->string = g_strdup("str");
+ tmp->u.udfu->enum1 = ENUM_ONE_VALUE1;
+ tmp->u.udfu->u.value1 = g_new0(UserDefA, 1);
+ tmp->u.udfu->u.value1->boolean = true;
+
+ visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort);
+ arg = qmp_output_get_qobject(data->qov);
+
+ g_assert_cmpint(qobject_type(arg), ==, QTYPE_QDICT);
+ qdict = qobject_to_qdict(arg);
+ g_assert_cmpint(qdict_size(qdict), ==, 4);
+ g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 1);
+ g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, "str");
+ g_assert_cmpstr(qdict_get_str(qdict, "enum1"), ==, "value1");
+ g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, true);
+
+ qapi_free_UserDefAlternate(tmp);
+ qobject_decref(arg);
}
static void test_visitor_out_empty(TestOutputVisitorData *data,