Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2014-06-18 16:49:17 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-06-18 20:09:16 +0400
commit306cbb82ecf0d7c1ba4fb0a1240175b1976bd25b (patch)
treee9eac65bf57126ac233f22fe88cc00df137ec4e5 /tests/gtests/blenlib/BLI_path_util_test.cc
parent47ec0394ca3d03e07c07a67e8f8d1625aedd39dd (diff)
GTest unit testing framework
Currently covers only small set of functionality.
Diffstat (limited to 'tests/gtests/blenlib/BLI_path_util_test.cc')
-rw-r--r--tests/gtests/blenlib/BLI_path_util_test.cc219
1 files changed, 219 insertions, 0 deletions
diff --git a/tests/gtests/blenlib/BLI_path_util_test.cc b/tests/gtests/blenlib/BLI_path_util_test.cc
new file mode 100644
index 00000000000..20ca3731b8f
--- /dev/null
+++ b/tests/gtests/blenlib/BLI_path_util_test.cc
@@ -0,0 +1,219 @@
+#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);
+#ifdef __linux__
+char *zLhm65070058860608_br_find_exe(const char *default_exe);
+#endif
+
+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) {}
+
+#ifdef __linux__
+char *zLhm65070058860608_br_find_exe(const char *default_exe)
+{
+ return NULL;
+}
+#endif
+
+}
+
+
+/* -------------------------------------------------------------------- */
+/* 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);
+ }
+}