aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2021-09-27 15:03:42 +0100
committerPeter Maydell <peter.maydell@linaro.org>2021-09-27 15:03:42 +0100
commitde8ed1055c2ce18c95f597eb10df360dcb534f99 (patch)
tree2554d4c016c5c7cc5bf9a8bc0dcde28b7ceef9b1 /tests
parent9b03a1178204598055f23f24e438fdddb5935df9 (diff)
parentf333681c6e277004796b0bed808697da1280d140 (diff)
downloadqemu-de8ed1055c2ce18c95f597eb10df360dcb534f99.zip
qemu-de8ed1055c2ce18c95f597eb10df360dcb534f99.tar.gz
qemu-de8ed1055c2ce18c95f597eb10df360dcb534f99.tar.bz2
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2021-09-25-v2' into staging
QAPI patches patches for 2021-09-25 # gpg: Signature made Mon 27 Sep 2021 13:44:23 BST # gpg: using RSA key 354BC8B3D7EB2A6B68674E5F3870B400EB918653 # gpg: issuer "armbru@redhat.com" # gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" [full] # gpg: aka "Markus Armbruster <armbru@pond.sub.org>" [full] # Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867 4E5F 3870 B400 EB91 8653 * remotes/armbru/tags/pull-qapi-2021-09-25-v2: (25 commits) tests/qapi-schema: Make test-qapi.py -u work when files are absent tests/qapi-schema: Use Python OSError instead of outmoded IOError test-clone-visitor: Correct an accidental rename tests/qapi-schema: Rename flat-union-* test cases to union-* qapi: Drop simple unions tests/qapi-schema: Purge simple unions from tests tests/qapi-schema: Drop simple union __org.qemu_x-Union1 test-clone-visitor: Wean off __org.qemu_x-Union1 tests/qapi-schema: Rewrite simple union TestIfUnion to be flat tests/qapi-schema: Simple union UserDefListUnion is now unused, drop tests/qapi-schema: Wean off UserDefListUnion test-clone-visitor: Wean off UserDefListUnion test-qobject-output-visitor: Wean off UserDefListUnion test-qobject-input-visitor: Wean off UserDefListUnion tests/qapi-schema: Prepare for simple union UserDefListUnion removal qapi: Convert simple union TransactionAction to flat one qapi: Convert simple union ImageInfoSpecific to flat one qapi: Convert simple union SocketAddressLegacy to flat one qapi: Convert simple union ChardevBackend to flat one qapi: Convert simple union MemoryDeviceInfo to flat one ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/qapi-schema/args-union.err2
-rw-r--r--tests/qapi-schema/args-union.json8
-rw-r--r--tests/qapi-schema/bad-base.err2
-rw-r--r--tests/qapi-schema/bad-base.json8
-rw-r--r--tests/qapi-schema/doc-good.json13
-rw-r--r--tests/qapi-schema/doc-good.out22
-rw-r--r--tests/qapi-schema/doc-good.txt20
-rw-r--r--tests/qapi-schema/enum-if-invalid.json4
-rw-r--r--tests/qapi-schema/flat-union-array-branch.err2
-rw-r--r--tests/qapi-schema/flat-union-bad-base.err2
-rw-r--r--tests/qapi-schema/flat-union-bad-discriminator.err2
-rw-r--r--tests/qapi-schema/flat-union-base-any.err2
-rw-r--r--tests/qapi-schema/flat-union-base-union.err2
-rw-r--r--tests/qapi-schema/flat-union-clash-member.err2
-rw-r--r--tests/qapi-schema/flat-union-discriminator-bad-name.err2
-rw-r--r--tests/qapi-schema/flat-union-empty.err2
-rw-r--r--tests/qapi-schema/flat-union-empty.json4
-rw-r--r--tests/qapi-schema/flat-union-inline-invalid-dict.err2
-rw-r--r--tests/qapi-schema/flat-union-int-branch.err2
-rw-r--r--tests/qapi-schema/flat-union-invalid-branch-key.err2
-rw-r--r--tests/qapi-schema/flat-union-invalid-discriminator.err2
-rw-r--r--tests/qapi-schema/flat-union-invalid-if-discriminator.err2
-rw-r--r--tests/qapi-schema/flat-union-no-base.err2
-rw-r--r--tests/qapi-schema/flat-union-optional-discriminator.err2
-rw-r--r--tests/qapi-schema/flat-union-string-discriminator.err2
-rw-r--r--tests/qapi-schema/flat-union-string-discriminator.out0
-rw-r--r--tests/qapi-schema/meson.build35
-rw-r--r--tests/qapi-schema/qapi-schema-test.json51
-rw-r--r--tests/qapi-schema/qapi-schema-test.out116
-rw-r--r--tests/qapi-schema/reserved-member-u.json2
-rw-r--r--tests/qapi-schema/reserved-type-kind.err2
-rw-r--r--tests/qapi-schema/reserved-type-kind.json2
-rw-r--r--tests/qapi-schema/reserved-type-kind.out0
-rwxr-xr-xtests/qapi-schema/test-qapi.py20
-rw-r--r--tests/qapi-schema/union-array-branch.err2
-rw-r--r--tests/qapi-schema/union-array-branch.json (renamed from tests/qapi-schema/flat-union-array-branch.json)2
-rw-r--r--tests/qapi-schema/union-array-branch.out (renamed from tests/qapi-schema/flat-union-array-branch.out)0
-rw-r--r--tests/qapi-schema/union-bad-base.err2
-rw-r--r--tests/qapi-schema/union-bad-base.json (renamed from tests/qapi-schema/flat-union-bad-base.json)0
-rw-r--r--tests/qapi-schema/union-bad-base.out (renamed from tests/qapi-schema/flat-union-bad-base.out)0
-rw-r--r--tests/qapi-schema/union-bad-discriminator.err2
-rw-r--r--tests/qapi-schema/union-bad-discriminator.json (renamed from tests/qapi-schema/flat-union-bad-discriminator.json)0
-rw-r--r--tests/qapi-schema/union-bad-discriminator.out (renamed from tests/qapi-schema/flat-union-bad-discriminator.out)0
-rw-r--r--tests/qapi-schema/union-base-any.err2
-rw-r--r--tests/qapi-schema/union-base-any.json (renamed from tests/qapi-schema/flat-union-base-any.json)0
-rw-r--r--tests/qapi-schema/union-base-any.out (renamed from tests/qapi-schema/flat-union-base-any.out)0
-rw-r--r--tests/qapi-schema/union-base-empty.json2
-rw-r--r--tests/qapi-schema/union-base-no-discriminator.err2
-rw-r--r--tests/qapi-schema/union-base-no-discriminator.json2
-rw-r--r--tests/qapi-schema/union-base-union.err2
-rw-r--r--tests/qapi-schema/union-base-union.json (renamed from tests/qapi-schema/flat-union-base-union.json)3
-rw-r--r--tests/qapi-schema/union-base-union.out (renamed from tests/qapi-schema/flat-union-base-union.out)0
-rw-r--r--tests/qapi-schema/union-branch-case.err2
-rw-r--r--tests/qapi-schema/union-branch-case.json2
-rw-r--r--tests/qapi-schema/union-branch-case.out0
-rw-r--r--tests/qapi-schema/union-branch-invalid-dict.err2
-rw-r--r--tests/qapi-schema/union-branch-invalid-dict.json4
-rw-r--r--tests/qapi-schema/union-clash-branches.err2
-rw-r--r--tests/qapi-schema/union-clash-branches.json7
-rw-r--r--tests/qapi-schema/union-clash-branches.out0
-rw-r--r--tests/qapi-schema/union-clash-member.err2
-rw-r--r--tests/qapi-schema/union-clash-member.json (renamed from tests/qapi-schema/flat-union-clash-member.json)0
-rw-r--r--tests/qapi-schema/union-clash-member.out (renamed from tests/qapi-schema/flat-union-clash-member.out)0
-rw-r--r--tests/qapi-schema/union-discriminator-bad-name.err2
-rw-r--r--tests/qapi-schema/union-discriminator-bad-name.json (renamed from tests/qapi-schema/flat-union-discriminator-bad-name.json)0
-rw-r--r--tests/qapi-schema/union-discriminator-bad-name.out (renamed from tests/qapi-schema/flat-union-discriminator-bad-name.out)0
-rw-r--r--tests/qapi-schema/union-empty.err2
-rw-r--r--tests/qapi-schema/union-empty.json6
-rw-r--r--tests/qapi-schema/union-inline-invalid-dict.err2
-rw-r--r--tests/qapi-schema/union-inline-invalid-dict.json (renamed from tests/qapi-schema/flat-union-inline-invalid-dict.json)0
-rw-r--r--tests/qapi-schema/union-inline-invalid-dict.out (renamed from tests/qapi-schema/flat-union-empty.out)0
-rw-r--r--tests/qapi-schema/union-int-branch.err2
-rw-r--r--tests/qapi-schema/union-int-branch.json (renamed from tests/qapi-schema/flat-union-int-branch.json)2
-rw-r--r--tests/qapi-schema/union-int-branch.out (renamed from tests/qapi-schema/flat-union-inline-invalid-dict.out)0
-rw-r--r--tests/qapi-schema/union-invalid-branch-key.err2
-rw-r--r--tests/qapi-schema/union-invalid-branch-key.json (renamed from tests/qapi-schema/flat-union-invalid-branch-key.json)0
-rw-r--r--tests/qapi-schema/union-invalid-branch-key.out (renamed from tests/qapi-schema/flat-union-int-branch.out)0
-rw-r--r--tests/qapi-schema/union-invalid-discriminator.err2
-rw-r--r--tests/qapi-schema/union-invalid-discriminator.json (renamed from tests/qapi-schema/flat-union-invalid-discriminator.json)0
-rw-r--r--tests/qapi-schema/union-invalid-discriminator.out (renamed from tests/qapi-schema/flat-union-invalid-branch-key.out)0
-rw-r--r--tests/qapi-schema/union-invalid-if-discriminator.err2
-rw-r--r--tests/qapi-schema/union-invalid-if-discriminator.json (renamed from tests/qapi-schema/flat-union-invalid-if-discriminator.json)0
-rw-r--r--tests/qapi-schema/union-invalid-if-discriminator.out (renamed from tests/qapi-schema/flat-union-invalid-discriminator.out)0
-rw-r--r--tests/qapi-schema/union-no-base.err2
-rw-r--r--tests/qapi-schema/union-no-base.json (renamed from tests/qapi-schema/flat-union-no-base.json)2
-rw-r--r--tests/qapi-schema/union-no-base.out (renamed from tests/qapi-schema/flat-union-invalid-if-discriminator.out)0
-rw-r--r--tests/qapi-schema/union-optional-branch.err2
-rw-r--r--tests/qapi-schema/union-optional-branch.json2
-rw-r--r--tests/qapi-schema/union-optional-branch.out0
-rw-r--r--tests/qapi-schema/union-optional-discriminator.err2
-rw-r--r--tests/qapi-schema/union-optional-discriminator.json (renamed from tests/qapi-schema/flat-union-optional-discriminator.json)0
-rw-r--r--tests/qapi-schema/union-optional-discriminator.out (renamed from tests/qapi-schema/flat-union-no-base.out)0
-rw-r--r--tests/qapi-schema/union-string-discriminator.err2
-rw-r--r--tests/qapi-schema/union-string-discriminator.json (renamed from tests/qapi-schema/flat-union-string-discriminator.json)0
-rw-r--r--tests/qapi-schema/union-string-discriminator.out (renamed from tests/qapi-schema/flat-union-optional-discriminator.out)0
-rw-r--r--tests/qapi-schema/union-unknown.err2
-rw-r--r--tests/qapi-schema/union-unknown.json5
-rw-r--r--tests/unit/test-clone-visitor.c104
-rw-r--r--tests/unit/test-qmp-cmds.c18
-rw-r--r--tests/unit/test-qobject-input-visitor.c460
-rw-r--r--tests/unit/test-qobject-output-visitor.c389
-rw-r--r--tests/unit/test-yank.c6
102 files changed, 466 insertions, 937 deletions
diff --git a/tests/qapi-schema/args-union.err b/tests/qapi-schema/args-union.err
index 4bf4955..4b80a99 100644
--- a/tests/qapi-schema/args-union.err
+++ b/tests/qapi-schema/args-union.err
@@ -1,2 +1,2 @@
args-union.json: In command 'oops':
-args-union.json:3: command's 'data' can take union type 'Uni' only with 'boxed': true
+args-union.json:9: command's 'data' can take union type 'Uni' only with 'boxed': true
diff --git a/tests/qapi-schema/args-union.json b/tests/qapi-schema/args-union.json
index 2fcaeaa..aabb159 100644
--- a/tests/qapi-schema/args-union.json
+++ b/tests/qapi-schema/args-union.json
@@ -1,3 +1,9 @@
# use of union arguments requires 'boxed':true
-{ 'union': 'Uni', 'data': { 'case1': 'int', 'case2': 'str' } }
+{ 'enum': 'Enum', 'data': [ 'case1', 'case2' ] }
+{ 'struct': 'Case1', 'data': { 'data': 'int' } }
+{ 'struct': 'Case2', 'data': { 'data': 'str' } }
+{ 'union': 'Uni',
+ 'base': { 'type': 'Enum' },
+ 'discriminator': 'type',
+ 'data': { 'case1': 'Case1', 'case2': 'Case2' } }
{ 'command': 'oops', 'data': 'Uni' }
diff --git a/tests/qapi-schema/bad-base.err b/tests/qapi-schema/bad-base.err
index 61a1efc..1fad63e 100644
--- a/tests/qapi-schema/bad-base.err
+++ b/tests/qapi-schema/bad-base.err
@@ -1,2 +1,2 @@
bad-base.json: In struct 'MyType':
-bad-base.json:3: 'base' requires a struct type, union type 'Union' isn't
+bad-base.json:9: 'base' requires a struct type, union type 'Union' isn't
diff --git a/tests/qapi-schema/bad-base.json b/tests/qapi-schema/bad-base.json
index a634331..8c773ff 100644
--- a/tests/qapi-schema/bad-base.json
+++ b/tests/qapi-schema/bad-base.json
@@ -1,3 +1,9 @@
# we reject a base that is not a struct
-{ 'union': 'Union', 'data': { 'a': 'int', 'b': 'str' } }
+{ 'enum': 'Enum', 'data': [ 'a', 'b' ] }
+{ 'struct': 'Int', 'data': { 'data': 'int' } }
+{ 'struct': 'Str', 'data': { 'data': 'str' } }
+{ 'union': 'Union',
+ 'base': { 'type': 'Enum' },
+ 'discriminator': 'type',
+ 'data': { 'a': 'Int', 'b': 'Str' } }
{ 'struct': 'MyType', 'base': 'Union', 'data': { 'c': 'int' } }
diff --git a/tests/qapi-schema/doc-good.json b/tests/qapi-schema/doc-good.json
index e0027e4..a20acff 100644
--- a/tests/qapi-schema/doc-good.json
+++ b/tests/qapi-schema/doc-good.json
@@ -60,8 +60,8 @@
#
# @two is undocumented
##
-{ 'enum': 'Enum', 'data':
- [ { 'name': 'one', 'if': 'IFONE' }, 'two' ],
+{ 'enum': 'Enum',
+ 'data': [ { 'name': 'one', 'if': 'IFONE' }, 'two' ],
'features': [ 'enum-feat' ],
'if': 'IFCOND' }
@@ -108,15 +108,6 @@
'if': { 'any': ['IFONE', 'IFTWO'] } } } }
##
-# @SugaredUnion:
-# Features:
-# @union-feat2: a feature
-##
-{ 'union': 'SugaredUnion',
- 'features': [ 'union-feat2' ],
- 'data': { 'one': 'Variant1', 'two': { 'type': 'Variant2', 'if': 'IFTWO' } } }
-
-##
# @Alternate:
# @i: an integer
# @b is undocumented
diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out
index 478fe6f..5a324e2 100644
--- a/tests/qapi-schema/doc-good.out
+++ b/tests/qapi-schema/doc-good.out
@@ -32,21 +32,6 @@ object Object
case two: Variant2
if {'any': ['IFONE', 'IFTWO']}
feature union-feat1
-object q_obj_Variant1-wrapper
- member data: Variant1 optional=False
-object q_obj_Variant2-wrapper
- member data: Variant2 optional=False
-enum SugaredUnionKind
- member one
- member two
- if IFTWO
-object SugaredUnion
- member type: SugaredUnionKind optional=False
- tag type
- case one: q_obj_Variant1-wrapper
- case two: q_obj_Variant2-wrapper
- if IFTWO
- feature union-feat2
alternate Alternate
tag type
case i: int
@@ -149,13 +134,6 @@ doc symbol=Object
feature=union-feat1
a feature
-doc symbol=SugaredUnion
- body=
-
- arg=type
-
- feature=union-feat2
-a feature
doc symbol=Alternate
body=
diff --git a/tests/qapi-schema/doc-good.txt b/tests/qapi-schema/doc-good.txt
index 0c59d75..701402e 100644
--- a/tests/qapi-schema/doc-good.txt
+++ b/tests/qapi-schema/doc-good.txt
@@ -130,26 +130,6 @@ Features
a feature
-"SugaredUnion" (Object)
------------------------
-
-
-Members
-~~~~~~~
-
-"type"
- One of "one", "two"
-
-"data": "Variant1" when "type" is ""one""
-"data": "Variant2" when "type" is ""two"" (**If: **"IFTWO")
-
-Features
-~~~~~~~~
-
-"union-feat2"
- a feature
-
-
"Alternate" (Alternate)
-----------------------
diff --git a/tests/qapi-schema/enum-if-invalid.json b/tests/qapi-schema/enum-if-invalid.json
index 60bd0ef..6bd2004 100644
--- a/tests/qapi-schema/enum-if-invalid.json
+++ b/tests/qapi-schema/enum-if-invalid.json
@@ -1,3 +1,3 @@
# check invalid 'if' type
-{ 'enum': 'TestIfEnum', 'data':
- [ 'foo', { 'name' : 'bar', 'if': { 'val': 'foo' } } ] }
+{ 'enum': 'TestIfEnum',
+ 'data': [ 'foo', { 'name' : 'bar', 'if': { 'val': 'foo' } } ] }
diff --git a/tests/qapi-schema/flat-union-array-branch.err b/tests/qapi-schema/flat-union-array-branch.err
deleted file mode 100644
index 20a8ef1..0000000
--- a/tests/qapi-schema/flat-union-array-branch.err
+++ /dev/null
@@ -1,2 +0,0 @@
-flat-union-array-branch.json: In union 'TestUnion':
-flat-union-array-branch.json:8: 'data' member 'value1' cannot be an array
diff --git a/tests/qapi-schema/flat-union-bad-base.err b/tests/qapi-schema/flat-union-bad-base.err
deleted file mode 100644
index e0a205a..0000000
--- a/tests/qapi-schema/flat-union-bad-base.err
+++ /dev/null
@@ -1,2 +0,0 @@
-flat-union-bad-base.json: In union 'TestUnion':
-flat-union-bad-base.json:8: member 'string' of type 'TestTypeA' collides with base member 'string'
diff --git a/tests/qapi-schema/flat-union-bad-discriminator.err b/tests/qapi-schema/flat-union-bad-discriminator.err
deleted file mode 100644
index b705439..0000000
--- a/tests/qapi-schema/flat-union-bad-discriminator.err
+++ /dev/null
@@ -1,2 +0,0 @@
-flat-union-bad-discriminator.json: In union 'TestUnion':
-flat-union-bad-discriminator.json:11: 'discriminator' requires a string name
diff --git a/tests/qapi-schema/flat-union-base-any.err b/tests/qapi-schema/flat-union-base-any.err
deleted file mode 100644
index c2d4de6..0000000
--- a/tests/qapi-schema/flat-union-base-any.err
+++ /dev/null
@@ -1,2 +0,0 @@
-flat-union-base-any.json: In union 'TestUnion':
-flat-union-base-any.json:8: 'base' requires a struct type, built-in type 'any' isn't
diff --git a/tests/qapi-schema/flat-union-base-union.err b/tests/qapi-schema/flat-union-base-union.err
deleted file mode 100644
index 3b00872..0000000
--- a/tests/qapi-schema/flat-union-base-union.err
+++ /dev/null
@@ -1,2 +0,0 @@
-flat-union-base-union.json: In union 'TestUnion':
-flat-union-base-union.json:14: 'base' requires a struct type, union type 'UnionBase' isn't
diff --git a/tests/qapi-schema/flat-union-clash-member.err b/tests/qapi-schema/flat-union-clash-member.err
deleted file mode 100644
index 07551e6..0000000
--- a/tests/qapi-schema/flat-union-clash-member.err
+++ /dev/null
@@ -1,2 +0,0 @@
-flat-union-clash-member.json: In union 'TestUnion':
-flat-union-clash-member.json:11: member 'name' of type 'Branch1' collides with member 'name' of type 'Base'
diff --git a/tests/qapi-schema/flat-union-discriminator-bad-name.err b/tests/qapi-schema/flat-union-discriminator-bad-name.err
deleted file mode 100644
index 28be49c..0000000
--- a/tests/qapi-schema/flat-union-discriminator-bad-name.err
+++ /dev/null
@@ -1,2 +0,0 @@
-flat-union-discriminator-bad-name.json: In union 'MyUnion':
-flat-union-discriminator-bad-name.json:6: discriminator '*switch' is not a member of 'base'
diff --git a/tests/qapi-schema/flat-union-empty.err b/tests/qapi-schema/flat-union-empty.err
deleted file mode 100644
index 89b0f25..0000000
--- a/tests/qapi-schema/flat-union-empty.err
+++ /dev/null
@@ -1,2 +0,0 @@
-flat-union-empty.json: In union 'Union':
-flat-union-empty.json:4: union has no branches
diff --git a/tests/qapi-schema/flat-union-empty.json b/tests/qapi-schema/flat-union-empty.json
deleted file mode 100644
index 83e1cc7..0000000
--- a/tests/qapi-schema/flat-union-empty.json
+++ /dev/null
@@ -1,4 +0,0 @@
-# flat union discriminator cannot be empty
-{ 'enum': 'Empty', 'data': [ ] }
-{ 'struct': 'Base', 'data': { 'type': 'Empty' } }
-{ 'union': 'Union', 'base': 'Base', 'discriminator': 'type', 'data': { } }
diff --git a/tests/qapi-schema/flat-union-inline-invalid-dict.err b/tests/qapi-schema/flat-union-inline-invalid-dict.err
deleted file mode 100644
index 53e5416..0000000
--- a/tests/qapi-schema/flat-union-inline-invalid-dict.err
+++ /dev/null
@@ -1,2 +0,0 @@
-flat-union-inline-invalid-dict.json: In union 'TestUnion':
-flat-union-inline-invalid-dict.json:7: 'data' member 'value1' misses key 'type'
diff --git a/tests/qapi-schema/flat-union-int-branch.err b/tests/qapi-schema/flat-union-int-branch.err
deleted file mode 100644
index ae7f800..0000000
--- a/tests/qapi-schema/flat-union-int-branch.err
+++ /dev/null
@@ -1,2 +0,0 @@
-flat-union-int-branch.json: In union 'TestUnion':
-flat-union-int-branch.json:8: branch 'value1' cannot use built-in type 'int'
diff --git a/tests/qapi-schema/flat-union-invalid-branch-key.err b/tests/qapi-schema/flat-union-invalid-branch-key.err
deleted file mode 100644
index 5576a25..0000000
--- a/tests/qapi-schema/flat-union-invalid-branch-key.err
+++ /dev/null
@@ -1,2 +0,0 @@
-flat-union-invalid-branch-key.json: In union 'TestUnion':
-flat-union-invalid-branch-key.json:13: branch 'value_wrong' is not a value of enum type 'TestEnum'
diff --git a/tests/qapi-schema/flat-union-invalid-discriminator.err b/tests/qapi-schema/flat-union-invalid-discriminator.err
deleted file mode 100644
index 99bca2d..0000000
--- a/tests/qapi-schema/flat-union-invalid-discriminator.err
+++ /dev/null
@@ -1,2 +0,0 @@
-flat-union-invalid-discriminator.json: In union 'TestUnion':
-flat-union-invalid-discriminator.json:10: discriminator 'enum_wrong' is not a member of 'base'
diff --git a/tests/qapi-schema/flat-union-invalid-if-discriminator.err b/tests/qapi-schema/flat-union-invalid-if-discriminator.err
deleted file mode 100644
index 350f28d..0000000
--- a/tests/qapi-schema/flat-union-invalid-if-discriminator.err
+++ /dev/null
@@ -1,2 +0,0 @@
-flat-union-invalid-if-discriminator.json: In union 'TestUnion':
-flat-union-invalid-if-discriminator.json:10: discriminator member 'enum1' of 'base' must not be conditional
diff --git a/tests/qapi-schema/flat-union-no-base.err b/tests/qapi-schema/flat-union-no-base.err
deleted file mode 100644
index 5167565..0000000
--- a/tests/qapi-schema/flat-union-no-base.err
+++ /dev/null
@@ -1,2 +0,0 @@
-flat-union-no-base.json: In union 'TestUnion':
-flat-union-no-base.json:8: 'discriminator' requires 'base'
diff --git a/tests/qapi-schema/flat-union-optional-discriminator.err b/tests/qapi-schema/flat-union-optional-discriminator.err
deleted file mode 100644
index 3d60a1b..0000000
--- a/tests/qapi-schema/flat-union-optional-discriminator.err
+++ /dev/null
@@ -1,2 +0,0 @@
-flat-union-optional-discriminator.json: In union 'MyUnion':
-flat-union-optional-discriminator.json:6: discriminator member 'switch' of base type 'Base' must not be optional
diff --git a/tests/qapi-schema/flat-union-string-discriminator.err b/tests/qapi-schema/flat-union-string-discriminator.err
deleted file mode 100644
index ff42c97..0000000
--- a/tests/qapi-schema/flat-union-string-discriminator.err
+++ /dev/null
@@ -1,2 +0,0 @@
-flat-union-string-discriminator.json: In union 'TestUnion':
-flat-union-string-discriminator.json:13: discriminator member 'kind' of base type 'TestBase' must be of enum type
diff --git a/tests/qapi-schema/flat-union-string-discriminator.out b/tests/qapi-schema/flat-union-string-discriminator.out
deleted file mode 100644
index e69de29..0000000
--- a/tests/qapi-schema/flat-union-string-discriminator.out
+++ /dev/null
diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build
index 6b2a4ce..6187efb 100644
--- a/tests/qapi-schema/meson.build
+++ b/tests/qapi-schema/meson.build
@@ -107,22 +107,6 @@ schemas = [
'features-name-bad-type.json',
'features-no-list.json',
'features-unknown-key.json',
- 'flat-union-array-branch.json',
- 'flat-union-bad-base.json',
- 'flat-union-bad-discriminator.json',
- 'flat-union-base-any.json',
- 'flat-union-base-union.json',
- 'flat-union-clash-member.json',
- 'flat-union-discriminator-bad-name.json',
- 'flat-union-empty.json',
- 'flat-union-inline-invalid-dict.json',
- 'flat-union-int-branch.json',
- 'flat-union-invalid-branch-key.json',
- 'flat-union-invalid-discriminator.json',
- 'flat-union-invalid-if-discriminator.json',
- 'flat-union-no-base.json',
- 'flat-union-optional-discriminator.json',
- 'flat-union-string-discriminator.json',
'funny-char.json',
'funny-word.json',
'ident-with-escape.json',
@@ -168,7 +152,6 @@ schemas = [
'reserved-member-q.json',
'reserved-member-u.json',
'reserved-member-underscore.json',
- 'reserved-type-kind.json',
'reserved-type-list.json',
'returns-alternate.json',
'returns-array-bad.json',
@@ -191,16 +174,28 @@ schemas = [
'unclosed-list.json',
'unclosed-object.json',
'unclosed-string.json',
+ 'union-array-branch.json',
+ 'union-bad-base.json',
+ 'union-bad-discriminator.json',
+ 'union-base-any.json',
'union-base-empty.json',
'union-base-no-discriminator.json',
- 'union-branch-case.json',
+ 'union-base-union.json',
'union-branch-if-invalid.json',
'union-branch-invalid-dict.json',
- 'union-clash-branches.json',
+ 'union-clash-member.json',
+ 'union-discriminator-bad-name.json',
'union-empty.json',
+ 'union-inline-invalid-dict.json',
+ 'union-int-branch.json',
'union-invalid-base.json',
+ 'union-invalid-branch-key.json',
'union-invalid-data.json',
- 'union-optional-branch.json',
+ 'union-invalid-discriminator.json',
+ 'union-invalid-if-discriminator.json',
+ 'union-no-base.json',
+ 'union-optional-discriminator.json',
+ 'union-string-discriminator.json',
'union-unknown.json',
'unknown-escape.json',
'unknown-expr-key.json',
diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json
index b6c36a9..2ec5010 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -30,7 +30,7 @@
{ 'struct': 'Empty1', 'data': { } }
{ 'struct': 'Empty2', 'base': 'Empty1', 'data': { } }
-# Likewise for an empty flat union
+# Likewise for an empty union
{ 'union': 'Union',
'base': { 'type': 'EnumOne' }, 'discriminator': 'type',
'data': { } }
@@ -123,8 +123,7 @@
# for testing use of 'str' within alternates
{ 'alternate': 'AltStrObj', 'data': { 's': 'str', 'o': 'TestStruct' } }
-# for testing lists
-{ 'union': 'UserDefListUnion',
+{ 'struct': 'ArrayStruct',
'data': { 'integer': ['int'],
's8': ['int8'],
's16': ['int16'],
@@ -137,9 +136,9 @@
'number': ['number'],
'boolean': ['bool'],
'string': ['str'],
- 'sizes': ['size'],
- 'any': ['any'],
- 'user': ['Status'] } } # intentional forward ref. to sub-module
+ '*sz': ['size'],
+ '*any': ['any'],
+ '*user': ['Status'] } } # intentional forward ref. to sub-module
# for testing sub-modules
{ 'include': 'include/sub-module.json' }
@@ -159,7 +158,7 @@
'returns': 'int' }
{ 'command': 'guest-sync', 'data': { 'arg': 'any' }, 'returns': 'any' }
{ 'command': 'boxed-struct', 'boxed': true, 'data': 'UserDefZero' }
-{ 'command': 'boxed-union', 'data': 'UserDefListUnion', 'boxed': true }
+{ 'command': 'boxed-union', 'data': 'UserDefFlatUnion', 'boxed': true }
{ 'command': 'boxed-empty', 'boxed': true, 'data': 'Empty1' }
# Smoke test on out-of-band and allow-preconfig-test
@@ -203,11 +202,10 @@
'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } }
{ 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base',
'data': { '__org.qemu_x-member2': 'str', '*wchar-t': 'int' } }
-{ 'union': '__org.qemu_x-Union1', 'data': { '__org.qemu_x-branch': 'str' } }
{ 'alternate': '__org.qemu_x-Alt1', 'data': { '__org.qemu_x-branch': 'str' } }
{ 'struct': '__org.qemu_x-Struct2',
- 'data': { 'array': ['__org.qemu_x-Union1'] } }
-{ 'union': '__org.qemu_x-Union2', 'base': '__org.qemu_x-Base',
+ 'data': { 'array': ['__org.qemu_x-Union'] } }
+{ 'union': '__org.qemu_x-Union', 'base': '__org.qemu_x-Base',
'discriminator': '__org.qemu_x-member1',
'data': { '__org.qemu_x-value': '__org.qemu_x-Struct2' } }
{ 'alternate': '__org.qemu_x-Alt',
@@ -215,32 +213,33 @@
{ 'event': '__ORG.QEMU_X-EVENT', 'data': '__org.qemu_x-Struct' }
{ 'command': '__org.qemu_x-command',
'data': { 'a': ['__org.qemu_x-Enum'], 'b': ['__org.qemu_x-Struct'],
- 'c': '__org.qemu_x-Union2', 'd': '__org.qemu_x-Alt' },
- 'returns': '__org.qemu_x-Union1' }
+ 'c': '__org.qemu_x-Union', 'd': '__org.qemu_x-Alt' } }
# test 'if' condition handling
-{ 'struct': 'TestIfStruct', 'data':
- { 'foo': 'int',
- 'bar': { 'type': 'int', 'if': 'TEST_IF_STRUCT_BAR'} },
+{ 'struct': 'TestIfStruct',
+ 'data': { 'foo': 'int',
+ 'bar': { 'type': 'int', 'if': 'TEST_IF_STRUCT_BAR'} },
'if': 'TEST_IF_STRUCT' }
-{ 'enum': 'TestIfEnum', 'data':
- [ 'foo', { 'name' : 'bar', 'if': 'TEST_IF_ENUM_BAR' } ],
+{ 'enum': 'TestIfEnum',
+ 'data': [ 'foo', { 'name' : 'bar', 'if': 'TEST_IF_ENUM_BAR' } ],
'if': 'TEST_IF_ENUM' }
-{ 'union': 'TestIfUnion', 'data':
- { 'foo': 'TestStruct',
- 'bar': { 'type': 'str', 'if': 'TEST_IF_UNION_BAR'} },
+{ 'union': 'TestIfUnion',
+ 'base': { 'type': 'TestIfEnum' },
+ 'discriminator': 'type',
+ 'data': { 'foo': 'TestStruct',
+ 'bar': { 'type': 'UserDefZero', 'if': 'TEST_IF_ENUM_BAR'} },
'if': { 'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT'] } }
{ 'command': 'test-if-union-cmd',
'data': { 'union-cmd-arg': 'TestIfUnion' },
'if': { 'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT'] } }
-{ 'alternate': 'TestIfAlternate', 'data':
- { 'foo': 'int',
- 'bar': { 'type': 'TestStruct', 'if': 'TEST_IF_ALT_BAR'} },
+{ 'alternate': 'TestIfAlternate',
+ 'data': { 'foo': 'int',
+ 'bar': { 'type': 'TestStruct', 'if': 'TEST_IF_ALT_BAR'} },
'if': { 'all': ['TEST_IF_ALT', 'TEST_IF_STRUCT'] } }
{ 'command': 'test-if-alternate-cmd',
@@ -256,9 +255,9 @@
{ 'command': 'test-cmd-return-def-three', 'returns': 'UserDefThree' }
-{ 'event': 'TEST_IF_EVENT', 'data':
- { 'foo': 'TestIfStruct',
- 'bar': { 'type': ['TestIfEnum'], 'if': 'TEST_IF_EVT_BAR' } },
+{ 'event': 'TEST_IF_EVENT',
+ 'data': { 'foo': 'TestIfStruct',
+ 'bar': { 'type': ['TestIfEnum'], 'if': 'TEST_IF_EVT_BAR' } },
'if': { 'all': ['TEST_IF_EVT', 'TEST_IF_STRUCT'] } }
{ 'event': 'TEST_IF_EVENT2', 'data': {},
diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out
index d557fe2..9337adc 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -125,70 +125,22 @@ alternate AltStrObj
tag type
case s: str
case o: TestStruct
-object q_obj_intList-wrapper
- member data: intList optional=False
-object q_obj_int8List-wrapper
- member data: int8List optional=False
-object q_obj_int16List-wrapper
- member data: int16List optional=False
-object q_obj_int32List-wrapper
- member data: int32List optional=False
-object q_obj_int64List-wrapper
- member data: int64List optional=False
-object q_obj_uint8List-wrapper
- member data: uint8List optional=False
-object q_obj_uint16List-wrapper
- member data: uint16List optional=False
-object q_obj_uint32List-wrapper
- member data: uint32List optional=False
-object q_obj_uint64List-wrapper
- member data: uint64List optional=False
-object q_obj_numberList-wrapper
- member data: numberList optional=False
-object q_obj_boolList-wrapper
- member data: boolList optional=False
-object q_obj_strList-wrapper
- member data: strList optional=False
-object q_obj_sizeList-wrapper
- member data: sizeList optional=False
-object q_obj_anyList-wrapper
- member data: anyList optional=False
-object q_obj_StatusList-wrapper
- member data: StatusList optional=False
-enum UserDefListUnionKind
- member integer
- member s8
- member s16
- member s32
- member s64
- member u8
- member u16
- member u32
- member u64
- member number
- member boolean
- member string
- member sizes
- member any
- member user
-object UserDefListUnion
- member type: UserDefListUnionKind optional=False
- tag type
- case integer: q_obj_intList-wrapper
- case s8: q_obj_int8List-wrapper
- case s16: q_obj_int16List-wrapper
- case s32: q_obj_int32List-wrapper
- case s64: q_obj_int64List-wrapper
- case u8: q_obj_uint8List-wrapper
- case u16: q_obj_uint16List-wrapper
- case u32: q_obj_uint32List-wrapper
- case u64: q_obj_uint64List-wrapper
- case number: q_obj_numberList-wrapper
- case boolean: q_obj_boolList-wrapper
- case string: q_obj_strList-wrapper
- case sizes: q_obj_sizeList-wrapper
- case any: q_obj_anyList-wrapper
- case user: q_obj_StatusList-wrapper
+object ArrayStruct
+ member integer: intList optional=False
+ member s8: int8List optional=False
+ member s16: int16List optional=False
+ member s32: int32List optional=False
+ member s64: int64List optional=False
+ member u8: uint8List optional=False
+ member u16: uint16List optional=False
+ member u32: uint32List optional=False
+ member u64: uint64List optional=False
+ member number: numberList optional=False
+ member boolean: boolList optional=False
+ member string: strList optional=False
+ member sz: sizeList optional=True
+ member any: anyList optional=True
+ member user: StatusList optional=True
include include/sub-module.json
command user-def-cmd None -> None
gen=True success_response=True boxed=False oob=False preconfig=False
@@ -216,7 +168,7 @@ command guest-sync q_obj_guest-sync-arg -> any
gen=True success_response=True boxed=False oob=False preconfig=False
command boxed-struct UserDefZero -> None
gen=True success_response=True boxed=True oob=False preconfig=False
-command boxed-union UserDefListUnion -> None
+command boxed-union UserDefFlatUnion -> None
gen=True success_response=True boxed=True oob=False preconfig=False
command boxed-empty Empty1 -> None
gen=True success_response=True boxed=True oob=False preconfig=False
@@ -263,21 +215,13 @@ object __org.qemu_x-Struct
base __org.qemu_x-Base
member __org.qemu_x-member2: str optional=False
member wchar-t: int optional=True
-object q_obj_str-wrapper
- member data: str optional=False
-enum __org.qemu_x-Union1Kind
- member __org.qemu_x-branch
-object __org.qemu_x-Union1
- member type: __org.qemu_x-Union1Kind optional=False
- tag type
- case __org.qemu_x-branch: q_obj_str-wrapper
alternate __org.qemu_x-Alt1
tag type
case __org.qemu_x-branch: str
-array __org.qemu_x-Union1List __org.qemu_x-Union1
+array __org.qemu_x-UnionList __org.qemu_x-Union
object __org.qemu_x-Struct2
- member array: __org.qemu_x-Union1List optional=False
-object __org.qemu_x-Union2
+ member array: __org.qemu_x-UnionList optional=False
+object __org.qemu_x-Union
base __org.qemu_x-Base
tag __org.qemu_x-member1
case __org.qemu_x-value: __org.qemu_x-Struct2
@@ -291,9 +235,9 @@ array __org.qemu_x-StructList __org.qemu_x-Struct
object q_obj___org.qemu_x-command-arg
member a: __org.qemu_x-EnumList optional=False
member b: __org.qemu_x-StructList optional=False
- member c: __org.qemu_x-Union2 optional=False
+ member c: __org.qemu_x-Union optional=False
member d: __org.qemu_x-Alt optional=False
-command __org.qemu_x-command q_obj___org.qemu_x-command-arg -> __org.qemu_x-Union1
+command __org.qemu_x-command q_obj___org.qemu_x-command-arg -> None
gen=True success_response=True boxed=False oob=False preconfig=False
object TestIfStruct
member foo: int optional=False
@@ -305,19 +249,15 @@ enum TestIfEnum
member bar
if TEST_IF_ENUM_BAR
if TEST_IF_ENUM
-object q_obj_TestStruct-wrapper
- member data: TestStruct optional=False
-enum TestIfUnionKind
- member foo
- member bar
- if TEST_IF_UNION_BAR
+object q_obj_TestIfUnion-base
+ member type: TestIfEnum optional=False
if {'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT']}
object TestIfUnion
- member type: TestIfUnionKind optional=False
+ base q_obj_TestIfUnion-base
tag type
- case foo: q_obj_TestStruct-wrapper
- case bar: q_obj_str-wrapper
- if TEST_IF_UNION_BAR
+ case foo: TestStruct
+ case bar: UserDefZero
+ if TEST_IF_ENUM_BAR
if {'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT']}
object q_obj_test-if-union-cmd-arg
member union-cmd-arg: TestIfUnion optional=False
diff --git a/tests/qapi-schema/reserved-member-u.json b/tests/qapi-schema/reserved-member-u.json
index 2bfb8f5..d982ab5 100644
--- a/tests/qapi-schema/reserved-member-u.json
+++ b/tests/qapi-schema/reserved-member-u.json
@@ -2,6 +2,6 @@
# We reject use of 'u' as a member name, to allow it for internal use in
# putting union branch members in a separate namespace from QMP members.
# This is true even for non-unions, because it is possible to convert a
-# struct to flat union while remaining backwards compatible in QMP.
+# struct to union while remaining backwards compatible in QMP.
# TODO - we could munge the member name to 'q_u' to avoid the collision
{ 'struct': 'Oops', 'data': { '*u': 'str' } }
diff --git a/tests/qapi-schema/reserved-type-kind.err b/tests/qapi-schema/reserved-type-kind.err
deleted file mode 100644
index d8fb769..0000000
--- a/tests/qapi-schema/reserved-type-kind.err
+++ /dev/null
@@ -1,2 +0,0 @@
-reserved-type-kind.json: In enum 'UnionKind':
-reserved-type-kind.json:2: enum name should not end in 'Kind'
diff --git a/tests/qapi-schema/reserved-type-kind.json b/tests/qapi-schema/reserved-type-kind.json
deleted file mode 100644
index 9ecaba1..0000000
--- a/tests/qapi-schema/reserved-type-kind.json
+++ /dev/null
@@ -1,2 +0,0 @@
-# we reject types that would conflict with implicit union enum
-{ 'enum': 'UnionKind', 'data': [ 'oops' ] }
diff --git a/tests/qapi-schema/reserved-type-kind.out b/tests/qapi-schema/reserved-type-kind.out
deleted file mode 100644
index e69de29..0000000
--- a/tests/qapi-schema/reserved-type-kind.out
+++ /dev/null
diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py
index 73cffae..c717a7a 100755
--- a/tests/qapi-schema/test-qapi.py
+++ b/tests/qapi-schema/test-qapi.py
@@ -132,6 +132,17 @@ def test_frontend(fname):
print(' section=%s\n%s' % (section.name, section.text))
+def open_test_result(dir_name, file_name, update):
+ mode = 'r+' if update else 'r'
+ try:
+ fp = open(os.path.join(dir_name, file_name), mode)
+ except FileNotFoundError:
+ if not update:
+ raise
+ fp = open(os.path.join(dir_name, file_name), 'w+')
+ return fp
+
+
def test_and_diff(test_name, dir_name, update):
sys.stdout = StringIO()
try:
@@ -148,13 +159,12 @@ def test_and_diff(test_name, dir_name, update):
sys.stdout.close()
sys.stdout = sys.__stdout__
- mode = 'r+' if update else 'r'
try:
- outfp = open(os.path.join(dir_name, test_name + '.out'), mode)
- errfp = open(os.path.join(dir_name, test_name + '.err'), mode)
+ outfp = open_test_result(dir_name, test_name + '.out', update)
+ errfp = open_test_result(dir_name, test_name + '.err', update)
expected_out = outfp.readlines()
expected_err = errfp.readlines()
- except IOError as err:
+ except OSError as err:
print("%s: can't open '%s': %s"
% (sys.argv[0], err.filename, err.strerror),
file=sys.stderr)
@@ -180,7 +190,7 @@ def test_and_diff(test_name, dir_name, update):
errfp.truncate(0)
errfp.seek(0)
errfp.writelines(actual_err)
- except IOError as err:
+ except OSError as err:
print("%s: can't write '%s': %s"
% (sys.argv[0], err.filename, err.strerror),
file=sys.stderr)
diff --git a/tests/qapi-schema/union-array-branch.err b/tests/qapi-schema/union-array-branch.err
new file mode 100644
index 0000000..5db9c17
--- /dev/null
+++ b/tests/qapi-schema/union-array-branch.err
@@ -0,0 +1,2 @@
+union-array-branch.json: In union 'TestUnion':
+union-array-branch.json:8: 'data' member 'value1' cannot be an array
diff --git a/tests/qapi-schema/flat-union-array-branch.json b/tests/qapi-schema/union-array-branch.json
index 0b98820..6dda7ec 100644
--- a/tests/qapi-schema/flat-union-array-branch.json
+++ b/tests/qapi-schema/union-array-branch.json
@@ -1,4 +1,4 @@
-# we require flat union branches to be a struct
+# we require union branches to be a struct
{ 'enum': 'TestEnum',
'data': [ 'value1', 'value2' ] }
{ 'struct': 'Base',
diff --git a/tests/qapi-schema/flat-union-array-branch.out b/tests/qapi-schema/union-array-branch.out
index e69de29..e69de29 100644
--- a/tests/qapi-schema/flat-union-array-branch.out
+++ b/tests/qapi-schema/union-array-branch.out
diff --git a/tests/qapi-schema/union-bad-base.err b/tests/qapi-schema/union-bad-base.err
new file mode 100644
index 0000000..42b2ed1
--- /dev/null
+++ b/tests/qapi-schema/union-bad-base.err
@@ -0,0 +1,2 @@
+union-bad-base.json: In union 'TestUnion':
+union-bad-base.json:8: member 'string' of type 'TestTypeA' collides with base member 'string'
diff --git a/tests/qapi-schema/flat-union-bad-base.json b/tests/qapi-schema/union-bad-base.json
index 74dd421..74dd421 100644
--- a/tests/qapi-schema/flat-union-bad-base.json
+++ b/tests/qapi-schema/union-bad-base.json
diff --git a/tests/qapi-schema/flat-union-bad-base.out b/tests/qapi-schema/union-bad-base.out
index e69de29..e69de29 100644
--- a/tests/qapi-schema/flat-union-bad-base.out
+++ b/tests/qapi-schema/union-bad-base.out
diff --git a/tests/qapi-schema/union-bad-discriminator.err b/tests/qapi-schema/union-bad-discriminator.err
new file mode 100644
index 0000000..7cfd470
--- /dev/null
+++ b/tests/qapi-schema/union-bad-discriminator.err
@@ -0,0 +1,2 @@
+union-bad-discriminator.json: In union 'TestUnion':
+union-bad-discriminator.json:11: 'discriminator' requires a string name
diff --git a/tests/qapi-schema/flat-union-bad-discriminator.json b/tests/qapi-schema/union-bad-discriminator.json
index cd10b9d..cd10b9d 100644
--- a/tests/qapi-schema/flat-union-bad-discriminator.json
+++ b/tests/qapi-schema/union-bad-discriminator.json
diff --git a/tests/qapi-schema/flat-union-bad-discriminator.out b/tests/qapi-schema/union-bad-discriminator.out
index e69de29..e69de29 100644
--- a/tests/qapi-schema/flat-union-bad-discriminator.out
+++ b/tests/qapi-schema/union-bad-discriminator.out
diff --git a/tests/qapi-schema/union-base-any.err b/tests/qapi-schema/union-base-any.err
new file mode 100644
index 0000000..82b48bc
--- /dev/null
+++ b/tests/qapi-schema/union-base-any.err
@@ -0,0 +1,2 @@
+union-base-any.json: In union 'TestUnion':
+union-base-any.json:8: 'base' requires a struct type, built-in type 'any' isn't
diff --git a/tests/qapi-schema/flat-union-base-any.json b/tests/qapi-schema/union-base-any.json
index fe66b71..fe66b71 100644
--- a/tests/qapi-schema/flat-union-base-any.json
+++ b/tests/qapi-schema/union-base-any.json
diff --git a/tests/qapi-schema/flat-union-base-any.out b/tests/qapi-schema/union-base-any.out
index e69de29..e69de29 100644
--- a/tests/qapi-schema/flat-union-base-any.out
+++ b/tests/qapi-schema/union-base-any.out
diff --git a/tests/qapi-schema/union-base-empty.json b/tests/qapi-schema/union-base-empty.json
index d1843d3..6f8ef00 100644
--- a/tests/qapi-schema/union-base-empty.json
+++ b/tests/qapi-schema/union-base-empty.json
@@ -1,4 +1,4 @@
-# Flat union with empty base and therefore without discriminator
+# Union with empty base and therefore without discriminator
{ 'struct': 'Empty', 'data': { } }
diff --git a/tests/qapi-schema/union-base-no-discriminator.err b/tests/qapi-schema/union-base-no-discriminator.err
index 9cd5d11..a730b7f 100644
--- a/tests/qapi-schema/union-base-no-discriminator.err
+++ b/tests/qapi-schema/union-base-no-discriminator.err
@@ -1,2 +1,2 @@
union-base-no-discriminator.json: In union 'TestUnion':
-union-base-no-discriminator.json:11: 'base' requires 'discriminator'
+union-base-no-discriminator.json:11: union misses key 'discriminator'
diff --git a/tests/qapi-schema/union-base-no-discriminator.json b/tests/qapi-schema/union-base-no-discriminator.json
index 1409cf5..2e7cae9 100644
--- a/tests/qapi-schema/union-base-no-discriminator.json
+++ b/tests/qapi-schema/union-base-no-discriminator.json
@@ -1,4 +1,4 @@
-# we reject simple unions with a base (or flat unions without discriminator)
+# we reject unions without discriminator
{ 'struct': 'TestTypeA',
'data': { 'string': 'str' } }
diff --git a/tests/qapi-schema/union-base-union.err b/tests/qapi-schema/union-base-union.err
new file mode 100644
index 0000000..2bddaf6
--- /dev/null
+++ b/tests/qapi-schema/union-base-union.err
@@ -0,0 +1,2 @@
+union-base-union.json: In union 'TestUnion':
+union-base-union.json:17: 'base' requires a struct type, union type 'UnionBase' isn't
diff --git a/tests/qapi-schema/flat-union-base-union.json b/tests/qapi-schema/union-base-union.json
index 98b4eba..82d4c96 100644
--- a/tests/qapi-schema/flat-union-base-union.json
+++ b/tests/qapi-schema/union-base-union.json
@@ -8,7 +8,10 @@
'data': { 'string': 'str' } }
{ 'struct': 'TestTypeB',
'data': { 'integer': 'int' } }
+{ 'enum': 'Enum', 'data': [ 'kind1', 'kind2' ] }
{ 'union': 'UnionBase',
+ 'base': { 'type': 'Enum' },
+ 'discriminator': 'type',
'data': { 'kind1': 'TestTypeA',
'kind2': 'TestTypeB' } }
{ 'union': 'TestUnion',
diff --git a/tests/qapi-schema/flat-union-base-union.out b/tests/qapi-schema/union-base-union.out
index e69de29..e69de29 100644
--- a/tests/qapi-schema/flat-union-base-union.out
+++ b/tests/qapi-schema/union-base-union.out
diff --git a/tests/qapi-schema/union-branch-case.err b/tests/qapi-schema/union-branch-case.err
deleted file mode 100644
index d2d5cb8..0000000
--- a/tests/qapi-schema/union-branch-case.err
+++ /dev/null
@@ -1,2 +0,0 @@
-union-branch-case.json: In union 'Uni':
-union-branch-case.json:2: name of 'data' member 'Branch' must not use uppercase or '_'
diff --git a/tests/qapi-schema/union-branch-case.json b/tests/qapi-schema/union-branch-case.json
deleted file mode 100644
index b7894b7..0000000
--- a/tests/qapi-schema/union-branch-case.json
+++ /dev/null
@@ -1,2 +0,0 @@
-# Branch names should be 'lower-case'
-{ 'union': 'Uni', 'data': { 'Branch': 'int' } }
diff --git a/tests/qapi-schema/union-branch-case.out b/tests/qapi-schema/union-branch-case.out
deleted file mode 100644
index e69de29..0000000
--- a/tests/qapi-schema/union-branch-case.out
+++ /dev/null
diff --git a/tests/qapi-schema/union-branch-invalid-dict.err b/tests/qapi-schema/union-branch-invalid-dict.err
index 8137c5a..001cdec 100644
--- a/tests/qapi-schema/union-branch-invalid-dict.err
+++ b/tests/qapi-schema/union-branch-invalid-dict.err
@@ -1,2 +1,2 @@
union-branch-invalid-dict.json: In union 'UnionInvalidBranch':
-union-branch-invalid-dict.json:2: 'data' member 'integer' misses key 'type'
+union-branch-invalid-dict.json:4: 'data' member 'integer' misses key 'type'
diff --git a/tests/qapi-schema/union-branch-invalid-dict.json b/tests/qapi-schema/union-branch-invalid-dict.json
index 9778598..c7c81c0 100644
--- a/tests/qapi-schema/union-branch-invalid-dict.json
+++ b/tests/qapi-schema/union-branch-invalid-dict.json
@@ -1,4 +1,8 @@
# Long form of member must have a value member 'type'
+{ 'enum': 'TestEnum',
+ 'data': [ 'integer', 's8' ] }
{ 'union': 'UnionInvalidBranch',
+ 'base': { 'type': 'TestEnum' },
+ 'discriminator': 'type',
'data': { 'integer': { 'if': 'foo'},
's8': 'int8' } }
diff --git a/tests/qapi-schema/union-clash-branches.err b/tests/qapi-schema/union-clash-branches.err
deleted file mode 100644
index ef53645..0000000
--- a/tests/qapi-schema/union-clash-branches.err
+++ /dev/null
@@ -1,2 +0,0 @@
-union-clash-branches.json: In union 'TestUnion':
-union-clash-branches.json:6: name of 'data' member 'a_b' must not use uppercase or '_'
diff --git a/tests/qapi-schema/union-clash-branches.json b/tests/qapi-schema/union-clash-branches.json
deleted file mode 100644
index 7bdda0b..0000000
--- a/tests/qapi-schema/union-clash-branches.json
+++ /dev/null
@@ -1,7 +0,0 @@
-# Union branch name collision
-# Naming rules make collision impossible (even with the pragma). If
-# that wasn't the case, then we'd get collisions in generated C: two
-# union members a_b, and two enum members TEST_UNION_A_B.
-{ 'pragma': { 'member-name-exceptions': [ 'TestUnion' ] } }
-{ 'union': 'TestUnion',
- 'data': { 'a-b': 'int', 'a_b': 'str' } }
diff --git a/tests/qapi-schema/union-clash-branches.out b/tests/qapi-schema/union-clash-branches.out
deleted file mode 100644
index e69de29..0000000
--- a/tests/qapi-schema/union-clash-branches.out
+++ /dev/null
diff --git a/tests/qapi-schema/union-clash-member.err b/tests/qapi-schema/union-clash-member.err
new file mode 100644
index 0000000..c1f3a02
--- /dev/null
+++ b/tests/qapi-schema/union-clash-member.err
@@ -0,0 +1,2 @@
+union-clash-member.json: In union 'TestUnion':
+union-clash-member.json:11: member 'name' of type 'Branch1' collides with member 'name' of type 'Base'
diff --git a/tests/qapi-schema/flat-union-clash-member.json b/tests/qapi-schema/union-clash-member.json
index 9efc771..9efc771 100644
--- a/tests/qapi-schema/flat-union-clash-member.json
+++ b/tests/qapi-schema/union-clash-member.json
diff --git a/tests/qapi-schema/flat-union-clash-member.out b/tests/qapi-schema/union-clash-member.out
index e69de29..e69de29 100644
--- a/tests/qapi-schema/flat-union-clash-member.out
+++ b/tests/qapi-schema/union-clash-member.out
diff --git a/tests/qapi-schema/union-discriminator-bad-name.err b/tests/qapi-schema/union-discriminator-bad-name.err
new file mode 100644
index 0000000..5793e9a
--- /dev/null
+++ b/tests/qapi-schema/union-discriminator-bad-name.err
@@ -0,0 +1,2 @@
+union-discriminator-bad-name.json: In union 'MyUnion':
+union-discriminator-bad-name.json:6: discriminator '*switch' is not a member of 'base'
diff --git a/tests/qapi-schema/flat-union-discriminator-bad-name.json b/tests/qapi-schema/union-discriminator-bad-name.json
index 3ae8c06..3ae8c06 100644
--- a/tests/qapi-schema/flat-union-discriminator-bad-name.json
+++ b/tests/qapi-schema/union-discriminator-bad-name.json
diff --git a/tests/qapi-schema/flat-union-discriminator-bad-name.out b/tests/qapi-schema/union-discriminator-bad-name.out
index e69de29..e69de29 100644
--- a/tests/qapi-schema/flat-union-discriminator-bad-name.out
+++ b/tests/qapi-schema/union-discriminator-bad-name.out
diff --git a/tests/qapi-schema/union-empty.err b/tests/qapi-schema/union-empty.err
index 59788c9..d428439 100644
--- a/tests/qapi-schema/union-empty.err
+++ b/tests/qapi-schema/union-empty.err
@@ -1,2 +1,2 @@
union-empty.json: In union 'Union':
-union-empty.json:2: union has no branches
+union-empty.json:4: union has no branches
diff --git a/tests/qapi-schema/union-empty.json b/tests/qapi-schema/union-empty.json
index df3e5e6..584ed60 100644
--- a/tests/qapi-schema/union-empty.json
+++ b/tests/qapi-schema/union-empty.json
@@ -1,2 +1,4 @@
-# simple unions cannot be empty
-{ 'union': 'Union', 'data': { } }
+# union discriminator enum cannot be empty
+{ 'enum': 'Empty', 'data': [ ] }
+{ 'struct': 'Base', 'data': { 'type': 'Empty' } }
+{ 'union': 'Union', 'base': 'Base', 'discriminator': 'type', 'data': { } }
diff --git a/tests/qapi-schema/union-inline-invalid-dict.err b/tests/qapi-schema/union-inline-invalid-dict.err
new file mode 100644
index 0000000..25ddf7c
--- /dev/null
+++ b/tests/qapi-schema/union-inline-invalid-dict.err
@@ -0,0 +1,2 @@
+union-inline-invalid-dict.json: In union 'TestUnion':
+union-inline-invalid-dict.json:7: 'data' member 'value1' misses key 'type'
diff --git a/tests/qapi-schema/flat-union-inline-invalid-dict.json b/tests/qapi-schema/union-inline-invalid-dict.json
index 1779712..1779712 100644
--- a/tests/qapi-schema/flat-union-inline-invalid-dict.json
+++ b/tests/qapi-schema/union-inline-invalid-dict.json
diff --git a/tests/qapi-schema/flat-union-empty.out b/tests/qapi-schema/union-inline-invalid-dict.out
index e69de29..e69de29 100644
--- a/tests/qapi-schema/flat-union-empty.out
+++ b/tests/qapi-schema/union-inline-invalid-dict.out
diff --git a/tests/qapi-schema/union-int-branch.err b/tests/qapi-schema/union-int-branch.err
new file mode 100644
index 0000000..8fdc81e
--- /dev/null
+++ b/tests/qapi-schema/union-int-branch.err
@@ -0,0 +1,2 @@
+union-int-branch.json: In union 'TestUnion':
+union-int-branch.json:8: branch 'value1' cannot use built-in type 'int'
diff --git a/tests/qapi-schema/flat-union-int-branch.json b/tests/qapi-schema/union-int-branch.json
index 9370c34..567043d 100644
--- a/tests/qapi-schema/flat-union-int-branch.json
+++ b/tests/qapi-schema/union-int-branch.json
@@ -1,4 +1,4 @@
-# we require flat union branches to be a struct
+# we require union branches to be a struct
{ 'enum': 'TestEnum',
'data': [ 'value1', 'value2' ] }
{ 'struct': 'Base',
diff --git a/tests/qapi-schema/flat-union-inline-invalid-dict.out b/tests/qapi-schema/union-int-branch.out
index e69de29..e69de29 100644
--- a/tests/qapi-schema/flat-union-inline-invalid-dict.out
+++ b/tests/qapi-schema/union-int-branch.out
diff --git a/tests/qapi-schema/union-invalid-branch-key.err b/tests/qapi-schema/union-invalid-branch-key.err
new file mode 100644
index 0000000..bf58800
--- /dev/null
+++ b/tests/qapi-schema/union-invalid-branch-key.err
@@ -0,0 +1,2 @@
+union-invalid-branch-key.json: In union 'TestUnion':
+union-invalid-branch-key.json:13: branch 'value_wrong' is not a value of enum type 'TestEnum'
diff --git a/tests/qapi-schema/flat-union-invalid-branch-key.json b/tests/qapi-schema/union-invalid-branch-key.json
index 95ff774..95ff774 100644
--- a/tests/qapi-schema/flat-union-invalid-branch-key.json
+++ b/tests/qapi-schema/union-invalid-branch-key.json
diff --git a/tests/qapi-schema/flat-union-int-branch.out b/tests/qapi-schema/union-invalid-branch-key.out
index e69de29..e69de29 100644
--- a/tests/qapi-schema/flat-union-int-branch.out
+++ b/tests/qapi-schema/union-invalid-branch-key.out
diff --git a/tests/qapi-schema/union-invalid-discriminator.err b/tests/qapi-schema/union-invalid-discriminator.err
new file mode 100644
index 0000000..38efb24
--- /dev/null
+++ b/tests/qapi-schema/union-invalid-discriminator.err
@@ -0,0 +1,2 @@
+union-invalid-discriminator.json: In union 'TestUnion':
+union-invalid-discriminator.json:10: discriminator 'enum_wrong' is not a member of 'base'
diff --git a/tests/qapi-schema/flat-union-invalid-discriminator.json b/tests/qapi-schema/union-invalid-discriminator.json
index c4fce97..c4fce97 100644
--- a/tests/qapi-schema/flat-union-invalid-discriminator.json
+++ b/tests/qapi-schema/union-invalid-discriminator.json
diff --git a/tests/qapi-schema/flat-union-invalid-branch-key.out b/tests/qapi-schema/union-invalid-discriminator.out
index e69de29..e69de29 100644
--- a/tests/qapi-schema/flat-union-invalid-branch-key.out
+++ b/tests/qapi-schema/union-invalid-discriminator.out
diff --git a/tests/qapi-schema/union-invalid-if-discriminator.err b/tests/qapi-schema/union-invalid-if-discriminator.err
new file mode 100644
index 0000000..3f41d03
--- /dev/null
+++ b/tests/qapi-schema/union-invalid-if-discriminator.err
@@ -0,0 +1,2 @@
+union-invalid-if-discriminator.json: In union 'TestUnion':
+union-invalid-if-discriminator.json:10: discriminator member 'enum1' of 'base' must not be conditional
diff --git a/tests/qapi-schema/flat-union-invalid-if-discriminator.json b/tests/qapi-schema/union-invalid-if-discriminator.json
index e49992b..e49992b 100644
--- a/tests/qapi-schema/flat-union-invalid-if-discriminator.json
+++ b/tests/qapi-schema/union-invalid-if-discriminator.json
diff --git a/tests/qapi-schema/flat-union-invalid-discriminator.out b/tests/qapi-schema/union-invalid-if-discriminator.out
index e69de29..e69de29 100644
--- a/tests/qapi-schema/flat-union-invalid-discriminator.out
+++ b/tests/qapi-schema/union-invalid-if-discriminator.out
diff --git a/tests/qapi-schema/union-no-base.err b/tests/qapi-schema/union-no-base.err
new file mode 100644
index 0000000..cbf12ac
--- /dev/null
+++ b/tests/qapi-schema/union-no-base.err
@@ -0,0 +1,2 @@
+union-no-base.json: In union 'TestUnion':
+union-no-base.json:8: union misses key 'base'
diff --git a/tests/qapi-schema/flat-union-no-base.json b/tests/qapi-schema/union-no-base.json
index 327877b..f6fe12d 100644
--- a/tests/qapi-schema/flat-union-no-base.json
+++ b/tests/qapi-schema/union-no-base.json
@@ -1,4 +1,4 @@
-# flat unions require a base
+# unions require a base
{ 'struct': 'TestTypeA',
'data': { 'string': 'str' } }
{ 'struct': 'TestTypeB',
diff --git a/tests/qapi-schema/flat-union-invalid-if-discriminator.out b/tests/qapi-schema/union-no-base.out
index e69de29..e69de29 100644
--- a/tests/qapi-schema/flat-union-invalid-if-discriminator.out
+++ b/tests/qapi-schema/union-no-base.out
diff --git a/tests/qapi-schema/union-optional-branch.err b/tests/qapi-schema/union-optional-branch.err
deleted file mode 100644
index b33f111..0000000
--- a/tests/qapi-schema/union-optional-branch.err
+++ /dev/null
@@ -1,2 +0,0 @@
-union-optional-branch.json: In union 'Union':
-union-optional-branch.json:2: 'data' member '*a' has an invalid name
diff --git a/tests/qapi-schema/union-optional-branch.json b/tests/qapi-schema/union-optional-branch.json
deleted file mode 100644
index 591615f..0000000
--- a/tests/qapi-schema/union-optional-branch.json
+++ /dev/null
@@ -1,2 +0,0 @@
-# union branches cannot be optional
-{ 'union': 'Union', 'data': { '*a': 'int', 'b': 'str' } }
diff --git a/tests/qapi-schema/union-optional-branch.out b/tests/qapi-schema/union-optional-branch.out
deleted file mode 100644
index e69de29..0000000
--- a/tests/qapi-schema/union-optional-branch.out
+++ /dev/null
diff --git a/tests/qapi-schema/union-optional-discriminator.err b/tests/qapi-schema/union-optional-discriminator.err
new file mode 100644
index 0000000..8d980bd
--- /dev/null
+++ b/tests/qapi-schema/union-optional-discriminator.err
@@ -0,0 +1,2 @@
+union-optional-discriminator.json: In union 'MyUnion':
+union-optional-discriminator.json:6: discriminator member 'switch' of base type 'Base' must not be optional
diff --git a/tests/qapi-schema/flat-union-optional-discriminator.json b/tests/qapi-schema/union-optional-discriminator.json
index 2e7f766..2e7f766 100644
--- a/tests/qapi-schema/flat-union-optional-discriminator.json
+++ b/tests/qapi-schema/union-optional-discriminator.json
diff --git a/tests/qapi-schema/flat-union-no-base.out b/tests/qapi-schema/union-optional-discriminator.out
index e69de29..e69de29 100644
--- a/tests/qapi-schema/flat-union-no-base.out
+++ b/tests/qapi-schema/union-optional-discriminator.out
diff --git a/tests/qapi-schema/union-string-discriminator.err b/tests/qapi-schema/union-string-discriminator.err
new file mode 100644
index 0000000..eccbe68
--- /dev/null
+++ b/tests/qapi-schema/union-string-discriminator.err
@@ -0,0 +1,2 @@
+union-string-discriminator.json: In union 'TestUnion':
+union-string-discriminator.json:13: discriminator member 'kind' of base type 'TestBase' must be of enum type
diff --git a/tests/qapi-schema/flat-union-string-discriminator.json b/tests/qapi-schema/union-string-discriminator.json
index 8af6033..8af6033 100644
--- a/tests/qapi-schema/flat-union-string-discriminator.json
+++ b/tests/qapi-schema/union-string-discriminator.json
diff --git a/tests/qapi-schema/flat-union-optional-discriminator.out b/tests/qapi-schema/union-string-discriminator.out
index e69de29..e69de29 100644
--- a/tests/qapi-schema/flat-union-optional-discriminator.out
+++ b/tests/qapi-schema/union-string-discriminator.out
diff --git a/tests/qapi-schema/union-unknown.err b/tests/qapi-schema/union-unknown.err
index 7aba9f9..dad79be 100644
--- a/tests/qapi-schema/union-unknown.err
+++ b/tests/qapi-schema/union-unknown.err
@@ -1,2 +1,2 @@
union-unknown.json: In union 'Union':
-union-unknown.json:2: union uses unknown type 'MissingType'
+union-unknown.json:3: branch 'unknown' uses unknown type 'MissingType'
diff --git a/tests/qapi-schema/union-unknown.json b/tests/qapi-schema/union-unknown.json
index 64d3666..4736f1a 100644
--- a/tests/qapi-schema/union-unknown.json
+++ b/tests/qapi-schema/union-unknown.json
@@ -1,3 +1,6 @@
# we reject a union with unknown type in branch
+{ 'enum': 'Enum', 'data': [ 'unknown' ] }
{ 'union': 'Union',
- 'data': { 'unknown': ['MissingType'] } }
+ 'base': { 'type': 'Enum' },
+ 'discriminator': 'type',
+ 'data': { 'unknown': 'MissingType' } }
diff --git a/tests/unit/test-clone-visitor.c b/tests/unit/test-clone-visitor.c
index 4944b3d..5d48e12 100644
--- a/tests/unit/test-clone-visitor.c
+++ b/tests/unit/test-clone-visitor.c
@@ -63,7 +63,7 @@ static void test_clone_alternate(void)
qapi_free_AltEnumBool(s_dst);
}
-static void test_clone_list_union(void)
+static void test_clone_list(void)
{
uint8List *src = NULL, *dst;
uint8List *tmp = NULL;
@@ -99,18 +99,26 @@ static void test_clone_empty(void)
static void test_clone_complex1(void)
{
- UserDefListUnion *src, *dst;
+ UserDefFlatUnion *src, *dst;
- src = g_new0(UserDefListUnion, 1);
- src->type = USER_DEF_LIST_UNION_KIND_STRING;
+ src = g_new0(UserDefFlatUnion, 1);
+ src->integer = 123;
+ src->string = g_strdup("abc");
+ src->enum1 = ENUM_ONE_VALUE1;
+ src->u.value1.boolean = true;
- dst = QAPI_CLONE(UserDefListUnion, src);
+ dst = QAPI_CLONE(UserDefFlatUnion, src);
g_assert(dst);
- g_assert_cmpint(dst->type, ==, src->type);
- g_assert(!dst->u.string.data);
- qapi_free_UserDefListUnion(src);
- qapi_free_UserDefListUnion(dst);
+ g_assert_cmpint(dst->integer, ==, 123);
+ g_assert_cmpstr(dst->string, ==, "abc");
+ g_assert_cmpint(dst->enum1, ==, ENUM_ONE_VALUE1);
+ g_assert(dst->u.value1.boolean);
+ g_assert(!dst->u.value1.has_a_b);
+ g_assert_cmpint(dst->u.value1.a_b, ==, 0);
+
+ qapi_free_UserDefFlatUnion(src);
+ qapi_free_UserDefFlatUnion(dst);
}
static void test_clone_complex2(void)
@@ -145,42 +153,48 @@ static void test_clone_complex2(void)
static void test_clone_complex3(void)
{
- __org_qemu_x_Struct2 *src, *dst;
- __org_qemu_x_Union1List *tmp;
-
- src = g_new0(__org_qemu_x_Struct2, 1);
- tmp = src->array = g_new0(__org_qemu_x_Union1List, 1);
- tmp->value = g_new0(__org_qemu_x_Union1, 1);
- tmp->value->type = ORG_QEMU_X_UNION1_KIND___ORG_QEMU_X_BRANCH;
- tmp->value->u.__org_qemu_x_branch.data = g_strdup("one");
- tmp = tmp->next = g_new0(__org_qemu_x_Union1List, 1);
- tmp->value = g_new0(__org_qemu_x_Union1, 1);
- tmp->value->type = ORG_QEMU_X_UNION1_KIND___ORG_QEMU_X_BRANCH;
- tmp->value->u.__org_qemu_x_branch.data = g_strdup("two");
- tmp = tmp->next = g_new0(__org_qemu_x_Union1List, 1);
- tmp->value = g_new0(__org_qemu_x_Union1, 1);
- tmp->value->type = ORG_QEMU_X_UNION1_KIND___ORG_QEMU_X_BRANCH;
- tmp->value->u.__org_qemu_x_branch.data = g_strdup("three");
-
- dst = QAPI_CLONE(__org_qemu_x_Struct2, src);
- g_assert(dst);
- tmp = dst->array;
- g_assert(tmp);
- g_assert(tmp->value);
- g_assert_cmpstr(tmp->value->u.__org_qemu_x_branch.data, ==, "one");
- tmp = tmp->next;
- g_assert(tmp);
- g_assert(tmp->value);
- g_assert_cmpstr(tmp->value->u.__org_qemu_x_branch.data, ==, "two");
- tmp = tmp->next;
- g_assert(tmp);
- g_assert(tmp->value);
- g_assert_cmpstr(tmp->value->u.__org_qemu_x_branch.data, ==, "three");
- tmp = tmp->next;
- g_assert(!tmp);
+ UserDefOneList *src, *dst, *tail;
+ UserDefOne *elt;
+
+ src = NULL;
+ elt = g_new0(UserDefOne, 1);
+ elt->integer = 3;
+ elt->string = g_strdup("three");
+ elt->has_enum1 = true;
+ elt->enum1 = ENUM_ONE_VALUE3;
+ QAPI_LIST_PREPEND(src, elt);
+ elt = g_new0(UserDefOne, 1);
+ elt->integer = 2;
+ elt->string = g_strdup("two");
+ QAPI_LIST_PREPEND(src, elt);
+ elt = g_new0(UserDefOne, 1);
+ elt->integer = 1;
+ elt->string = g_strdup("one");
+ QAPI_LIST_PREPEND(src, elt);
+
+ dst = QAPI_CLONE(UserDefOneList, src);
- qapi_free___org_qemu_x_Struct2(src);
- qapi_free___org_qemu_x_Struct2(dst);
+ g_assert(dst);
+ tail = dst;
+ elt = tail->value;
+ g_assert_cmpint(elt->integer, ==, 1);
+ g_assert_cmpstr(elt->string, ==, "one");
+ g_assert(!elt->has_enum1);
+ tail = tail->next;
+ elt = tail->value;
+ g_assert_cmpint(elt->integer, ==, 2);
+ g_assert_cmpstr(elt->string, ==, "two");
+ g_assert(!elt->has_enum1);
+ tail = tail->next;
+ elt = tail->value;
+ g_assert_cmpint(elt->integer, ==, 3);
+ g_assert_cmpstr(elt->string, ==, "three");
+ g_assert(elt->has_enum1);
+ g_assert_cmpint(elt->enum1, ==, ENUM_ONE_VALUE3);
+ g_assert(!tail->next);
+
+ qapi_free_UserDefOneList(src);
+ qapi_free_UserDefOneList(dst);
}
int main(int argc, char **argv)
@@ -189,7 +203,7 @@ int main(int argc, char **argv)
g_test_add_func("/visitor/clone/struct", test_clone_struct);
g_test_add_func("/visitor/clone/alternate", test_clone_alternate);
- g_test_add_func("/visitor/clone/list_union", test_clone_list_union);
+ g_test_add_func("/visitor/clone/list", test_clone_list);
g_test_add_func("/visitor/clone/empty", test_clone_empty);
g_test_add_func("/visitor/clone/complex1", test_clone_complex1);
g_test_add_func("/visitor/clone/complex2", test_clone_complex2);
diff --git a/tests/unit/test-qmp-cmds.c b/tests/unit/test-qmp-cmds.c
index 83efa39..faa8586 100644
--- a/tests/unit/test-qmp-cmds.c
+++ b/tests/unit/test-qmp-cmds.c
@@ -119,7 +119,7 @@ void qmp_boxed_struct(UserDefZero *arg, Error **errp)
{
}
-void qmp_boxed_union(UserDefListUnion *arg, Error **errp)
+void qmp_boxed_union(UserDefFlatUnion *arg, Error **errp)
{
}
@@ -127,22 +127,16 @@ void qmp_boxed_empty(Empty1 *arg, Error **errp)
{
}
-__org_qemu_x_Union1 *qmp___org_qemu_x_command(__org_qemu_x_EnumList *a,
- __org_qemu_x_StructList *b,
- __org_qemu_x_Union2 *c,
- __org_qemu_x_Alt *d,
- Error **errp)
+void qmp___org_qemu_x_command(__org_qemu_x_EnumList *a,
+ __org_qemu_x_StructList *b,
+ __org_qemu_x_Union *c,
+ __org_qemu_x_Alt *d,
+ Error **errp)
{
- __org_qemu_x_Union1 *ret = g_new0(__org_qemu_x_Union1, 1);
-
- ret->type = ORG_QEMU_X_UNION1_KIND___ORG_QEMU_X_BRANCH;
- ret->u.__org_qemu_x_branch.data = strdup("blah1");
-
/* Also test that 'wchar-t' was munged to 'q_wchar_t' */
if (b && b->value && !b->value->has_q_wchar_t) {
b->value->q_wchar_t = 1;
}
- return ret;
}
diff --git a/tests/unit/test-qobject-input-visitor.c b/tests/unit/test-qobject-input-visitor.c
index e41b91a..6f59a7f 100644
--- a/tests/unit/test-qobject-input-visitor.c
+++ b/tests/unit/test-qobject-input-visitor.c
@@ -464,6 +464,151 @@ static void test_visitor_in_list(TestInputVisitorData *data,
g_assert(!head);
}
+static void test_visitor_in_list_struct(TestInputVisitorData *data,
+ const void *unused)
+{
+ const char *int_member[] = {
+ "integer", "s8", "s16", "s32", "s64", "u8", "u16", "u32", "u64" };
+ g_autoptr(GString) json = g_string_new("");
+ int i, j;
+ const char *sep;
+ g_autoptr(ArrayStruct) arrs = NULL;
+ Visitor *v;
+ intList *int_list;
+ int8List *s8_list;
+ int16List *s16_list;
+ int32List *s32_list;
+ int64List *s64_list;
+ uint8List *u8_list;
+ uint16List *u16_list;
+ uint32List *u32_list;
+ uint64List *u64_list;
+ numberList *num_list;
+ boolList *bool_list;
+ strList *str_list;
+
+ g_string_append_printf(json, "{");
+
+ for (i = 0; i < G_N_ELEMENTS(int_member); i++) {
+ g_string_append_printf(json, "'%s': [", int_member[i]);
+ sep = "";
+ for (j = 0; j < 32; j++) {
+ g_string_append_printf(json, "%s%d", sep, j);
+ sep = ", ";
+ }
+ g_string_append_printf(json, "], ");
+ }
+
+ g_string_append_printf(json, "'number': [");
+ sep = "";
+ for (i = 0; i < 32; i++) {
+ g_string_append_printf(json, "%s%f", sep, (double)i / 3);
+ sep = ", ";
+ }
+ g_string_append_printf(json, "], ");
+
+ g_string_append_printf(json, "'boolean': [");
+ sep = "";
+ for (i = 0; i < 32; i++) {
+ g_string_append_printf(json, "%s%s",
+ sep, i % 3 == 0 ? "true" : "false");
+ sep = ", ";
+ }
+ g_string_append_printf(json, "], ");
+
+ g_string_append_printf(json, "'string': [");
+ sep = "";
+ for (i = 0; i < 32; i++) {
+ g_string_append_printf(json, "%s'%d'", sep, i);
+ sep = ", ";
+ }
+ g_string_append_printf(json, "]");
+
+ g_string_append_printf(json, "}");
+
+ v = visitor_input_test_init_raw(data, json->str);
+ visit_type_ArrayStruct(v, NULL, &arrs, &error_abort);
+
+ i = 0;
+ for (int_list = arrs->integer; int_list; int_list = int_list->next) {
+ g_assert_cmpint(int_list->value, ==, i);
+ i++;
+ }
+
+ i = 0;
+ for (s8_list = arrs->s8; s8_list; s8_list = s8_list->next) {
+ g_assert_cmpint(s8_list->value, ==, i);
+ i++;
+ }
+
+ i = 0;
+ for (s16_list = arrs->s16; s16_list; s16_list = s16_list->next) {
+ g_assert_cmpint(s16_list->value, ==, i);
+ i++;
+ }
+
+ i = 0;
+ for (s32_list = arrs->s32; s32_list; s32_list = s32_list->next) {
+ g_assert_cmpint(s32_list->value, ==, i);
+ i++;
+ }
+
+ i = 0;
+ for (s64_list = arrs->s64; s64_list; s64_list = s64_list->next) {
+ g_assert_cmpint(s64_list->value, ==, i);
+ i++;
+ }
+
+ i = 0;
+ for (u8_list = arrs->u8; u8_list; u8_list = u8_list->next) {
+ g_assert_cmpint(u8_list->value, ==, i);
+ i++;
+ }
+
+ i = 0;
+ for (u16_list = arrs->u16; u16_list; u16_list = u16_list->next) {
+ g_assert_cmpint(u16_list->value, ==, i);
+ i++;
+ }
+
+ i = 0;
+ for (u32_list = arrs->u32; u32_list; u32_list = u32_list->next) {
+ g_assert_cmpint(u32_list->value, ==, i);
+ i++;
+ }
+
+ i = 0;
+ for (u64_list = arrs->u64; u64_list; u64_list = u64_list->next) {
+ g_assert_cmpint(u64_list->value, ==, i);
+ i++;
+ }
+
+ i = 0;
+ for (num_list = arrs->number; num_list; num_list = num_list->next) {
+ char expected[32], actual[32];
+
+ sprintf(expected, "%.6f", (double)i / 3);
+ sprintf(actual, "%.6f", num_list->value);
+ g_assert_cmpstr(expected, ==, actual);
+ i++;
+ }
+
+ i = 0;
+ for (bool_list = arrs->boolean; bool_list; bool_list = bool_list->next) {
+ g_assert_cmpint(bool_list->value, ==, i % 3 == 0);
+ i++;
+ }
+
+ i = 0;
+ for (str_list = arrs->string; str_list; str_list = str_list->next) {
+ char expected[32];
+
+ sprintf(expected, "%d", i);
+ g_assert_cmpstr(str_list->value, ==, expected);
+ i++;
+ }
+}
+
static void test_visitor_in_any(TestInputVisitorData *data,
const void *unused)
{
@@ -682,276 +827,6 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data,
qapi_free_AltEnumInt(asi);
}
-static void test_list_union_integer_helper(TestInputVisitorData *data,
- const void *unused,
- UserDefListUnionKind kind)
-{
- g_autoptr(UserDefListUnion) cvalue = NULL;
- Visitor *v;
- GString *gstr_list = g_string_new("");
- GString *gstr_union = g_string_new("");
- int i;
-
- for (i = 0; i < 32; i++) {
- g_string_append_printf(gstr_list, "%d", i);
- if (i != 31) {
- g_string_append(gstr_list, ", ");
- }
- }
- g_string_append_printf(gstr_union, "{ 'type': '%s', 'data': [ %s ] }",
- UserDefListUnionKind_str(kind),
- gstr_list->str);
- v = visitor_input_test_init_raw(data, gstr_union->str);
-
- visit_type_UserDefListUnion(v, NULL, &cvalue, &error_abort);
- g_assert(cvalue != NULL);
- g_assert_cmpint(cvalue->type, ==, kind);
-
- switch (kind) {
- case USER_DEF_LIST_UNION_KIND_INTEGER: {
- intList *elem = NULL;
- for (i = 0, elem = cvalue->u.integer.data;
- elem; elem = elem->next, i++) {
- g_assert_cmpint(elem->value, ==, i);
- }
- break;
- }
- case USER_DEF_LIST_UNION_KIND_S8: {
- int8List *elem = NULL;
- for (i = 0, elem = cvalue->u.s8.data; elem; elem = elem->next, i++) {
- g_assert_cmpint(elem->value, ==, i);
- }
- break;
- }
- case USER_DEF_LIST_UNION_KIND_S16: {
- int16List *elem = NULL;
- for (i = 0, elem = cvalue->u.s16.data; elem; elem = elem->next, i++) {
- g_assert_cmpint(elem->value, ==, i);
- }
- break;
- }
- case USER_DEF_LIST_UNION_KIND_S32: {
- int32List *elem = NULL;
- for (i = 0, elem = cvalue->u.s32.data; elem; elem = elem->next, i++) {
- g_assert_cmpint(elem->value, ==, i);
- }
- break;
- }
- case USER_DEF_LIST_UNION_KIND_S64: {
- int64List *elem = NULL;
- for (i = 0, elem = cvalue->u.s64.data; elem; elem = elem->next, i++) {
- g_assert_cmpint(elem->value, ==, i);
- }
- break;
- }
- case USER_DEF_LIST_UNION_KIND_U8: {
- uint8List *elem = NULL;
- for (i = 0, elem = cvalue->u.u8.data; elem; elem = elem->next, i++) {
- g_assert_cmpint(elem->value, ==, i);
- }
- break;
- }
- case USER_DEF_LIST_UNION_KIND_U16: {
- uint16List *elem = NULL;
- for (i = 0, elem = cvalue->u.u16.data; elem; elem = elem->next, i++) {
- g_assert_cmpint(elem->value, ==, i);
- }
- break;
- }
- case USER_DEF_LIST_UNION_KIND_U32: {
- uint32List *elem = NULL;
- for (i = 0, elem = cvalue->u.u32.data; elem; elem = elem->next, i++) {
- g_assert_cmpint(elem->value, ==, i);
- }
- break;
- }
- case USER_DEF_LIST_UNION_KIND_U64: {
- uint64List *elem = NULL;
- for (i = 0, elem = cvalue->u.u64.data; elem; elem = elem->next, i++) {
- g_assert_cmpint(elem->value, ==, i);
- }
- break;
- }
- default:
- g_assert_not_reached();
- }
-
- g_string_free(gstr_union, true);
- g_string_free(gstr_list, true);
-}
-
-static void test_visitor_in_list_union_int(TestInputVisitorData *data,
- const void *unused)
-{
- test_list_union_integer_helper(data, unused,
- USER_DEF_LIST_UNION_KIND_INTEGER);
-}
-
-static void test_visitor_in_list_union_int8(TestInputVisitorData *data,
- const void *unused)
-{
- test_list_union_integer_helper(data, unused,
- USER_DEF_LIST_UNION_KIND_S8);
-}
-
-static void test_visitor_in_list_union_int16(TestInputVisitorData *data,
- const void *unused)
-{
- test_list_union_integer_helper(data, unused,
- USER_DEF_LIST_UNION_KIND_S16);
-}
-
-static void test_visitor_in_list_union_int32(TestInputVisitorData *data,
- const void *unused)
-{
- test_list_union_integer_helper(data, unused,
- USER_DEF_LIST_UNION_KIND_S32);
-}
-
-static void test_visitor_in_list_union_int64(TestInputVisitorData *data,
- const void *unused)
-{
- test_list_union_integer_helper(data, unused,
- USER_DEF_LIST_UNION_KIND_S64);
-}
-
-static void test_visitor_in_list_union_uint8(TestInputVisitorData *data,
- const void *unused)
-{
- test_list_union_integer_helper(data, unused,
- USER_DEF_LIST_UNION_KIND_U8);
-}
-
-static void test_visitor_in_list_union_uint16(TestInputVisitorData *data,
- const void *unused)
-{
- test_list_union_integer_helper(data, unused,
- USER_DEF_LIST_UNION_KIND_U16);
-}
-
-static void test_visitor_in_list_union_uint32(TestInputVisitorData *data,
- const void *unused)
-{
- test_list_union_integer_helper(data, unused,
- USER_DEF_LIST_UNION_KIND_U32);
-}
-
-static void test_visitor_in_list_union_uint64(TestInputVisitorData *data,
- const void *unused)
-{
- test_list_union_integer_helper(data, unused,
- USER_DEF_LIST_UNION_KIND_U64);
-}
-
-static void test_visitor_in_list_union_bool(TestInputVisitorData *data,
- const void *unused)
-{
- g_autoptr(UserDefListUnion) cvalue = NULL;
- boolList *elem = NULL;
- Visitor *v;
- GString *gstr_list = g_string_new("");
- GString *gstr_union = g_string_new("");
- int i;
-
- for (i = 0; i < 32; i++) {
- g_string_append_printf(gstr_list, "%s",
- (i % 3 == 0) ? "true" : "false");
- if (i != 31) {
- g_string_append(gstr_list, ", ");
- }
- }
- g_string_append_printf(gstr_union, "{ 'type': 'boolean', 'data': [ %s ] }",
- gstr_list->str);
- v = visitor_input_test_init_raw(data, gstr_union->str);
-
- visit_type_UserDefListUnion(v, NULL, &cvalue, &error_abort);
- g_assert(cvalue != NULL);
- g_assert_cmpint(cvalue->type, ==, USER_DEF_LIST_UNION_KIND_BOOLEAN);
-
- for (i = 0, elem = cvalue->u.boolean.data; elem; elem = elem->next, i++) {
- g_assert_cmpint(elem->value, ==, (i % 3 == 0) ? 1 : 0);
- }
-
- g_string_free(gstr_union, true);
- g_string_free(gstr_list, true);
-}
-
-static void test_visitor_in_list_union_string(TestInputVisitorData *data,
- const void *unused)
-{
- g_autoptr(UserDefListUnion) cvalue = NULL;
- strList *elem = NULL;
- Visitor *v;
- GString *gstr_list = g_string_new("");
- GString *gstr_union = g_string_new("");
- int i;
-
- for (i = 0; i < 32; i++) {
- g_string_append_printf(gstr_list, "'%d'", i);
- if (i != 31) {
- g_string_append(gstr_list, ", ");
- }
- }
- g_string_append_printf(gstr_union, "{ 'type': 'string', 'data': [ %s ] }",
- gstr_list->str);
- v = visitor_input_test_init_raw(data, gstr_union->str);
-
- visit_type_UserDefListUnion(v, NULL, &cvalue, &error_abort);
- g_assert(cvalue != NULL);
- g_assert_cmpint(cvalue->type, ==, USER_DEF_LIST_UNION_KIND_STRING);
-
- for (i = 0, elem = cvalue->u.string.data; elem; elem = elem->next, i++) {
- gchar str[8];
- sprintf(str, "%d", i);
- g_assert_cmpstr(elem->value, ==, str);
- }
-
- g_string_free(gstr_union, true);
- g_string_free(gstr_list, true);
-}
-
-#define DOUBLE_STR_MAX 16
-
-static void test_visitor_in_list_union_number(TestInputVisitorData *data,
- const void *unused)
-{
- g_autoptr(UserDefListUnion) cvalue = NULL;
- numberList *elem = NULL;
- Visitor *v;
- GString *gstr_list = g_string_new("");
- GString *gstr_union = g_string_new("");
- int i;
-
- for (i = 0; i < 32; i++) {
- g_string_append_printf(gstr_list, "%f", (double)i / 3);
- if (i != 31) {
- g_string_append(gstr_list, ", ");
- }
- }
- g_string_append_printf(gstr_union, "{ 'type': 'number', 'data': [ %s ] }",
- gstr_list->str);
- v = visitor_input_test_init_raw(data, gstr_union->str);
-
- visit_type_UserDefListUnion(v, NULL, &cvalue, &error_abort);
- g_assert(cvalue != NULL);
- g_assert_cmpint(cvalue->type, ==, USER_DEF_LIST_UNION_KIND_NUMBER);
-
- for (i = 0, elem = cvalue->u.number.data; elem; elem = elem->next, i++) {
- GString *double_expected = g_string_new("");
- GString *double_actual = g_string_new("");
-
- g_string_printf(double_expected, "%.6f", (double)i / 3);
- g_string_printf(double_actual, "%.6f", elem->value);
- g_assert_cmpstr(double_expected->str, ==, double_actual->str);
-
- g_string_free(double_expected, true);
- g_string_free(double_actual, true);
- }
-
- g_string_free(gstr_union, true);
- g_string_free(gstr_list, true);
-}
-
static void input_visitor_test_add(const char *testpath,
const void *user_data,
void (*test_func)(TestInputVisitorData *data,
@@ -1184,21 +1059,6 @@ static void test_visitor_in_fail_list_nested(TestInputVisitorData *data,
visit_end_list(v, NULL);
}
-static void test_visitor_in_fail_union_list(TestInputVisitorData *data,
- const void *unused)
-{
- UserDefListUnion *tmp = NULL;
- Error *err = NULL;
- Visitor *v;
-
- v = visitor_input_test_init(data,
- "{ 'type': 'integer', 'data' : [ 'string' ] }");
-
- visit_type_UserDefListUnion(v, NULL, &tmp, &err);
- error_free_or_abort(&err);
- g_assert(!tmp);
-}
-
static void test_visitor_in_fail_union_flat(TestInputVisitorData *data,
const void *unused)
{
@@ -1206,7 +1066,7 @@ static void test_visitor_in_fail_union_flat(TestInputVisitorData *data,
Error *err = NULL;
Visitor *v;
- v = visitor_input_test_init(data, "{ 'string': 'c', 'integer': 41, 'boolean': true }");
+ v = visitor_input_test_init(data, "{ 'enum1': 'value2', 'string': 'c', 'integer': 41, 'boolean': true }");
visit_type_UserDefFlatUnion(v, NULL, &tmp, &err);
error_free_or_abort(&err);
@@ -1310,6 +1170,8 @@ int main(int argc, char **argv)
NULL, test_visitor_in_struct);
input_visitor_test_add("/visitor/input/struct-nested",
NULL, test_visitor_in_struct_nested);
+ input_visitor_test_add("/visitor/input/list2",
+ NULL, test_visitor_in_list_struct);
input_visitor_test_add("/visitor/input/list",
NULL, test_visitor_in_list);
input_visitor_test_add("/visitor/input/any",
@@ -1326,30 +1188,6 @@ int main(int argc, char **argv)
NULL, test_visitor_in_wrong_type);
input_visitor_test_add("/visitor/input/alternate-number",
NULL, test_visitor_in_alternate_number);
- input_visitor_test_add("/visitor/input/list_union/int",
- NULL, test_visitor_in_list_union_int);
- input_visitor_test_add("/visitor/input/list_union/int8",
- NULL, test_visitor_in_list_union_int8);
- input_visitor_test_add("/visitor/input/list_union/int16",
- NULL, test_visitor_in_list_union_int16);
- input_visitor_test_add("/visitor/input/list_union/int32",
- NULL, test_visitor_in_list_union_int32);
- input_visitor_test_add("/visitor/input/list_union/int64",
- NULL, test_visitor_in_list_union_int64);
- input_visitor_test_add("/visitor/input/list_union/uint8",
- NULL, test_visitor_in_list_union_uint8);
- input_visitor_test_add("/visitor/input/list_union/uint16",
- NULL, test_visitor_in_list_union_uint16);
- input_visitor_test_add("/visitor/input/list_union/uint32",
- NULL, test_visitor_in_list_union_uint32);
- input_visitor_test_add("/visitor/input/list_union/uint64",
- NULL, test_visitor_in_list_union_uint64);
- input_visitor_test_add("/visitor/input/list_union/bool",
- NULL, test_visitor_in_list_union_bool);
- input_visitor_test_add("/visitor/input/list_union/str",
- NULL, test_visitor_in_list_union_string);
- input_visitor_test_add("/visitor/input/list_union/number",
- NULL, test_visitor_in_list_union_number);
input_visitor_test_add("/visitor/input/fail/struct",
NULL, test_visitor_in_fail_struct);
input_visitor_test_add("/visitor/input/fail/struct-nested",
@@ -1368,8 +1206,6 @@ int main(int argc, char **argv)
NULL, test_visitor_in_fail_union_flat_no_discrim);
input_visitor_test_add("/visitor/input/fail/alternate",
NULL, test_visitor_in_fail_alternate);
- input_visitor_test_add("/visitor/input/fail/union-list",
- NULL, test_visitor_in_fail_union_list);
input_visitor_test_add("/visitor/input/qapi-introspect",
NULL, test_visitor_in_qmp_introspect);
diff --git a/tests/unit/test-qobject-output-visitor.c b/tests/unit/test-qobject-output-visitor.c
index 9dc1e07..34d67a4 100644
--- a/tests/unit/test-qobject-output-visitor.c
+++ b/tests/unit/test-qobject-output-visitor.c
@@ -437,289 +437,118 @@ static void test_visitor_out_null(TestOutputVisitorData *data,
g_assert(qobject_type(nil) == QTYPE_QNULL);
}
-static void init_list_union(UserDefListUnion *cvalue)
+static void test_visitor_out_list_struct(TestOutputVisitorData *data,
+ const void *unused)
{
- int i;
- switch (cvalue->type) {
- case USER_DEF_LIST_UNION_KIND_INTEGER: {
- intList **tail = &cvalue->u.integer.data;
- for (i = 0; i < 32; i++) {
- QAPI_LIST_APPEND(tail, i);
- }
- break;
- }
- case USER_DEF_LIST_UNION_KIND_S8: {
- int8List **tail = &cvalue->u.s8.data;
- for (i = 0; i < 32; i++) {
- QAPI_LIST_APPEND(tail, i);
- }
- break;
+ const char *int_member[] = {
+ "integer", "s8", "s16", "s32", "s64", "u8", "u16", "u32", "u64" };
+ g_autoptr(ArrayStruct) arrs = g_new0(ArrayStruct, 1);
+ int i, j;
+ QDict *qdict;
+ QList *qlist;
+ QListEntry *e;
+
+ for (i = 31; i >= 0; i--) {
+ QAPI_LIST_PREPEND(arrs->integer, i);
}
- case USER_DEF_LIST_UNION_KIND_S16: {
- int16List **tail = &cvalue->u.s16.data;
- for (i = 0; i < 32; i++) {
- QAPI_LIST_APPEND(tail, i);
- }
- break;
+
+ for (i = 31; i >= 0; i--) {
+ QAPI_LIST_PREPEND(arrs->s8, i);
}
- case USER_DEF_LIST_UNION_KIND_S32: {
- int32List **tail = &cvalue->u.s32.data;
- for (i = 0; i < 32; i++) {
- QAPI_LIST_APPEND(tail, i);
- }
- break;
+
+ for (i = 31; i >= 0; i--) {
+ QAPI_LIST_PREPEND(arrs->s16, i);
}
- case USER_DEF_LIST_UNION_KIND_S64: {
- int64List **tail = &cvalue->u.s64.data;
- for (i = 0; i < 32; i++) {
- QAPI_LIST_APPEND(tail, i);
- }
- break;
+
+ for (i = 31; i >= 0; i--) {
+ QAPI_LIST_PREPEND(arrs->s32, i);
}
- case USER_DEF_LIST_UNION_KIND_U8: {
- uint8List **tail = &cvalue->u.u8.data;
- for (i = 0; i < 32; i++) {
- QAPI_LIST_APPEND(tail, i);
- }
- break;
+
+ for (i = 31; i >= 0; i--) {
+ QAPI_LIST_PREPEND(arrs->s64, i);
}
- case USER_DEF_LIST_UNION_KIND_U16: {
- uint16List **tail = &cvalue->u.u16.data;
- for (i = 0; i < 32; i++) {
- QAPI_LIST_APPEND(tail, i);
- }
- break;
+
+ for (i = 31; i >= 0; i--) {
+ QAPI_LIST_PREPEND(arrs->u8, i);
}
- case USER_DEF_LIST_UNION_KIND_U32: {
- uint32List **tail = &cvalue->u.u32.data;
- for (i = 0; i < 32; i++) {
- QAPI_LIST_APPEND(tail, i);
- }
- break;
+
+ for (i = 31; i >= 0; i--) {
+ QAPI_LIST_PREPEND(arrs->u16, i);
}
- case USER_DEF_LIST_UNION_KIND_U64: {
- uint64List **tail = &cvalue->u.u64.data;
- for (i = 0; i < 32; i++) {
- QAPI_LIST_APPEND(tail, i);
- }
- break;
+
+ for (i = 31; i >= 0; i--) {
+ QAPI_LIST_PREPEND(arrs->u32, i);
}
- case USER_DEF_LIST_UNION_KIND_BOOLEAN: {
- boolList **tail = &cvalue->u.boolean.data;
- for (i = 0; i < 32; i++) {
- QAPI_LIST_APPEND(tail, QEMU_IS_ALIGNED(i, 3));
- }
- break;
+
+ for (i = 31; i >= 0; i--) {
+ QAPI_LIST_PREPEND(arrs->u64, i);
}
- case USER_DEF_LIST_UNION_KIND_STRING: {
- strList **tail = &cvalue->u.string.data;
- for (i = 0; i < 32; i++) {
- QAPI_LIST_APPEND(tail, g_strdup_printf("%d", i));
- }
- break;
+
+ for (i = 31; i >= 0; i--) {
+ QAPI_LIST_PREPEND(arrs->number, (double)i / 3);
}
- case USER_DEF_LIST_UNION_KIND_NUMBER: {
- numberList **tail = &cvalue->u.number.data;
- for (i = 0; i < 32; i++) {
- QAPI_LIST_APPEND(tail, (double)i / 3);
- }
- break;
+
+ for (i = 31; i >= 0; i--) {
+ QAPI_LIST_PREPEND(arrs->boolean, QEMU_IS_ALIGNED(i, 3));
}
- default:
- g_assert_not_reached();
+
+ for (i = 31; i >= 0; i--) {
+ QAPI_LIST_PREPEND(arrs->string, g_strdup_printf("%d", i));
}
-}
-static void check_list_union(QObject *qobj,
- UserDefListUnionKind kind)
-{
- QDict *qdict;
- QList *qlist;
- int i;
+ visit_type_ArrayStruct(data->ov, NULL, &arrs, &error_abort);
- qdict = qobject_to(QDict, qobj);
+ qdict = qobject_to(QDict, visitor_get(data));
g_assert(qdict);
- g_assert(qdict_haskey(qdict, "data"));
- qlist = qlist_copy(qobject_to(QList, qdict_get(qdict, "data")));
-
- switch (kind) {
- case USER_DEF_LIST_UNION_KIND_U8:
- case USER_DEF_LIST_UNION_KIND_U16:
- case USER_DEF_LIST_UNION_KIND_U32:
- case USER_DEF_LIST_UNION_KIND_U64:
- for (i = 0; i < 32; i++) {
- QObject *tmp;
- QNum *qvalue;
- uint64_t val;
-
- tmp = qlist_peek(qlist);
- g_assert(tmp);
- qvalue = qobject_to(QNum, tmp);
- g_assert(qnum_get_try_uint(qvalue, &val));
- g_assert_cmpint(val, ==, i);
- qobject_unref(qlist_pop(qlist));
- }
- break;
-
- case USER_DEF_LIST_UNION_KIND_S8:
- case USER_DEF_LIST_UNION_KIND_S16:
- case USER_DEF_LIST_UNION_KIND_S32:
- case USER_DEF_LIST_UNION_KIND_S64:
- /*
- * All integer elements in JSON arrays get stored into QNums
- * when we convert to QObjects, so we can check them all in
- * the same fashion, so simply fall through here.
- */
- case USER_DEF_LIST_UNION_KIND_INTEGER:
- for (i = 0; i < 32; i++) {
- QObject *tmp;
- QNum *qvalue;
- int64_t val;
-
- tmp = qlist_peek(qlist);
- g_assert(tmp);
- qvalue = qobject_to(QNum, tmp);
- g_assert(qnum_get_try_int(qvalue, &val));
- g_assert_cmpint(val, ==, i);
- qobject_unref(qlist_pop(qlist));
- }
- break;
- case USER_DEF_LIST_UNION_KIND_BOOLEAN:
- for (i = 0; i < 32; i++) {
- QObject *tmp;
- QBool *qvalue;
- tmp = qlist_peek(qlist);
- g_assert(tmp);
- qvalue = qobject_to(QBool, tmp);
- g_assert_cmpint(qbool_get_bool(qvalue), ==, i % 3 == 0);
- qobject_unref(qlist_pop(qlist));
- }
- break;
- case USER_DEF_LIST_UNION_KIND_STRING:
- for (i = 0; i < 32; i++) {
- QObject *tmp;
- QString *qvalue;
- gchar str[8];
- tmp = qlist_peek(qlist);
- g_assert(tmp);
- qvalue = qobject_to(QString, tmp);
- sprintf(str, "%d", i);
- g_assert_cmpstr(qstring_get_str(qvalue), ==, str);
- qobject_unref(qlist_pop(qlist));
- }
- break;
- case USER_DEF_LIST_UNION_KIND_NUMBER:
- for (i = 0; i < 32; i++) {
- QObject *tmp;
- QNum *qvalue;
- GString *double_expected = g_string_new("");
- GString *double_actual = g_string_new("");
-
- tmp = qlist_peek(qlist);
- g_assert(tmp);
- qvalue = qobject_to(QNum, tmp);
- g_string_printf(double_expected, "%.6f", (double)i / 3);
- g_string_printf(double_actual, "%.6f", qnum_get_double(qvalue));
- g_assert_cmpstr(double_actual->str, ==, double_expected->str);
-
- qobject_unref(qlist_pop(qlist));
- g_string_free(double_expected, true);
- g_string_free(double_actual, true);
+
+ for (i = 0; i < G_N_ELEMENTS(int_member); i++) {
+ qlist = qdict_get_qlist(qdict, int_member[i]);
+ g_assert(qlist);
+ j = 0;
+ QLIST_FOREACH_ENTRY(qlist, e) {
+ QNum *qvalue = qobject_to(QNum, qlist_entry_obj(e));
+ g_assert(qvalue);
+ g_assert_cmpint(qnum_get_int(qvalue), ==, j);
+ j++;
}
- break;
- default:
- g_assert_not_reached();
}
- qobject_unref(qlist);
-}
-
-static void test_list_union(TestOutputVisitorData *data,
- const void *unused,
- UserDefListUnionKind kind)
-{
- UserDefListUnion *cvalue = g_new0(UserDefListUnion, 1);
- QObject *obj;
-
- cvalue->type = kind;
- init_list_union(cvalue);
-
- visit_type_UserDefListUnion(data->ov, NULL, &cvalue, &error_abort);
-
- obj = visitor_get(data);
- check_list_union(obj, cvalue->type);
- qapi_free_UserDefListUnion(cvalue);
-}
-
-static void test_visitor_out_list_union_int(TestOutputVisitorData *data,
- const void *unused)
-{
- test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_INTEGER);
-}
-
-static void test_visitor_out_list_union_int8(TestOutputVisitorData *data,
- const void *unused)
-{
- test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_S8);
-}
-
-static void test_visitor_out_list_union_int16(TestOutputVisitorData *data,
- const void *unused)
-{
- test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_S16);
-}
-
-static void test_visitor_out_list_union_int32(TestOutputVisitorData *data,
- const void *unused)
-{
- test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_S32);
-}
-
-static void test_visitor_out_list_union_int64(TestOutputVisitorData *data,
- const void *unused)
-{
- test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_S64);
-}
-
-static void test_visitor_out_list_union_uint8(TestOutputVisitorData *data,
- const void *unused)
-{
- test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_U8);
-}
-
-static void test_visitor_out_list_union_uint16(TestOutputVisitorData *data,
- const void *unused)
-{
- test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_U16);
-}
-static void test_visitor_out_list_union_uint32(TestOutputVisitorData *data,
- const void *unused)
-{
- test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_U32);
-}
-
-static void test_visitor_out_list_union_uint64(TestOutputVisitorData *data,
- const void *unused)
-{
- test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_U64);
-}
+ qlist = qdict_get_qlist(qdict, "number");
+ g_assert(qlist);
+ i = 0;
+ QLIST_FOREACH_ENTRY(qlist, e) {
+ QNum *qvalue = qobject_to(QNum, qlist_entry_obj(e));
+ char expected[32], actual[32];
+
+ g_assert(qvalue);
+ sprintf(expected, "%.6f", (double)i / 3);
+ sprintf(actual, "%.6f", qnum_get_double(qvalue));
+ g_assert_cmpstr(actual, ==, expected);
+ i++;
+ }
-static void test_visitor_out_list_union_bool(TestOutputVisitorData *data,
- const void *unused)
-{
- test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_BOOLEAN);
-}
+ qlist = qdict_get_qlist(qdict, "boolean");
+ g_assert(qlist);
+ i = 0;
+ QLIST_FOREACH_ENTRY(qlist, e) {
+ QBool *qvalue = qobject_to(QBool, qlist_entry_obj(e));
+ g_assert(qvalue);
+ g_assert_cmpint(qbool_get_bool(qvalue), ==, i % 3 == 0);
+ i++;
+ }
-static void test_visitor_out_list_union_str(TestOutputVisitorData *data,
- const void *unused)
-{
- test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_STRING);
-}
+ qlist = qdict_get_qlist(qdict, "string");
+ g_assert(qlist);
+ i = 0;
+ QLIST_FOREACH_ENTRY(qlist, e) {
+ QString *qvalue = qobject_to(QString, qlist_entry_obj(e));
+ char expected[32];
-static void test_visitor_out_list_union_number(TestOutputVisitorData *data,
- const void *unused)
-{
- test_list_union(data, unused, USER_DEF_LIST_UNION_KIND_NUMBER);
+ g_assert(qvalue);
+ sprintf(expected, "%d", i);
+ g_assert_cmpstr(qstring_get_str(qvalue), ==, expected);
+ i++;
+ }
}
static void output_visitor_test_add(const char *testpath,
@@ -764,42 +593,8 @@ int main(int argc, char **argv)
&out_visitor_data, test_visitor_out_alternate);
output_visitor_test_add("/visitor/output/null",
&out_visitor_data, test_visitor_out_null);
- output_visitor_test_add("/visitor/output/list_union/int",
- &out_visitor_data,
- test_visitor_out_list_union_int);
- output_visitor_test_add("/visitor/output/list_union/int8",
- &out_visitor_data,
- test_visitor_out_list_union_int8);
- output_visitor_test_add("/visitor/output/list_union/int16",
- &out_visitor_data,
- test_visitor_out_list_union_int16);
- output_visitor_test_add("/visitor/output/list_union/int32",
- &out_visitor_data,
- test_visitor_out_list_union_int32);
- output_visitor_test_add("/visitor/output/list_union/int64",
- &out_visitor_data,
- test_visitor_out_list_union_int64);
- output_visitor_test_add("/visitor/output/list_union/uint8",
- &out_visitor_data,
- test_visitor_out_list_union_uint8);
- output_visitor_test_add("/visitor/output/list_union/uint16",
- &out_visitor_data,
- test_visitor_out_list_union_uint16);
- output_visitor_test_add("/visitor/output/list_union/uint32",
- &out_visitor_data,
- test_visitor_out_list_union_uint32);
- output_visitor_test_add("/visitor/output/list_union/uint64",
- &out_visitor_data,
- test_visitor_out_list_union_uint64);
- output_visitor_test_add("/visitor/output/list_union/bool",
- &out_visitor_data,
- test_visitor_out_list_union_bool);
- output_visitor_test_add("/visitor/output/list_union/string",
- &out_visitor_data,
- test_visitor_out_list_union_str);
- output_visitor_test_add("/visitor/output/list_union/number",
- &out_visitor_data,
- test_visitor_out_list_union_number);
+ output_visitor_test_add("/visitor/output/list_struct",
+ &out_visitor_data, test_visitor_out_list_struct);
g_test_run();
diff --git a/tests/unit/test-yank.c b/tests/unit/test-yank.c
index 2383d29..e6c036a 100644
--- a/tests/unit/test-yank.c
+++ b/tests/unit/test-yank.c
@@ -88,7 +88,7 @@ static void char_change_test(gconstpointer opaque)
.type = CHARDEV_BACKEND_KIND_SOCKET,
.u.socket.data = &(ChardevSocket) {
.addr = &(SocketAddressLegacy) {
- .type = SOCKET_ADDRESS_LEGACY_KIND_INET,
+ .type = SOCKET_ADDRESS_TYPE_INET,
.u.inet.data = &addr->u.inet
},
.has_server = true,
@@ -102,7 +102,7 @@ static void char_change_test(gconstpointer opaque)
.type = CHARDEV_BACKEND_KIND_UDP,
.u.udp.data = &(ChardevUdp) {
.remote = &(SocketAddressLegacy) {
- .type = SOCKET_ADDRESS_LEGACY_KIND_UNIX,
+ .type = SOCKET_ADDRESS_TYPE_UNIX,
.u.q_unix.data = &(UnixSocketAddress) {
.path = (char *)""
}
@@ -114,7 +114,7 @@ static void char_change_test(gconstpointer opaque)
.type = CHARDEV_BACKEND_KIND_SOCKET,
.u.socket.data = &(ChardevSocket) {
.addr = &(SocketAddressLegacy) {
- .type = SOCKET_ADDRESS_LEGACY_KIND_INET,
+ .type = SOCKET_ADDRESS_TYPE_INET,
.u.inet.data = &(InetSocketAddress) {
.host = (char *)"127.0.0.1",
.port = (char *)"0"