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