diff options
author | Markus Armbruster <armbru@redhat.com> | 2017-02-21 21:13:56 +0100 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2017-02-23 20:35:35 +0100 |
commit | a6b4373fa257fdd7139a74187851575709a5ecb6 (patch) | |
tree | 72d0591c0b6c6abd5544ab090216c9e39c4dc1ff /tests/test-cutils.c | |
parent | 18aec47967814f4a6261edd0130f7e9da985f65b (diff) | |
download | qemu-a6b4373fa257fdd7139a74187851575709a5ecb6.zip qemu-a6b4373fa257fdd7139a74187851575709a5ecb6.tar.gz qemu-a6b4373fa257fdd7139a74187851575709a5ecb6.tar.bz2 |
test-cutils: Cover qemu_strtosz() with trailing crap
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <1487708048-2131-13-git-send-email-armbru@redhat.com>
Diffstat (limited to 'tests/test-cutils.c')
-rw-r--r-- | tests/test-cutils.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/test-cutils.c b/tests/test-cutils.c index dc8cd8d..1773f15 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", |