From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40740) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZvqWo-0002Rk-5v for qemu-devel@nongnu.org; Mon, 09 Nov 2015 12:46:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZvqWl-0000M7-S7 for qemu-devel@nongnu.org; Mon, 09 Nov 2015 12:46:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37127) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZvqWl-0000Lt-LO for qemu-devel@nongnu.org; Mon, 09 Nov 2015 12:46:47 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 5971F354180 for ; Mon, 9 Nov 2015 17:46:47 +0000 (UTC) From: Markus Armbruster Date: Mon, 9 Nov 2015 18:46:34 +0100 Message-Id: <1447091204-10226-3-git-send-email-armbru@redhat.com> In-Reply-To: <1447091204-10226-1-git-send-email-armbru@redhat.com> References: <1447091204-10226-1-git-send-email-armbru@redhat.com> Subject: [Qemu-devel] [PULL 02/12] qapi: Strengthen test of TestStructList List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org From: Eric Blake Make each list element different, to ensure that order is preserved, and use the generated free function instead of hand-rolling our own to ensure (under valgrind) that the list is properly cleaned. Suggested-by: Markus Armbruster Signed-off-by: Eric Blake Message-Id: <1446791754-23823-3-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- tests/test-qmp-output-visitor.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/tests/test-qmp-output-visitor.c b/tests/test-qmp-output-visitor.c index baf58dc..9364843 100644 --- a/tests/test-qmp-output-visitor.c +++ b/tests/test-qmp-output-visitor.c @@ -283,7 +283,7 @@ static void test_visitor_out_struct_errors(TestOutputVisitorData *data, static void test_visitor_out_list(TestOutputVisitorData *data, const void *unused) { - char *value_str = (char *) "list value"; + const char *value_str = "list value"; TestStructList *p, *head = NULL; const int max_items = 10; bool value_bool = true; @@ -294,12 +294,13 @@ static void test_visitor_out_list(TestOutputVisitorData *data, QList *qlist; int i; + /* Build the list in reverse order... */ for (i = 0; i < max_items; i++) { p = g_malloc0(sizeof(*p)); p->value = g_malloc0(sizeof(*p->value)); - p->value->integer = value_int; + p->value->integer = value_int + (max_items - i - 1); p->value->boolean = value_bool; - p->value->string = value_str; + p->value->string = g_strdup(value_str); p->next = head; head = p; @@ -315,6 +316,7 @@ static void test_visitor_out_list(TestOutputVisitorData *data, qlist = qobject_to_qlist(obj); g_assert(!qlist_empty(qlist)); + /* ...and ensure that the visitor sees it in order */ i = 0; QLIST_FOREACH_ENTRY(qlist, entry) { QDict *qdict; @@ -322,7 +324,7 @@ static void test_visitor_out_list(TestOutputVisitorData *data, g_assert(qobject_type(entry->value) == QTYPE_QDICT); qdict = qobject_to_qdict(entry->value); g_assert_cmpint(qdict_size(qdict), ==, 3); - g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, value_int); + g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, value_int + i); g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, value_bool); g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, value_str); i++; @@ -330,13 +332,7 @@ static void test_visitor_out_list(TestOutputVisitorData *data, g_assert_cmpint(i, ==, max_items); QDECREF(qlist); - - for (p = head; p;) { - TestStructList *tmp = p->next; - g_free(p->value); - g_free(p); - p = tmp; - } + qapi_free_TestStructList(head); } static void test_visitor_out_list_qapi_free(TestOutputVisitorData *data, -- 2.4.3