[Bf-blender-cvs] [fb83716] gtest-testing: Add initial tests for path_utils
Campbell Barton
noreply at git.blender.org
Sun May 18 10:46:57 CEST 2014
Commit: fb8371680f53b0c0c57eac551bf6784d2e87e618
Author: Campbell Barton
Date: Sun May 18 18:46:06 2014 +1000
https://developer.blender.org/rBfb8371680f53b0c0c57eac551bf6784d2e87e618
Add initial tests for path_utils
===================================================================
M source/tests/blenlib_tests/CMakeLists.txt
A source/tests/blenlib_tests/path_util_test.cc
===================================================================
diff --git a/source/tests/blenlib_tests/CMakeLists.txt b/source/tests/blenlib_tests/CMakeLists.txt
index 49cba0a..1db767e 100644
--- a/source/tests/blenlib_tests/CMakeLists.txt
+++ b/source/tests/blenlib_tests/CMakeLists.txt
@@ -31,3 +31,4 @@ include_directories(${INC})
BLENDER_TEST(mathutils_color "bf_blenlib")
BLENDER_TEST(mathutils_geom "bf_blenlib")
+BLENDER_TEST(path_util "bf_blenlib;extern_wcwidth;extern_binreloc;${ZLIB_LIBRARIES}")
diff --git a/source/tests/blenlib_tests/path_util_test.cc b/source/tests/blenlib_tests/path_util_test.cc
new file mode 100644
index 0000000..4c1100a
--- /dev/null
+++ b/source/tests/blenlib_tests/path_util_test.cc
@@ -0,0 +1,209 @@
+#include "testing/testing.h"
+
+extern "C" {
+#include "BLI_fileops.h"
+#include "BLI_path_util.h"
+#include "../../../source/blender/imbuf/IMB_imbuf.h"
+}
+
+/* -------------------------------------------------------------------- */
+/* stubs */
+
+extern "C" {
+
+const char *GHOST_getUserDir(int version, const char *versionstr);
+const char *GHOST_getSystemDir(int version, const char *versionstr);
+
+const char *GHOST_getUserDir(int version, const char *versionstr)
+{
+ return "/home/user";
+}
+
+const char *GHOST_getSystemDir(int version, const char *versionstr)
+{
+ return "/system/path";
+}
+
+struct ImBuf;
+void IMB_freeImBuf(struct ImBuf *ibuf) {}
+
+}
+
+
+/* -------------------------------------------------------------------- */
+/* tests */
+
+/* BLI_cleanup_path */
+TEST(pathutils, PathUtilClean)
+{
+ /* "/./" -> "/" */
+ {
+ char path[FILE_MAX] = "/a/./b/./c/./";
+ BLI_cleanup_path(NULL, path);
+ EXPECT_STREQ("/a/b/c/", path);
+ }
+
+ {
+ char path[FILE_MAX] = "/./././";
+ BLI_cleanup_path(NULL, path);
+ EXPECT_STREQ("/", path);
+ }
+
+ {
+ char path[FILE_MAX] = "/a/./././b/";
+ BLI_cleanup_path(NULL, path);
+ EXPECT_STREQ("/a/b/", path);
+ }
+
+ /* "//" -> "/" */
+ {
+ char path[FILE_MAX] = "a////";
+ BLI_cleanup_path(NULL, path);
+ EXPECT_STREQ("a/", path);
+ }
+
+ if (0) /* FIXME */
+ {
+ char path[FILE_MAX] = "./a////";
+ BLI_cleanup_path(NULL, path);
+ EXPECT_STREQ("./a/", path);
+ }
+
+ /* "foo/bar/../" -> "foo/" */
+ {
+ char path[FILE_MAX] = "/a/b/c/../../../";
+ BLI_cleanup_path(NULL, path);
+ EXPECT_STREQ("/", path);
+ }
+
+ {
+ char path[FILE_MAX] = "/a/../a/b/../b/c/../c/";
+ BLI_cleanup_path(NULL, path);
+ EXPECT_STREQ("/a/b/c/", path);
+ }
+
+ {
+ char path[FILE_MAX] = "//../";
+ BLI_cleanup_path("/a/b/c/", path);
+ EXPECT_STREQ("/a/b/", path);
+ }
+}
+
+/* BLI_path_frame */
+TEST(pathutils, PathUtilFrame)
+{
+ bool ret;
+
+ {
+ char path[FILE_MAX] = "";
+ ret = BLI_path_frame(path, 123, 1);
+ EXPECT_EQ(1, ret);
+ EXPECT_STREQ("123", path);
+ }
+
+ {
+ char path[FILE_MAX] = "";
+ ret = BLI_path_frame(path, 123, 12);
+ EXPECT_EQ(1, ret);
+ EXPECT_STREQ("000000000123", path);
+ }
+
+ {
+ char path[FILE_MAX] = "test_";
+ ret = BLI_path_frame(path, 123, 1);
+ EXPECT_EQ(1, ret);
+ EXPECT_STREQ("test_123", path);
+ }
+
+ {
+ char path[FILE_MAX] = "test_";
+ ret = BLI_path_frame(path, 1, 12);
+ EXPECT_EQ(1, ret);
+ EXPECT_STREQ("test_000000000001", path);
+ }
+
+ {
+ char path[FILE_MAX] = "test_############";
+ ret = BLI_path_frame(path, 1, 0);
+ EXPECT_EQ(1, ret);
+ EXPECT_STREQ("test_000000000001", path);
+ }
+
+ {
+ char path[FILE_MAX] = "test_#_#_middle";
+ ret = BLI_path_frame(path, 123, 0);
+ EXPECT_EQ(1, ret);
+ EXPECT_STREQ("test_#_123_middle", path);
+ }
+
+ /* intentionally fail */
+ {
+ char path[FILE_MAX] = "";
+ ret = BLI_path_frame(path, 123, 0);
+ EXPECT_EQ(0, ret);
+ EXPECT_STREQ("", path);
+ }
+
+ {
+ char path[FILE_MAX] = "test_middle";
+ ret = BLI_path_frame(path, 123, 0);
+ EXPECT_EQ(0, ret);
+ EXPECT_STREQ("test_middle", path);
+ }
+}
+
+/* BLI_split_dirfile */
+TEST(pathutils, PathUtilSplitDirfile)
+{
+ {
+ const char *path = "";
+ char dir[FILE_MAX], file[FILE_MAX];
+ BLI_split_dirfile(path, dir, file, sizeof(dir), sizeof(file));
+ EXPECT_STREQ("", dir);
+ EXPECT_STREQ("", file);
+ }
+
+ {
+ const char *path = "/";
+ char dir[FILE_MAX], file[FILE_MAX];
+ BLI_split_dirfile(path, dir, file, sizeof(dir), sizeof(file));
+ EXPECT_STREQ("/", dir);
+ EXPECT_STREQ("", file);
+ }
+
+ {
+ const char *path = "fileonly";
+ char dir[FILE_MAX], file[FILE_MAX];
+ BLI_split_dirfile(path, dir, file, sizeof(dir), sizeof(file));
+ EXPECT_STREQ("", dir);
+ EXPECT_STREQ("fileonly", file);
+ }
+
+ {
+ const char *path = "dironly/";
+ char dir[FILE_MAX], file[FILE_MAX];
+ BLI_split_dirfile(path, dir, file, sizeof(dir), sizeof(file));
+ EXPECT_STREQ("dironly/", dir);
+ EXPECT_STREQ("", file);
+ }
+
+ {
+ const char *path = "/a/b";
+ char dir[FILE_MAX], file[FILE_MAX];
+ BLI_split_dirfile(path, dir, file, sizeof(dir), sizeof(file));
+ EXPECT_STREQ("/a/", dir);
+ EXPECT_STREQ("b", file);
+ }
+
+ {
+ const char *path = "/dirtoobig/filetoobig";
+ char dir[5], file[5];
+ BLI_split_dirfile(path, dir, file, sizeof(dir), sizeof(file));
+ EXPECT_STREQ("/dir", dir);
+ EXPECT_STREQ("file", file);
+
+ BLI_split_dirfile(path, dir, file, 1, 1);
+ EXPECT_STREQ("", dir);
+ EXPECT_STREQ("", file);
+ }
+}
More information about the Bf-blender-cvs
mailing list