qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Andreas Färber" <afaerber@suse.de>
To: Stefan Hajnoczi <stefanha@redhat.com>, qemu-devel@nongnu.org
Cc: Markus Armbruster <armbru@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] qdev-monitor-test: simplify using g_assert_cmpstr()
Date: Wed, 18 Dec 2013 19:31:48 +0100	[thread overview]
Message-ID: <52B1EA14.7050700@suse.de> (raw)
In-Reply-To: <1387384489-25671-1-git-send-email-stefanha@redhat.com>

Am 18.12.2013 17:34, schrieb Stefan Hajnoczi:
> Use g_assert_cmpstr() instead of combining g_assert() and strcmp(3).

I vaguely remember that some such handy function was introduced only
after the minimum GLib version we require. Did you check on that?
But IIRC we already have higher requirements for qtest that for the
non-check code so it might not really matter...

Andreas

> 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 */
> @@ -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();
> 


-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

  parent reply	other threads:[~2013-12-18 18:32 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
2013-12-18 17:49   ` Andreas Färber
2013-12-18 18:31 ` Andreas Färber [this message]
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=52B1EA14.7050700@suse.de \
    --to=afaerber@suse.de \
    --cc=armbru@redhat.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).