new file mode 100644
@@ -0,0 +1,2 @@
+flat-union-allow-flat.json: In union 'MyUnion':
+flat-union-allow-flat.json:6: 'allow-flat' requires simple union
new file mode 100644
@@ -0,0 +1,10 @@
+# Flat unions must not use allow-flat
+{ 'enum': 'Enum', 'data': [ 'one', 'two' ] }
+{ 'struct': 'Base',
+ 'data': { 'switch': 'Enum' } }
+{ 'struct': 'Branch', 'data': { 'name': 'str' } }
+{ 'union': 'MyUnion',
+ 'base': 'Base',
+ 'discriminator': 'switch',
+ 'data': { 'one': { 'type': 'Branch', 'allow-flat': true },
+ 'two': 'Branch' } }
new file mode 100644
@@ -103,6 +103,7 @@ schemas = [
'features-name-bad-type.json',
'features-no-list.json',
'features-unknown-key.json',
+ 'flat-union-allow-flat.json',
'flat-union-array-branch.json',
'flat-union-bad-base.json',
'flat-union-bad-discriminator.json',
@@ -184,12 +185,15 @@ schemas = [
'unclosed-list.json',
'unclosed-object.json',
'unclosed-string.json',
+ 'union-allow-flat-bad.json',
+ 'union-allow-flat-builtin-type.json',
'union-base-empty.json',
'union-base-no-discriminator.json',
'union-branch-case.json',
'union-branch-if-invalid.json',
'union-branch-invalid-dict.json',
'union-clash-branches.json',
+ 'union-clash-member.json',
'union-empty.json',
'union-invalid-base.json',
'union-optional-branch.json',
@@ -110,6 +110,16 @@
{ 'struct': 'UserDefC',
'data': { 'string1': 'str', 'string2': 'str' } }
+{ 'struct': 'UserDefD',
+ 'data': { 'type': 'str' } }
+
+{ 'union': 'UserDefSimpleUnion',
+ 'data': { 'value1' : {'type': 'UserDefA'},
+ 'value2' : 'UserDefB',
+ 'value3' : 'UserDefB',
+ 'value4' : { 'type': 'UserDefD', 'allow-flat': false }
+ } }
+
# for testing use of 'number' within alternates
{ 'alternate': 'AltEnumBool', 'data': { 'e': 'EnumOne', 'b': 'bool' } }
{ 'alternate': 'AltEnumNum', 'data': { 'e': 'EnumOne', 'n': 'number' } }
@@ -105,6 +105,20 @@ alternate UserDefAlternate
object UserDefC
member string1: str optional=False
member string2: str optional=False
+object UserDefD
+ member type: str optional=False
+enum UserDefSimpleUnionKind
+ member value1
+ member value2
+ member value3
+ member value4
+object UserDefSimpleUnion
+ member type: UserDefSimpleUnionKind optional=False
+ tag type
+ case value1: UserDefA
+ case value2: UserDefB
+ case value3: UserDefB
+ case value4: UserDefD
alternate AltEnumBool
tag type
case e: EnumOne
new file mode 100644
@@ -0,0 +1,2 @@
+union-allow-flat-bad.json: In union 'MyUnion':
+union-allow-flat-bad.json:3: 'allow-flat' must be a boolean
new file mode 100644
@@ -0,0 +1,5 @@
+# allow-flat must be a boolean
+{ 'struct': 'Branch', 'data': { 'name': 'str' } }
+{ 'union': 'MyUnion',
+ 'data': { 'one': { 'type': 'Branch', 'allow-flat': 'maybe' },
+ 'two': 'Branch' } }
new file mode 100644
new file mode 100644
@@ -0,0 +1,2 @@
+union-allow-flat-builtin-type.json: In union 'MyUnion':
+union-allow-flat-builtin-type.json:3: branch 'one' cannot use built-in type 'int'
new file mode 100644
@@ -0,0 +1,5 @@
+# Can't use built-in types for branches with 'allow-flat': true
+{ 'struct': 'Branch', 'data': { 'name': 'str' } }
+{ 'union': 'MyUnion',
+ 'data': { 'one': { 'type': 'int', 'allow-flat': true },
+ 'two': 'Branch' } }
new file mode 100644
new file mode 100644
@@ -0,0 +1,2 @@
+union-clash-member.json: In union 'MyUnion':
+union-clash-member.json:4: member 'type' of type 'Branch' collides with member 'type'
new file mode 100644
@@ -0,0 +1,6 @@
+# 'type' is in the implicit base type and clashes with a 'type' member
+# in branches if flat representation is not disabled
+{ 'struct': 'Branch', 'data': { 'type': 'str' } }
+{ 'union': 'MyUnion',
+ 'data': { 'one': 'Branch',
+ 'two': 'Branch' } }
This adds some test cases related to flat representation of simple unions and the 'allow-flat' option for union branches. Signed-off-by: Kevin Wolf <kwolf@redhat.com> --- tests/qapi-schema/flat-union-allow-flat.err | 2 ++ tests/qapi-schema/flat-union-allow-flat.json | 10 ++++++++++ tests/qapi-schema/flat-union-allow-flat.out | 0 tests/qapi-schema/meson.build | 4 ++++ tests/qapi-schema/qapi-schema-test.json | 10 ++++++++++ tests/qapi-schema/qapi-schema-test.out | 14 ++++++++++++++ tests/qapi-schema/union-allow-flat-bad.err | 2 ++ tests/qapi-schema/union-allow-flat-bad.json | 5 +++++ tests/qapi-schema/union-allow-flat-bad.out | 0 .../qapi-schema/union-allow-flat-builtin-type.err | 2 ++ .../qapi-schema/union-allow-flat-builtin-type.json | 5 +++++ .../qapi-schema/union-allow-flat-builtin-type.out | 0 tests/qapi-schema/union-clash-member.err | 2 ++ tests/qapi-schema/union-clash-member.json | 6 ++++++ tests/qapi-schema/union-clash-member.out | 0 15 files changed, 62 insertions(+) create mode 100644 tests/qapi-schema/flat-union-allow-flat.err create mode 100644 tests/qapi-schema/flat-union-allow-flat.json create mode 100644 tests/qapi-schema/flat-union-allow-flat.out create mode 100644 tests/qapi-schema/union-allow-flat-bad.err create mode 100644 tests/qapi-schema/union-allow-flat-bad.json create mode 100644 tests/qapi-schema/union-allow-flat-bad.out create mode 100644 tests/qapi-schema/union-allow-flat-builtin-type.err create mode 100644 tests/qapi-schema/union-allow-flat-builtin-type.json create mode 100644 tests/qapi-schema/union-allow-flat-builtin-type.out create mode 100644 tests/qapi-schema/union-clash-member.err create mode 100644 tests/qapi-schema/union-clash-member.json create mode 100644 tests/qapi-schema/union-clash-member.out diff --git a/tests/qapi-schema/union-clash-member.out b/tests/qapi-schema/union-clash-member.out new file mode 100644 index 0000000000..e69de29bb2