diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-09-16 10:08:12 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-09-19 09:35:52 +0200 |
commit | 3b6cabd806c6eb5eec4ac21c903a5033bea94e9d (patch) | |
tree | a0e1c673d70a4288bafd5142e150d01b947bc502 /src/test/test-parse-util.c | |
parent | sd-network: modernize log error messages (diff) | |
download | systemd-3b6cabd806c6eb5eec4ac21c903a5033bea94e9d.tar.xz systemd-3b6cabd806c6eb5eec4ac21c903a5033bea94e9d.zip |
basic/parse-util: add helper to parse bounded unsigned values
"parse_range" is already used for stuff like "a-b", so use "bounded" here to
avoid confusion.
Diffstat (limited to '')
-rw-r--r-- | src/test/test-parse-util.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/test/test-parse-util.c b/src/test/test-parse-util.c index 1ba8c8987f..7a485f390f 100644 --- a/src/test/test-parse-util.c +++ b/src/test/test-parse-util.c @@ -417,6 +417,32 @@ TEST(parse_range) { assert_se(upper == 9999); } +TEST(safe_atou_bounded) { + int r; + unsigned x; + + r = safe_atou_bounded("12345", 12, 20000, &x); + assert_se(r == 0); + assert_se(x == 12345); + + r = safe_atou_bounded("12", 12, 20000, &x); + assert_se(r == 0); + assert_se(x == 12); + + r = safe_atou_bounded("20000", 12, 20000, &x); + assert_se(r == 0); + assert_se(x == 20000); + + r = safe_atou_bounded("-1", 12, 20000, &x); + assert_se(r == -ERANGE); + + r = safe_atou_bounded("11", 12, 20000, &x); + assert_se(r == -ERANGE); + + r = safe_atou_bounded("20001", 12, 20000, &x); + assert_se(r == -ERANGE); +} + TEST(safe_atolli) { int r; long long l; |