From a6b4373fa257fdd7139a74187851575709a5ecb6 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 21 Feb 2017 21:13:56 +0100 Subject: [PATCH] test-cutils: Cover qemu_strtosz() with trailing crap Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <1487708048-2131-13-git-send-email-armbru@redhat.com> --- tests/test-cutils.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test-cutils.c b/tests/test-cutils.c index dc8cd8d02d..1773f15a64 100644 --- a/tests/test-cutils.c +++ b/tests/test-cutils.c @@ -1463,6 +1463,23 @@ static void test_qemu_strtosz_invalid(void) g_assert(endptr == str); } +static void test_qemu_strtosz_trailing(void) +{ + const char *str; + char *endptr = NULL; + int64_t res; + + str = "123xxx"; + res = qemu_strtosz(str, &endptr); + g_assert_cmpint(res, ==, 123 * M_BYTE); + g_assert(endptr == str + 3); + + str = "1kiB"; + res = qemu_strtosz(str, &endptr); + g_assert_cmpint(res, ==, 1024); + g_assert(endptr == str + 2); +} + static void test_qemu_strtosz_erange(void) { const char *str = "10E"; @@ -1676,6 +1693,8 @@ int main(int argc, char **argv) test_qemu_strtosz_float); g_test_add_func("/cutils/strtosz/invalid", test_qemu_strtosz_invalid); + g_test_add_func("/cutils/strtosz/trailing", + test_qemu_strtosz_trailing); g_test_add_func("/cutils/strtosz/erange", test_qemu_strtosz_erange); g_test_add_func("/cutils/strtosz/suffix-unit",