qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: marcandre.lureau@redhat.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 2/2] tests: add some qemu_strtosz() tests
Date: Wed, 16 Sep 2015 10:19:06 -0600	[thread overview]
Message-ID: <55F9967A.2010408@redhat.com> (raw)
In-Reply-To: <1442419377-9309-2-git-send-email-marcandre.lureau@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1673 bytes --]

On 09/16/2015 10:02 AM, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> While reading the function I decided to write some tests.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  tests/test-cutils.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 91 insertions(+)
> 
> diff --git a/tests/test-cutils.c b/tests/test-cutils.c
> index 0046c61..a3de6ab 100644
> --- a/tests/test-cutils.c
> +++ b/tests/test-cutils.c
> @@ -1352,6 +1352,86 @@ static void test_qemu_strtoull_full_max(void)
>      g_assert_cmpint(res, ==, ULLONG_MAX);
>  }
>  
> +static void test_qemu_strtosz_simple(void)
> +{
> +    const char *str = "12345M";
> +    char *endptr = NULL;
> +    int64_t res;
> +
> +    res = qemu_strtosz(str, &endptr);
> +    g_assert_cmpint(res, ==, 12345 * M_BYTE);
> +    g_assert(endptr == str + 6);
> +
> +    res = qemu_strtosz(str, NULL);
> +    g_assert_cmpint(res, ==, 12345 * M_BYTE);
> +}

Would it also be worth some negative tests, such as bogus suffix (for
example, does "1234x" fail to parse, or parse "1234" and leave "x"
unparsed?)

But what you have is a strict improvement (any test is better than none!) so

Reviewed-by: Eric Blake <eblake@redhat.com>


> +static void test_qemu_strtosz_erange(void)
> +{
> +    const char *str = "10E";
> +    int64_t res;
> +
> +    res = qemu_strtosz(str, NULL);
> +    g_assert_cmpint(res, ==, -ERANGE);
> +}

This was the only negative test I see.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

  reply	other threads:[~2015-09-16 16:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-16 16:02 [Qemu-devel] [PATCH 1/2] utils: rename strtosz to use qemu prefix marcandre.lureau
2015-09-16 16:02 ` [Qemu-devel] [PATCH 2/2] tests: add some qemu_strtosz() tests marcandre.lureau
2015-09-16 16:19   ` Eric Blake [this message]
2015-09-16 16:13 ` [Qemu-devel] [PATCH 1/2] utils: rename strtosz to use qemu prefix Eric Blake
2015-09-16 16:17   ` Marc-André Lureau
2015-09-16 16:34 ` Paolo Bonzini

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=55F9967A.2010408@redhat.com \
    --to=eblake@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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).