diff options
author | Campbell Barton <campbell@blender.org> | 2022-11-01 13:30:02 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-11-01 23:21:10 +0300 |
commit | 513dfa179f3d7becf2e88da1084741e0c70a8da7 (patch) | |
tree | 29223992c2b577b7bfe18dce1f740b85a9761b4b | |
parent | f8699881d6bf1c02586d356b1c816e77e144ad32 (diff) |
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.
-rw-r--r-- | source/blender/blenlib/tests/BLI_path_util_test.cc | 97 |
1 files changed, 51 insertions, 46 deletions
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 |