summaryrefslogtreecommitdiffstats
path: root/test/paths.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/paths.c')
-rw-r--r--test/paths.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/test/paths.c b/test/paths.c
index aa610db437..13b3b26779 100644
--- a/test/paths.c
+++ b/test/paths.c
@@ -10,6 +10,7 @@ static void test_join(char *file, int line, char *a, char *b, char *c)
if (strcmp(res, c) != 0) {
printf("%s:%d: '%s' + '%s' = '%s', expected '%s'\n", file, line,
a, b, res, c);
+ fflush(stdout);
abort();
}
talloc_free(res);
@@ -20,16 +21,33 @@ static void test_abs(char *file, int line, bool abs, char *a)
if (mp_path_is_absolute(bstr0(a)) != abs) {
printf("%s:%d: mp_path_is_absolute('%s') => %d, expected %d\n",
file, line, a, !abs, abs);
+ fflush(stdout);
abort();
}
}
+static void test_normalize(char *file, int line, char *expected, char *path)
+{
+ void *ctx = talloc_new(NULL);
+ char *normalized = mp_normalize_path(ctx, path);
+ if (strcmp(normalized, expected)) {
+ printf("%s:%d: mp_normalize_path('%s') => %s, expected %s\n",
+ file, line, path, normalized, expected);
+ fflush(stdout);
+ abort();
+ }
+ talloc_free(ctx);
+}
+
#define TEST_JOIN(a, b, c) \
test_join(__FILE__, __LINE__, a, b, c);
#define TEST_ABS(abs, a) \
test_abs(__FILE__, __LINE__, abs, a)
+#define TEST_NORMALIZE(expected, path) \
+ test_normalize(__FILE__, __LINE__, expected, path)
+
int main(void)
{
TEST_ABS(true, "/ab");
@@ -61,5 +79,44 @@ int main(void)
TEST_JOIN("c:a", "b", "c:a/b");
TEST_JOIN("c:", "b", "c:b");
#endif
+
+ TEST_NORMALIZE("https://foo", "https://foo");
+#if !HAVE_DOS_PATHS
+ TEST_NORMALIZE("/foo", "/foo");
+#endif
+
+ void *ctx = talloc_new(NULL);
+ bstr dst = bstr0(mp_getcwd(ctx));
+ bstr_xappend(ctx, &dst, bstr0("/foo"));
+#if HAVE_DOS_PATHS
+ char *p = dst.start;
+ while (*p) {
+ *p = *p == '/' ? '\\' : *p;
+ p++;
+ }
+#endif
+ TEST_NORMALIZE(dst.start, "foo");
+ talloc_free(ctx);
+
+#if HAVE_DOS_PATHS
+ TEST_NORMALIZE("C:\\foo\\baz", "C:/foo/bar/../baz");
+ TEST_NORMALIZE("C:\\", "C:/foo/../..");
+ TEST_NORMALIZE("C:\\foo\\baz", "C:/foo/bar/./../baz");
+ TEST_NORMALIZE("C:\\foo\\bar\\baz", "C:/foo//bar/./baz");
+ TEST_NORMALIZE("C:\\foo\\bar\\baz", "C:/foo\\./bar\\/baz");
+ TEST_NORMALIZE("C:\\file.mkv", "\\\\?\\C:\\folder\\..\\file.mkv");
+ TEST_NORMALIZE("C:\\dir", "\\\\?\\C:\\dir\\subdir\\..\\.");
+ TEST_NORMALIZE("D:\\newfile.txt", "\\\\?\\D:\\\\new\\subdir\\..\\..\\newfile.txt");
+ TEST_NORMALIZE("\\\\server\\share\\path", "\\\\?\\UNC/server/share/path/.");
+ TEST_NORMALIZE("C:\\", "C:/.");
+ TEST_NORMALIZE("C:\\", "C:/../");
+#else
+ TEST_NORMALIZE("/foo/bar", "/foo//bar");
+ TEST_NORMALIZE("/foo/bar", "/foo///bar");
+ TEST_NORMALIZE("/foo/bar", "/foo/bar/");
+ TEST_NORMALIZE("/foo/bar", "/foo/./bar");
+ TEST_NORMALIZE("/usr", "/usr/bin/..");
+#endif
+
return 0;
}