diff options
Diffstat (limited to 'src/test/test-path-util.c')
-rw-r--r-- | src/test/test-path-util.c | 140 |
1 files changed, 135 insertions, 5 deletions
diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c index 8c3a27f228..96a4fce630 100644 --- a/src/test/test-path-util.c +++ b/src/test/test-path-util.c @@ -26,10 +26,6 @@ TEST(path) { assert_se(path_is_absolute("/")); assert_se(!path_is_absolute("./")); - assert_se(is_path("/dir")); - assert_se(is_path("a/b")); - assert_se(!is_path(".")); - assert_se(streq(basename("./aa/bb/../file.da."), "file.da.")); assert_se(streq(basename("/aa///.file"), ".file")); assert_se(streq(basename("/aa///file..."), "file...")); @@ -48,6 +44,100 @@ TEST(path) { assert_se(!path_equal_ptr(NULL, "/a")); } +TEST(is_path) { + assert_se(!is_path("foo")); + assert_se(!is_path("dos.ext")); + assert_se( is_path("/dir")); + assert_se( is_path("a/b")); + assert_se( is_path("a/b.ext")); + + assert_se(!is_path(".")); + assert_se(!is_path("")); + assert_se(!is_path("..")); + + assert_se( is_path("/dev")); + assert_se( is_path("/./dev")); + assert_se( is_path("/./dev/.")); + assert_se( is_path("/./dev.")); + assert_se( is_path("//dev")); + assert_se( is_path("///dev")); + assert_se( is_path("/dev/")); + assert_se( is_path("///dev/")); + assert_se( is_path("/./dev/")); + assert_se( is_path("/../dev/")); + assert_se( is_path("/dev/sda")); + assert_se( is_path("/dev/sda5")); + assert_se( is_path("/dev/sda5b3")); + assert_se( is_path("/dev/sda5b3/idontexit")); + assert_se( is_path("/../dev/sda")); + assert_se( is_path("/../../dev/sda5")); + assert_se( is_path("/../../../dev/sda5b3")); + assert_se( is_path("/.././.././dev/sda5b3/idontexit")); + assert_se( is_path("/sys")); + assert_se( is_path("/sys/")); + assert_se( is_path("/./sys")); + assert_se( is_path("/./sys/.")); + assert_se( is_path("/./sys.")); + assert_se( is_path("/sys/what")); + assert_se( is_path("/sys/something/..")); + assert_se( is_path("/sys/something/../")); + assert_se( is_path("/sys////")); + assert_se( is_path("/sys////.")); + assert_se( is_path("/sys/..")); + assert_se( is_path("/sys/../")); + assert_se( is_path("/usr/../dev/sda")); +} + +TEST(is_device_path) { + assert_se(!is_device_path("foo")); + assert_se(!is_device_path("dos.ext")); + assert_se(!is_device_path("/dir")); + assert_se(!is_device_path("a/b")); + assert_se(!is_device_path("a/b.ext")); + + assert_se(!is_device_path(".")); + assert_se(!is_device_path("")); + assert_se(!is_device_path("..")); + + assert_se(!is_device_path("/dev")); + assert_se(!is_device_path("/./dev")); + assert_se(!is_device_path("/./dev/.")); + assert_se(!is_device_path("/./dev.")); + assert_se( is_device_path("/./dev/foo")); + assert_se( is_device_path("/./dev/./foo")); + assert_se(!is_device_path("/./dev./foo")); + assert_se(!is_device_path("//dev")); + assert_se(!is_device_path("///dev")); + assert_se(!is_device_path("/dev/")); + assert_se(!is_device_path("///dev/")); + assert_se(!is_device_path("/./dev/")); + assert_se(!is_device_path("/../dev/")); + assert_se( is_device_path("/dev/sda")); + assert_se( is_device_path("/dev/sda5")); + assert_se( is_device_path("/dev/sda5b3")); + assert_se( is_device_path("/dev/sda5b3/idontexit")); + assert_se(!is_device_path("/../dev/sda")); + assert_se(!is_device_path("/../../dev/sda5")); + assert_se(!is_device_path("/../../../dev/sda5b3")); + assert_se(!is_device_path("/.././.././dev/sda5b3/idontexit")); + assert_se(!is_device_path("/sys")); + assert_se(!is_device_path("/sys/")); + assert_se(!is_device_path("/./sys")); + assert_se(!is_device_path("/./sys/.")); + assert_se(!is_device_path("/./sys.")); + assert_se( is_device_path("/./sys/foo")); + assert_se( is_device_path("/./sys/./foo")); + assert_se(!is_device_path("/./sys./foo")); + assert_se( is_device_path("/sys/what")); + assert_se( is_device_path("/sys/something/..")); + assert_se( is_device_path("/sys/something/../")); + assert_se(!is_device_path("/sys////")); + assert_se(!is_device_path("/sys////.")); + assert_se( is_device_path("/sys/..")); + assert_se( is_device_path("/sys/../")); + assert_se(!is_device_path("/usr/../dev/sda")); +} + static void test_path_simplify_one(const char *in, const char *out, PathSimplifyFlags flags) { char *p; @@ -68,7 +158,7 @@ TEST(path_simplify) { 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("./", ".", 0); test_path_simplify_one("./", "./", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); @@ -84,6 +174,46 @@ TEST(path_simplify) { "../aaa/.bbb/../c./d.dd/..eeee/..", 0); test_path_simplify_one("abc///", "abc/", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/../abc", "/abc", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/../abc///", "/abc/", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/../abc///", "/abc", 0); + test_path_simplify_one("/../abc", "/abc", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/../abc///..", "/abc/..", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/../abc///../", "/abc/../", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/../abc///../", "/abc/..", 0); + + test_path_simplify_one("/../../abc", "/abc", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/../../abc///", "/abc/", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/../../abc///", "/abc", 0); + test_path_simplify_one("/../../abc", "/abc", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/../../abc///../..", "/abc/../..", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/../../abc///../../", "/abc/../../", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/../../abc///../../", "/abc/../..", 0); + + test_path_simplify_one("/.././../abc", "/abc", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/.././../abc///", "/abc/", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/.././../abc///", "/abc", 0); + test_path_simplify_one("/.././../abc", "/abc", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/.././../abc///../..", "/abc/../..", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/.././../abc///../../", "/abc/../../", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/.././../abc///../../", "/abc/../..", 0); + + test_path_simplify_one("/./.././../abc", "/abc", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/./.././../abc///", "/abc/", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/./.././../abc///", "/abc", 0); + test_path_simplify_one("/./.././../abc", "/abc", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/./.././../abc///../..", "/abc/../..", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/./.././../abc///../../", "/abc/../../", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/./.././../abc///../../", "/abc/../..", 0); + + test_path_simplify_one("/.../abc", "/.../abc", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/.../abc///", "/.../abc/", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/.../abc///", "/.../abc", 0); + test_path_simplify_one("/.../abc", "/.../abc", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/.../abc///...", "/.../abc/...", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/.../abc///.../", "/.../abc/.../", PATH_SIMPLIFY_KEEP_TRAILING_SLASH); + test_path_simplify_one("/.../abc///.../", "/.../abc/...", 0); + memset(foo, 'a', sizeof(foo) -1); char_array_0(foo); |