diff options
author | Wenchao Xia <wenchaoqemu@gmail.com> | 2014-03-06 17:08:56 -0800 |
---|---|---|
committer | Luiz Capitulino <lcapitulino@redhat.com> | 2014-03-11 09:07:42 -0400 |
commit | bceae7697ff1711675c26f715b945737bc6849ae (patch) | |
tree | b528a35656db4d66e9c5be5be54edc7cbeb79344 /tests | |
parent | b0b58195e4a3039b6a473124dc27ed707db50240 (diff) | |
download | qemu-bceae7697ff1711675c26f715b945737bc6849ae.tar.gz qemu-bceae7697ff1711675c26f715b945737bc6849ae.tar.bz2 qemu-bceae7697ff1711675c26f715b945737bc6849ae.zip |
qapi script: support enum type as discriminator in union
By default, any union will automatically generate a enum type as
"[UnionName]Kind" in C code, and it is duplicated when the discriminator
is specified as a pre-defined enum type in schema. After this patch,
the pre-defined enum type will be really used as the switch case
condition in generated C code, if discriminator is an enum field.
Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile | 2 | ||||
-rw-r--r-- | tests/qapi-schema/flat-union-reverse-define.err | 0 | ||||
-rw-r--r-- | tests/qapi-schema/flat-union-reverse-define.exit | 1 | ||||
-rw-r--r-- | tests/qapi-schema/flat-union-reverse-define.json | 17 | ||||
-rw-r--r-- | tests/qapi-schema/flat-union-reverse-define.out | 9 |
5 files changed, 28 insertions, 1 deletions
diff --git a/tests/Makefile b/tests/Makefile index 6ac988932b..88fca31276 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -145,7 +145,7 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \ unclosed-list.json unclosed-object.json unclosed-string.json \ duplicate-key.json union-invalid-base.json flat-union-no-base.json \ flat-union-invalid-discriminator.json \ - flat-union-invalid-branch-key.json) + flat-union-invalid-branch-key.json flat-union-reverse-define.json) GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h tests/test-qmp-commands.h diff --git a/tests/qapi-schema/flat-union-reverse-define.err b/tests/qapi-schema/flat-union-reverse-define.err new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/qapi-schema/flat-union-reverse-define.err diff --git a/tests/qapi-schema/flat-union-reverse-define.exit b/tests/qapi-schema/flat-union-reverse-define.exit new file mode 100644 index 0000000000..573541ac97 --- /dev/null +++ b/tests/qapi-schema/flat-union-reverse-define.exit @@ -0,0 +1 @@ +0 diff --git a/tests/qapi-schema/flat-union-reverse-define.json b/tests/qapi-schema/flat-union-reverse-define.json new file mode 100644 index 0000000000..9ea7e72201 --- /dev/null +++ b/tests/qapi-schema/flat-union-reverse-define.json @@ -0,0 +1,17 @@ +{ 'union': 'TestUnion', + 'base': 'TestBase', + 'discriminator': 'enum1', + 'data': { 'value1': 'TestTypeA', + 'value2': 'TestTypeB' } } + +{ 'type': 'TestBase', + 'data': { 'enum1': 'TestEnum' } } + +{ 'enum': 'TestEnum', + 'data': [ 'value1', 'value2' ] } + +{ 'type': 'TestTypeA', + 'data': { 'string': 'str' } } + +{ 'type': 'TestTypeB', + 'data': { 'integer': 'int' } } diff --git a/tests/qapi-schema/flat-union-reverse-define.out b/tests/qapi-schema/flat-union-reverse-define.out new file mode 100644 index 0000000000..03c952e28a --- /dev/null +++ b/tests/qapi-schema/flat-union-reverse-define.out @@ -0,0 +1,9 @@ +[OrderedDict([('union', 'TestUnion'), ('base', 'TestBase'), ('discriminator', 'enum1'), ('data', OrderedDict([('value1', 'TestTypeA'), ('value2', 'TestTypeB')]))]), + OrderedDict([('type', 'TestBase'), ('data', OrderedDict([('enum1', 'TestEnum')]))]), + OrderedDict([('enum', 'TestEnum'), ('data', ['value1', 'value2'])]), + OrderedDict([('type', 'TestTypeA'), ('data', OrderedDict([('string', 'str')]))]), + OrderedDict([('type', 'TestTypeB'), ('data', OrderedDict([('integer', 'int')]))])] +[{'enum_name': 'TestEnum', 'enum_values': ['value1', 'value2']}] +[OrderedDict([('type', 'TestBase'), ('data', OrderedDict([('enum1', 'TestEnum')]))]), + OrderedDict([('type', 'TestTypeA'), ('data', OrderedDict([('string', 'str')]))]), + OrderedDict([('type', 'TestTypeB'), ('data', OrderedDict([('integer', 'int')]))])] |