aboutsummaryrefslogtreecommitdiff
path: root/tests/qapi-schema/flat-union-bad-discriminator.json
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2015-05-04 09:05:05 -0600
committerMarkus Armbruster <armbru@redhat.com>2015-05-05 18:39:00 +0200
commit3d0c48292633260269cb21551d9bab006b2f2781 (patch)
tree597530c70700eb11506447f078e7726a541aabf4 /tests/qapi-schema/flat-union-bad-discriminator.json
parentcf3935907b5df16f667d54ad6761c7e937dcf425 (diff)
qapi: Add some union tests
Demonstrate that the qapi generator doesn't deal well with unions that aren't up to par. Later patches will update the expected reseults as the generator is made stricter. A few tests work as planned, but most show poor or missing error messages. Of particular note, qapi-code-gen.txt documents 'base' only for flat unions, but the tests here demonstrate that we currently allow a 'base' to a simple union, although it is exercised only in the testsuite. Later patches will remove this undocumented feature, to give us more flexibility in adding other future extensions to union types. For example, one possible extension is the idea of a type-safe simple enum, where added fields tie the discriminator to a user-defined enum type rather than creating an implicit enum from the names in 'data'. But adding such safety on top of a simple enum with a base type could look ambiguous with a flat enum; besides, the documentation also mentions how any simple union can be represented by an equivalent flat union. So it will be simpler to just outlaw support for something we aren't using. Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'tests/qapi-schema/flat-union-bad-discriminator.json')
-rw-r--r--tests/qapi-schema/flat-union-bad-discriminator.json14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/qapi-schema/flat-union-bad-discriminator.json b/tests/qapi-schema/flat-union-bad-discriminator.json
new file mode 100644
index 0000000000..1599a59454
--- /dev/null
+++ b/tests/qapi-schema/flat-union-bad-discriminator.json
@@ -0,0 +1,14 @@
+# FIXME: we should require the discriminator to be a string naming a base-type member
+{ 'enum': 'TestEnum',
+ 'data': [ 'value1', 'value2' ] }
+{ 'type': 'TestBase',
+ 'data': { 'enum1': 'TestEnum', 'kind': 'str' } }
+{ 'type': 'TestTypeA',
+ 'data': { 'string': 'str' } }
+{ 'type': 'TestTypeB',
+ 'data': { 'integer': 'int' } }
+{ 'union': 'TestUnion',
+ 'base': 'TestBase',
+ 'discriminator': [],
+ 'data': { 'kind1': 'TestTypeA',
+ 'kind2': 'TestTypeB' } }