diff options
author | Daniel Mack <github@zonque.org> | 2015-11-11 10:48:39 +0100 |
---|---|---|
committer | Daniel Mack <github@zonque.org> | 2015-11-11 10:48:39 +0100 |
commit | 2d0246bbd268c96d6e44197901b387415a0d3b34 (patch) | |
tree | 8c521d56df8e5635c6f4281b141b6ac4b18c063e | |
parent | 7042fc14ff2bd30648aea6602c95d3cf6946e7be (diff) | |
parent | 5c280bcc5a726e53d7108ad2bbed9cd47df6a7b6 (diff) |
Merge pull request #1844 from martinpitt/master
test-parse-util: cover negative numbers, leading spaces, and more range errors
-rw-r--r-- | src/test/test-parse-util.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/test/test-parse-util.c b/src/test/test-parse-util.c index d3ae0599ab..f0d5d71083 100644 --- a/src/test/test-parse-util.c +++ b/src/test/test-parse-util.c @@ -352,6 +352,24 @@ static void test_safe_atolli(void) { assert_se(r == 0); assert_se(l == 12345); + r = safe_atolli(" 12345", &l); + assert_se(r == 0); + assert_se(l == 12345); + + r = safe_atolli("-12345", &l); + assert_se(r == 0); + assert_se(l == -12345); + + r = safe_atolli(" -12345", &l); + assert_se(r == 0); + assert_se(l == -12345); + + r = safe_atolli("12345678901234567890", &l); + assert_se(r == -ERANGE); + + r = safe_atolli("-12345678901234567890", &l); + assert_se(r == -ERANGE); + r = safe_atolli("junk", &l); assert_se(r == -EINVAL); } @@ -364,9 +382,19 @@ static void test_safe_atou16(void) { assert_se(r == 0); assert_se(l == 12345); + r = safe_atou16(" 12345", &l); + assert_se(r == 0); + assert_se(l == 12345); + r = safe_atou16("123456", &l); assert_se(r == -ERANGE); + r = safe_atou16("-1", &l); + assert_se(r == -ERANGE); + + r = safe_atou16(" -1", &l); + assert_se(r == -ERANGE); + r = safe_atou16("junk", &l); assert_se(r == -EINVAL); } @@ -379,9 +407,24 @@ static void test_safe_atoi16(void) { assert_se(r == 0); assert_se(l == -12345); + r = safe_atoi16(" -12345", &l); + assert_se(r == 0); + assert_se(l == -12345); + + r = safe_atoi16("32767", &l); + assert_se(r == 0); + assert_se(l == 32767); + + r = safe_atoi16(" 32767", &l); + assert_se(r == 0); + assert_se(l == 32767); + r = safe_atoi16("36536", &l); assert_se(r == -ERANGE); + r = safe_atoi16("-32769", &l); + assert_se(r == -ERANGE); + r = safe_atoi16("junk", &l); assert_se(r == -EINVAL); } |