summaryrefslogtreecommitdiff
path: root/src/test/test-parse-util.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2017-11-09 17:36:07 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2017-11-09 18:39:50 +0900
commit3fcf65c35253e5f54906f5784f2695f3ce94ceb5 (patch)
treee956eb530b1eff392f113d227f24ef163d530b34 /src/test/test-parse-util.c
parentccd1fc2f694849d646f80980912a54ba2c51a38c (diff)
downloadsystemd-3fcf65c35253e5f54906f5784f2695f3ce94ceb5.tar.gz
test-parse-util: add more tests, mainly for empty string
Diffstat (limited to 'src/test/test-parse-util.c')
-rw-r--r--src/test/test-parse-util.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/test/test-parse-util.c b/src/test/test-parse-util.c
index 1b29b2ea87..c0abc8130a 100644
--- a/src/test/test-parse-util.c
+++ b/src/test/test-parse-util.c
@@ -79,6 +79,9 @@ static void test_parse_pid(void) {
r = parse_pid("junk", &pid);
assert_se(r == -EINVAL);
+
+ r = parse_pid("", &pid);
+ assert_se(r == -EINVAL);
}
static void test_parse_mode(void) {
@@ -98,6 +101,8 @@ static void test_parse_mode(void) {
static void test_parse_size(void) {
uint64_t bytes;
+ assert_se(parse_size("", 1024, &bytes) == -EINVAL);
+
assert_se(parse_size("111", 1024, &bytes) == 0);
assert_se(bytes == 111);
@@ -257,6 +262,10 @@ static void test_parse_range(void) {
assert_se(lower == 9999);
assert_se(upper == 9999);
+ assert_se(parse_range("-123", &lower, &upper) == -EINVAL);
+ assert_se(lower == 9999);
+ assert_se(upper == 9999);
+
assert_se(parse_range("-111-123", &lower, &upper) == -EINVAL);
assert_se(lower == 9999);
assert_se(upper == 9999);
@@ -370,6 +379,15 @@ static void test_safe_atolli(void) {
r = safe_atolli("junk", &l);
assert_se(r == -EINVAL);
+
+ r = safe_atolli("123x", &l);
+ assert_se(r == -EINVAL);
+
+ r = safe_atolli("12.3", &l);
+ assert_se(r == -EINVAL);
+
+ r = safe_atolli("", &l);
+ assert_se(r == -EINVAL);
}
static void test_safe_atou16(void) {
@@ -398,6 +416,12 @@ static void test_safe_atou16(void) {
r = safe_atou16("123x", &l);
assert_se(r == -EINVAL);
+
+ r = safe_atou16("12.3", &l);
+ assert_se(r == -EINVAL);
+
+ r = safe_atou16("", &l);
+ assert_se(r == -EINVAL);
}
static void test_safe_atoi16(void) {
@@ -431,6 +455,12 @@ static void test_safe_atoi16(void) {
r = safe_atoi16("123x", &l);
assert_se(r == -EINVAL);
+
+ r = safe_atoi16("12.3", &l);
+ assert_se(r == -EINVAL);
+
+ r = safe_atoi16("", &l);
+ assert_se(r == -EINVAL);
}
static void test_safe_atou64(void) {
@@ -459,6 +489,12 @@ static void test_safe_atou64(void) {
r = safe_atou64("123x", &l);
assert_se(r == -EINVAL);
+
+ r = safe_atou64("12.3", &l);
+ assert_se(r == -EINVAL);
+
+ r = safe_atou64("", &l);
+ assert_se(r == -EINVAL);
}
static void test_safe_atoi64(void) {
@@ -492,6 +528,12 @@ static void test_safe_atoi64(void) {
r = safe_atoi64("123x", &l);
assert_se(r == -EINVAL);
+
+ r = safe_atoi64("12.3", &l);
+ assert_se(r == -EINVAL);
+
+ r = safe_atoi64("", &l);
+ assert_se(r == -EINVAL);
}
static void test_safe_atod(void) {
@@ -513,6 +555,9 @@ static void test_safe_atod(void) {
strtod("0,5", &e);
assert_se(*e == ',');
+ r = safe_atod("", &d);
+ assert_se(r == -EINVAL);
+
/* Check if this really is locale independent */
if (setlocale(LC_NUMERIC, "de_DE.utf8")) {
@@ -525,6 +570,9 @@ static void test_safe_atod(void) {
errno = 0;
assert_se(fabs(strtod("0,5", &e) - 0.5) < 0.00001);
+
+ r = safe_atod("", &d);
+ assert_se(r == -EINVAL);
}
/* And check again, reset */
@@ -540,6 +588,9 @@ static void test_safe_atod(void) {
errno = 0;
strtod("0,5", &e);
assert_se(*e == ',');
+
+ r = safe_atod("", &d);
+ assert_se(r == -EINVAL);
}
static void test_parse_percent(void) {
@@ -558,6 +609,7 @@ static void test_parse_percent(void) {
assert_se(parse_percent("%%") == -EINVAL);
assert_se(parse_percent("%1") == -EINVAL);
assert_se(parse_percent("1%%") == -EINVAL);
+ assert_se(parse_percent("3.2%") == -EINVAL);
}
static void test_parse_percent_unbounded(void) {
@@ -596,6 +648,8 @@ static void test_parse_nice(void) {
static void test_parse_dev(void) {
dev_t dev;
+ assert_se(parse_dev("", &dev) == -EINVAL);
+ assert_se(parse_dev("junk", &dev) == -EINVAL);
assert_se(parse_dev("0", &dev) == -EINVAL);
assert_se(parse_dev("5", &dev) == -EINVAL);
assert_se(parse_dev("5:", &dev) == -EINVAL);