diff options
author | Ronny Chevalier <chevalier.ronny@gmail.com> | 2014-10-22 00:58:24 +0200 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-10-31 10:57:21 +0100 |
commit | 5895b62f1da8db93677d2bc369dff34fcaa97f91 (patch) | |
tree | 707b84a2b9c11d30ac1049b72356e8e180ddae66 | |
parent | d3774a1b15ea86f6156269e7ed813830f0c4abb8 (diff) |
tests: add tests for path_startswith
-rw-r--r-- | src/test/test-path-util.c | 21 |
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; } |