mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 23:33:54 -06:00
qapi script: do not allow string discriminator
Since enum based discriminators provide better type-safety and ensure that future qapi additions do not forget to adjust dependent unions, forbid using string as discriminator from now on. Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
This commit is contained in:
parent
59ca664ef8
commit
5223070c47
12 changed files with 53 additions and 18 deletions
|
@ -449,10 +449,11 @@ static void test_visitor_out_union_flat(TestOutputVisitorData *data,
|
|||
Error *err = NULL;
|
||||
|
||||
UserDefFlatUnion *tmp = g_malloc0(sizeof(UserDefFlatUnion));
|
||||
tmp->kind = USER_DEF_UNION_KIND_A;
|
||||
tmp->a = g_malloc0(sizeof(UserDefA));
|
||||
tmp->kind = ENUM_ONE_VALUE1;
|
||||
tmp->string = g_strdup("str");
|
||||
tmp->value1 = g_malloc0(sizeof(UserDefA));
|
||||
/* TODO when generator bug is fixed: tmp->integer = 41; */
|
||||
tmp->a->boolean = true;
|
||||
tmp->value1->boolean = true;
|
||||
|
||||
visit_type_UserDefFlatUnion(data->ov, &tmp, NULL, &err);
|
||||
g_assert(err == NULL);
|
||||
|
@ -461,7 +462,8 @@ static void test_visitor_out_union_flat(TestOutputVisitorData *data,
|
|||
g_assert(qobject_type(arg) == QTYPE_QDICT);
|
||||
qdict = qobject_to_qdict(arg);
|
||||
|
||||
g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, "a");
|
||||
g_assert_cmpstr(qdict_get_str(qdict, "enum1"), ==, "value1");
|
||||
g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, "str");
|
||||
/* TODO g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 41); */
|
||||
g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, true);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue