Message ID | 1487067971-10443-12-git-send-email-armbru@redhat.com |
---|---|
State | New |
Headers | show |
On 02/14/2017 04:25 AM, Markus Armbruster wrote: > Signed-off-by: Markus Armbruster <armbru@redhat.com> > --- > tests/test-cutils.c | 24 ++++++++++++++++++++++++ > 1 file changed, 24 insertions(+) > Perhaps you could also add a test of "-". Either way, Reviewed-by: Eric Blake <eblake@redhat.com>
Eric Blake <eblake@redhat.com> writes: > On 02/14/2017 04:25 AM, Markus Armbruster wrote: >> Signed-off-by: Markus Armbruster <armbru@redhat.com> >> --- >> tests/test-cutils.c | 24 ++++++++++++++++++++++++ >> 1 file changed, 24 insertions(+) >> > > Perhaps you could also add a test of "-". Either way, The test cases match the ones for qemu_strtol() & friends: test_qemu_stro*_{empty,whitespace,invalid}(). If we add "-" here, we should probably add it there as well. I think we totally should if we were testing a strtol() implementation. But we're only testing a wrapper, and other test cases cover the "strtol() fails without converting anything" case, so I think we're okay. > Reviewed-by: Eric Blake <eblake@redhat.com> Thanks!
diff --git a/tests/test-cutils.c b/tests/test-cutils.c index 2dc6832..3dcd4c1 100644 --- a/tests/test-cutils.c +++ b/tests/test-cutils.c @@ -1441,6 +1441,28 @@ static void test_qemu_strtosz_float(void) g_assert(endptr == str + 7); } +static void test_qemu_strtosz_invalid(void) +{ + const char *str; + char *endptr = NULL; + int64_t res; + + str = ""; + res = qemu_strtosz(str, &endptr); + g_assert_cmpint(res, ==, -EINVAL); + g_assert(endptr == str); + + str = " \t "; + res = qemu_strtosz(str, &endptr); + g_assert_cmpint(res, ==, -EINVAL); + g_assert(endptr == str); + + str = "crap"; + res = qemu_strtosz(str, &endptr); + g_assert_cmpint(res, ==, -EINVAL); + g_assert(endptr == str); +} + static void test_qemu_strtosz_erange(void) { const char *str = "10E"; @@ -1652,6 +1674,8 @@ int main(int argc, char **argv) test_qemu_strtosz_units); g_test_add_func("/cutils/strtosz/float", test_qemu_strtosz_float); + g_test_add_func("/cutils/strtosz/invalid", + test_qemu_strtosz_invalid); g_test_add_func("/cutils/strtosz/erange", test_qemu_strtosz_erange); g_test_add_func("/cutils/strtosz/suffix-unit",
Signed-off-by: Markus Armbruster <armbru@redhat.com> --- tests/test-cutils.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)