summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-06-08 19:25:38 +0200
committerLennart Poettering <lennart@poettering.net>2016-06-14 19:50:38 +0200
commit9184ca48ea43e009cd6f379f319926109a30926c (patch)
tree0db1fa083fb240966e47d621d861cd7cb45501e6 /src/test
parentd9ab2bcf0591b496f1a4750c7ff790b33f9c7e59 (diff)
util-lib: introduce parse_percent() for parsing percent specifications
And port a couple of users over to it.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-parse-util.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/test/test-parse-util.c b/src/test/test-parse-util.c
index 7d8677e17c..0a76308f72 100644
--- a/src/test/test-parse-util.c
+++ b/src/test/test-parse-util.c
@@ -475,6 +475,24 @@ static void test_safe_atod(void) {
assert_se(*e == ',');
}
+static void test_parse_percent(void) {
+ assert_se(parse_percent("") == -EINVAL);
+ assert_se(parse_percent("foo") == -EINVAL);
+ assert_se(parse_percent("0") == -EINVAL);
+ assert_se(parse_percent("50") == -EINVAL);
+ assert_se(parse_percent("100") == -EINVAL);
+ assert_se(parse_percent("-1") == -EINVAL);
+ assert_se(parse_percent("0%") == 0);
+ assert_se(parse_percent("55%") == 55);
+ assert_se(parse_percent("100%") == 100);
+ assert_se(parse_percent("-7%") == -ERANGE);
+ assert_se(parse_percent("107%") == -ERANGE);
+ assert_se(parse_percent("%") == -EINVAL);
+ assert_se(parse_percent("%%") == -EINVAL);
+ assert_se(parse_percent("%1") == -EINVAL);
+ assert_se(parse_percent("1%%") == -EINVAL);
+}
+
int main(int argc, char *argv[]) {
log_parse_environment();
log_open();
@@ -488,6 +506,7 @@ int main(int argc, char *argv[]) {
test_safe_atou16();
test_safe_atoi16();
test_safe_atod();
+ test_parse_percent();
return 0;
}