summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-02-06 13:44:16 +0100
committerwm4 <wm4@nowhere>2020-02-06 13:50:41 +0100
commit1293c40623bc718b0b1a238a86d681e1f0ee5278 (patch)
tree45a2177000f673846a867bcc2427eae4d7ee44a9
parentcce7062a8a6b6a3b3666aea3ff86db879cba67b6 (diff)
downloadmpv-1293c40623bc718b0b1a238a86d681e1f0ee5278.tar.bz2
mpv-1293c40623bc718b0b1a238a86d681e1f0ee5278.tar.xz
test: add some path handling tests
Exhaustive tests would be nice, but I'm only adding a test for a function I'm going to change.
-rw-r--r--test/paths.c48
-rw-r--r--test/tests.c1
-rw-r--r--test/tests.h1
-rw-r--r--wscript_build.py1
4 files changed, 51 insertions, 0 deletions
diff --git a/test/paths.c b/test/paths.c
new file mode 100644
index 0000000000..5ec2eb8859
--- /dev/null
+++ b/test/paths.c
@@ -0,0 +1,48 @@
+#include "common/common.h"
+#include "config.h"
+#include "options/path.h"
+#include "tests.h"
+
+static void test_join(char *file, int line, char *a, char *b, char *c)
+{
+ char *res = mp_path_join(NULL, a, b);
+ if (strcmp(res, c) != 0) {
+ printf("%s:%d: '%s' + '%s' = '%s', expected '%s'\n", file, line,
+ a, b, res, c);
+ abort();
+ }
+ talloc_free(res);
+}
+
+#define TEST_JOIN(a, b, c) \
+ test_join(__FILE__, __LINE__, a, b, c);
+
+static void run(struct test_ctx *ctx)
+{
+ TEST_JOIN("", "", "");
+ TEST_JOIN("a", "", "a");
+ TEST_JOIN("/a", "", "/a");
+ TEST_JOIN("", "b", "b");
+ TEST_JOIN("", "/b", "/b");
+ TEST_JOIN("ab", "cd", "ab/cd");
+ TEST_JOIN("ab/", "cd", "ab/cd");
+ TEST_JOIN("ab/", "/cd", "/cd");
+ // Note: we prefer "/" on win32, but tolerate "\".
+#if HAVE_DOS_PATHS
+ TEST_JOIN("ab\\", "cd", "ab\\cd");
+ TEST_JOIN("ab\\", "\\cd", "\\cd");
+ TEST_JOIN("c:/", "de", "c:/de");
+ TEST_JOIN("c:/a", "de", "c:/a/de");
+ TEST_JOIN("c:\\a", "c:\\b", "c:\\b");
+ TEST_JOIN("c:/a", "c:/b", "c:/b");
+ // Note: drive-relative paths are not always supported "properly"
+ TEST_JOIN("c:/a", "d:b", "d:b");
+ TEST_JOIN("c:a", "b", "c:a/b");
+ TEST_JOIN("c:", "b", "c:b");
+#endif
+}
+
+const struct unittest test_paths = {
+ .name = "paths",
+ .run = run,
+};
diff --git a/test/tests.c b/test/tests.c
index c13f75c06c..9ef88f4a8d 100644
--- a/test/tests.c
+++ b/test/tests.c
@@ -9,6 +9,7 @@ static const struct unittest *unittests[] = {
&test_img_format,
&test_json,
&test_linked_list,
+ &test_paths,
&test_repack_sws,
#if HAVE_ZIMG
&test_repack_zimg,
diff --git a/test/tests.h b/test/tests.h
index 14e6f6ea63..f4065f596f 100644
--- a/test/tests.h
+++ b/test/tests.h
@@ -43,6 +43,7 @@ extern const struct unittest test_json;
extern const struct unittest test_linked_list;
extern const struct unittest test_repack_sws;
extern const struct unittest test_repack_zimg;
+extern const struct unittest test_paths;
#define assert_true(x) assert(x)
#define assert_false(x) assert(!(x))
diff --git a/wscript_build.py b/wscript_build.py
index bbce31dfea..488a81f57f 100644
--- a/wscript_build.py
+++ b/wscript_build.py
@@ -403,6 +403,7 @@ def build(ctx):
( "test/img_format.c", "tests" ),
( "test/json.c", "tests" ),
( "test/linked_list.c", "tests" ),
+ ( "test/paths.c", "tests" ),
( "test/scale_sws.c", "tests" ),
( "test/scale_test.c", "tests" ),
( "test/scale_zimg.c", "tests && zimg" ),