chiark / gitweb /
tests: add tests for path_startswith
authorRonny Chevalier <chevalier.ronny@gmail.com>
Tue, 21 Oct 2014 22:58:24 +0000 (00:58 +0200)
committerTom Gundersen <teg@jklm.no>
Fri, 31 Oct 2014 09:57:21 +0000 (10:57 +0100)
src/test/test-path-util.c

index 63d64b28b0d390c04915bb663ce075d44ef52920..82090ce99f51d4d9b7c45e2d388938c492783c8b 100644 (file)
@@ -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;
 }