summaryrefslogtreecommitdiff
path: root/tests/test-qmp-input-strict.c
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2014-03-04 17:01:07 +0000
committerPeter Maydell <peter.maydell@linaro.org>2014-03-04 17:01:07 +0000
commite00ef747f08db1c7dd58a5366db4dc3038a7307f (patch)
tree270bc41abb51663b18142fd6aeeb58c64f820230 /tests/test-qmp-input-strict.c
parent4a29420ea1c5a34191281855f5f51e70deab8940 (diff)
parentb774539743c52ef605c6e2cbac19376c2757cb86 (diff)
downloadqemu-e00ef747f08db1c7dd58a5366db4dc3038a7307f.tar.gz
Merge remote-tracking branch 'remotes/qmp-unstable/queue/qmp' into staging
* remotes/qmp-unstable/queue/qmp: (32 commits) qapi: Add missing null check to opts_start_struct() qapi: Clean up superfluous null check in qapi_dealloc_type_str() qapi: Clean up null checking in generated visitors qapi: Drop unused code in qapi-commands.py qapi: Drop nonsensical header guard in generated qapi-visit.c qapi: Fix licensing of scripts tests/qapi-schema: Cover flat union types tests/qapi-schema: Cover union types with base tests/qapi-schema: Cover complex types with base tests/qapi-schema: Cover anonymous union types tests/qapi-schema: Cover simple argument types tests/qapi-schema: Cover optional command arguments tests/qapi-schema: Actually check successful QMP command response monitor: Remove left-over code in do_info_profile. qerror: Improve QERR_DEVICE_NOT_ACTIVE message qmp: Check for returned data from __json_read in get_events dump: add 'query-dump-guest-memory-capability' command Define the architecture for compressed dump format dump: make kdump-compressed format available for 'dump-guest-memory' dump: add API to write dump pages ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests/test-qmp-input-strict.c')
-rw-r--r--tests/test-qmp-input-strict.c69
1 files changed, 67 insertions, 2 deletions
diff --git a/tests/test-qmp-input-strict.c b/tests/test-qmp-input-strict.c
index 38bdf5ec7c..64d72f6f05 100644
--- a/tests/test-qmp-input-strict.c
+++ b/tests/test-qmp-input-strict.c
@@ -132,13 +132,42 @@ static void test_validate_union(TestInputVisitorData *data,
Visitor *v;
Error *errp = NULL;
- v = validate_test_init(data, "{ 'type': 'b', 'data' : { 'integer': 42 } }");
+ v = validate_test_init(data, "{ 'type': 'b', 'integer': 41, 'data' : { 'integer': 42 } }");
visit_type_UserDefUnion(v, &tmp, NULL, &errp);
g_assert(!errp);
qapi_free_UserDefUnion(tmp);
}
+static void test_validate_union_flat(TestInputVisitorData *data,
+ const void *unused)
+{
+ UserDefFlatUnion *tmp = NULL;
+ Visitor *v;
+ Error *errp = NULL;
+
+ v = validate_test_init(data, "{ 'string': 'a', 'boolean': true }");
+ /* TODO when generator bug is fixed, add 'integer': 41 */
+
+ visit_type_UserDefFlatUnion(v, &tmp, NULL, &errp);
+ g_assert(!error_is_set(&errp));
+ qapi_free_UserDefFlatUnion(tmp);
+}
+
+static void test_validate_union_anon(TestInputVisitorData *data,
+ const void *unused)
+{
+ UserDefAnonUnion *tmp = NULL;
+ Visitor *v;
+ Error *errp = NULL;
+
+ v = validate_test_init(data, "42");
+
+ visit_type_UserDefAnonUnion(v, &tmp, NULL, &errp);
+ g_assert(!error_is_set(&errp));
+ qapi_free_UserDefAnonUnion(tmp);
+}
+
static void test_validate_fail_struct(TestInputVisitorData *data,
const void *unused)
{
@@ -191,13 +220,41 @@ static void test_validate_fail_union(TestInputVisitorData *data,
Error *errp = NULL;
Visitor *v;
- v = validate_test_init(data, "{ 'type': 'b', 'data' : { 'integer': 42 }, 'extra': 'yyy' }");
+ v = validate_test_init(data, "{ 'type': 'b', 'data' : { 'integer': 42 } }");
visit_type_UserDefUnion(v, &tmp, NULL, &errp);
g_assert(errp);
qapi_free_UserDefUnion(tmp);
}
+static void test_validate_fail_union_flat(TestInputVisitorData *data,
+ const void *unused)
+{
+ UserDefFlatUnion *tmp = NULL;
+ Error *errp = NULL;
+ Visitor *v;
+
+ v = validate_test_init(data, "{ 'string': 'c', 'integer': 41, 'boolean': true }");
+
+ visit_type_UserDefFlatUnion(v, &tmp, NULL, &errp);
+ g_assert(error_is_set(&errp));
+ qapi_free_UserDefFlatUnion(tmp);
+}
+
+static void test_validate_fail_union_anon(TestInputVisitorData *data,
+ const void *unused)
+{
+ UserDefAnonUnion *tmp = NULL;
+ Visitor *v;
+ Error *errp = NULL;
+
+ v = validate_test_init(data, "3.14");
+
+ visit_type_UserDefAnonUnion(v, &tmp, NULL, &errp);
+ g_assert(error_is_set(&errp));
+ qapi_free_UserDefAnonUnion(tmp);
+}
+
static void validate_test_add(const char *testpath,
TestInputVisitorData *data,
void (*test_func)(TestInputVisitorData *data, const void *user_data))
@@ -220,6 +277,10 @@ int main(int argc, char **argv)
&testdata, test_validate_list);
validate_test_add("/visitor/input-strict/pass/union",
&testdata, test_validate_union);
+ validate_test_add("/visitor/input-strict/pass/union-flat",
+ &testdata, test_validate_union_flat);
+ validate_test_add("/visitor/input-strict/pass/union-anon",
+ &testdata, test_validate_union_anon);
validate_test_add("/visitor/input-strict/fail/struct",
&testdata, test_validate_fail_struct);
validate_test_add("/visitor/input-strict/fail/struct-nested",
@@ -228,6 +289,10 @@ int main(int argc, char **argv)
&testdata, test_validate_fail_list);
validate_test_add("/visitor/input-strict/fail/union",
&testdata, test_validate_fail_union);
+ validate_test_add("/visitor/input-strict/fail/union-flat",
+ &testdata, test_validate_fail_union_flat);
+ validate_test_add("/visitor/input-strict/fail/union-anon",
+ &testdata, test_validate_fail_union_anon);
g_test_run();