]> git.ipfire.org Git - pakfire.git/blobdiff - tests/libpakfire/path.c
path: Add function to compute relative paths
[pakfire.git] / tests / libpakfire / path.c
index ffc0d51d24a2042bf3c6a40da847ad281dfd46c9..c7214c46ff73c8050e870f4c3c2a1b71194ed90b 100644 (file)
@@ -118,12 +118,37 @@ FAIL:
        return EXIT_FAILURE;
 }
 
+static int test_path_relative(const struct test* t) {
+       char path[PATH_MAX];
+
+       ASSERT_SUCCESS(pakfire_path_relative(path, "/", "/usr/bin/bash"));
+       ASSERT_STRING_EQUALS(path, "usr/bin/bash");
+
+       ASSERT_SUCCESS(pakfire_path_relative(path, "/usr", "/usr/bin/bash"));
+       ASSERT_STRING_EQUALS(path, "bin/bash");
+
+       ASSERT_SUCCESS(pakfire_path_relative(path, "/usr/bin", "/usr/bin/bash"));
+       ASSERT_STRING_EQUALS(path, "bash");
+
+       ASSERT_SUCCESS(pakfire_path_relative(path, "/usr/sbin", "/usr/bin/bash"));
+       ASSERT_STRING_EQUALS(path, "../bin/bash");
+
+       ASSERT_SUCCESS(pakfire_path_relative(path, "/dev", "/usr/bin/bash"));
+       ASSERT_STRING_EQUALS(path, "../usr/bin/bash");
+
+       return EXIT_SUCCESS;
+
+FAIL:
+       return EXIT_FAILURE;
+}
+
 int main(int argc, const char* argv[]) {
        testsuite_add_test(test_path_normalize, 0);
        testsuite_add_test(test_path_append, 0);
        testsuite_add_test(test_path_merge, 0);
        testsuite_add_test(test_path_basename, 0);
        testsuite_add_test(test_path_dirname, 0);
+       testsuite_add_test(test_path_relative, 0);
 
        return testsuite_run(argc, argv);
 }