summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-04-18 14:20:49 +0200
committerSven Eden <yamakuzure@gmx.net>2018-08-24 16:47:08 +0200
commite5e0c80fdfa8861931df799574d5a60c96b6aa13 (patch)
tree3ff055d308feb83a85c3d8a2edd0eb9ebcfd42a4 /src/test
parentd1dbf40d47cfa883c4c9fa264dfd84cd57a03b85 (diff)
util-lib: introduce new empty_or_root() helper (#8746)
We check the same condition at various places. Let's add a trivial, common helper for this, and use it everywhere. It's not going to make things much faster or much shorter, but I think a lot more readable
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-path-util.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c
index f7e96283f..e7a247027 100644
--- a/src/test/test-path-util.c
+++ b/src/test/test-path-util.c
@@ -478,6 +478,19 @@ static void test_skip_dev_prefix(void) {
assert_se(streq(skip_dev_prefix("foo"), "foo"));
}
+static void test_empty_or_root(void) {
+ assert_se(empty_or_root(NULL));
+ assert_se(empty_or_root(""));
+ assert_se(empty_or_root("/"));
+ assert_se(empty_or_root("//"));
+ assert_se(empty_or_root("///"));
+ assert_se(empty_or_root("/////////////////"));
+ assert_se(!empty_or_root("xxx"));
+ assert_se(!empty_or_root("/xxx"));
+ assert_se(!empty_or_root("/xxx/"));
+ assert_se(!empty_or_root("//yy//"));
+}
+
int main(int argc, char **argv) {
log_set_max_level(LOG_DEBUG);
log_parse_environment();
@@ -500,6 +513,7 @@ int main(int argc, char **argv) {
test_filename_is_valid();
test_hidden_or_backup_file();
test_skip_dev_prefix();
+ test_empty_or_root();
#if 0 /// UNNEEDED by elogind
test_systemd_installation_has_version(argv[1]); /* NULL is OK */