From: Markus Armbruster <armbru@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: qemu-devel@nongnu.org, "Andreas Färber" <afaerber@suse.de>
Subject: Re: [Qemu-devel] [PATCH] qdev-monitor-test: simplify using g_assert_cmpstr()
Date: Wed, 18 Dec 2013 18:11:57 +0100 [thread overview]
Message-ID: <87y53ixew2.fsf@blackfin.pond.sub.org> (raw)
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")
Stefan Hajnoczi <stefanha@redhat.com> 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 <armbru@redhat.com>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
> 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 <armbru@redhat.com>
next prev parent reply other threads:[~2013-12-18 17:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-18 16:34 [Qemu-devel] [PATCH] qdev-monitor-test: simplify using g_assert_cmpstr() Stefan Hajnoczi
2013-12-18 17:11 ` Markus Armbruster [this message]
2013-12-18 17:49 ` Andreas Färber
2013-12-18 18:31 ` Andreas Färber
2013-12-19 15:38 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y53ixew2.fsf@blackfin.pond.sub.org \
--to=armbru@redhat.com \
--cc=afaerber@suse.de \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.