diff options
author | Swen Schillig <swen@linux.ibm.com> | 2019-04-10 10:52:35 +0200 |
---|---|---|
committer | Ralph Boehme <slow@samba.org> | 2019-06-30 11:32:18 +0000 |
commit | ba021e3cfb2d8497f0e62001782387547e996ded (patch) | |
tree | bf03dad0ecbeb288c4741ff8975a757753e98740 | |
parent | 9af0614bcb1750e29a1018e7c6fb6f655cb594fd (diff) | |
download | samba-ba021e3cfb2d8497f0e62001782387547e996ded.tar.gz |
tests-util: Adding test to verify "no-conversion" detection
The standard string to integer conversion routines return zero
if a string was to be converted which did not reflect a number.
It is not flag'ed as an error.
The wrapper functions strtoul_err() and strtoull_err() are expected
to exactly do this.
Signed-off-by: Swen Schillig <swen@linux.ibm.com>
Reviewed-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Christof Schmitt <cs@samba.org>
-rw-r--r-- | lib/util/tests/util.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/util/tests/util.c b/lib/util/tests/util.c index c45f3835cf7..de9dca1ffc5 100644 --- a/lib/util/tests/util.c +++ b/lib/util/tests/util.c @@ -481,6 +481,31 @@ static bool test_strtoul_err_negative(struct torture_context *tctx) return true; } +static bool test_strtoul_err_no_number(struct torture_context *tctx) +{ + const char *number = "ghijk"; + const char *blank = ""; + int err; + + err = 0; + strtoul_err(number, NULL, 0, &err); + torture_assert(tctx, err == EINVAL, "strtoul_err: Expected EINVAL"); + + err = 0; + strtoull_err(number, NULL, 0, &err); + torture_assert(tctx, err == EINVAL, "strtoull_err: Expected EINVAL"); + + err = 0; + strtoul_err(blank, NULL, 0, &err); + torture_assert(tctx, err == EINVAL, "strtoul_err: Expected EINVAL"); + + err = 0; + strtoull_err(blank, NULL, 0, &err); + torture_assert(tctx, err == EINVAL, "strtoull_err: Expected EINVAL"); + + return true; +} + struct torture_suite *torture_local_util(TALLOC_CTX *mem_ctx) { struct torture_suite *suite = @@ -498,5 +523,8 @@ struct torture_suite *torture_local_util(TALLOC_CTX *mem_ctx) torture_suite_add_simple_test(suite, "strtoul(l)_err negative", test_strtoul_err_negative); + torture_suite_add_simple_test(suite, + "strtoul(l)_err no number", + test_strtoul_err_no_number); return suite; } |