diff options
Diffstat (limited to 'tests/gtests')
-rw-r--r-- | tests/gtests/CMakeLists.txt | 13 | ||||
-rw-r--r-- | tests/gtests/blenkernel/BKE_armature_test.cc | 89 | ||||
-rw-r--r-- | tests/gtests/blenkernel/BKE_fcurve_test.cc | 211 | ||||
-rw-r--r-- | tests/gtests/blenkernel/CMakeLists.txt | 44 | ||||
-rw-r--r-- | tests/gtests/runner/CMakeLists.txt | 63 | ||||
-rw-r--r-- | tests/gtests/runner/blender_test.cc | 25 | ||||
-rw-r--r-- | tests/gtests/testing/CMakeLists.txt | 4 |
7 files changed, 96 insertions, 353 deletions
diff --git a/tests/gtests/CMakeLists.txt b/tests/gtests/CMakeLists.txt index 0dfe041974e..4ce68a6f4c0 100644 --- a/tests/gtests/CMakeLists.txt +++ b/tests/gtests/CMakeLists.txt @@ -1,18 +1,13 @@ -# GTest if(WITH_GTESTS) - - include(GTestTesting) - - add_definitions(${GFLAGS_DEFINES}) - add_definitions(${GLOG_DEFINES}) - add_definitions(-DBLENDER_GFLAGS_NAMESPACE=${GFLAGS_NAMESPACE}) - # Otherwise we get warnings here that we cant fix in external projects remove_strict_flags() + # Build common test runner + add_subdirectory(runner) + + # Build tests not yet ported to the common runner add_subdirectory(testing) - add_subdirectory(blenkernel) add_subdirectory(blenlib) add_subdirectory(blenloader) add_subdirectory(guardedalloc) diff --git a/tests/gtests/blenkernel/BKE_armature_test.cc b/tests/gtests/blenkernel/BKE_armature_test.cc deleted file mode 100644 index ed6045081d4..00000000000 --- a/tests/gtests/blenkernel/BKE_armature_test.cc +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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) 2020 Blender Foundation - * All rights reserved. - */ - -#include "BKE_armature.h" - -#include "BLI_math.h" - -#include "testing/testing.h" - -static const float FLOAT_EPSILON = 1.2e-7; - -TEST(mat3_vec_to_roll, UnitMatrix) -{ - float unit_matrix[3][3]; - float roll; - - unit_m3(unit_matrix); - - // Any vector with a unit matrix should return zero roll. - mat3_vec_to_roll(unit_matrix, unit_matrix[0], &roll); - EXPECT_FLOAT_EQ(0.0f, roll); - - mat3_vec_to_roll(unit_matrix, unit_matrix[1], &roll); - EXPECT_FLOAT_EQ(0.0f, roll); - - mat3_vec_to_roll(unit_matrix, unit_matrix[2], &roll); - EXPECT_FLOAT_EQ(0.0f, roll); - - { - // Non-unit vector. - float vector[3] = {1.0f, 1.0f, 1.0f}; - mat3_vec_to_roll(unit_matrix, vector, &roll); - EXPECT_NEAR(0.0f, roll, FLOAT_EPSILON); - - // Normalized version of the above vector. - normalize_v3(vector); - mat3_vec_to_roll(unit_matrix, vector, &roll); - EXPECT_NEAR(0.0f, roll, FLOAT_EPSILON); - } -} - -TEST(mat3_vec_to_roll, Rotationmatrix) -{ - float rotation_matrix[3][3]; - float roll; - - const float rot_around_x[3] = {1.234f, 0.0f, 0.0f}; - eul_to_mat3(rotation_matrix, rot_around_x); - - { - const float unit_axis_x[3] = {1.0f, 0.0f, 0.0f}; - mat3_vec_to_roll(rotation_matrix, unit_axis_x, &roll); - EXPECT_NEAR(1.234f, roll, FLOAT_EPSILON); - } - - { - const float unit_axis_y[3] = {0.0f, 1.0f, 0.0f}; - mat3_vec_to_roll(rotation_matrix, unit_axis_y, &roll); - EXPECT_NEAR(0, roll, FLOAT_EPSILON); - } - - { - const float unit_axis_z[3] = {0.0f, 0.0f, 1.0f}; - mat3_vec_to_roll(rotation_matrix, unit_axis_z, &roll); - EXPECT_NEAR(0, roll, FLOAT_EPSILON); - } - - { - const float between_x_and_y[3] = {1.0f, 1.0f, 0.0f}; - mat3_vec_to_roll(rotation_matrix, between_x_and_y, &roll); - EXPECT_NEAR(0.57158958f, roll, FLOAT_EPSILON); - } -} diff --git a/tests/gtests/blenkernel/BKE_fcurve_test.cc b/tests/gtests/blenkernel/BKE_fcurve_test.cc deleted file mode 100644 index e994dd43af9..00000000000 --- a/tests/gtests/blenkernel/BKE_fcurve_test.cc +++ /dev/null @@ -1,211 +0,0 @@ -/* - * 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) 2020 by Blender Foundation. - */ -#include "testing/testing.h" - -#include "MEM_guardedalloc.h" - -extern "C" { -#include "BKE_fcurve.h" - -#include "ED_keyframing.h" - -#include "DNA_anim_types.h" -} - -// Epsilon for floating point comparisons. -static const float EPSILON = 1e-7f; - -TEST(evaluate_fcurve, EmptyFCurve) -{ - FCurve *fcu = BKE_fcurve_create(); - EXPECT_EQ(evaluate_fcurve(fcu, 47.0f), 0.0f); - BKE_fcurve_free(fcu); -} - -TEST(evaluate_fcurve, OnKeys) -{ - FCurve *fcu = BKE_fcurve_create(); - - insert_vert_fcurve(fcu, 1.0f, 7.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF); - insert_vert_fcurve(fcu, 2.0f, 13.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF); - insert_vert_fcurve(fcu, 3.0f, 19.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF); - - EXPECT_NEAR(evaluate_fcurve(fcu, 1.0f), 7.0f, EPSILON); // hits 'on or before first' function - EXPECT_NEAR(evaluate_fcurve(fcu, 2.0f), 13.0f, EPSILON); // hits 'between' function - EXPECT_NEAR(evaluate_fcurve(fcu, 3.0f), 19.0f, EPSILON); // hits 'on or after last' function - - /* Also test within a specific time epsilon of the keys, as this was an issue in T39207. - * This epsilon is just slightly smaller than the epsilon given to binarysearch_bezt_index_ex() - * in fcurve_eval_between_keyframes(), so it should hit the "exact" code path. */ - float time_epsilon = 0.00008f; - EXPECT_NEAR(evaluate_fcurve(fcu, 2.0f - time_epsilon), 13.0f, EPSILON); - EXPECT_NEAR(evaluate_fcurve(fcu, 2.0f + time_epsilon), 13.0f, EPSILON); - - BKE_fcurve_free(fcu); -} - -TEST(evaluate_fcurve, InterpolationConstant) -{ - FCurve *fcu = BKE_fcurve_create(); - - EXPECT_EQ(insert_vert_fcurve(fcu, 1.0f, 7.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF), 0); - EXPECT_EQ(insert_vert_fcurve(fcu, 2.0f, 13.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF), 1); - - fcu->bezt[0].ipo = BEZT_IPO_CONST; - fcu->bezt[1].ipo = BEZT_IPO_CONST; - - EXPECT_NEAR(evaluate_fcurve(fcu, 1.25f), 7.0f, EPSILON); - EXPECT_NEAR(evaluate_fcurve(fcu, 1.50f), 7.0f, EPSILON); - - BKE_fcurve_free(fcu); -} - -TEST(evaluate_fcurve, InterpolationLinear) -{ - FCurve *fcu = BKE_fcurve_create(); - - EXPECT_EQ(insert_vert_fcurve(fcu, 1.0f, 7.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF), 0); - EXPECT_EQ(insert_vert_fcurve(fcu, 2.0f, 13.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF), 1); - - fcu->bezt[0].ipo = BEZT_IPO_LIN; - fcu->bezt[1].ipo = BEZT_IPO_LIN; - - EXPECT_NEAR(evaluate_fcurve(fcu, 1.25f), 8.5f, EPSILON); - EXPECT_NEAR(evaluate_fcurve(fcu, 1.50f), 10.0f, EPSILON); - EXPECT_NEAR(evaluate_fcurve(fcu, 1.75f), 11.5f, EPSILON); - - BKE_fcurve_free(fcu); -} - -TEST(evaluate_fcurve, InterpolationBezier) -{ - FCurve *fcu = BKE_fcurve_create(); - - EXPECT_EQ(insert_vert_fcurve(fcu, 1.0f, 7.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF), 0); - EXPECT_EQ(insert_vert_fcurve(fcu, 2.0f, 13.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF), 1); - - EXPECT_EQ(fcu->bezt[0].ipo, BEZT_IPO_BEZ); - EXPECT_EQ(fcu->bezt[1].ipo, BEZT_IPO_BEZ); - - // Test with default handles. - EXPECT_NEAR(evaluate_fcurve(fcu, 1.25f), 7.8297067f, EPSILON); - EXPECT_NEAR(evaluate_fcurve(fcu, 1.50f), 10.0f, EPSILON); - EXPECT_NEAR(evaluate_fcurve(fcu, 1.75f), 12.170294f, EPSILON); - - // Test with modified handles. - fcu->bezt[0].vec[0][0] = 0.71855f; // left handle X - fcu->bezt[0].vec[0][1] = 6.22482f; // left handle Y - fcu->bezt[0].vec[2][0] = 1.35148f; // right handle X - fcu->bezt[0].vec[2][1] = 7.96806f; // right handle Y - - fcu->bezt[1].vec[0][0] = 1.66667f; // left handle X - fcu->bezt[1].vec[0][1] = 10.4136f; // left handle Y - fcu->bezt[1].vec[2][0] = 2.33333f; // right handle X - fcu->bezt[1].vec[2][1] = 15.5864f; // right handle Y - - EXPECT_NEAR(evaluate_fcurve(fcu, 1.25f), 7.945497f, EPSILON); - EXPECT_NEAR(evaluate_fcurve(fcu, 1.50f), 9.3495407f, EPSILON); - EXPECT_NEAR(evaluate_fcurve(fcu, 1.75f), 11.088551f, EPSILON); - - BKE_fcurve_free(fcu); -} - -TEST(evaluate_fcurve, InterpolationBounce) -{ - FCurve *fcu = BKE_fcurve_create(); - - EXPECT_EQ(insert_vert_fcurve(fcu, 1.0f, 7.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF), 0); - EXPECT_EQ(insert_vert_fcurve(fcu, 2.0f, 13.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF), 1); - - fcu->bezt[0].ipo = BEZT_IPO_BOUNCE; - fcu->bezt[1].ipo = BEZT_IPO_BOUNCE; - - fcu->bezt[0].easing = BEZT_IPO_EASE_IN; - fcu->bezt[1].easing = BEZT_IPO_EASE_AUTO; - - EXPECT_NEAR(evaluate_fcurve(fcu, 1.4f), 8.3649998f, EPSILON); - EXPECT_NEAR(evaluate_fcurve(fcu, 1.5f), 8.4062500f, EPSILON); - EXPECT_NEAR(evaluate_fcurve(fcu, 1.8f), 11.184999f, EPSILON); - - BKE_fcurve_free(fcu); -} - -TEST(evaluate_fcurve, ExtrapolationLinearKeys) -{ - FCurve *fcu = BKE_fcurve_create(); - - EXPECT_EQ(insert_vert_fcurve(fcu, 1.0f, 7.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF), 0); - EXPECT_EQ(insert_vert_fcurve(fcu, 2.0f, 13.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF), 1); - fcu->bezt[0].ipo = BEZT_IPO_LIN; - fcu->bezt[1].ipo = BEZT_IPO_LIN; - - fcu->extend = FCURVE_EXTRAPOLATE_LINEAR; - // Before first keyframe. - EXPECT_NEAR(evaluate_fcurve(fcu, 0.75f), 5.5f, EPSILON); - EXPECT_NEAR(evaluate_fcurve(fcu, 0.50f), 4.0f, EPSILON); - EXPECT_NEAR(evaluate_fcurve(fcu, -1.50f), -8.0f, EPSILON); - // After last keyframe. - EXPECT_NEAR(evaluate_fcurve(fcu, 2.75f), 17.5f, EPSILON); - EXPECT_NEAR(evaluate_fcurve(fcu, 3.50f), 22.0f, EPSILON); - - fcu->extend = FCURVE_EXTRAPOLATE_CONSTANT; - // Before first keyframe. - EXPECT_NEAR(evaluate_fcurve(fcu, 0.75f), 7.0f, EPSILON); - EXPECT_NEAR(evaluate_fcurve(fcu, -1.50f), 7.0f, EPSILON); - // After last keyframe. - EXPECT_NEAR(evaluate_fcurve(fcu, 2.75f), 13.0f, EPSILON); - EXPECT_NEAR(evaluate_fcurve(fcu, 3.50f), 13.0f, EPSILON); - - BKE_fcurve_free(fcu); -} - -TEST(evaluate_fcurve, ExtrapolationBezierKeys) -{ - FCurve *fcu = BKE_fcurve_create(); - - EXPECT_EQ(insert_vert_fcurve(fcu, 1.0f, 7.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF), 0); - EXPECT_EQ(insert_vert_fcurve(fcu, 2.0f, 13.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF), 1); - - fcu->bezt[0].vec[0][0] = 0.71855f; // left handle X - fcu->bezt[0].vec[0][1] = 6.22482f; // left handle Y - fcu->bezt[0].vec[2][0] = 1.35148f; // right handle X - fcu->bezt[0].vec[2][1] = 7.96806f; // right handle Y - - fcu->bezt[1].vec[0][0] = 1.66667f; // left handle X - fcu->bezt[1].vec[0][1] = 10.4136f; // left handle Y - fcu->bezt[1].vec[2][0] = 2.33333f; // right handle X - fcu->bezt[1].vec[2][1] = 15.5864f; // right handle Y - - fcu->extend = FCURVE_EXTRAPOLATE_LINEAR; - // Before first keyframe. - EXPECT_NEAR(evaluate_fcurve(fcu, 0.75f), 6.3114409f, EPSILON); - EXPECT_NEAR(evaluate_fcurve(fcu, -0.50f), 2.8686447f, EPSILON); - // After last keyframe. - EXPECT_NEAR(evaluate_fcurve(fcu, 2.75f), 18.81946f, EPSILON); - EXPECT_NEAR(evaluate_fcurve(fcu, 3.50f), 24.63892f, EPSILON); - - fcu->extend = FCURVE_EXTRAPOLATE_CONSTANT; - // Before first keyframe. - EXPECT_NEAR(evaluate_fcurve(fcu, 0.75f), 7.0f, EPSILON); - EXPECT_NEAR(evaluate_fcurve(fcu, -1.50f), 7.0f, EPSILON); - // After last keyframe. - EXPECT_NEAR(evaluate_fcurve(fcu, 2.75f), 13.0f, EPSILON); - EXPECT_NEAR(evaluate_fcurve(fcu, 3.50f), 13.0f, EPSILON); - - BKE_fcurve_free(fcu); -} diff --git a/tests/gtests/blenkernel/CMakeLists.txt b/tests/gtests/blenkernel/CMakeLists.txt deleted file mode 100644 index 5cf4c7a27af..00000000000 --- a/tests/gtests/blenkernel/CMakeLists.txt +++ /dev/null @@ -1,44 +0,0 @@ -# ***** 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) 2020, Blender Foundation -# All rights reserved. -# ***** END GPL LICENSE BLOCK ***** - -set(INC - . - .. - ../../../source/blender/blenkernel - ../../../source/blender/blenlib - ../../../source/blender/editors/include - ../../../source/blender/makesdna - ../../../source/blender/makesrna - ../../../intern/guardedalloc - ../../../intern/atomic -) - -setup_libdirs() -include_directories(${INC}) - -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}") - -if(WITH_BUILDINFO) - set(BUILDINFO buildinfoobj) -endif() - -BLENDER_TEST(BKE_armature "bf_blenloader;bf_blenkernel;bf_blenlib;${BUILDINFO}") -BLENDER_TEST(BKE_fcurve "bf_blenloader;bf_blenkernel;bf_editor_animation;${BUILDINFO}") diff --git a/tests/gtests/runner/CMakeLists.txt b/tests/gtests/runner/CMakeLists.txt new file mode 100644 index 00000000000..e7cbabfe7c6 --- /dev/null +++ b/tests/gtests/runner/CMakeLists.txt @@ -0,0 +1,63 @@ +# ***** 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) 2020, Blender Foundation +# All rights reserved. +# ***** END GPL LICENSE BLOCK ***** + +# Build the test runner. This runner takes care of running all GTests, i.e. +# the code that was built using the blender_add_test_lib() CMake macro (see +# macros.cmake). +set(SRC + blender_test.cc +) + +if(WITH_BUILDINFO) + list(APPEND SRC + "$<TARGET_OBJECTS:buildinfoobj>" + ) +endif() + + +# Test libraries need to be linked "whole archive", because they're not +# directly referenced from other code. +get_property(_test_libs GLOBAL PROPERTY BLENDER_TEST_LIBS) +if(WIN32) + list(APPEND TEST_LIBS ${_test_libs}) +elseif(APPLE) + list(APPEND TEST_LIBS "-Wl,-force_load" ${_test_libs}) +elseif(UNIX) + list(APPEND TEST_LIBS "-Wl,--whole-archive" ${_test_libs} "-Wl,--no-whole-archive") +else() + message(FATAL_ERROR "Unknown how to link whole-archive with your compiler ${CMAKE_CXX_COMPILER_ID}") +endif() +unset(_test_libs) + +# This builds `bin/tests/blender_test`, but does not add it as a single test. +setup_libdirs() +BLENDER_SRC_GTEST_EX( + NAME blender + SRC "${SRC}" + EXTRA_LIBS "${TEST_LIBS}" + SKIP_ADD_TEST +) +setup_liblinks(blender_test) + +# This runs the blender_test executable with `--gtest_list_tests`, then +# exposes those tests individually to the ctest runner. +# See https://cmake.org/cmake/help/v3.18/module/GoogleTest.html +include(GoogleTest) +gtest_discover_tests(blender_test) diff --git a/tests/gtests/runner/blender_test.cc b/tests/gtests/runner/blender_test.cc new file mode 100644 index 00000000000..fbce7a4283f --- /dev/null +++ b/tests/gtests/runner/blender_test.cc @@ -0,0 +1,25 @@ +/* + * 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) 2020 Blender Foundation. + * All rights reserved. + */ + +/* This file is intentionally left blank. It is necessary for CMake to have a source file for each + * executable. However, the blender_tests test runner only comprises of statically linked library + * files, including its main function. + * + * See source/blender/blenkernel/CMakeLists.txt for an example of how to add unit tests to the test + * runner. */ diff --git a/tests/gtests/testing/CMakeLists.txt b/tests/gtests/testing/CMakeLists.txt index e08ee486933..c8a7f487c5d 100644 --- a/tests/gtests/testing/CMakeLists.txt +++ b/tests/gtests/testing/CMakeLists.txt @@ -18,6 +18,10 @@ # All rights reserved. # ***** END GPL LICENSE BLOCK ***** +add_definitions(${GFLAGS_DEFINES}) +add_definitions(${GLOG_DEFINES}) +add_definitions(-DBLENDER_GFLAGS_NAMESPACE=${GFLAGS_NAMESPACE}) + set(INC . .. |