summaryrefslogtreecommitdiffstats
path: root/src/test/test-path-util.c
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2023-08-17 13:09:19 +0200
committerDaan De Meyer <daan.j.demeyer@gmail.com>2023-08-17 13:23:36 +0200
commit4541d045b2cc2834add853f06293d4474ac403e4 (patch)
tree87a1379654250fce79472e0e6293f2c8c446d7e0 /src/test/test-path-util.c
parentMerge pull request #28862 from DaanDeMeyer/swap (diff)
downloadsystemd-4541d045b2cc2834add853f06293d4474ac403e4.tar.xz
systemd-4541d045b2cc2834add853f06293d4474ac403e4.zip
path-util: Add path_simplify_full()
Sometimes its useful to keep a trailing slash in the path so let's add path_simplify_full() and a flag to do just that.
Diffstat (limited to 'src/test/test-path-util.c')
-rw-r--r--src/test/test-path-util.c43
1 files changed, 23 insertions, 20 deletions
diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c
index 31e2a3d296..8c3a27f228 100644
--- a/src/test/test-path-util.c
+++ b/src/test/test-path-util.c
@@ -48,11 +48,11 @@ TEST(path) {
assert_se(!path_equal_ptr(NULL, "/a"));
}
-static void test_path_simplify_one(const char *in, const char *out) {
+static void test_path_simplify_one(const char *in, const char *out, PathSimplifyFlags flags) {
char *p;
p = strdupa_safe(in);
- path_simplify(p);
+ path_simplify_full(p, flags);
log_debug("/* test_path_simplify(%s) → %s (expected: %s) */", in, p, out);
assert_se(streq(p, out));
}
@@ -61,34 +61,37 @@ TEST(path_simplify) {
_cleanup_free_ char *hoge = NULL, *hoge_out = NULL;
char foo[NAME_MAX * 2];
- test_path_simplify_one("", "");
- test_path_simplify_one("aaa/bbb////ccc", "aaa/bbb/ccc");
- test_path_simplify_one("//aaa/.////ccc", "/aaa/ccc");
- test_path_simplify_one("///", "/");
- test_path_simplify_one("///.//", "/");
- test_path_simplify_one("///.//.///", "/");
- test_path_simplify_one("////.././///../.", "/../..");
- test_path_simplify_one(".", ".");
- test_path_simplify_one("./", ".");
- test_path_simplify_one(".///.//./.", ".");
- test_path_simplify_one(".///.//././/", ".");
+ test_path_simplify_one("", "", 0);
+ test_path_simplify_one("aaa/bbb////ccc", "aaa/bbb/ccc", 0);
+ test_path_simplify_one("//aaa/.////ccc", "/aaa/ccc", 0);
+ test_path_simplify_one("///", "/", 0);
+ test_path_simplify_one("///", "/", PATH_SIMPLIFY_KEEP_TRAILING_SLASH);
+ test_path_simplify_one("///.//", "/", 0);
+ test_path_simplify_one("///.//.///", "/", 0);
+ test_path_simplify_one("////.././///../.", "/../..", 0);
+ test_path_simplify_one(".", ".", 0);
+ test_path_simplify_one("./", ".", 0);
+ test_path_simplify_one("./", "./", PATH_SIMPLIFY_KEEP_TRAILING_SLASH);
+ test_path_simplify_one(".///.//./.", ".", 0);
+ test_path_simplify_one(".///.//././/", ".", 0);
test_path_simplify_one("//./aaa///.//./.bbb/..///c.//d.dd///..eeee/.",
- "/aaa/.bbb/../c./d.dd/..eeee");
+ "/aaa/.bbb/../c./d.dd/..eeee", 0);
test_path_simplify_one("//./aaa///.//./.bbb/..///c.//d.dd///..eeee/..",
- "/aaa/.bbb/../c./d.dd/..eeee/..");
+ "/aaa/.bbb/../c./d.dd/..eeee/..", 0);
test_path_simplify_one(".//./aaa///.//./.bbb/..///c.//d.dd///..eeee/..",
- "aaa/.bbb/../c./d.dd/..eeee/..");
+ "aaa/.bbb/../c./d.dd/..eeee/..", 0);
test_path_simplify_one("..//./aaa///.//./.bbb/..///c.//d.dd///..eeee/..",
- "../aaa/.bbb/../c./d.dd/..eeee/..");
+ "../aaa/.bbb/../c./d.dd/..eeee/..", 0);
+ test_path_simplify_one("abc///", "abc/", PATH_SIMPLIFY_KEEP_TRAILING_SLASH);
memset(foo, 'a', sizeof(foo) -1);
char_array_0(foo);
- test_path_simplify_one(foo, foo);
+ test_path_simplify_one(foo, foo, 0);
hoge = strjoin("/", foo);
assert_se(hoge);
- test_path_simplify_one(hoge, hoge);
+ test_path_simplify_one(hoge, hoge, 0);
hoge = mfree(hoge);
hoge = strjoin("a////.//././//./b///././/./c/////././//./", foo, "//.//////d/e/.//f/");
@@ -97,7 +100,7 @@ TEST(path_simplify) {
hoge_out = strjoin("a/b/c/", foo, "//.//////d/e/.//f/");
assert_se(hoge_out);
- test_path_simplify_one(hoge, hoge_out);
+ test_path_simplify_one(hoge, hoge_out, 0);
}
static void test_path_compare_one(const char *a, const char *b, int expected) {