[Bf-blender-cvs] [306cbb8] master: GTest unit testing framework

Sergey Sharybin noreply at git.blender.org
Wed Jun 18 18:10:17 CEST 2014


Commit: 306cbb82ecf0d7c1ba4fb0a1240175b1976bd25b
Author: Sergey Sharybin
Date:   Wed Jun 18 22:49:17 2014 +1000
https://developer.blender.org/rB306cbb82ecf0d7c1ba4fb0a1240175b1976bd25b

GTest unit testing framework

Currently covers only small set of functionality.

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

M	CMakeLists.txt
A	build_files/cmake/Modules/GTestTesting.cmake
M	build_files/cmake/macros.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/SConscript
M	extern/libmv/bundle.sh
M	extern/libmv/files.txt
A	extern/libmv/libmv/base/scoped_ptr_test.cc
A	extern/libmv/libmv/base/vector_test.cc
A	extern/libmv/libmv/image/array_nd_test.cc
A	extern/libmv/libmv/image/convolve_test.cc
A	extern/libmv/libmv/image/image_drawing.h
A	extern/libmv/libmv/image/image_test.cc
A	extern/libmv/libmv/image/sample_test.cc
A	extern/libmv/libmv/image/tuple_test.cc
A	extern/libmv/libmv/multiview/euclidean_resection_test.cc
A	extern/libmv/libmv/multiview/fundamental_test.cc
A	extern/libmv/libmv/multiview/homography_error.h
A	extern/libmv/libmv/multiview/homography_test.cc
A	extern/libmv/libmv/multiview/nviewtriangulation_test.cc
A	extern/libmv/libmv/multiview/panography_kernel.cc
A	extern/libmv/libmv/multiview/panography_kernel.h
A	extern/libmv/libmv/multiview/panography_test.cc
A	extern/libmv/libmv/multiview/projection_test.cc
A	extern/libmv/libmv/multiview/resection_test.cc
A	extern/libmv/libmv/multiview/test_data_sets.cc
A	extern/libmv/libmv/multiview/test_data_sets.h
A	extern/libmv/libmv/multiview/triangulation_test.cc
A	extern/libmv/libmv/multiview/two_view_kernel.h
A	extern/libmv/libmv/numeric/dogleg_test.cc
A	extern/libmv/libmv/numeric/function_derivative_test.cc
A	extern/libmv/libmv/numeric/levenberg_marquardt_test.cc
A	extern/libmv/libmv/numeric/numeric_test.cc
A	extern/libmv/libmv/numeric/poly_test.cc
A	extern/libmv/libmv/simple_pipeline/camera_intrinsics_test.cc
A	extern/libmv/libmv/simple_pipeline/detect_test.cc
A	extern/libmv/libmv/simple_pipeline/intersect_test.cc
A	extern/libmv/libmv/simple_pipeline/keyframe_selection_test.cc
A	extern/libmv/libmv/simple_pipeline/modal_solver_test.cc
A	extern/libmv/libmv/simple_pipeline/resect_test.cc
A	extern/libmv/libmv/tracking/brute_region_tracker_test.cc
A	extern/libmv/libmv/tracking/klt_region_tracker_test.cc
A	extern/libmv/libmv/tracking/pyramid_region_tracker_test.cc
M	source/blenderplayer/CMakeLists.txt
M	source/creator/CMakeLists.txt
M	tests/CMakeLists.txt
A	tests/gtests/CMakeLists.txt
A	tests/gtests/blenlib/BLI_math_color_test.cc
A	tests/gtests/blenlib/BLI_math_geom_test.cc
A	tests/gtests/blenlib/BLI_path_util_test.cc
A	tests/gtests/blenlib/CMakeLists.txt
A	tests/gtests/testing/CMakeLists.txt
A	tests/gtests/testing/testing.h
A	tests/gtests/testing/testing_main.cc

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

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5593820..7e21f97 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -109,6 +109,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
@@ -300,6 +301,9 @@ if(CMAKE_COMPILER_IS_GNUCC)
 	mark_as_advanced(WITH_GCC_MUDFLAP)
 endif()
 
+# Unit testsing
+option(WITH_GTESTS "Enable GTest unit testing" OFF)
+
 if(APPLE)
 	cmake_minimum_required(VERSION 2.8.8)
 	cmake_policy(VERSION 2.8.8)
@@ -2330,10 +2334,17 @@ endif()
 #-----------------------------------------------------------------------------
 # Libraries
 
+if(WITH_TESTS)
+	include(GTestTesting)
+endif()
+
 if(WITH_BLENDER OR WITH_PLAYER)
-	add_subdirectory(source)
 	add_subdirectory(intern)
 	add_subdirectory(extern)
+
+	# source after intern and extern to gather all
+	# internal and external library information first, for test linking
+	add_subdirectory(source)
 elseif(WITH_CYCLES_STANDALONE)
 	add_subdirectory(intern/cycles)
 	if(NOT WITH_SYSTEM_GLEW)
diff --git a/build_files/cmake/Modules/GTestTesting.cmake b/build_files/cmake/Modules/GTestTesting.cmake
new file mode 100644
index 0000000..c039a1e
--- /dev/null
+++ b/build_files/cmake/Modules/GTestTesting.cmake
@@ -0,0 +1,47 @@
+#=============================================================================
+# 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_SRC_GTEST NAME SRC EXTRA_LIBS)
+	if(WITH_TESTS)
+		get_property(_current_include_directories
+		             DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+		             PROPERTY INCLUDE_DIRECTORIES)
+		set(TEST_INC
+			${_current_include_directories}
+			${CMAKE_SOURCE_DIR}/tests/gtests
+			${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 ${SRC})
+		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              "${TEST_INC}")
+		add_test(${NAME}_test ${TESTS_OUTPUT_DIR}/${NAME}_test)
+	endif()
+endmacro()
+
+macro(BLENDER_TEST NAME EXTRA_LIBS)
+	BLENDER_SRC_GTEST("${NAME}" "${NAME}_test.cc" "${EXTRA_LIBS}")
+endmacro()
diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index bdd3883..f8720f0 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -413,6 +413,240 @@ macro(setup_liblinks
 	target_link_libraries(${target} ${PLATFORM_LINKLIBS} ${CMAKE_DL_LIBS})
 endmacro()
 
+macro(SETUP_BLENDER_SORTED_LIBS)
+	get_property(BLENDER_LINK_LIBS GLOBAL PROPERTY BLENDER_LINK_LIBS)
+
+	list(APPEND BLENDER_LINK_LIBS
+		bf_windowmanager
+		bf_render
+	)
+
+	if(WITH_MOD_FLUID)
+		list(APPEND BLENDER_LINK_LIBS bf_intern_elbeem)
+	endif()
+
+	if(WITH_CYCLES)
+		list(APPEND BLENDER_LINK_LIBS
+			cycles_render
+			cycles_bvh
+			cycles_device
+			cycles_kernel
+			cycles_util
+			cycles_subd)
+		if(WITH_CYCLES_OSL)
+			list(APPEND BLENDER_LINK_LIBS cycles_kernel_osl)
+		endif()
+	endif()
+
+	# Sort libraries
+	set(BLENDER_SORTED_LIBS
+		bf_windowmanager
+
+		bf_editor_space_api
+		bf_editor_space_action
+		bf_editor_space_buttons
+		bf_editor_space_console
+		bf_editor_space_file
+		bf_editor_space_graph
+		bf_editor_space_image
+		bf_editor_space_info
+		bf_editor_space_logic
+		bf_editor_space_nla
+		bf_editor_space_node
+		bf_editor_space_outliner
+		bf_editor_space_script
+		bf_editor_space_sequencer
+		bf_editor_space_text
+		bf_editor_space_time
+		bf_editor_space_userpref
+		bf_editor_space_view3d
+		bf_editor_space_clip
+
+		bf_editor_transform
+		bf_editor_util
+		bf_editor_uvedit
+		bf_editor_curve
+		bf_editor_gpencil
+		bf_editor_interface
+		bf_editor_mesh
+		bf_editor_metaball
+		bf_editor_object
+		bf_editor_armature
+		bf_editor_physics
+		bf_editor_render
+		bf_editor_screen
+		bf_editor_sculpt_paint
+		bf_editor_sound
+		bf_editor_animation
+		bf_editor_datafiles
+		bf_editor_mask
+		bf_editor_io
+
+		bf_render
+		bf_python
+		bf_python_ext
+		bf_python_mathutils
+		bf_python_bmesh
+		bf_freestyle
+		bf_ikplugin
+		bf_modifiers
+		bf_bmesh
+		bf_blenkernel
+		bf_nodes
+		bf_gpu
+		bf_blenloader
+		bf_imbuf
+		bf_blenlib
+		bf_intern_ghost
+		bf_intern_string
+		bf_avi
+		bf_imbuf_cineon
+		bf_imbuf_openexr
+		bf_imbuf_openimageio
+		bf_imbuf_dds
+		bf_collada
+		bf_intern_elbeem
+		bf_intern_memutil
+		bf_intern_guardedalloc
+		bf_intern_ctr
+		bf_intern_utfconv
+		ge_blen_routines
+		ge_converter
+		ge_phys_dummy
+		ge_phys_bullet
+		bf_intern_smoke
+		extern_minilzo
+		extern_lzma
+		extern_colamd
+		ge_logic_ketsji
+		extern_recastnavigation
+		ge_logic
+		ge_rasterizer
+		ge_oglrasterizer
+		ge_logic_expressions
+		ge_scenegraph
+		ge_logic_network
+		ge_logic_ngnetwork
+		ge_logic_loopbacknetwork
+		bf_intern_moto
+		extern_openjpeg
+		extern_redcode
+		ge_videotex
+		bf_rna
+		bf_dna
+		bf_blenfont
+		bf_intern_audaspace
+		bf_intern_mikktspace
+		bf_intern_dualcon
+		bf_intern_cycles
+		cycles_render
+		cycles_bvh
+		cycles_device
+		cycles_kernel
+		cycles_util
+		cycles_subd
+		bf_intern_raskter
+		bf_intern_opencolorio
+		extern_rangetree
+		extern_wcwidth
+		extern_libmv
+		extern_glog
+	)
+
+	if(WITH_COMPOSITOR)
+		# added for opencl compositor
+		list_insert_before(BLENDER_SORTED_LIBS "bf_blenkernel" "bf_compositor")
+		list_insert_after(BLENDER_SORTED_LIBS "bf_compositor" "bf_intern_opencl")
+	endif()
+
+	if(WITH_LIBMV)
+		list(APPEND BLENDER_SORTED_LIBS extern_ceres)
+	endif()
+
+	if(WITH_MOD_CLOTH_ELTOPO)
+		list(APPEND BLENDER_SORTED_LIBS extern_eltopo)
+	endif()
+
+	if(NOT WITH_SYSTEM_GLEW)
+		list(APPEND BLENDER_SORTED_LIBS extern_glew)
+	endif()
+
+	if(WITH_BINRELOC)
+		list(APPEND BLENDER_SORTED_LIBS extern_binreloc)
+	endif()
+
+	if(WITH_CXX_GUARDEDALLOC)
+		list(APPEND BLENDER_SORTED_LIBS bf_intern_guardedalloc_cpp)
+	endif()
+
+	if(WITH_IK_SOLVER)
+		list_insert_after(BLENDER_SORTED_LIBS "bf_intern_elbeem" "bf_intern_iksolver")
+	endif()
+
+	if(WITH_IK_ITASC)
+		list(APPEND BLENDER_SORTED_LIBS bf_intern_itasc)
+	endif()
+
+	if(WITH_CODEC_QUICKTIME)
+		list(APPEND BLENDER_SORTED_LIBS bf_quicktime)
+	endif()
+
+	if(WITH_INPUT_NDOF)
+		list(APPEND BLENDER_SORTED_LIBS bf_intern_ghostndof3dconnexion)
+	endif()
+	
+	if(WITH_MOD_BOOLEAN)
+		list(APPEND BLENDER_SORTED_LIBS extern_carve)
+	endif()
+
+	if(WITH_GHOST_XDND)
+		list(APPEND BLENDER_SORTED_LIBS extern_xdnd)
+	endif()
+
+	if(WITH_CYCLES_OSL)
+		list_insert_after(BLENDER_SORTED_LIBS "cycles_kernel" "cycles_kernel_osl")
+	endif()
+
+	if(WITH_INTERNATIONAL)
+		list(APPEND BLENDER_SORTED_LIBS bf_intern_locale)
+	endif()
+
+	if(WITH_OPENNL)
+		list_insert_after(BLENDER_SORTED_LIBS "bf_render" "bf_intern_opennl")
+	endif()
+
+	if(WITH_BULLET)
+		list_insert_after(BLENDER_SORTED_LIBS "bf_blenkernel" "bf_intern_rigidbody")
+	endif()
+
+	if(WITH_BULLET AND NOT WITH_SYSTEM_BULLET)
+		list_insert_after(BLENDER_SORTED_LIBS "ge_logic_ngnetwork" "extern_bullet")
+	endif()
+
+	foreach(SORTLIB ${BLENDER_SORTED_LIBS})
+		set(REMLIB ${SORTLIB})
+		foreach(SEARCHLIB ${BLENDER_LINK_LIBS})
+			if(${SEARCHLIB} STREQUAL ${SORTLIB})
+				set(REMLIB "")
+			endif()
+		endforeach()
+		if(REMLIB)
+			# message(STATUS "Removing library ${REMLIB} from blender linking because: not configured")
+			list(APPEND REM_MSG ${REMLIB})
+			list(REMOVE_ITEM BLENDER_SORTED_LIBS ${REMLIB})
+		endif()
+	endforeach()
+	if(REM_MSG)
+		list(SORT REM_MSG)
+		message(STATUS "Blender Skipping: (${REM_MSG})")
+	endif()
+
+	unset(SEARCHLIB)
+	unset(SORTLIB)
+	unset(REMLIB)
+	unset(REM_MSG)
+endmacro()
+
 macro(TEST_SSE_SUPPORT
 	_sse_flags
 	_sse2_flags)
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
+	.


@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list