summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-path-util.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c
index 63d64b28b0..82090ce99f 100644
--- a/src/test/test-path-util.c
+++ b/src/test/test-path-util.c
@@ -242,6 +242,25 @@ static void test_strv_resolve(void) {
assert_se(rm_rf_dangerous(tmp_dir, false, true, false) == 0);
}
+static void test_path_startswith(void) {
+ assert_se(path_startswith("/foo/bar/barfoo/", "/foo"));
+ assert_se(path_startswith("/foo/bar/barfoo/", "/foo/"));
+ assert_se(path_startswith("/foo/bar/barfoo/", "/"));
+ assert_se(path_startswith("/foo/bar/barfoo/", "////"));
+ assert_se(path_startswith("/foo/bar/barfoo/", "/foo//bar/////barfoo///"));
+ assert_se(path_startswith("/foo/bar/barfoo/", "/foo/bar/barfoo////"));
+ assert_se(path_startswith("/foo/bar/barfoo/", "/foo/bar///barfoo/"));
+ assert_se(path_startswith("/foo/bar/barfoo/", "/foo////bar/barfoo/"));
+ assert_se(path_startswith("/foo/bar/barfoo/", "////foo/bar/barfoo/"));
+ assert_se(path_startswith("/foo/bar/barfoo/", "/foo/bar/barfoo"));
+
+ assert_se(!path_startswith("/foo/bar/barfoo/", "/foo/bar/barfooa/"));
+ assert_se(!path_startswith("/foo/bar/barfoo/", "/foo/bar/barfooa"));
+ assert_se(!path_startswith("/foo/bar/barfoo/", ""));
+ assert_se(!path_startswith("/foo/bar/barfoo/", "/bar/foo"));
+ assert_se(!path_startswith("/foo/bar/barfoo/", "/f/b/b/"));
+}
+
int main(int argc, char **argv) {
test_path();
test_find_binary(argv[0]);
@@ -250,5 +269,7 @@ int main(int argc, char **argv) {
test_fsck_exists();
test_make_relative();
test_strv_resolve();
+ test_path_startswith();
+
return 0;
}