On 09/16/2015 10:02 AM, marcandre.lur...@redhat.com wrote: > From: Marc-André Lureau <marcandre.lur...@redhat.com> > > While reading the function I decided to write some tests. > > Signed-off-by: Marc-André Lureau <marcandre.lur...@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 <ebl...@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
signature.asc
Description: OpenPGP digital signature