qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 2/2] tests: add some qemu_strtosz() tests


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH 2/2] tests: add some qemu_strtosz() tests
Date: Wed, 16 Sep 2015 10:19:06 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0

On 09/16/2015 10:02 AM, address@hidden wrote:
> From: Marc-André Lureau <address@hidden>
> 
> While reading the function I decided to write some tests.
> 
> Signed-off-by: Marc-André Lureau <address@hidden>
> ---
>  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 <address@hidden>


> +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: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]