qapi: Drop tests for inline nested structs

A future patch will be using a 'name':{dictionary} entry in the
QAPI schema to specify a default value for an optional argument;
but existing use of inline nested structs conflicts with that goal.

More precisely, a definition in the QAPI schema associates a name
with a set of properties:

Example 1: { 'struct': 'Foo', 'data': { MEMBERS... } }
associates the global name 'Foo' with properties (meta-type struct)
and MEMBERS...

Example 2: 'mumble': TYPE
within MEMBERS... above associates 'mumble' with properties (type
TYPE) and (optional false) within type Foo

The syntax of example 1 is extensible; if we need another property,
we add another name/value pair to the dictionary (such as
'base':TYPE).  The syntax of example 2 is not extensible, because
the right hand side can only be a type.

We have used name encoding to add a property: "'*mumble': 'int'"
associates 'mumble' with (type int) and (optional true).  Nice,
but doesn't scale.  So the solution is to change our existing uses
to be syntactic sugar to an extensible form:

   NAME: TYPE   --> NAME:  { 'type': TYPE, 'optional': false }
   *ONAME: TYPE --> ONAME: { 'type': TYPE, 'optional': true }

This patch fixes the testsuite to avoid inline nested types, by
breaking the nesting into explicit types; it means that the type
is now boxed instead of unboxed in C code, but makes no difference
on the wire (and if desired, a later patch could change the
generator to not do so much boxing in C).  When touching code to
add new allocations, also convert existing allocations to
consistently prefer typesafe g_new0 over g_malloc0 when a type
name is involved.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
Eric Blake 2015-05-04 09:05:30 -06:00 committed by Markus Armbruster
parent b6fcf32d9b
commit 6446a59276
6 changed files with 88 additions and 61 deletions

View file

@ -244,19 +244,23 @@ static void test_visitor_out_struct_nested(TestOutputVisitorData *data,
ud2 = g_malloc0(sizeof(*ud2));
ud2->string0 = g_strdup(strings[0]);
ud2->dict1.string1 = g_strdup(strings[1]);
ud2->dict1.dict2.userdef = g_new0(UserDefOne, 1);
ud2->dict1.dict2.userdef->string = g_strdup(string);
ud2->dict1.dict2.userdef->base = g_new0(UserDefZero, 1);
ud2->dict1.dict2.userdef->base->integer = value;
ud2->dict1.dict2.string = g_strdup(strings[2]);
ud2->dict1 = g_malloc0(sizeof(*ud2->dict1));
ud2->dict1->string1 = g_strdup(strings[1]);
ud2->dict1.has_dict3 = true;
ud2->dict1.dict3.userdef = g_new0(UserDefOne, 1);
ud2->dict1.dict3.userdef->string = g_strdup(string);
ud2->dict1.dict3.userdef->base = g_new0(UserDefZero, 1);
ud2->dict1.dict3.userdef->base->integer = value;
ud2->dict1.dict3.string = g_strdup(strings[3]);
ud2->dict1->dict2 = g_malloc0(sizeof(*ud2->dict1->dict2));
ud2->dict1->dict2->userdef = g_new0(UserDefOne, 1);
ud2->dict1->dict2->userdef->string = g_strdup(string);
ud2->dict1->dict2->userdef->base = g_new0(UserDefZero, 1);
ud2->dict1->dict2->userdef->base->integer = value;
ud2->dict1->dict2->string = g_strdup(strings[2]);
ud2->dict1->dict3 = g_malloc0(sizeof(*ud2->dict1->dict3));
ud2->dict1->has_dict3 = true;
ud2->dict1->dict3->userdef = g_new0(UserDefOne, 1);
ud2->dict1->dict3->userdef->string = g_strdup(string);
ud2->dict1->dict3->userdef->base = g_new0(UserDefZero, 1);
ud2->dict1->dict3->userdef->base->integer = value;
ud2->dict1->dict3->string = g_strdup(strings[3]);
visit_type_UserDefTwo(data->ov, &ud2, "unused", &err);
g_assert(!err);
@ -407,13 +411,15 @@ static void test_visitor_out_list_qapi_free(TestOutputVisitorData *data,
p->value = g_malloc0(sizeof(*p->value));
p->value->string0 = g_strdup(string);
p->value->dict1.string1 = g_strdup(string);
p->value->dict1.dict2.userdef = g_new0(UserDefOne, 1);
p->value->dict1.dict2.userdef->string = g_strdup(string);
p->value->dict1.dict2.userdef->base = g_new0(UserDefZero, 1);
p->value->dict1.dict2.userdef->base->integer = 42;
p->value->dict1.dict2.string = g_strdup(string);
p->value->dict1.has_dict3 = false;
p->value->dict1 = g_new0(UserDefTwoDict, 1);
p->value->dict1->string1 = g_strdup(string);
p->value->dict1->dict2 = g_new0(UserDefTwoDictDict, 1);
p->value->dict1->dict2->userdef = g_new0(UserDefOne, 1);
p->value->dict1->dict2->userdef->string = g_strdup(string);
p->value->dict1->dict2->userdef->base = g_new0(UserDefZero, 1);
p->value->dict1->dict2->userdef->base->integer = 42;
p->value->dict1->dict2->string = g_strdup(string);
p->value->dict1->has_dict3 = false;
p->next = head;
head = p;