In the testsuite, UserDefTwo and UserDefNested were identical structs other than the member names. Reduce code duplication by having just one type, and choose names that also favor reuse. This will also make it easier for a later patch to get rid of inline nested types in QAPI. When touching code related to allocations, convert g_malloc0(sizeof(Type)) to the more typesafe g_new0(Type, 1).
Ensure that 'make check-qapi-schema check-unit' still passes. Signed-off-by: Eric Blake <ebl...@redhat.com> Reviewed-by: Markus Armbruster <arm...@redhat.com> --- tests/qapi-schema/qapi-schema-test.json | 10 +---- tests/qapi-schema/qapi-schema-test.out | 6 +-- tests/test-qmp-commands.c | 34 +++++++-------- tests/test-qmp-input-strict.c | 17 ++++---- tests/test-qmp-input-visitor.c | 17 ++++---- tests/test-qmp-output-visitor.c | 48 +++++++++++----------- tests/test-visitor-serialization.c | 73 +++++++++++++++++---------------- 7 files changed, 102 insertions(+), 103 deletions(-) diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json index f10efe2..a6be983 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -15,16 +15,10 @@ 'data': { 'string': 'str', '*enum1': 'EnumOne' } } { 'struct': 'UserDefTwo', - 'data': { 'string': 'str', - 'dict': { 'string': 'str', - 'dict': { 'userdef': 'UserDefOne', 'string': 'str' }, - '*dict2': { 'userdef': 'UserDefOne', 'string': 'str' } } } } - -{ 'struct': 'UserDefNested', 'data': { 'string0': 'str', 'dict1': { 'string1': 'str', - 'dict2': { 'userdef1': 'UserDefOne', 'string2': 'str' }, - '*dict3': { 'userdef2': 'UserDefOne', 'string3': 'str' } } } } + 'dict2': { 'userdef': 'UserDefOne', 'string': 'str' }, + '*dict3': { 'userdef': 'UserDefOne', 'string': 'str' } } } } # for testing unions { 'struct': 'UserDefA', diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out index 83ab1a5..48f8f0e 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -2,8 +2,7 @@ OrderedDict([('struct', 'NestedEnumsOne'), ('data', OrderedDict([('enum1', 'EnumOne'), ('*enum2', 'EnumOne'), ('enum3', 'EnumOne'), ('*enum4', 'EnumOne')]))]), OrderedDict([('struct', 'UserDefZero'), ('data', OrderedDict([('integer', 'int')]))]), OrderedDict([('struct', 'UserDefOne'), ('base', 'UserDefZero'), ('data', OrderedDict([('string', 'str'), ('*enum1', 'EnumOne')]))]), - OrderedDict([('struct', 'UserDefTwo'), ('data', OrderedDict([('string', 'str'), ('dict', OrderedDict([('string', 'str'), ('dict', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')])), ('*dict2', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')]))]))]))]), - OrderedDict([('struct', 'UserDefNested'), ('data', OrderedDict([('string0', 'str'), ('dict1', OrderedDict([('string1', 'str'), ('dict2', OrderedDict([('userdef1', 'UserDefOne'), ('string2', 'str')])), ('*dict3', OrderedDict([('userdef2', 'UserDefOne'), ('string3', 'str')]))]))]))]), + OrderedDict([('struct', 'UserDefTwo'), ('data', OrderedDict([('string0', 'str'), ('dict1', OrderedDict([('string1', 'str'), ('dict2', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')])), ('*dict3', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')]))]))]))]), OrderedDict([('struct', 'UserDefA'), ('data', OrderedDict([('boolean', 'bool')]))]), OrderedDict([('struct', 'UserDefB'), ('data', OrderedDict([('integer', 'int')]))]), OrderedDict([('struct', 'UserDefC'), ('data', OrderedDict([('string1', 'str'), ('string2', 'str')]))]), @@ -28,8 +27,7 @@ [OrderedDict([('struct', 'NestedEnumsOne'), ('data', OrderedDict([('enum1', 'EnumOne'), ('*enum2', 'EnumOne'), ('enum3', 'EnumOne'), ('*enum4', 'EnumOne')]))]), OrderedDict([('struct', 'UserDefZero'), ('data', OrderedDict([('integer', 'int')]))]), OrderedDict([('struct', 'UserDefOne'), ('base', 'UserDefZero'), ('data', OrderedDict([('string', 'str'), ('*enum1', 'EnumOne')]))]), - OrderedDict([('struct', 'UserDefTwo'), ('data', OrderedDict([('string', 'str'), ('dict', OrderedDict([('string', 'str'), ('dict', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')])), ('*dict2', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')]))]))]))]), - OrderedDict([('struct', 'UserDefNested'), ('data', OrderedDict([('string0', 'str'), ('dict1', OrderedDict([('string1', 'str'), ('dict2', OrderedDict([('userdef1', 'UserDefOne'), ('string2', 'str')])), ('*dict3', OrderedDict([('userdef2', 'UserDefOne'), ('string3', 'str')]))]))]))]), + OrderedDict([('struct', 'UserDefTwo'), ('data', OrderedDict([('string0', 'str'), ('dict1', OrderedDict([('string1', 'str'), ('dict2', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')])), ('*dict3', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')]))]))]))]), OrderedDict([('struct', 'UserDefA'), ('data', OrderedDict([('boolean', 'bool')]))]), OrderedDict([('struct', 'UserDefB'), ('data', OrderedDict([('integer', 'int')]))]), OrderedDict([('struct', 'UserDefC'), ('data', OrderedDict([('string1', 'str'), ('string2', 'str')]))]), diff --git a/tests/test-qmp-commands.c b/tests/test-qmp-commands.c index 554e222..8b50eac 100644 --- a/tests/test-qmp-commands.c +++ b/tests/test-qmp-commands.c @@ -31,14 +31,14 @@ UserDefTwo *qmp_user_def_cmd2(UserDefOne *ud1a, ud1d->base = g_new0(UserDefZero, 1); ud1d->base->integer = has_udb1 ? ud1b->base->integer : 0; - ret = g_malloc0(sizeof(UserDefTwo)); - ret->string = strdup("blah1"); - ret->dict.string = strdup("blah2"); - ret->dict.dict.userdef = ud1c; - ret->dict.dict.string = strdup("blah3"); - ret->dict.has_dict2 = true; - ret->dict.dict2.userdef = ud1d; - ret->dict.dict2.string = strdup("blah4"); + ret = g_new0(UserDefTwo, 1); + ret->string0 = strdup("blah1"); + ret->dict1.string1 = strdup("blah2"); + ret->dict1.dict2.userdef = ud1c; + ret->dict1.dict2.string = strdup("blah3"); + ret->dict1.has_dict3 = true; + ret->dict1.dict3.userdef = ud1d; + ret->dict1.dict3.string = strdup("blah4"); return ret; } @@ -120,15 +120,15 @@ static void test_dispatch_cmd_io(void) ret = qobject_to_qdict(test_qmp_dispatch(req)); - assert(!strcmp(qdict_get_str(ret, "string"), "blah1")); - ret_dict = qdict_get_qdict(ret, "dict"); - assert(!strcmp(qdict_get_str(ret_dict, "string"), "blah2")); - ret_dict_dict = qdict_get_qdict(ret_dict, "dict"); + assert(!strcmp(qdict_get_str(ret, "string0"), "blah1")); + ret_dict = qdict_get_qdict(ret, "dict1"); + assert(!strcmp(qdict_get_str(ret_dict, "string1"), "blah2")); + ret_dict_dict = qdict_get_qdict(ret_dict, "dict2"); ret_dict_dict_userdef = qdict_get_qdict(ret_dict_dict, "userdef"); assert(qdict_get_int(ret_dict_dict_userdef, "integer") == 42); assert(!strcmp(qdict_get_str(ret_dict_dict_userdef, "string"), "hello")); assert(!strcmp(qdict_get_str(ret_dict_dict, "string"), "blah3")); - ret_dict_dict2 = qdict_get_qdict(ret_dict, "dict2"); + ret_dict_dict2 = qdict_get_qdict(ret_dict, "dict3"); ret_dict_dict2_userdef = qdict_get_qdict(ret_dict_dict2, "userdef"); assert(qdict_get_int(ret_dict_dict2_userdef, "integer") == 422); assert(!strcmp(qdict_get_str(ret_dict_dict2_userdef, "string"), "hello2")); @@ -192,7 +192,7 @@ static void test_dealloc_partial(void) QmpInputVisitor *qiv; ud2_dict = qdict_new(); - qdict_put_obj(ud2_dict, "string", QOBJECT(qstring_from_str(text))); + qdict_put_obj(ud2_dict, "string0", QOBJECT(qstring_from_str(text))); qiv = qmp_input_visitor_new(QOBJECT(ud2_dict)); visit_type_UserDefTwo(qmp_input_get_visitor(qiv), &ud2, NULL, &err); @@ -202,9 +202,9 @@ static void test_dealloc_partial(void) /* verify partial success */ assert(ud2 != NULL); - assert(ud2->string != NULL); - assert(strcmp(ud2->string, text) == 0); - assert(ud2->dict.dict.userdef == NULL); + assert(ud2->string0 != NULL); + assert(strcmp(ud2->string0, text) == 0); + assert(ud2->dict1.dict2.userdef == NULL); /* confirm & release construction error */ assert(err != NULL); diff --git a/tests/test-qmp-input-strict.c b/tests/test-qmp-input-strict.c index a5f7bf3..68f855b 100644 --- a/tests/test-qmp-input-strict.c +++ b/tests/test-qmp-input-strict.c @@ -116,15 +116,18 @@ static void test_validate_struct(TestInputVisitorData *data, static void test_validate_struct_nested(TestInputVisitorData *data, const void *unused) { - UserDefNested *udp = NULL; + UserDefTwo *udp = NULL; Error *err = NULL; Visitor *v; - v = validate_test_init(data, "{ 'string0': 'string0', 'dict1': { 'string1': 'string1', 'dict2': { 'userdef1': { 'integer': 42, 'string': 'string' }, 'string2': 'string2'}}}"); + v = validate_test_init(data, "{ 'string0': 'string0', " + "'dict1': { 'string1': 'string1', " + "'dict2': { 'userdef': { 'integer': 42, " + "'string': 'string' }, 'string': 'string2'}}}"); - visit_type_UserDefNested(v, &udp, NULL, &err); + visit_type_UserDefTwo(v, &udp, NULL, &err); g_assert(!err); - qapi_free_UserDefNested(udp); + qapi_free_UserDefTwo(udp); } static void test_validate_list(TestInputVisitorData *data, @@ -207,15 +210,15 @@ static void test_validate_fail_struct(TestInputVisitorData *data, static void test_validate_fail_struct_nested(TestInputVisitorData *data, const void *unused) { - UserDefNested *udp = NULL; + UserDefTwo *udp = NULL; Error *err = NULL; Visitor *v; v = validate_test_init(data, "{ 'string0': 'string0', 'dict1': { 'string1': 'string1', 'dict2': { 'userdef1': { 'integer': 42, 'string': 'string', 'extra': [42, 23, {'foo':'bar'}] }, 'string2': 'string2'}}}"); - visit_type_UserDefNested(v, &udp, NULL, &err); + visit_type_UserDefTwo(v, &udp, NULL, &err); g_assert(err); - qapi_free_UserDefNested(udp); + qapi_free_UserDefTwo(udp); } static void test_validate_fail_list(TestInputVisitorData *data, diff --git a/tests/test-qmp-input-visitor.c b/tests/test-qmp-input-visitor.c index 882359a..115fb22 100644 --- a/tests/test-qmp-input-visitor.c +++ b/tests/test-qmp-input-visitor.c @@ -248,23 +248,26 @@ static void check_and_free_str(char *str, const char *cmp) static void test_visitor_in_struct_nested(TestInputVisitorData *data, const void *unused) { - UserDefNested *udp = NULL; + UserDefTwo *udp = NULL; Error *err = NULL; Visitor *v; - v = visitor_input_test_init(data, "{ 'string0': 'string0', 'dict1': { 'string1': 'string1', 'dict2': { 'userdef1': { 'integer': 42, 'string': 'string' }, 'string2': 'string2'}}}"); + v = visitor_input_test_init(data, "{ 'string0': 'string0', " + "'dict1': { 'string1': 'string1', " + "'dict2': { 'userdef': { 'integer': 42, " + "'string': 'string' }, 'string': 'string2'}}}"); - visit_type_UserDefNested(v, &udp, NULL, &err); + visit_type_UserDefTwo(v, &udp, NULL, &err); g_assert(!err); check_and_free_str(udp->string0, "string0"); check_and_free_str(udp->dict1.string1, "string1"); - g_assert_cmpint(udp->dict1.dict2.userdef1->base->integer, ==, 42); - check_and_free_str(udp->dict1.dict2.userdef1->string, "string"); - check_and_free_str(udp->dict1.dict2.string2, "string2"); + g_assert_cmpint(udp->dict1.dict2.userdef->base->integer, ==, 42); + check_and_free_str(udp->dict1.dict2.userdef->string, "string"); + check_and_free_str(udp->dict1.dict2.string, "string2"); g_assert(udp->dict1.has_dict3 == false); - g_free(udp->dict1.dict2.userdef1); + g_free(udp->dict1.dict2.userdef); g_free(udp); } diff --git a/tests/test-qmp-output-visitor.c b/tests/test-qmp-output-visitor.c index 602bc12..0584b4d 100644 --- a/tests/test-qmp-output-visitor.c +++ b/tests/test-qmp-output-visitor.c @@ -234,7 +234,7 @@ static void test_visitor_out_struct_nested(TestOutputVisitorData *data, { int64_t value = 42; Error *err = NULL; - UserDefNested *ud2; + UserDefTwo *ud2; QObject *obj; QDict *qdict, *dict1, *dict2, *dict3, *userdef; const char *string = "user def string"; @@ -245,20 +245,20 @@ static void test_visitor_out_struct_nested(TestOutputVisitorData *data, ud2->string0 = g_strdup(strings[0]); ud2->dict1.string1 = g_strdup(strings[1]); - ud2->dict1.dict2.userdef1 = g_malloc0(sizeof(UserDefOne)); - ud2->dict1.dict2.userdef1->string = g_strdup(string); - ud2->dict1.dict2.userdef1->base = g_new0(UserDefZero, 1); - ud2->dict1.dict2.userdef1->base->integer = value; - ud2->dict1.dict2.string2 = g_strdup(strings[2]); + 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.has_dict3 = true; - ud2->dict1.dict3.userdef2 = g_malloc0(sizeof(UserDefOne)); - ud2->dict1.dict3.userdef2->string = g_strdup(string); - ud2->dict1.dict3.userdef2->base = g_new0(UserDefZero, 1); - ud2->dict1.dict3.userdef2->base->integer = value; - ud2->dict1.dict3.string3 = g_strdup(strings[3]); + 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_UserDefNested(data->ov, &ud2, "unused", &err); + visit_type_UserDefTwo(data->ov, &ud2, "unused", &err); g_assert(!err); obj = qmp_output_get_qobject(data->qov); @@ -275,22 +275,22 @@ static void test_visitor_out_struct_nested(TestOutputVisitorData *data, dict2 = qdict_get_qdict(dict1, "dict2"); g_assert_cmpint(qdict_size(dict2), ==, 2); - g_assert_cmpstr(qdict_get_str(dict2, "string2"), ==, strings[2]); - userdef = qdict_get_qdict(dict2, "userdef1"); + g_assert_cmpstr(qdict_get_str(dict2, "string"), ==, strings[2]); + userdef = qdict_get_qdict(dict2, "userdef"); g_assert_cmpint(qdict_size(userdef), ==, 2); g_assert_cmpint(qdict_get_int(userdef, "integer"), ==, value); g_assert_cmpstr(qdict_get_str(userdef, "string"), ==, string); dict3 = qdict_get_qdict(dict1, "dict3"); g_assert_cmpint(qdict_size(dict3), ==, 2); - g_assert_cmpstr(qdict_get_str(dict3, "string3"), ==, strings[3]); - userdef = qdict_get_qdict(dict3, "userdef2"); + g_assert_cmpstr(qdict_get_str(dict3, "string"), ==, strings[3]); + userdef = qdict_get_qdict(dict3, "userdef"); g_assert_cmpint(qdict_size(userdef), ==, 2); g_assert_cmpint(qdict_get_int(userdef, "integer"), ==, value); g_assert_cmpstr(qdict_get_str(userdef, "string"), ==, string); QDECREF(qdict); - qapi_free_UserDefNested(ud2); + qapi_free_UserDefTwo(ud2); } static void test_visitor_out_struct_errors(TestOutputVisitorData *data, @@ -398,7 +398,7 @@ static void test_visitor_out_list(TestOutputVisitorData *data, static void test_visitor_out_list_qapi_free(TestOutputVisitorData *data, const void *unused) { - UserDefNestedList *p, *head = NULL; + UserDefTwoList *p, *head = NULL; const char string[] = "foo bar"; int i, max_count = 1024; @@ -408,18 +408,18 @@ static void test_visitor_out_list_qapi_free(TestOutputVisitorData *data, p->value->string0 = g_strdup(string); p->value->dict1.string1 = g_strdup(string); - p->value->dict1.dict2.userdef1 = g_malloc0(sizeof(UserDefOne)); - p->value->dict1.dict2.userdef1->string = g_strdup(string); - p->value->dict1.dict2.userdef1->base = g_new0(UserDefZero, 1); - p->value->dict1.dict2.userdef1->base->integer = 42; - p->value->dict1.dict2.string2 = 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->next = head; head = p; } - qapi_free_UserDefNestedList(head); + qapi_free_UserDefTwoList(head); } static void test_visitor_out_union_flat(TestOutputVisitorData *data, diff --git a/tests/test-visitor-serialization.c b/tests/test-visitor-serialization.c index 7ad1886..1ccaaa9 100644 --- a/tests/test-visitor-serialization.c +++ b/tests/test-visitor-serialization.c @@ -249,57 +249,57 @@ static void visit_struct(Visitor *v, void **native, Error **errp) visit_type_TestStruct(v, (TestStruct **)native, NULL, errp); } -static UserDefNested *nested_struct_create(void) +static UserDefTwo *nested_struct_create(void) { - UserDefNested *udnp = g_malloc0(sizeof(*udnp)); + UserDefTwo *udnp = g_malloc0(sizeof(*udnp)); udnp->string0 = strdup("test_string0"); udnp->dict1.string1 = strdup("test_string1"); - udnp->dict1.dict2.userdef1 = g_malloc0(sizeof(UserDefOne)); - udnp->dict1.dict2.userdef1->base = g_new0(UserDefZero, 1); - udnp->dict1.dict2.userdef1->base->integer = 42; - udnp->dict1.dict2.userdef1->string = strdup("test_string"); - udnp->dict1.dict2.string2 = strdup("test_string2"); + udnp->dict1.dict2.userdef = g_new0(UserDefOne, 1); + udnp->dict1.dict2.userdef->base = g_new0(UserDefZero, 1); + udnp->dict1.dict2.userdef->base->integer = 42; + udnp->dict1.dict2.userdef->string = strdup("test_string"); + udnp->dict1.dict2.string = strdup("test_string2"); udnp->dict1.has_dict3 = true; - udnp->dict1.dict3.userdef2 = g_malloc0(sizeof(UserDefOne)); - udnp->dict1.dict3.userdef2->base = g_new0(UserDefZero, 1); - udnp->dict1.dict3.userdef2->base->integer = 43; - udnp->dict1.dict3.userdef2->string = strdup("test_string"); - udnp->dict1.dict3.string3 = strdup("test_string3"); + udnp->dict1.dict3.userdef = g_new0(UserDefOne, 1); + udnp->dict1.dict3.userdef->base = g_new0(UserDefZero, 1); + udnp->dict1.dict3.userdef->base->integer = 43; + udnp->dict1.dict3.userdef->string = strdup("test_string"); + udnp->dict1.dict3.string = strdup("test_string3"); return udnp; } -static void nested_struct_compare(UserDefNested *udnp1, UserDefNested *udnp2) +static void nested_struct_compare(UserDefTwo *udnp1, UserDefTwo *udnp2) { g_assert(udnp1); g_assert(udnp2); g_assert_cmpstr(udnp1->string0, ==, udnp2->string0); g_assert_cmpstr(udnp1->dict1.string1, ==, udnp2->dict1.string1); - g_assert_cmpint(udnp1->dict1.dict2.userdef1->base->integer, ==, - udnp2->dict1.dict2.userdef1->base->integer); - g_assert_cmpstr(udnp1->dict1.dict2.userdef1->string, ==, - udnp2->dict1.dict2.userdef1->string); - g_assert_cmpstr(udnp1->dict1.dict2.string2, ==, udnp2->dict1.dict2.string2); + g_assert_cmpint(udnp1->dict1.dict2.userdef->base->integer, ==, + udnp2->dict1.dict2.userdef->base->integer); + g_assert_cmpstr(udnp1->dict1.dict2.userdef->string, ==, + udnp2->dict1.dict2.userdef->string); + g_assert_cmpstr(udnp1->dict1.dict2.string, ==, udnp2->dict1.dict2.string); g_assert(udnp1->dict1.has_dict3 == udnp2->dict1.has_dict3); - g_assert_cmpint(udnp1->dict1.dict3.userdef2->base->integer, ==, - udnp2->dict1.dict3.userdef2->base->integer); - g_assert_cmpstr(udnp1->dict1.dict3.userdef2->string, ==, - udnp2->dict1.dict3.userdef2->string); - g_assert_cmpstr(udnp1->dict1.dict3.string3, ==, udnp2->dict1.dict3.string3); + g_assert_cmpint(udnp1->dict1.dict3.userdef->base->integer, ==, + udnp2->dict1.dict3.userdef->base->integer); + g_assert_cmpstr(udnp1->dict1.dict3.userdef->string, ==, + udnp2->dict1.dict3.userdef->string); + g_assert_cmpstr(udnp1->dict1.dict3.string, ==, udnp2->dict1.dict3.string); } -static void nested_struct_cleanup(UserDefNested *udnp) +static void nested_struct_cleanup(UserDefTwo *udnp) { - qapi_free_UserDefNested(udnp); + qapi_free_UserDefTwo(udnp); } static void visit_nested_struct(Visitor *v, void **native, Error **errp) { - visit_type_UserDefNested(v, (UserDefNested **)native, NULL, errp); + visit_type_UserDefTwo(v, (UserDefTwo **)native, NULL, errp); } static void visit_nested_struct_list(Visitor *v, void **native, Error **errp) { - visit_type_UserDefNestedList(v, (UserDefNestedList **)native, NULL, errp); + visit_type_UserDefTwoList(v, (UserDefTwoList **)native, NULL, errp); } /* test cases */ @@ -715,13 +715,14 @@ static void test_nested_struct(gconstpointer opaque) { TestArgs *args = (TestArgs *) opaque; const SerializeOps *ops = args->ops; - UserDefNested *udnp = nested_struct_create(); - UserDefNested *udnp_copy = NULL; + UserDefTwo *udnp = nested_struct_create(); + UserDefTwo *udnp_copy = NULL; Error *err = NULL; void *serialize_data; - + ops->serialize(udnp, &serialize_data, visit_nested_struct, &err); - ops->deserialize((void **)&udnp_copy, serialize_data, visit_nested_struct, &err); + ops->deserialize((void **)&udnp_copy, serialize_data, visit_nested_struct, + &err); g_assert(err == NULL); nested_struct_compare(udnp, udnp_copy); @@ -737,18 +738,18 @@ static void test_nested_struct_list(gconstpointer opaque) { TestArgs *args = (TestArgs *) opaque; const SerializeOps *ops = args->ops; - UserDefNestedList *listp = NULL, *tmp, *tmp_copy, *listp_copy = NULL; + UserDefTwoList *listp = NULL, *tmp, *tmp_copy, *listp_copy = NULL; Error *err = NULL; void *serialize_data; int i = 0; for (i = 0; i < 8; i++) { - tmp = g_malloc0(sizeof(UserDefNestedList)); + tmp = g_new0(UserDefTwoList, 1); tmp->value = nested_struct_create(); tmp->next = listp; listp = tmp; } - + ops->serialize(listp, &serialize_data, visit_nested_struct_list, &err); ops->deserialize((void **)&listp_copy, serialize_data, visit_nested_struct_list, &err); @@ -764,8 +765,8 @@ static void test_nested_struct_list(gconstpointer opaque) listp_copy = listp_copy->next; } - qapi_free_UserDefNestedList(tmp); - qapi_free_UserDefNestedList(tmp_copy); + qapi_free_UserDefTwoList(tmp); + qapi_free_UserDefTwoList(tmp_copy); ops->cleanup(serialize_data); g_free(args); -- 2.1.0