[Bf-blender-cvs] [3993eca] gtest-testing: Integrate gtest into blender and use it for unit tests

Sergey Sharybin noreply at git.blender.org
Fri May 16 13:47:37 CEST 2014


Commit: 3993eca823dbc5a152ec0bc895349f6ee9f57775
Author: Sergey Sharybin
Date:   Wed Apr 23 17:47:32 2014 +0600
https://developer.blender.org/rB3993eca823dbc5a152ec0bc895349f6ee9f57775

Integrate gtest into blender and use it for unit tests

Basically title says it all, now we're using gtest to perform
unit tests of different code parts of blender.

Currently only covered really tiny small subset of mathutils,
more coverage would be done later.

Reviewers: campbellbarton

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

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

M	CMakeLists.txt
A	build_files/cmake/Modules/Testing.cmake
M	extern/CMakeLists.txt
A	extern/gtest/CMakeLists.txt
A	extern/gtest/LICENSE
A	extern/gtest/README
A	extern/gtest/include/gtest/gtest-death-test.h
A	extern/gtest/include/gtest/gtest-message.h
A	extern/gtest/include/gtest/gtest-param-test.h
A	extern/gtest/include/gtest/gtest-printers.h
A	extern/gtest/include/gtest/gtest-spi.h
A	extern/gtest/include/gtest/gtest-test-part.h
A	extern/gtest/include/gtest/gtest-typed-test.h
A	extern/gtest/include/gtest/gtest.h
A	extern/gtest/include/gtest/gtest_pred_impl.h
A	extern/gtest/include/gtest/gtest_prod.h
A	extern/gtest/include/gtest/internal/gtest-death-test-internal.h
A	extern/gtest/include/gtest/internal/gtest-filepath.h
A	extern/gtest/include/gtest/internal/gtest-internal.h
A	extern/gtest/include/gtest/internal/gtest-linked_ptr.h
A	extern/gtest/include/gtest/internal/gtest-param-util-generated.h
A	extern/gtest/include/gtest/internal/gtest-param-util.h
A	extern/gtest/include/gtest/internal/gtest-port.h
A	extern/gtest/include/gtest/internal/gtest-string.h
A	extern/gtest/include/gtest/internal/gtest-tuple.h
A	extern/gtest/include/gtest/internal/gtest-type-util.h
A	extern/gtest/src/gtest-all.cc
A	extern/gtest/src/gtest-death-test.cc
A	extern/gtest/src/gtest-filepath.cc
A	extern/gtest/src/gtest-internal-inl.h
A	extern/gtest/src/gtest-port.cc
A	extern/gtest/src/gtest-printers.cc
A	extern/gtest/src/gtest-test-part.cc
A	extern/gtest/src/gtest-typed-test.cc
A	extern/gtest/src/gtest.cc
A	extern/gtest/src/gtest_main.cc
M	extern/libmv/CMakeLists.txt
M	extern/libmv/bundle.sh
M	source/blenderplayer/CMakeLists.txt
M	source/creator/CMakeLists.txt
M	source/tests/CMakeLists.txt
A	source/tests/blenlib_tests/CMakeLists.txt
A	source/tests/blenlib_tests/mathutils_test.cc
A	source/tests/testing/CMakeLists.txt
A	source/tests/testing/testing.h
A	source/tests/testing/testing_main.cc

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

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2962b58..5c8257c7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -104,6 +104,7 @@ enable_testing()
 
 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE INTERNAL "" FORCE)
 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "" FORCE)
+set(TESTS_OUTPUT_DIR ${EXECUTABLE_OUTPUT_PATH}/tests CACHE INTERNAL "" FORCE)
 
 #-----------------------------------------------------------------------------
 # Set default config options
@@ -295,6 +296,9 @@ if(CMAKE_COMPILER_IS_GNUCC)
 	mark_as_advanced(WITH_GCC_MUDFLAP)
 endif()
 
+# Unit testsing
+OPTION(WITH_TESTS "Enable unit tests" OFF)
+
 if(APPLE)
 	cmake_minimum_required(VERSION 2.8.8)
 	cmake_policy(VERSION 2.8.8)
diff --git a/build_files/cmake/Modules/Testing.cmake b/build_files/cmake/Modules/Testing.cmake
new file mode 100644
index 0000000..a28af7e
--- /dev/null
+++ b/build_files/cmake/Modules/Testing.cmake
@@ -0,0 +1,42 @@
+#=============================================================================
+# Copyright 2014 Blender Foundation.
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#
+# Inspired on the Testing.cmake from Libmv
+#
+#=============================================================================
+
+macro(BLENDER_TEST NAME EXTRA_LIBS)
+	if(WITH_TESTS)
+		get_property(_current_include_directories
+		             DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+		             PROPERTY INCLUDE_DIRECTORIES)
+		set(INC
+			${_current_include_directories}
+			${CMAKE_SOURCE_DIR}/extern/libmv/third_party/glog/src
+			${CMAKE_SOURCE_DIR}/extern/libmv/third_party/gflags
+			${CMAKE_SOURCE_DIR}/extern/gtest/include
+		)
+		unset(_current_include_directories)
+
+		add_executable(${NAME}_test ${NAME}_test.cc)
+		target_link_libraries(${NAME}_test
+		                      ${EXTRA_LIBS}
+		                      bf_testing_main
+		                      bf_intern_guardedalloc
+		                      extern_gtest
+		                      extern_glog)
+		set_target_properties(${NAME}_test PROPERTIES
+		                      RUNTIME_OUTPUT_DIRECTORY         "${TESTS_OUTPUT_DIR}"
+		                      RUNTIME_OUTPUT_DIRECTORY_RELEASE "${TESTS_OUTPUT_DIR}"
+		                      RUNTIME_OUTPUT_DIRECTORY_DEBUG   "${TESTS_OUTPUT_DIR}"
+		                      INCLUDE_DIRECTORIES              "${INC}")
+		add_test(${NAME}_test ${TESTS_OUTPUT_DIR}/${NAME}_test)
+	endif()
+endmacro()
diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt
index f6de873..999ffda 100644
--- a/extern/CMakeLists.txt
+++ b/extern/CMakeLists.txt
@@ -79,3 +79,7 @@ if(WITH_GHOST_XDND)
 		add_subdirectory(xdnd)
 	endif()
 endif()
+
+if(WITH_TESTS)
+	add_subdirectory(gtest)
+endif()
diff --git a/extern/gtest/CMakeLists.txt b/extern/gtest/CMakeLists.txt
new file mode 100644
index 0000000..b5e4002
--- /dev/null
+++ b/extern/gtest/CMakeLists.txt
@@ -0,0 +1,64 @@
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# The Original Code is Copyright (C) 2014, Blender Foundation
+# All rights reserved.
+#
+# Contributor(s): Sergey Sharybin
+#
+# ***** END GPL LICENSE BLOCK *****
+
+set(INC
+	.
+	include
+)
+
+set(INC_SYS
+
+)
+
+set(SRC
+	src/gtest.cc
+	src/gtest-death-test.cc
+	src/gtest-filepath.cc
+	src/gtest-port.cc
+	src/gtest-printers.cc
+	src/gtest-test-part.cc
+	src/gtest-typed-test.cc
+
+	include/gtest/gtest-death-test.h
+	include/gtest/gtest.h
+	include/gtest/gtest-message.h
+	include/gtest/gtest-param-test.h
+	include/gtest/gtest_pred_impl.h
+	include/gtest/gtest-printers.h
+	include/gtest/gtest_prod.h
+	include/gtest/gtest-spi.h
+	include/gtest/gtest-test-part.h
+	include/gtest/gtest-typed-test.h
+	include/gtest/internal/gtest-death-test-internal.h
+	include/gtest/internal/gtest-filepath.h
+	include/gtest/internal/gtest-internal.h
+	include/gtest/internal/gtest-linked_ptr.h
+	include/gtest/internal/gtest-param-util-generated.h
+	include/gtest/internal/gtest-param-util.h
+	include/gtest/internal/gtest-port.h
+	include/gtest/internal/gtest-string.h
+	include/gtest/internal/gtest-tuple.h
+	include/gtest/internal/gtest-type-util.h
+)
+
+blender_add_lib(extern_gtest "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/extern/gtest/LICENSE b/extern/gtest/LICENSE
new file mode 100644
index 0000000..1941a11
--- /dev/null
+++ b/extern/gtest/LICENSE
@@ -0,0 +1,28 @@
+Copyright 2008, Google Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+    * Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above
+copyright notice, this list of conditions and the following disclaimer
+in the documentation and/or other materials provided with the
+distribution.
+    * Neither the name of Google Inc. nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/extern/gtest/README b/extern/gtest/README
new file mode 100644
index 0000000..27e4eff
--- /dev/null
+++ b/extern/gtest/README
@@ -0,0 +1,7 @@
+Project: Google C++ Testing Framework
+URL: http://code.google.com/p/googletest
+License: New BSD
+Upstream version: 1.7.0
+Local modifications:
+
+None.
diff --git a/extern/gtest/include/gtest/gtest-death-test.h b/extern/gtest/include/gtest/gtest-death-test.h
new file mode 100644
index 0000000..957a69c
--- /dev/null
+++ b/extern/gtest/include/gtest/gtest-death-test.h
@@ -0,0 +1,294 @@
+// Copyright 2005, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//     * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+//     * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Author: wan at google.com (Zhanyong Wan)
+//
+// The Google C++ Testing Framework (Google Test)
+//
+// This header file defines the public API for death tests.  It is
+// #included by gtest.h so a user doesn't need to include this
+// directly.
+
+#ifndef GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
+#define GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
+
+#include "gtest/internal/gtest-death-test-internal.h"
+
+namespace testing {
+
+// This flag controls the style of death tests.  Valid values are "threadsafe",
+// meaning that the death test child process will re-execute the test binary
+// from the start, running only a single death test, or "fast",
+// meaning that the child process will execute the test logic immediately
+// after forking.
+GTEST_DECLARE_string_(death_test_style);
+
+#if GTEST_HAS_DEATH_TEST
+
+namespace internal {
+
+// Returns a Boolean value indicating whether the caller is currently
+// executing in the context of the death test child process.  Tools such as
+// Valgrind heap checkers may need this to modify their behavior in death
+// tests.  IMPORTANT: This is an internal utility.  Using it may break the
+// implementation of death tests.  User code MUST NOT use it.
+GTEST_API_ bool InDeathTestChild();
+
+}  // namespace internal
+
+// The following macros are useful for w

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list