[Bf-blender-cvs] [7623d3e] master: Cycles: Add some utility tests using GTests

Sergey Sharybin noreply at git.blender.org
Sat Feb 6 19:47:56 CET 2016


Commit: 7623d3e071e6356ce4519073b1a29d984ba86cd9
Author: Sergey Sharybin
Date:   Sat Feb 6 19:09:44 2016 +0100
Branches: master
https://developer.blender.org/rB7623d3e071e6356ce4519073b1a29d984ba86cd9

Cycles: Add some utility tests using GTests

This is an initial move to have unittests to at least cover
utility functions, which then could be extended further to
test such areas as shader optimization and such.

Currently only based on initial "infrastructure" layout and
writing tests needed to test the no-boost patch.

Note: This patch starts to use "<dir>/<header>.h" notation
for the include statements which i just got used to do in
other projects. Something what would be cool to use globally
in the code eventually.

Reviewers: dingto, juicyfruit, lukasstockner97, brecht

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D1770

===================================================================

M	intern/cycles/CMakeLists.txt
A	intern/cycles/test/CMakeLists.txt
A	intern/cycles/test/util_aligned_malloc_test.cpp
A	intern/cycles/test/util_path_test.cpp
A	intern/cycles/test/util_string_test.cpp

===================================================================

diff --git a/intern/cycles/CMakeLists.txt b/intern/cycles/CMakeLists.txt
index bd75f4d..2a08945 100644
--- a/intern/cycles/CMakeLists.txt
+++ b/intern/cycles/CMakeLists.txt
@@ -225,6 +225,11 @@ add_subdirectory(render)
 add_subdirectory(subd)
 add_subdirectory(util)
 
+# TODO(sergey): Make this to work with standalone repository.
+if(WITH_GTESTS)
+	add_subdirectory(test)
+endif()
+
 if(NOT WITH_BLENDER AND WITH_CYCLES_STANDALONE)
 	delayed_do_install(${CMAKE_BINARY_DIR}/bin)
 endif()
diff --git a/intern/cycles/test/CMakeLists.txt b/intern/cycles/test/CMakeLists.txt
new file mode 100644
index 0000000..f8bd58c
--- /dev/null
+++ b/intern/cycles/test/CMakeLists.txt
@@ -0,0 +1,30 @@
+if(WITH_GTESTS)
+	Include(GTestTesting)
+
+	# Otherwise we get warnings here that we cant fix in external projects
+	remove_strict_flags()
+endif()
+
+macro(CYCLES_TEST SRC EXTRA_LIBS)
+	if(WITH_GTESTS)
+		BLENDER_SRC_GTEST("cycles_${SRC}" "${SRC}_test.cpp" "${EXTRA_LIBS}")
+	endif()
+endmacro()
+
+set(INC
+	.
+	..
+	../util
+)
+
+include_directories(${INC})
+
+link_directories(${BOOST_LIBPATH})
+link_directories(${OPENIMAGEIO_LIBPATH})
+
+set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}")
+set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}")
+
+CYCLES_TEST(util_aligned_malloc "cycles_util")
+CYCLES_TEST(util_path "cycles_util;${BOOST_LIBRARIES};${OPENIMAGEIO_LIBRARIES}")
+CYCLES_TEST(util_string "cycles_util;${BOOST_LIBRARIES}")
diff --git a/intern/cycles/test/util_aligned_malloc_test.cpp b/intern/cycles/test/util_aligned_malloc_test.cpp
new file mode 100644
index 0000000..479070f
--- /dev/null
+++ b/intern/cycles/test/util_aligned_malloc_test.cpp
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2011-2016 Blender Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "testing/testing.h"
+
+#include "util/util_aligned_malloc.h"
+
+#define CHECK_ALIGNMENT(ptr, align) EXPECT_EQ(0, (size_t)ptr % align)
+
+CCL_NAMESPACE_BEGIN
+
+TEST(util_aligned_malloc, aligned_malloc_16)
+{
+	int *mem = (int*)util_aligned_malloc(sizeof(int), 16);
+	CHECK_ALIGNMENT(mem, 16);
+	util_aligned_free(mem);
+}
+
+/* On Apple we currently only support 16 bytes alignment. */
+#ifndef __APPLE__
+TEST(util_aligned_malloc, aligned_malloc_32)
+{
+	int *mem = (int*)util_aligned_malloc(sizeof(int), 32);
+	CHECK_ALIGNMENT(mem, 32);
+	util_aligned_free(mem);
+}
+#endif  /* __APPLE__ */
+
+CCL_NAMESPACE_END
diff --git a/intern/cycles/test/util_path_test.cpp b/intern/cycles/test/util_path_test.cpp
new file mode 100644
index 0000000..92be1dd
--- /dev/null
+++ b/intern/cycles/test/util_path_test.cpp
@@ -0,0 +1,401 @@
+/*
+ * Copyright 2011-2016 Blender Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "testing/testing.h"
+
+#include "util/util_path.h"
+
+CCL_NAMESPACE_BEGIN
+
+/* ******** Tests for path_filename() ******** */
+
+#ifndef _WIN32
+TEST(util_path_filename, simple_unix)
+{
+	string str = path_filename("/tmp/foo.txt");
+	EXPECT_EQ("foo.txt", str);
+}
+
+TEST(util_path_filename, root_unix)
+{
+	string str = path_filename("/");
+	EXPECT_EQ("/", str);
+}
+
+TEST(util_path_filename, last_slash_unix)
+{
+	string str = path_filename("/tmp/foo.txt/");
+	EXPECT_EQ(".", str);
+}
+
+TEST(util_path_filename, alternate_slash_unix)
+{
+	string str = path_filename("/tmp\\foo.txt");
+	EXPECT_EQ("tmp\\foo.txt", str);
+}
+#endif  /* !_WIN32 */
+
+TEST(util_path_filename, file_only)
+{
+	string str = path_filename("foo.txt");
+	EXPECT_EQ("foo.txt", str);
+}
+
+TEST(util_path_filename, empty)
+{
+	string str = path_filename("");
+	EXPECT_EQ("", str);
+}
+
+#ifdef _WIN32
+TEST(util_path_filename, simple_windows)
+{
+	string str = path_filename("C:\\tmp\\foo.txt");
+	EXPECT_EQ("foo.txt", str);
+}
+
+TEST(util_path_filename, root_windows)
+{
+	string str = path_filename("C:\\");
+	EXPECT_EQ("\\", str);
+}
+
+TEST(util_path_filename, last_slash_windows)
+{
+	string str = path_filename("C:\\tmp\\foo.txt\\");
+	EXPECT_EQ(".", str);
+}
+
+TEST(util_path_filename, alternate_slash_windows)
+{
+	string str = path_filename("C:\\tmp/foo.txt");
+	EXPECT_EQ("foo.txt", str);
+}
+#endif  /* _WIN32 */
+
+/* ******** Tests for path_dirname() ******** */
+
+#ifndef _WIN32
+TEST(util_path_dirname, simple_unix)
+{
+	string str = path_dirname("/tmp/foo.txt");
+	EXPECT_EQ("/tmp", str);
+}
+
+TEST(util_path_dirname, root_unix)
+{
+	string str = path_dirname("/");
+	EXPECT_EQ("", str);
+}
+
+TEST(util_path_dirname, last_slash_unix)
+{
+	string str = path_dirname("/tmp/foo.txt/");
+	EXPECT_EQ("/tmp/foo.txt", str);
+}
+
+TEST(util_path_dirname, alternate_slash_unix)
+{
+	string str = path_dirname("/tmp\\foo.txt");
+	EXPECT_EQ("/", str);
+}
+#endif  /* !_WIN32 */
+
+TEST(util_path_dirname, file_only)
+{
+	string str = path_dirname("foo.txt");
+	EXPECT_EQ("", str);
+}
+
+TEST(util_path_dirname, empty)
+{
+	string str = path_dirname("");
+	EXPECT_EQ("", str);
+}
+
+#ifdef _WIN32
+TEST(util_path_dirname, simple_windows)
+{
+	string str = path_dirname("C:\\tmp\\foo.txt");
+	EXPECT_EQ("C:\\tmp", str);
+}
+
+TEST(util_path_dirname, root_windows)
+{
+	string str = path_dirname("C:\\");
+	EXPECT_EQ("C:", str);
+}
+
+TEST(util_path_dirname, last_slash_windows)
+{
+	string str = path_dirname("C:\\tmp\\foo.txt\\");
+	EXPECT_EQ("C:\\tmp\\foo.txt", str);
+}
+
+TEST(util_path_dirname, alternate_slash_windows)
+{
+	string str = path_dirname("C:\\tmp/foo.txt");
+	EXPECT_EQ("C:\\tmp", str);
+}
+#endif  /* _WIN32 */
+
+/* ******** Tests for path_join() ******** */
+
+TEST(util_path_join, empty_both)
+{
+	string str = path_join("", "");
+	EXPECT_EQ("", str);
+}
+
+TEST(util_path_join, empty_directory)
+{
+	string str = path_join("", "foo.txt");
+	EXPECT_EQ("foo.txt", str);
+}
+
+TEST(util_path_join, empty_filename)
+{
+	string str = path_join("foo", "");
+	EXPECT_EQ("foo", str);
+}
+
+#ifndef _WIN32
+TEST(util_path_join, simple_unix)
+{
+	string str = path_join("foo", "bar");
+	EXPECT_EQ("foo/bar", str);
+}
+
+TEST(util_path_join, directory_slash_unix)
+{
+	string str = path_join("foo/", "bar");
+	EXPECT_EQ("foo/bar", str);
+}
+
+TEST(util_path_join, filename_slash_unix)
+{
+	string str = path_join("foo", "/bar");
+	EXPECT_EQ("foo/bar", str);
+}
+
+TEST(util_path_join, both_slash_unix)
+{
+	string str = path_join("foo/", "/bar");
+	EXPECT_EQ("foo//bar", str);
+}
+
+TEST(util_path_join, directory_alternate_slash_unix)
+{
+	string str = path_join("foo\\", "bar");
+	EXPECT_EQ("foo\\/bar", str);
+}
+
+TEST(util_path_join, filename_alternate_slash_unix)
+{
+	string str = path_join("foo", "\\bar");
+	EXPECT_EQ("foo/\\bar", str);
+}
+
+TEST(util_path_join, both_alternate_slash_unix)
+{
+	string str = path_join("foo", "\\bar");
+	EXPECT_EQ("foo/\\bar", str);
+}
+
+TEST(util_path_join, empty_dir_filename_slash_unix)
+{
+	string str = path_join("", "/foo.txt");
+	EXPECT_EQ("/foo.txt", str);
+}
+
+TEST(util_path_join, empty_dir_filename_alternate_slash_unix)
+{
+	string str = path_join("", "\\foo.txt");
+	EXPECT_EQ("\\foo.txt", str);
+}
+
+TEST(util_path_join, empty_filename_dir_slash_unix)
+{
+	string str = path_join("foo/", "");
+	EXPECT_EQ("foo/", str);
+}
+
+TEST(util_path_join, empty_filename_dir_alternate_slash_unix)
+{
+	string str = path_join("foo\\", "");
+	EXPECT_EQ("foo\\", str);
+}
+#else  /* !_WIN32 */
+TEST(util_path_join, simple_windows)
+{
+	string str = path_join("foo", "bar");
+	EXPECT_EQ("foo\\bar", str);
+}
+
+TEST(util_path_join, directory_slash_windows)
+{
+	string str = path_join("foo\\", "bar");
+	EXPECT_EQ("foo\\bar", str);
+}
+
+TEST(util_path_join, filename_slash_windows)
+{
+	string str = path_join("foo", "\\bar");
+	EXPECT_EQ("foo\\bar", str);
+}
+
+TEST(util_path_join, both_slash_windows)
+{
+	string str = path_join("foo\\", "\\bar");
+	EXPECT_EQ("foo\\\\bar", str);
+}
+
+TEST(util_path_join, directory_alternate_slash_windows)
+{
+	string str = path_join("foo/", "bar");
+	EXPECT_EQ("foo/bar", str);
+}
+
+TEST(util_path_join, filename_alternate_slash_windows)
+{
+	string str = path_join("foo", "/bar");
+	EXPECT_EQ("foo/bar", str);
+}
+
+TEST(util_path_join, both_alternate_slash_windows)
+{
+	string str = path_join("foo/", "/bar");
+	EXPECT_EQ("foo//bar", str);
+}
+
+TEST(util_path_join, empty_dir_filename_slash_windows)
+{
+	string str = path_join("", "\\foo.txt");
+	EXPECT_EQ("\\foo.txt", str);
+}
+
+TEST(util_path_join, empty_dir_filename_alternate_slash_windows)
+{
+	string str = path_join("", "/foo.txt");
+	EXPECT_EQ("/foo.txt", str);
+}
+
+TEST(util_path_join, empty_filename_dir_slash_windows)
+{
+	string str = path_join("foo\\", "");
+	EXPECT_EQ("foo\\", str);
+}
+
+TEST(util_path_join, empty_filename_dir_alternate_slash_windows)
+{
+	string str = path_join("foo/", "");
+	EXPECT_EQ("foo/", str);
+}
+#endif  /* !_WIN32 */
+
+/* ******** Tests for path_escape() ******** */
+
+TEST(util_path_escape, no_escape_chars)
+{
+	string str = path_escape("/tmp/foo/bar");
+	EXPECT_EQ("/tmp/foo/bar", str);
+}
+
+TEST(util_path_escape, simple)
+{
+	string str = path_escape("/tmp/foo bar");
+	EXPECT_EQ("/tmp/foo\\ bar", str);
+}
+
+TEST(util_path_escape, simple_end)
+{
+	string str = path_escape("/tmp/foo/bar ");
+	EXPECT_EQ("/tmp/foo/bar\

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list