提交 ad11dbb9 编写于 作者: E Eric Blake 提交者: Markus Armbruster

qapi: Add some enum tests

Demonstrate that the qapi generator doesn't deal well with enums
that aren't up to par. Later patches will update the expected
results as the generator is made stricter.
Signed-off-by: NEric Blake <eblake@redhat.com>
Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
上级 fe2a9303
......@@ -207,7 +207,11 @@ $(foreach target,$(SYSEMU_TARGET_LIST), \
$(eval check-qtest-$(target)-y += tests/qom-test$(EXESUF))))
check-qapi-schema-y := $(addprefix tests/qapi-schema/, \
comments.json empty.json funny-char.json indented-expr.json \
comments.json empty.json enum-empty.json enum-missing-data.json \
enum-wrong-data.json enum-int-member.json enum-dict-member.json \
enum-clash-member.json enum-max-member.json enum-union-clash.json \
enum-bad-name.json \
funny-char.json indented-expr.json \
missing-colon.json missing-comma-list.json \
missing-comma-object.json non-objects.json \
qapi-schema-test.json quoted-structural-chars.json \
......
# FIXME: we should ensure all enum names can map to C
{ 'enum': 'MyEnum', 'data': [ 'not^possible' ] }
[OrderedDict([('enum', 'MyEnum'), ('data', ['not^possible'])])]
[{'enum_name': 'MyEnum', 'enum_values': ['not^possible']}]
[]
# FIXME: we should reject enums where members will clash when mapped to C enum
{ 'enum': 'MyEnum', 'data': [ 'one', 'ONE' ] }
[OrderedDict([('enum', 'MyEnum'), ('data', ['one', 'ONE'])])]
[{'enum_name': 'MyEnum', 'enum_values': ['one', 'ONE']}]
[]
# FIXME: we should reject any enum member that is not a string
{ 'enum': 'MyEnum', 'data': [ { 'value': 'str' } ] }
[OrderedDict([('enum', 'MyEnum'), ('data', [OrderedDict([('value', 'str')])])])]
[{'enum_name': 'MyEnum', 'enum_values': [OrderedDict([('value', 'str')])]}]
[]
# An empty enum, although unusual, is currently acceptable
{ 'enum': 'MyEnum', 'data': [ ] }
[OrderedDict([('enum', 'MyEnum'), ('data', [])])]
[{'enum_name': 'MyEnum', 'enum_values': []}]
[]
tests/qapi-schema/enum-int-member.json:3:31: Stray "1"
# we reject any enum member that is not a string
# FIXME: once the parser understands integer inputs, improve the error message
{ 'enum': 'MyEnum', 'data': [ 1 ] }
# FIXME: we should reject user-supplied 'max' for clashing with implicit enum end
# TODO: should we instead munge the implicit value to avoid the clash?
{ 'enum': 'MyEnum', 'data': [ 'max' ] }
[OrderedDict([('enum', 'MyEnum'), ('data', ['max'])])]
[{'enum_name': 'MyEnum', 'enum_values': ['max']}]
[]
Traceback (most recent call last):
File "tests/qapi-schema/test-qapi.py", line 19, in <module>
exprs = parse_schema(sys.argv[1])
File "scripts/qapi.py", line 334, in parse_schema
add_enum(expr['enum'], expr['data'])
KeyError: 'data'
# FIXME: we should require that all QAPI enums have a data array
{ 'enum': 'MyEnum' }
# FIXME: we should reject types that would conflict with implicit union enum
{ 'enum': 'UnionKind', 'data': [ 'oops' ] }
{ 'union': 'Union',
'data': { 'a': 'int' } }
[OrderedDict([('enum', 'UnionKind'), ('data', ['oops'])]),
OrderedDict([('union', 'Union'), ('data', OrderedDict([('a', 'int')]))])]
[{'enum_name': 'UnionKind', 'enum_values': ['oops']},
{'enum_name': 'UnionKind', 'enum_values': None}]
[]
# FIXME: we should require that all qapi enums have an array for data
{ 'enum': 'MyEnum', 'data': { 'value': 'str' } }
[OrderedDict([('enum', 'MyEnum'), ('data', OrderedDict([('value', 'str')]))])]
[{'enum_name': 'MyEnum', 'enum_values': OrderedDict([('value', 'str')])}]
[]
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册