Received: from eggs.gnu.org ([2001:4830:134:3::10]:58828) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtKfK-0007jk-Kc for qemu-devel@nongnu.org; Wed, 18 Dec 2013 12:12:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VtKfB-0004MR-5h for qemu-devel@nongnu.org; Wed, 18 Dec 2013 12:12:10 -0500 Received: from mx1.redhat.com ([209.132.183.28]:18973) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtKfA-0004LJ-Tb for qemu-devel@nongnu.org; Wed, 18 Dec 2013 12:12:01 -0500 From: Markus Armbruster References: <1387384489-25671-1-git-send-email-stefanha@redhat.com> Date: Wed, 18 Dec 2013 18:11:57 +0100 In-Reply-To: <1387384489-25671-1-git-send-email-stefanha@redhat.com> (Stefan Hajnoczi's message of "Wed, 18 Dec 2013 17:34:49 +0100") Message-ID: <87y53ixew2.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH] qdev-monitor-test: simplify using g_assert_cmpstr() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: qemu-devel@nongnu.org, Andreas =?utf-8?Q?F=C3=A4rber?= Stefan Hajnoczi writes: > Use g_assert_cmpstr() instead of combining g_assert() and strcmp(3). > This simplifies the code since we no longer have to play games to > distinguish NULL from "" using "(null)". > > gcc extension haters will also be happy that ?: was dropped. > > Suggested-by: Markus Armbruster > Signed-off-by: Stefan Hajnoczi > --- > tests/qdev-monitor-test.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/tests/qdev-monitor-test.c b/tests/qdev-monitor-test.c > index ba7f9cc..eefaab8 100644 > --- a/tests/qdev-monitor-test.c > +++ b/tests/qdev-monitor-test.c > @@ -32,8 +32,9 @@ static void test_device_add(void) > "}}"); > g_assert(response); > error = qdict_get_qdict(response, "error"); > - g_assert(!strcmp(qdict_get_try_str(error, "desc") ?: "", > - "Device needs media, but drive is empty")); > + g_assert_cmpstr(qdict_get_try_str(error, "desc"), > + ==, > + "Device needs media, but drive is empty"); > QDECREF(response); > > /* Delete the drive */ Outside this patch's scope, but here goes anyway: why do we test the value of member desc? Isn't that awfully fragile? It broke once already, in Andreas's commit 75884af "virtio-blk: Convert to QOM realize". Andreas, do you remember why you tossed the class == GenericError check instead of the desc check? > @@ -42,7 +43,7 @@ static void test_device_add(void) > " \"command-line\": \"drive_del drive0\"" > "}}"); > g_assert(response); > - g_assert(!strcmp(qdict_get_try_str(response, "return") ?: "(null)", "")); > + g_assert_cmpstr(qdict_get_try_str(response, "return"), ==, ""); > QDECREF(response); > > /* Try to re-add the drive. This fails with duplicate IDs if a leaked > @@ -53,8 +54,7 @@ static void test_device_add(void) > " \"command-line\": \"drive_add pci-addr=auto if=none,id=drive0\"" > "}}"); > g_assert(response); > - g_assert(!strcmp(qdict_get_try_str(response, "return") ?: "", > - "OK\r\n")); > + g_assert_cmpstr(qdict_get_try_str(response, "return"), ==, "OK\r\n"); > QDECREF(response); > > qtest_end(); Reviewed-by: Markus Armbruster