From e5e0c80fdfa8861931df799574d5a60c96b6aa13 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 18 Apr 2018 14:20:49 +0200 Subject: 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 --- src/test/test-path-util.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/test') 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 */ -- cgit v1.2.3