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,16 @@ 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-data.json',
+ 'union-clash-member-type.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-data.json: In union 'MyUnion':
+union-clash-member-data.json:4: member 'data' of type 'Branch' collides with flat representation of branch 'one'
new file mode 100644
@@ -0,0 +1,6 @@
+# For simple union branches, a 'data' member would prevent conversion
+# to flat representation, so we don't want to allow it
+{ 'struct': 'Branch', 'data': { 'data': 'str' } }
+{ 'union': 'MyUnion',
+ 'data': { 'one': 'Branch',
+ 'two': 'Branch' } }
new file mode 100644
new file mode 100644
@@ -0,0 +1,2 @@
+union-clash-member-type.json: In union 'MyUnion':
+union-clash-member-type.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 | 5 +++++ 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-data.err | 2 ++ tests/qapi-schema/union-clash-member-data.json | 6 ++++++ tests/qapi-schema/union-clash-member-data.out | 0 tests/qapi-schema/union-clash-member-type.err | 2 ++ tests/qapi-schema/union-clash-member-type.json | 6 ++++++ tests/qapi-schema/union-clash-member-type.out | 0 18 files changed, 71 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-data.err create mode 100644 tests/qapi-schema/union-clash-member-data.json create mode 100644 tests/qapi-schema/union-clash-member-data.out create mode 100644 tests/qapi-schema/union-clash-member-type.err create mode 100644 tests/qapi-schema/union-clash-member-type.json create mode 100644 tests/qapi-schema/union-clash-member-type.out diff --git a/tests/qapi-schema/union-clash-member-type.out b/tests/qapi-schema/union-clash-member-type.out new file mode 100644 index 0000000000..e69de29bb2