diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2015-09-10 10:02:00 +0200 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2015-09-10 10:02:00 +0200 |
commit | 47d4be12c3997343e436c6cca89aefbbbeb70863 (patch) | |
tree | a4edcff0049477f2a63a375f29263f4d222d8696 /tests/test-cutils.c | |
parent | 9fd1a94888cd6a559f95c3596ec1ac28b74838c1 (diff) |
cutils: work around platform differences in strto{l,ul,ll,ull}
Linux returns 0 if no conversion was made, while OS X and presumably
the BSDs return EINVAL. The OS X convention rejects more invalid
inputs, so convert to it and adjust the test case.
Windows returns 1 from strtoul and strtoull (instead of -1) for
negative out-of-range input; fix it up.
Reported-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tests/test-cutils.c')
-rw-r--r-- | tests/test-cutils.c | 57 |
1 files changed, 16 insertions, 41 deletions
diff --git a/tests/test-cutils.c b/tests/test-cutils.c index a7a15a5efe..0046c61fe9 100644 --- a/tests/test-cutils.c +++ b/tests/test-cutils.c @@ -264,9 +264,7 @@ static void test_qemu_strtol_empty(void) err = qemu_strtol(str, &endptr, 0, &res); - g_assert_cmpint(err, ==, 0); - g_assert_cmpint(res, ==, 0); - g_assert(endptr == str); + g_assert_cmpint(err, ==, -EINVAL); } static void test_qemu_strtol_whitespace(void) @@ -279,9 +277,7 @@ static void test_qemu_strtol_whitespace(void) err = qemu_strtol(str, &endptr, 0, &res); - g_assert_cmpint(err, ==, 0); - g_assert_cmpint(res, ==, 0); - g_assert(endptr == str); + g_assert_cmpint(err, ==, -EINVAL); } static void test_qemu_strtol_invalid(void) @@ -294,9 +290,7 @@ static void test_qemu_strtol_invalid(void) err = qemu_strtol(str, &endptr, 0, &res); - g_assert_cmpint(err, ==, 0); - g_assert_cmpint(res, ==, 0); - g_assert(endptr == str); + g_assert_cmpint(err, ==, -EINVAL); } static void test_qemu_strtol_trailing(void) @@ -478,8 +472,7 @@ static void test_qemu_strtol_full_empty(void) err = qemu_strtol(str, NULL, 0, &res); - g_assert_cmpint(err, ==, 0); - g_assert_cmpint(res, ==, 0); + g_assert_cmpint(err, ==, -EINVAL); } static void test_qemu_strtol_full_negative(void) @@ -555,9 +548,7 @@ static void test_qemu_strtoul_empty(void) err = qemu_strtoul(str, &endptr, 0, &res); - g_assert_cmpint(err, ==, 0); - g_assert_cmpint(res, ==, 0); - g_assert(endptr == str); + g_assert_cmpint(err, ==, -EINVAL); } static void test_qemu_strtoul_whitespace(void) @@ -570,9 +561,7 @@ static void test_qemu_strtoul_whitespace(void) err = qemu_strtoul(str, &endptr, 0, &res); - g_assert_cmpint(err, ==, 0); - g_assert_cmpint(res, ==, 0); - g_assert(endptr == str); + g_assert_cmpint(err, ==, -EINVAL); } static void test_qemu_strtoul_invalid(void) @@ -585,8 +574,7 @@ static void test_qemu_strtoul_invalid(void) err = qemu_strtoul(str, &endptr, 0, &res); - g_assert_cmpint(err, ==, 0); - g_assert(endptr == str); + g_assert_cmpint(err, ==, -EINVAL); } static void test_qemu_strtoul_trailing(void) @@ -765,8 +753,7 @@ static void test_qemu_strtoul_full_empty(void) err = qemu_strtoul(str, NULL, 0, &res); - g_assert_cmpint(err, ==, 0); - g_assert_cmpint(res, ==, 0); + g_assert_cmpint(err, ==, -EINVAL); } static void test_qemu_strtoul_full_negative(void) { @@ -840,9 +827,7 @@ static void test_qemu_strtoll_empty(void) err = qemu_strtoll(str, &endptr, 0, &res); - g_assert_cmpint(err, ==, 0); - g_assert_cmpint(res, ==, 0); - g_assert(endptr == str); + g_assert_cmpint(err, ==, -EINVAL); } static void test_qemu_strtoll_whitespace(void) @@ -855,9 +840,7 @@ static void test_qemu_strtoll_whitespace(void) err = qemu_strtoll(str, &endptr, 0, &res); - g_assert_cmpint(err, ==, 0); - g_assert_cmpint(res, ==, 0); - g_assert(endptr == str); + g_assert_cmpint(err, ==, -EINVAL); } static void test_qemu_strtoll_invalid(void) @@ -870,8 +853,7 @@ static void test_qemu_strtoll_invalid(void) err = qemu_strtoll(str, &endptr, 0, &res); - g_assert_cmpint(err, ==, 0); - g_assert(endptr == str); + g_assert_cmpint(err, ==, -EINVAL); } static void test_qemu_strtoll_trailing(void) @@ -1050,8 +1032,7 @@ static void test_qemu_strtoll_full_empty(void) err = qemu_strtoll(str, NULL, 0, &res); - g_assert_cmpint(err, ==, 0); - g_assert_cmpint(res, ==, 0); + g_assert_cmpint(err, ==, -EINVAL); } static void test_qemu_strtoll_full_negative(void) @@ -1128,9 +1109,7 @@ static void test_qemu_strtoull_empty(void) err = qemu_strtoull(str, &endptr, 0, &res); - g_assert_cmpint(err, ==, 0); - g_assert_cmpint(res, ==, 0); - g_assert(endptr == str); + g_assert_cmpint(err, ==, -EINVAL); } static void test_qemu_strtoull_whitespace(void) @@ -1143,9 +1122,7 @@ static void test_qemu_strtoull_whitespace(void) err = qemu_strtoull(str, &endptr, 0, &res); - g_assert_cmpint(err, ==, 0); - g_assert_cmpint(res, ==, 0); - g_assert(endptr == str); + g_assert_cmpint(err, ==, -EINVAL); } static void test_qemu_strtoull_invalid(void) @@ -1158,8 +1135,7 @@ static void test_qemu_strtoull_invalid(void) err = qemu_strtoull(str, &endptr, 0, &res); - g_assert_cmpint(err, ==, 0); - g_assert(endptr == str); + g_assert_cmpint(err, ==, -EINVAL); } static void test_qemu_strtoull_trailing(void) @@ -1338,8 +1314,7 @@ static void test_qemu_strtoull_full_empty(void) err = qemu_strtoull(str, NULL, 0, &res); - g_assert_cmpint(err, ==, 0); - g_assert_cmpint(res, ==, 0); + g_assert_cmpint(err, ==, -EINVAL); } static void test_qemu_strtoull_full_negative(void) |