summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-chase.c74
-rw-r--r--src/test/test-path-util.c39
2 files changed, 74 insertions, 39 deletions
diff --git a/src/test/test-chase.c b/src/test/test-chase.c
index 1e98f5c6ed..558f4109e3 100644
--- a/src/test/test-chase.c
+++ b/src/test/test-chase.c
@@ -442,6 +442,43 @@ TEST(chaseat) {
assert_se(streq(result, "/usr"));
result = mfree(result);
+ /* If the file descriptor points to the root directory, the result will be absolute. */
+
+ fd = open("/", O_CLOEXEC | O_DIRECTORY | O_PATH);
+ assert_se(fd >= 0);
+
+ assert_se(chaseat(fd, p, 0, &result, NULL) >= 0);
+ assert_se(streq(result, "/usr"));
+ result = mfree(result);
+
+ assert_se(chaseat(fd, p, CHASE_AT_RESOLVE_IN_ROOT, &result, NULL) >= 0);
+ assert_se(streq(result, "/usr"));
+ result = mfree(result);
+
+ fd = safe_close(fd);
+
+ /* If the file descriptor does not point to the root directory, the result will be relative
+ * unless the result is outside of the specified file descriptor. */
+
+ assert_se(chaseat(tfd, "abc", 0, &result, NULL) >= 0);
+ assert_se(streq(result, "/usr"));
+ result = mfree(result);
+
+ assert_se(chaseat(tfd, "/abc", 0, &result, NULL) >= 0);
+ assert_se(streq(result, "/usr"));
+ result = mfree(result);
+
+ assert_se(chaseat(tfd, "abc", CHASE_AT_RESOLVE_IN_ROOT, NULL, NULL) == -ENOENT);
+ assert_se(chaseat(tfd, "/abc", CHASE_AT_RESOLVE_IN_ROOT, NULL, NULL) == -ENOENT);
+
+ assert_se(chaseat(tfd, "abc", CHASE_AT_RESOLVE_IN_ROOT | CHASE_NONEXISTENT, &result, NULL) >= 0);
+ assert_se(streq(result, "usr"));
+ result = mfree(result);
+
+ assert_se(chaseat(tfd, "/abc", CHASE_AT_RESOLVE_IN_ROOT | CHASE_NONEXISTENT, &result, NULL) >= 0);
+ assert_se(streq(result, "usr"));
+ result = mfree(result);
+
/* Test that absolute path or not are the same when resolving relative to a directory file
* descriptor and that we always get a relative path back. */
@@ -611,4 +648,41 @@ static int intro(void) {
return EXIT_SUCCESS;
}
+TEST(chaseat_prefix_root) {
+ _cleanup_free_ char *cwd = NULL, *ret = NULL, *expected = NULL;
+
+ assert_se(safe_getcwd(&cwd) >= 0);
+
+ assert_se(chaseat_prefix_root("/hoge", NULL, &ret) >= 0);
+ assert_se(streq(ret, "/hoge"));
+
+ ret = mfree(ret);
+
+ assert_se(chaseat_prefix_root("/hoge", "a/b/c", &ret) >= 0);
+ assert_se(streq(ret, "/hoge"));
+
+ ret = mfree(ret);
+
+ assert_se(chaseat_prefix_root("hoge", "/a/b//./c///", &ret) >= 0);
+ assert_se(streq(ret, "/a/b/c/hoge"));
+
+ ret = mfree(ret);
+
+ assert_se(chaseat_prefix_root("hoge", "a/b//./c///", &ret) >= 0);
+ assert_se(expected = path_join(cwd, "a/b/c/hoge"));
+ assert_se(streq(ret, expected));
+
+ ret = mfree(ret);
+ expected = mfree(expected);
+
+ assert_se(chaseat_prefix_root("./hoge/aaa/../././b", "/a/b//./c///", &ret) >= 0);
+ assert_se(streq(ret, "/a/b/c/hoge/aaa/../././b"));
+
+ ret = mfree(ret);
+
+ assert_se(chaseat_prefix_root("./hoge/aaa/../././b", "a/b//./c///", &ret) >= 0);
+ assert_se(expected = path_join(cwd, "a/b/c/hoge/aaa/../././b"));
+ assert_se(streq(ret, expected));
+}
+
DEFINE_TEST_MAIN_WITH_INTRO(LOG_INFO, intro);
diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c
index 22e8f3481a..e40ffea4d5 100644
--- a/src/test/test-path-util.c
+++ b/src/test/test-path-util.c
@@ -494,45 +494,6 @@ TEST(fsck_exists) {
assert_se(fsck_exists_for_fstype("/../bin/") == 0);
}
-TEST(path_prefix_root_cwd) {
- _cleanup_free_ char *cwd = NULL, *ret = NULL, *expected = NULL;
-
- assert_se(safe_getcwd(&cwd) >= 0);
-
- assert_se(path_prefix_root_cwd("hoge", NULL, &ret) >= 0);
- assert_se(expected = path_join(cwd, "hoge"));
- assert_se(streq(ret, expected));
-
- ret = mfree(ret);
- expected = mfree(expected);
-
- assert_se(path_prefix_root_cwd("/hoge", NULL, &ret) >= 0);
- assert_se(streq(ret, "/hoge"));
-
- ret = mfree(ret);
-
- assert_se(path_prefix_root_cwd("hoge", "/a/b//./c///", &ret) >= 0);
- assert_se(streq(ret, "/a/b/c/hoge"));
-
- ret = mfree(ret);
-
- assert_se(path_prefix_root_cwd("hoge", "a/b//./c///", &ret) >= 0);
- assert_se(expected = path_join(cwd, "a/b/c/hoge"));
- assert_se(streq(ret, expected));
-
- ret = mfree(ret);
- expected = mfree(expected);
-
- assert_se(path_prefix_root_cwd("/../hoge/aaa/../././b", "/a/b//./c///", &ret) >= 0);
- assert_se(streq(ret, "/a/b/c/../hoge/aaa/../././b"));
-
- ret = mfree(ret);
-
- assert_se(path_prefix_root_cwd("/../hoge/aaa/../././b", "a/b//./c///", &ret) >= 0);
- assert_se(expected = path_join(cwd, "a/b/c/../hoge/aaa/../././b"));
- assert_se(streq(ret, expected));
-}
-
static void test_path_make_relative_one(const char *from, const char *to, const char *expected) {
_cleanup_free_ char *z = NULL;
int r;