mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-01 23:03:54 -06:00
qapi: allow unions to contain further unions
This extends the QAPI schema validation to permit unions inside unions, provided the checks for clashing fields pass. Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-Id: <20230420102619.348173-4-berrange@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
1e148b545f
commit
a17dbc4b79
12 changed files with 234 additions and 3 deletions
|
@ -706,6 +706,51 @@ static void test_visitor_in_union_flat(TestInputVisitorData *data,
|
|||
g_assert(&base->enum1 == &tmp->enum1);
|
||||
}
|
||||
|
||||
static void test_visitor_in_union_in_union(TestInputVisitorData *data,
|
||||
const void *unused)
|
||||
{
|
||||
Visitor *v;
|
||||
g_autoptr(TestUnionInUnion) tmp = NULL;
|
||||
|
||||
v = visitor_input_test_init(data,
|
||||
"{ 'type': 'value-a', "
|
||||
" 'type-a': 'value-a1', "
|
||||
" 'integer': 2, "
|
||||
" 'name': 'fish' }");
|
||||
|
||||
visit_type_TestUnionInUnion(v, NULL, &tmp, &error_abort);
|
||||
g_assert_cmpint(tmp->type, ==, TEST_UNION_ENUM_VALUE_A);
|
||||
g_assert_cmpint(tmp->u.value_a.type_a, ==, TEST_UNION_ENUMA_VALUE_A1);
|
||||
g_assert_cmpint(tmp->u.value_a.u.value_a1.integer, ==, 2);
|
||||
g_assert_cmpint(strcmp(tmp->u.value_a.u.value_a1.name, "fish"), ==, 0);
|
||||
|
||||
qapi_free_TestUnionInUnion(tmp);
|
||||
|
||||
v = visitor_input_test_init(data,
|
||||
"{ 'type': 'value-a', "
|
||||
" 'type-a': 'value-a2', "
|
||||
" 'integer': 1729, "
|
||||
" 'size': 87539319 }");
|
||||
|
||||
visit_type_TestUnionInUnion(v, NULL, &tmp, &error_abort);
|
||||
g_assert_cmpint(tmp->type, ==, TEST_UNION_ENUM_VALUE_A);
|
||||
g_assert_cmpint(tmp->u.value_a.type_a, ==, TEST_UNION_ENUMA_VALUE_A2);
|
||||
g_assert_cmpint(tmp->u.value_a.u.value_a2.integer, ==, 1729);
|
||||
g_assert_cmpint(tmp->u.value_a.u.value_a2.size, ==, 87539319);
|
||||
|
||||
qapi_free_TestUnionInUnion(tmp);
|
||||
|
||||
v = visitor_input_test_init(data,
|
||||
"{ 'type': 'value-b', "
|
||||
" 'integer': 1729, "
|
||||
" 'onoff': true }");
|
||||
|
||||
visit_type_TestUnionInUnion(v, NULL, &tmp, &error_abort);
|
||||
g_assert_cmpint(tmp->type, ==, TEST_UNION_ENUM_VALUE_B);
|
||||
g_assert_cmpint(tmp->u.value_b.integer, ==, 1729);
|
||||
g_assert_cmpint(tmp->u.value_b.onoff, ==, true);
|
||||
}
|
||||
|
||||
static void test_visitor_in_alternate(TestInputVisitorData *data,
|
||||
const void *unused)
|
||||
{
|
||||
|
@ -1216,6 +1261,8 @@ int main(int argc, char **argv)
|
|||
NULL, test_visitor_in_null);
|
||||
input_visitor_test_add("/visitor/input/union-flat",
|
||||
NULL, test_visitor_in_union_flat);
|
||||
input_visitor_test_add("/visitor/input/union-in-union",
|
||||
NULL, test_visitor_in_union_in_union);
|
||||
input_visitor_test_add("/visitor/input/alternate",
|
||||
NULL, test_visitor_in_alternate);
|
||||
input_visitor_test_add("/visitor/input/errors",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue