[Bf-blender-cvs] [513dfa179f3] master: Tests: add BLI_path_parent_dir tests, split BLI_path_normalize tests
Campbell Barton
noreply at git.blender.org
Tue Nov 1 21:22:59 CET 2022
Commit: 513dfa179f3d7becf2e88da1084741e0c70a8da7
Author: Campbell Barton
Date: Tue Nov 1 21:30:02 2022 +1100
Branches: master
https://developer.blender.org/rB513dfa179f3d7becf2e88da1084741e0c70a8da7
Tests: add BLI_path_parent_dir tests, split BLI_path_normalize tests
Also enable a test that was disabled with a fix FIXME comment but works.
===================================================================
M source/blender/blenlib/tests/BLI_path_util_test.cc
===================================================================
diff --git a/source/blender/blenlib/tests/BLI_path_util_test.cc b/source/blender/blenlib/tests/BLI_path_util_test.cc
index 1241c71cf94..2f0e730129c 100644
--- a/source/blender/blenlib/tests/BLI_path_util_test.cc
+++ b/source/blender/blenlib/tests/BLI_path_util_test.cc
@@ -13,59 +13,64 @@
/* BLI_path_normalize */
#ifndef _WIN32
-TEST(path_util, Clean)
-{
- /* "/./" -> "/" */
- {
- char path[FILE_MAX] = "/a/./b/./c/./";
- BLI_path_normalize(nullptr, path);
- EXPECT_STREQ("/a/b/c/", path);
- }
- {
- char path[FILE_MAX] = "/./././";
- BLI_path_normalize(nullptr, path);
- EXPECT_STREQ("/", path);
- }
+# define NORMALIZE_WITH_BASEDIR(input, input_base, output) \
+ { \
+ char path[FILE_MAX] = input; \
+ BLI_path_normalize(input_base, path); \
+ EXPECT_STREQ(output, path); \
+ } \
+ ((void)0)
- {
- char path[FILE_MAX] = "/a/./././b/";
- BLI_path_normalize(nullptr, path);
- EXPECT_STREQ("/a/b/", path);
- }
+# define NORMALIZE(input, output) NORMALIZE_WITH_BASEDIR(input, nullptr, output)
- /* "//" -> "/" */
- {
- char path[FILE_MAX] = "a////";
- BLI_path_normalize(nullptr, path);
- EXPECT_STREQ("a/", path);
- }
+/* #BLI_path_normalize: "/./" -> "/" */
+TEST(path_util, Clean_Dot)
+{
+ NORMALIZE("/./", "/");
+ NORMALIZE("/a/./b/./c/./", "/a/b/c/");
+ NORMALIZE("/./././", "/");
+ NORMALIZE("/a/./././b/", "/a/b/");
+}
+/* #BLI_path_normalize: "//" -> "/" */
+TEST(path_util, Clean_DoubleSlash)
+{
+ NORMALIZE("//", "//"); /* Exception, double forward slash. */
+ NORMALIZE(".//", "./");
+ NORMALIZE("a////", "a/");
+ NORMALIZE("./a////", "./a/");
+}
+/* #BLI_path_normalize: "foo/bar/../" -> "foo/" */
+TEST(path_util, Clean_Parent)
+{
+ NORMALIZE("/a/b/c/../../../", "/");
+ NORMALIZE("/a/../a/b/../b/c/../c/", "/a/b/c/");
+ NORMALIZE_WITH_BASEDIR("//../", "/a/b/c/", "/a/b/");
+}
- if (false) /* FIXME */
- {
- char path[FILE_MAX] = "./a////";
- BLI_path_normalize(nullptr, path);
- EXPECT_STREQ("./a/", path);
- }
+# undef NORMALIZE_WITH_BASEDIR
+# undef NORMALIZE
- /* "foo/bar/../" -> "foo/" */
- {
- char path[FILE_MAX] = "/a/b/c/../../../";
- BLI_path_normalize(nullptr, path);
- EXPECT_STREQ("/", path);
- }
+#endif /* _WIN32 */
- {
- char path[FILE_MAX] = "/a/../a/b/../b/c/../c/";
- BLI_path_normalize(nullptr, path);
- EXPECT_STREQ("/a/b/c/", path);
- }
+/* #BLI_path_parent_dir */
+#ifndef _WIN32
+TEST(path_util, ParentDir)
+{
+# define PARENT_DIR(input, output) \
+ { \
+ char path[FILE_MAX] = input; \
+ BLI_path_parent_dir(path); \
+ EXPECT_STREQ(output, path); \
+ } \
+ ((void)0)
- {
- char path[FILE_MAX] = "//../";
- BLI_path_normalize("/a/b/c/", path);
- EXPECT_STREQ("/a/b/", path);
- }
+ PARENT_DIR("/a/b/", "/a/");
+ PARENT_DIR("/a/b", "/a/");
+ PARENT_DIR("/a", "/");
+ PARENT_DIR("/", "/");
+
+# undef PARENT_DIR
}
#endif
More information about the Bf-blender-cvs
mailing list