Received: from eggs.gnu.org ([2001:4830:134:3::10]:34084) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZtrRL-00042m-TS for qemu-devel@nongnu.org; Wed, 04 Nov 2015 01:21:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZtrRH-00068N-W2 for qemu-devel@nongnu.org; Wed, 04 Nov 2015 01:20:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50222) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZtrRH-00068B-RW for qemu-devel@nongnu.org; Wed, 04 Nov 2015 01:20:55 -0500 From: Eric Blake Date: Tue, 3 Nov 2015 23:20:27 -0700 Message-Id: <1446618049-13596-6-git-send-email-eblake@redhat.com> In-Reply-To: <1446618049-13596-1-git-send-email-eblake@redhat.com> References: <1446618049-13596-1-git-send-email-eblake@redhat.com> Subject: [Qemu-devel] [PATCH v9 05/27] qapi: More tests of alternate output List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: armbru@redhat.com, Michael Roth The testsuite was only covering that we could output a built-in branch of an alternate; make sure that things still work even when a branch involves allocation, to ensure that we don't leak when run under valgrind. Update to modern style of g_new0() over g_malloc0() while touching it. Signed-off-by: Eric Blake --- v9: new patch, split off of 10/17 --- tests/test-qmp-output-visitor.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/test-qmp-output-visitor.c b/tests/test-qmp-output-visitor.c index 0164984..0d0c859 100644 --- a/tests/test-qmp-output-visitor.c +++ b/tests/test-qmp-output-visitor.c @@ -425,8 +425,9 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data, const void *unused) { QObject *arg; + UserDefAlternate *tmp; - UserDefAlternate *tmp = g_malloc0(sizeof(UserDefAlternate)); + tmp = g_new0(UserDefAlternate, 1); tmp->type = USER_DEF_ALTERNATE_KIND_I; tmp->u.i = 42; @@ -438,6 +439,19 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data, qapi_free_UserDefAlternate(tmp); qobject_decref(arg); + + tmp = g_new0(UserDefAlternate, 1); + tmp->type = USER_DEF_ALTERNATE_KIND_S; + tmp->u.s = g_strdup("hello"); + + visit_type_UserDefAlternate(data->ov, &tmp, NULL, &error_abort); + arg = qmp_output_get_qobject(data->qov); + + g_assert(qobject_type(arg) == QTYPE_QSTRING); + g_assert_cmpstr(qstring_get_str(qobject_to_qstring(arg)), ==, "hello"); + + qapi_free_UserDefAlternate(tmp); + qobject_decref(arg); } static void test_visitor_out_empty(TestOutputVisitorData *data, -- 2.4.3