summaryrefslogtreecommitdiffstats
path: root/src/test/test-fs-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-10-22 15:49:00 +0200
committerLennart Poettering <lennart@poettering.net>2021-10-27 22:37:56 +0200
commit68def5a975fd8c6dd2061250a0f7aeb8c149ea7b (patch)
treed25f93b644ee22d4e365bf521523367dae2f95d2 /src/test/test-fs-util.c
parenthomework: apply mount flags also for CIFS mounts (diff)
downloadsystemd-68def5a975fd8c6dd2061250a0f7aeb8c149ea7b.tar.xz
systemd-68def5a975fd8c6dd2061250a0f7aeb8c149ea7b.zip
fs-util: add helper that can split CIFS services names
Diffstat (limited to 'src/test/test-fs-util.c')
-rw-r--r--src/test/test-fs-util.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c
index cd024ef7f1..41ddec4783 100644
--- a/src/test/test-fs-util.c
+++ b/src/test/test-fs-util.c
@@ -921,6 +921,36 @@ static void test_rmdir_parents(void) {
assert_se(rm_rf(temp, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
}
+static void test_parse_cifs_service_one(const char *f, const char *h, const char *s, const char *d, int ret) {
+ _cleanup_free_ char *a = NULL, *b = NULL, *c = NULL;
+
+ assert_se(parse_cifs_service(f, &a, &b, &c) == ret);
+ assert_se(streq_ptr(a, h));
+ assert_se(streq_ptr(b, s));
+ assert_se(streq_ptr(c, d));
+}
+
+static void test_parse_cifs_service(void) {
+ log_info("/* %s */", __func__);
+
+ test_parse_cifs_service_one("//foo/bar/baz", "foo", "bar", "baz", 0);
+ test_parse_cifs_service_one("\\\\foo\\bar\\baz", "foo", "bar", "baz", 0);
+ test_parse_cifs_service_one("//foo/bar", "foo", "bar", NULL, 0);
+ test_parse_cifs_service_one("\\\\foo\\bar", "foo", "bar", NULL, 0);
+ test_parse_cifs_service_one("//foo/bar/baz/uuu", "foo", "bar", "baz/uuu", 0);
+ test_parse_cifs_service_one("\\\\foo\\bar\\baz\\uuu", "foo", "bar", "baz/uuu", 0);
+
+ test_parse_cifs_service_one(NULL, NULL, NULL, NULL, -EINVAL);
+ test_parse_cifs_service_one("", NULL, NULL, NULL, -EINVAL);
+ test_parse_cifs_service_one("abc", NULL, NULL, NULL, -EINVAL);
+ test_parse_cifs_service_one("abc/cde/efg", NULL, NULL, NULL, -EINVAL);
+ test_parse_cifs_service_one("//foo/bar/baz/..", NULL, NULL, NULL, -EINVAL);
+ test_parse_cifs_service_one("//foo///", NULL, NULL, NULL, -EINVAL);
+ test_parse_cifs_service_one("//foo/.", NULL, NULL, NULL, -EINVAL);
+ test_parse_cifs_service_one("//foo/a/.", NULL, NULL, NULL, -EINVAL);
+ test_parse_cifs_service_one("//./a", NULL, NULL, NULL, -EINVAL);
+}
+
int main(int argc, char *argv[]) {
test_setup_logging(LOG_INFO);
@@ -940,6 +970,7 @@ int main(int argc, char *argv[]) {
test_chmod_and_chown();
test_conservative_rename();
test_rmdir_parents();
+ test_parse_cifs_service();
return 0;
}