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
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt18
-rw-r--r--tests/gtests/CMakeLists.txt1
-rw-r--r--tests/gtests/alembic/abc_matrix_test.cc2
-rw-r--r--tests/gtests/blenkernel/BKE_armature_test.cc89
-rw-r--r--tests/gtests/blenkernel/BKE_fcurve_test.cc211
-rw-r--r--tests/gtests/blenkernel/CMakeLists.txt44
-rw-r--r--tests/gtests/blenlib/BLI_array_ref_test.cc4
-rw-r--r--tests/gtests/blenlib/BLI_array_test.cc2
-rw-r--r--tests/gtests/blenlib/BLI_index_range_test.cc4
-rw-r--r--tests/gtests/blenlib/BLI_linear_allocator_test.cc113
-rw-r--r--tests/gtests/blenlib/BLI_linklist_lockfree_test.cc11
-rw-r--r--tests/gtests/blenlib/BLI_map_test.cc19
-rw-r--r--tests/gtests/blenlib/BLI_optional_test.cc2
-rw-r--r--tests/gtests/blenlib/BLI_set_test.cc25
-rw-r--r--tests/gtests/blenlib/BLI_stack_cxx_test.cc2
-rw-r--r--tests/gtests/blenlib/BLI_string_map_test.cc45
-rw-r--r--tests/gtests/blenlib/BLI_string_ref_test.cc15
-rw-r--r--tests/gtests/blenlib/BLI_task_graph_test.cc188
-rw-r--r--tests/gtests/blenlib/BLI_task_performance_test.cc86
-rw-r--r--tests/gtests/blenlib/BLI_task_test.cc90
-rw-r--r--tests/gtests/blenlib/BLI_type_construct_mock.hh63
-rw-r--r--tests/gtests/blenlib/BLI_vector_set_test.cc25
-rw-r--r--tests/gtests/blenlib/BLI_vector_test.cc165
-rw-r--r--tests/gtests/blenlib/CMakeLists.txt2
-rw-r--r--tests/gtests/usd/abstract_hierarchy_iterator_test.cc2
-rw-r--r--tests/gtests/usd/hierarchy_context_order_test.cc44
-rw-r--r--tests/python/CMakeLists.txt16
-rw-r--r--[-rwxr-xr-x]tests/python/alembic_tests.py2
-rw-r--r--[-rwxr-xr-x]tests/python/cycles_render_tests.py0
-rw-r--r--[-rwxr-xr-x]tests/python/eevee_render_tests.py0
-rw-r--r--[-rwxr-xr-x]tests/python/ffmpeg_tests.py0
-rw-r--r--[-rwxr-xr-x]tests/python/opengl_draw_tests.py0
-rw-r--r--[-rwxr-xr-x]tests/python/workbench_render_tests.py0
33 files changed, 1002 insertions, 288 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 966572b23e7..80d749c7040 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -14,15 +14,27 @@ endif()
# Path to Blender and Python executables for all platforms.
if(MSVC)
set(TEST_BLENDER_EXE ${TEST_INSTALL_DIR}/blender.exe)
- set(TEST_PYTHON_EXE "${TEST_INSTALL_DIR}/${BLENDER_VERSION_MAJOR}.${BLENDER_VERSION_MINOR}/python/bin/python$<$<CONFIG:Debug>:_d>")
+ set(_default_test_python_exe "${TEST_INSTALL_DIR}/${BLENDER_VERSION_MAJOR}.${BLENDER_VERSION_MINOR}/python/bin/python$<$<CONFIG:Debug>:_d>")
elseif(APPLE)
set(TEST_BLENDER_EXE ${TEST_INSTALL_DIR}/Blender.app/Contents/MacOS/Blender)
- set(TEST_PYTHON_EXE)
+ set(_default_test_python_exe ${PYTHON_EXECUTABLE})
else()
set(TEST_BLENDER_EXE ${TEST_INSTALL_DIR}/blender)
- set(TEST_PYTHON_EXE)
+ set(_default_test_python_exe ${PYTHON_EXECUTABLE})
endif()
+# The installation directory's Python is the best one to use. However, it can only be there after the install step,
+# which means that Python will never be there on a fresh system. To suit different needs, the user can pass
+# -DTEST_PYTHON_EXE=/path/to/python to CMake.
+if (NOT TEST_PYTHON_EXE)
+ set(TEST_PYTHON_EXE ${_default_test_python_exe})
+ message(STATUS "Tests: Using Python executable: ${TEST_PYTHON_EXE}")
+elseif(NOT EXISTS ${TEST_PYTHON_EXE})
+ message(FATAL_ERROR "Tests: TEST_PYTHON_EXE ${TEST_PYTHON_EXE} does not exist")
+endif()
+unset(_default_test_python_exe)
+
+
# For testing with Valgrind
# set(TEST_BLENDER_EXE valgrind --track-origins=yes --error-limit=no ${TEST_BLENDER_EXE})
diff --git a/tests/gtests/CMakeLists.txt b/tests/gtests/CMakeLists.txt
index bcf77fb6de7..c02bad471ff 100644
--- a/tests/gtests/CMakeLists.txt
+++ b/tests/gtests/CMakeLists.txt
@@ -12,6 +12,7 @@ if(WITH_GTESTS)
remove_strict_flags()
add_subdirectory(testing)
+ add_subdirectory(blenkernel)
add_subdirectory(blenlib)
add_subdirectory(blenloader)
add_subdirectory(guardedalloc)
diff --git a/tests/gtests/alembic/abc_matrix_test.cc b/tests/gtests/alembic/abc_matrix_test.cc
index 59ccd57937a..9b16eb108be 100644
--- a/tests/gtests/alembic/abc_matrix_test.cc
+++ b/tests/gtests/alembic/abc_matrix_test.cc
@@ -1,7 +1,7 @@
#include "testing/testing.h"
// Keep first since utildefines defines AT which conflicts with STL
-#include "intern/abc_util.h"
+#include "intern/abc_axis_conversion.h"
extern "C" {
#include "BLI_math.h"
diff --git a/tests/gtests/blenkernel/BKE_armature_test.cc b/tests/gtests/blenkernel/BKE_armature_test.cc
new file mode 100644
index 00000000000..ed6045081d4
--- /dev/null
+++ b/tests/gtests/blenkernel/BKE_armature_test.cc
@@ -0,0 +1,89 @@
+/*
+ * 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
new file mode 100644
index 00000000000..d28c5075bd8
--- /dev/null
+++ b/tests/gtests/blenkernel/BKE_fcurve_test.cc
@@ -0,0 +1,211 @@
+/*
+ * 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 = static_cast<FCurve *>(MEM_callocN(sizeof(FCurve), "FCurve"));
+ EXPECT_EQ(evaluate_fcurve(fcu, 47.0f), 0.0f);
+ free_fcurve(fcu);
+}
+
+TEST(evaluate_fcurve, OnKeys)
+{
+ FCurve *fcu = static_cast<FCurve *>(MEM_callocN(sizeof(FCurve), "FCurve"));
+
+ 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);
+
+ free_fcurve(fcu);
+}
+
+TEST(evaluate_fcurve, InterpolationConstant)
+{
+ FCurve *fcu = static_cast<FCurve *>(MEM_callocN(sizeof(FCurve), "FCurve"));
+
+ 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);
+
+ free_fcurve(fcu);
+}
+
+TEST(evaluate_fcurve, InterpolationLinear)
+{
+ FCurve *fcu = static_cast<FCurve *>(MEM_callocN(sizeof(FCurve), "FCurve"));
+
+ 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);
+
+ free_fcurve(fcu);
+}
+
+TEST(evaluate_fcurve, InterpolationBezier)
+{
+ FCurve *fcu = static_cast<FCurve *>(MEM_callocN(sizeof(FCurve), "FCurve"));
+
+ 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);
+
+ free_fcurve(fcu);
+}
+
+TEST(evaluate_fcurve, InterpolationBounce)
+{
+ FCurve *fcu = static_cast<FCurve *>(MEM_callocN(sizeof(FCurve), "FCurve"));
+
+ 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);
+
+ free_fcurve(fcu);
+}
+
+TEST(evaluate_fcurve, ExtrapolationLinearKeys)
+{
+ FCurve *fcu = static_cast<FCurve *>(MEM_callocN(sizeof(FCurve), "FCurve"));
+
+ 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);
+
+ free_fcurve(fcu);
+}
+
+TEST(evaluate_fcurve, ExtrapolationBezierKeys)
+{
+ FCurve *fcu = static_cast<FCurve *>(MEM_callocN(sizeof(FCurve), "FCurve"));
+
+ 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);
+
+ free_fcurve(fcu);
+}
diff --git a/tests/gtests/blenkernel/CMakeLists.txt b/tests/gtests/blenkernel/CMakeLists.txt
new file mode 100644
index 00000000000..5cf4c7a27af
--- /dev/null
+++ b/tests/gtests/blenkernel/CMakeLists.txt
@@ -0,0 +1,44 @@
+# ***** 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/blenlib/BLI_array_ref_test.cc b/tests/gtests/blenlib/BLI_array_ref_test.cc
index aacd6113161..7a1f54e7458 100644
--- a/tests/gtests/blenlib/BLI_array_ref_test.cc
+++ b/tests/gtests/blenlib/BLI_array_ref_test.cc
@@ -1,5 +1,5 @@
-#include "BLI_array_ref.h"
-#include "BLI_vector.h"
+#include "BLI_array_ref.hh"
+#include "BLI_vector.hh"
#include "testing/testing.h"
using namespace BLI;
diff --git a/tests/gtests/blenlib/BLI_array_test.cc b/tests/gtests/blenlib/BLI_array_test.cc
index dd09c2d20f8..b1aa24aa808 100644
--- a/tests/gtests/blenlib/BLI_array_test.cc
+++ b/tests/gtests/blenlib/BLI_array_test.cc
@@ -1,4 +1,4 @@
-#include "BLI_array_cxx.h"
+#include "BLI_array.hh"
#include "testing/testing.h"
using namespace BLI;
diff --git a/tests/gtests/blenlib/BLI_index_range_test.cc b/tests/gtests/blenlib/BLI_index_range_test.cc
index 60da18b6baf..b12502f0d97 100644
--- a/tests/gtests/blenlib/BLI_index_range_test.cc
+++ b/tests/gtests/blenlib/BLI_index_range_test.cc
@@ -1,5 +1,5 @@
-#include "BLI_index_range.h"
-#include "BLI_vector.h"
+#include "BLI_index_range.hh"
+#include "BLI_vector.hh"
#include "testing/testing.h"
using BLI::ArrayRef;
diff --git a/tests/gtests/blenlib/BLI_linear_allocator_test.cc b/tests/gtests/blenlib/BLI_linear_allocator_test.cc
new file mode 100644
index 00000000000..0c67d1e76c9
--- /dev/null
+++ b/tests/gtests/blenlib/BLI_linear_allocator_test.cc
@@ -0,0 +1,113 @@
+#include "BLI_linear_allocator.hh"
+#include "testing/testing.h"
+
+using namespace BLI;
+
+static bool is_aligned(void *ptr, uint alignment)
+{
+ BLI_assert(is_power_of_2_i(alignment));
+ return (POINTER_AS_UINT(ptr) & (alignment - 1)) == 0;
+}
+
+TEST(linear_allocator, AllocationAlignment)
+{
+ LinearAllocator<> allocator;
+
+ EXPECT_TRUE(is_aligned(allocator.allocate(10, 4), 4));
+ EXPECT_TRUE(is_aligned(allocator.allocate(10, 4), 4));
+ EXPECT_TRUE(is_aligned(allocator.allocate(10, 4), 4));
+ EXPECT_TRUE(is_aligned(allocator.allocate(10, 8), 8));
+ EXPECT_TRUE(is_aligned(allocator.allocate(10, 4), 4));
+ EXPECT_TRUE(is_aligned(allocator.allocate(10, 16), 16));
+ EXPECT_TRUE(is_aligned(allocator.allocate(10, 4), 4));
+ EXPECT_TRUE(is_aligned(allocator.allocate(10, 64), 64));
+ EXPECT_TRUE(is_aligned(allocator.allocate(10, 64), 64));
+ EXPECT_TRUE(is_aligned(allocator.allocate(10, 8), 8));
+ EXPECT_TRUE(is_aligned(allocator.allocate(10, 128), 128));
+}
+
+TEST(linear_allocator, PackedAllocation)
+{
+ LinearAllocator<> allocator;
+ BLI::AlignedBuffer<256, 32> buffer;
+ allocator.provide_buffer(buffer);
+
+ uintptr_t ptr1 = (uintptr_t)allocator.allocate(10, 4); /* 0 - 10 */
+ uintptr_t ptr2 = (uintptr_t)allocator.allocate(10, 4); /* 12 - 22 */
+ uintptr_t ptr3 = (uintptr_t)allocator.allocate(8, 32); /* 32 - 40 */
+ uintptr_t ptr4 = (uintptr_t)allocator.allocate(16, 8); /* 40 - 56 */
+ uintptr_t ptr5 = (uintptr_t)allocator.allocate(1, 8); /* 56 - 57 */
+ uintptr_t ptr6 = (uintptr_t)allocator.allocate(1, 4); /* 60 - 61 */
+ uintptr_t ptr7 = (uintptr_t)allocator.allocate(1, 1); /* 61 - 62 */
+
+ EXPECT_EQ(ptr2 - ptr1, 12); /* 12 - 0 = 12 */
+ EXPECT_EQ(ptr3 - ptr2, 20); /* 32 - 12 = 20 */
+ EXPECT_EQ(ptr4 - ptr3, 8); /* 40 - 32 = 8 */
+ EXPECT_EQ(ptr5 - ptr4, 16); /* 56 - 40 = 16 */
+ EXPECT_EQ(ptr6 - ptr5, 4); /* 60 - 56 = 4 */
+ EXPECT_EQ(ptr7 - ptr6, 1); /* 61 - 60 = 1 */
+}
+
+TEST(linear_allocator, CopyString)
+{
+ LinearAllocator<> allocator;
+ BLI::AlignedBuffer<256, 1> buffer;
+ allocator.provide_buffer(buffer);
+
+ StringRefNull ref1 = allocator.copy_string("Hello");
+ StringRefNull ref2 = allocator.copy_string("World");
+
+ EXPECT_EQ(ref1, "Hello");
+ EXPECT_EQ(ref2, "World");
+ EXPECT_EQ(ref2.data() - ref1.data(), 6);
+}
+
+TEST(linear_allocator, AllocateArray)
+{
+ LinearAllocator<> allocator;
+
+ MutableArrayRef<int> array = allocator.allocate_array<int>(5);
+ EXPECT_EQ(array.size(), 5);
+}
+
+TEST(linear_allocator, Construct)
+{
+ LinearAllocator<> allocator;
+
+ std::array<int, 5> values = {1, 2, 3, 4, 5};
+ Vector<int> *vector = allocator.construct<Vector<int>>(values);
+ EXPECT_EQ(vector->size(), 5);
+ EXPECT_EQ((*vector)[3], 4);
+ vector->~Vector();
+}
+
+TEST(linear_allocator, ConstructElementsAndPointerArray)
+{
+ LinearAllocator<> allocator;
+
+ std::array<int, 7> values = {1, 2, 3, 4, 5, 6, 7};
+ ArrayRef<Vector<int> *> vectors = allocator.construct_elements_and_pointer_array<Vector<int>>(
+ 5, values);
+
+ EXPECT_EQ(vectors.size(), 5);
+ EXPECT_EQ(vectors[3]->size(), 7);
+ EXPECT_EQ((*vectors[2])[5], 6);
+
+ for (Vector<int> *vector : vectors) {
+ vector->~Vector();
+ }
+}
+
+TEST(linear_allocator, ConstructArrayCopy)
+{
+ LinearAllocator<> allocator;
+
+ Vector<int> values = {1, 2, 3};
+ MutableArrayRef<int> array1 = allocator.construct_array_copy(values.as_ref());
+ MutableArrayRef<int> array2 = allocator.construct_array_copy(values.as_ref());
+ EXPECT_NE(array1.begin(), array2.begin());
+ EXPECT_EQ(array1.size(), 3);
+ EXPECT_EQ(array2.size(), 3);
+ EXPECT_EQ(array1[1], 2);
+ EXPECT_EQ(array2[2], 3);
+}
diff --git a/tests/gtests/blenlib/BLI_linklist_lockfree_test.cc b/tests/gtests/blenlib/BLI_linklist_lockfree_test.cc
index 9934d1a3337..d1a527d57ac 100644
--- a/tests/gtests/blenlib/BLI_linklist_lockfree_test.cc
+++ b/tests/gtests/blenlib/BLI_linklist_lockfree_test.cc
@@ -63,9 +63,9 @@ struct IndexedNode {
int index;
};
-void concurrent_insert(TaskPool *__restrict pool, void *taskdata, int /*threadid*/)
+void concurrent_insert(TaskPool *__restrict pool, void *taskdata)
{
- LockfreeLinkList *list = (LockfreeLinkList *)BLI_task_pool_userdata(pool);
+ LockfreeLinkList *list = (LockfreeLinkList *)BLI_task_pool_user_data(pool);
CHECK_NOTNULL(list);
IndexedNode *node = (IndexedNode *)MEM_mallocN(sizeof(IndexedNode), "test node");
node->index = POINTER_AS_INT(taskdata);
@@ -76,22 +76,18 @@ void concurrent_insert(TaskPool *__restrict pool, void *taskdata, int /*threadid
TEST(LockfreeLinkList, InsertMultipleConcurrent)
{
- static const int num_threads = 512;
static const int num_nodes = 655360;
/* Initialize list. */
LockfreeLinkList list;
BLI_linklist_lockfree_init(&list);
/* Initialize task scheduler and pool. */
- TaskScheduler *scheduler = BLI_task_scheduler_create(num_threads);
- TaskPool *pool = BLI_task_pool_create_suspended(scheduler, &list, TASK_PRIORITY_HIGH);
+ TaskPool *pool = BLI_task_pool_create_suspended(&list, TASK_PRIORITY_HIGH);
/* Push tasks to the pool. */
for (int i = 0; i < num_nodes; ++i) {
BLI_task_pool_push(pool, concurrent_insert, POINTER_FROM_INT(i), false, NULL);
}
/* Run all the tasks. */
- BLI_threaded_malloc_begin();
BLI_task_pool_work_and_wait(pool);
- BLI_threaded_malloc_end();
/* Verify we've got all the data properly inserted. */
EXPECT_EQ(list.head, &list.dummy_node);
bool *visited_nodes = (bool *)MEM_callocN(sizeof(bool) * num_nodes, "visited nodes");
@@ -112,5 +108,4 @@ TEST(LockfreeLinkList, InsertMultipleConcurrent)
/* Cleanup data. */
BLI_linklist_lockfree_free(&list, MEM_freeN);
BLI_task_pool_free(pool);
- BLI_task_scheduler_free(scheduler);
}
diff --git a/tests/gtests/blenlib/BLI_map_test.cc b/tests/gtests/blenlib/BLI_map_test.cc
index 7be23157e94..5a19216fa7c 100644
--- a/tests/gtests/blenlib/BLI_map_test.cc
+++ b/tests/gtests/blenlib/BLI_map_test.cc
@@ -1,5 +1,5 @@
-#include "BLI_map.h"
-#include "BLI_set.h"
+#include "BLI_map.hh"
+#include "BLI_set.hh"
#include "testing/testing.h"
using BLI::Map;
@@ -9,16 +9,20 @@ TEST(map, DefaultConstructor)
{
IntFloatMap map;
EXPECT_EQ(map.size(), 0);
+ EXPECT_TRUE(map.is_empty());
}
TEST(map, AddIncreasesSize)
{
IntFloatMap map;
EXPECT_EQ(map.size(), 0);
+ EXPECT_TRUE(map.is_empty());
map.add(2, 5.0f);
EXPECT_EQ(map.size(), 1);
+ EXPECT_FALSE(map.is_empty());
map.add(6, 2.0f);
EXPECT_EQ(map.size(), 2);
+ EXPECT_FALSE(map.is_empty());
}
TEST(map, Contains)
@@ -209,6 +213,17 @@ TEST(map, AddOverride)
EXPECT_EQ(map.lookup(3), 7.0f);
}
+TEST(map, LookupOrAddDefault)
+{
+ IntFloatMap map;
+ map.lookup_or_add_default(3) = 6;
+ EXPECT_EQ(map.lookup(3), 6);
+ map.lookup_or_add_default(5) = 2;
+ EXPECT_EQ(map.lookup(5), 2);
+ map.lookup_or_add_default(3) += 4;
+ EXPECT_EQ(map.lookup(3), 10);
+}
+
TEST(map, MoveConstructorSmall)
{
IntFloatMap map1;
diff --git a/tests/gtests/blenlib/BLI_optional_test.cc b/tests/gtests/blenlib/BLI_optional_test.cc
index a25a3cbd588..e0dec5681fe 100644
--- a/tests/gtests/blenlib/BLI_optional_test.cc
+++ b/tests/gtests/blenlib/BLI_optional_test.cc
@@ -1,4 +1,4 @@
-#include "BLI_optional.h"
+#include "BLI_optional.hh"
#include "testing/testing.h"
#include <string>
diff --git a/tests/gtests/blenlib/BLI_set_test.cc b/tests/gtests/blenlib/BLI_set_test.cc
index 555140f805c..90c052d7d2b 100644
--- a/tests/gtests/blenlib/BLI_set_test.cc
+++ b/tests/gtests/blenlib/BLI_set_test.cc
@@ -1,5 +1,5 @@
-#include "BLI_set.h"
-#include "BLI_vector.h"
+#include "BLI_set.hh"
+#include "BLI_vector.hh"
#include "testing/testing.h"
using BLI::Set;
@@ -10,6 +10,7 @@ TEST(set, Defaultconstructor)
{
IntSet set;
EXPECT_EQ(set.size(), 0);
+ EXPECT_TRUE(set.is_empty());
}
TEST(set, ContainsNotExistant)
@@ -22,8 +23,10 @@ TEST(set, ContainsExistant)
{
IntSet set;
EXPECT_FALSE(set.contains(5));
+ EXPECT_TRUE(set.is_empty());
set.add(5);
EXPECT_TRUE(set.contains(5));
+ EXPECT_FALSE(set.is_empty());
}
TEST(set, AddMany)
@@ -155,16 +158,6 @@ TEST(set, AddMultipleNew)
EXPECT_TRUE(a.contains(6));
}
-TEST(set, ToSmallVector)
-{
- IntSet a = {5, 2, 8};
- BLI::Vector<int> vec = a.to_small_vector();
- EXPECT_EQ(vec.size(), 3);
- EXPECT_TRUE(vec.contains(5));
- EXPECT_TRUE(vec.contains(2));
- EXPECT_TRUE(vec.contains(8));
-}
-
TEST(set, Iterator)
{
IntSet set = {1, 3, 2, 5, 4};
@@ -201,3 +194,11 @@ TEST(set, UniquePtrValues)
EXPECT_EQ(set.size(), 3);
}
+
+TEST(set, Clear)
+{
+ Set<int> set = {3, 4, 6, 7};
+ EXPECT_EQ(set.size(), 4);
+ set.clear();
+ EXPECT_EQ(set.size(), 0);
+}
diff --git a/tests/gtests/blenlib/BLI_stack_cxx_test.cc b/tests/gtests/blenlib/BLI_stack_cxx_test.cc
index 6376259927b..e49872f8643 100644
--- a/tests/gtests/blenlib/BLI_stack_cxx_test.cc
+++ b/tests/gtests/blenlib/BLI_stack_cxx_test.cc
@@ -1,4 +1,4 @@
-#include "BLI_stack_cxx.h"
+#include "BLI_stack.hh"
#include "testing/testing.h"
using BLI::Stack;
diff --git a/tests/gtests/blenlib/BLI_string_map_test.cc b/tests/gtests/blenlib/BLI_string_map_test.cc
index 4cb67d5fbac..6acad0ce581 100644
--- a/tests/gtests/blenlib/BLI_string_map_test.cc
+++ b/tests/gtests/blenlib/BLI_string_map_test.cc
@@ -1,5 +1,5 @@
-#include "BLI_string_map.h"
-#include "BLI_vector.h"
+#include "BLI_string_map.hh"
+#include "BLI_vector.hh"
#include "testing/testing.h"
using namespace BLI;
@@ -232,3 +232,44 @@ TEST(string_map, UniquePtrValues)
std::unique_ptr<int> *b = map.lookup_ptr("A");
EXPECT_EQ(a.get(), b->get());
}
+
+TEST(string_map, AddOrModify)
+{
+ StringMap<int> map;
+ auto create_func = [](int *value) {
+ *value = 10;
+ return true;
+ };
+ auto modify_func = [](int *value) {
+ *value += 5;
+ return false;
+ };
+ EXPECT_TRUE(map.add_or_modify("Hello", create_func, modify_func));
+ EXPECT_EQ(map.lookup("Hello"), 10);
+ EXPECT_FALSE(map.add_or_modify("Hello", create_func, modify_func));
+ EXPECT_EQ(map.lookup("Hello"), 15);
+}
+
+TEST(string_map, LookupOrAdd)
+{
+ StringMap<int> map;
+ auto return_5 = []() { return 5; };
+ auto return_8 = []() { return 8; };
+
+ int &a = map.lookup_or_add("A", return_5);
+ EXPECT_EQ(a, 5);
+ EXPECT_EQ(map.lookup_or_add("A", return_8), 5);
+ EXPECT_EQ(map.lookup_or_add("B", return_8), 8);
+}
+
+TEST(string_map, LookupOrAddDefault)
+{
+ StringMap<std::string> map;
+
+ std::string &a = map.lookup_or_add_default("A");
+ EXPECT_EQ(a.size(), 0);
+ a += "Test";
+ EXPECT_EQ(a.size(), 4);
+ std::string &b = map.lookup_or_add_default("A");
+ EXPECT_EQ(b, "Test");
+}
diff --git a/tests/gtests/blenlib/BLI_string_ref_test.cc b/tests/gtests/blenlib/BLI_string_ref_test.cc
index a268bf3215a..393f28d4fc1 100644
--- a/tests/gtests/blenlib/BLI_string_ref_test.cc
+++ b/tests/gtests/blenlib/BLI_string_ref_test.cc
@@ -1,5 +1,5 @@
-#include "BLI_string_ref.h"
-#include "BLI_vector.h"
+#include "BLI_string_ref.hh"
+#include "BLI_vector.hh"
#include "testing/testing.h"
using BLI::StringRef;
@@ -237,3 +237,14 @@ TEST(string_ref, Substr)
EXPECT_EQ(ref.substr(3, 4), "lo w");
EXPECT_EQ(ref.substr(6, 5), "world");
}
+
+TEST(string_ref, Copy)
+{
+ StringRef ref("hello");
+ char dst[10];
+ memset(dst, 0xFF, 10);
+ ref.copy(dst);
+ EXPECT_EQ(dst[5], '\0');
+ EXPECT_EQ(dst[6], 0xFF);
+ EXPECT_EQ(ref, dst);
+}
diff --git a/tests/gtests/blenlib/BLI_task_graph_test.cc b/tests/gtests/blenlib/BLI_task_graph_test.cc
new file mode 100644
index 00000000000..efcbf923625
--- /dev/null
+++ b/tests/gtests/blenlib/BLI_task_graph_test.cc
@@ -0,0 +1,188 @@
+/* Apache License, Version 2.0 */
+
+#include "testing/testing.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_task.h"
+
+struct TaskData {
+ int value;
+ int store;
+};
+
+static void TaskData_increase_value(void *taskdata)
+{
+ TaskData *data = (TaskData *)taskdata;
+ data->value += 1;
+}
+static void TaskData_decrease_value(void *taskdata)
+{
+ TaskData *data = (TaskData *)taskdata;
+ data->value -= 1;
+}
+static void TaskData_multiply_by_two_value(void *taskdata)
+{
+ TaskData *data = (TaskData *)taskdata;
+ data->value *= 2;
+}
+
+static void TaskData_multiply_by_two_store(void *taskdata)
+{
+ TaskData *data = (TaskData *)taskdata;
+ data->store *= 2;
+}
+
+static void TaskData_store_value(void *taskdata)
+{
+ TaskData *data = (TaskData *)taskdata;
+ data->store = data->value;
+}
+
+static void TaskData_square_value(void *taskdata)
+{
+ TaskData *data = (TaskData *)taskdata;
+ data->value *= data->value;
+}
+
+/* Sequential Test for using `BLI_task_graph` */
+TEST(task, GraphSequential)
+{
+ TaskData data = {0};
+ TaskGraph *graph = BLI_task_graph_create();
+
+ /* 0 => 1 */
+ TaskNode *node_a = BLI_task_graph_node_create(graph, TaskData_increase_value, &data, NULL);
+ /* 1 => 2 */
+ TaskNode *node_b = BLI_task_graph_node_create(
+ graph, TaskData_multiply_by_two_value, &data, NULL);
+ /* 2 => 1 */
+ TaskNode *node_c = BLI_task_graph_node_create(graph, TaskData_decrease_value, &data, NULL);
+ /* 2 => 1 */
+ TaskNode *node_d = BLI_task_graph_node_create(graph, TaskData_square_value, &data, NULL);
+ /* 1 => 1 */
+ TaskNode *node_e = BLI_task_graph_node_create(graph, TaskData_increase_value, &data, NULL);
+ /* 1 => 2 */
+ const int expected_value = 2;
+
+ BLI_task_graph_edge_create(node_a, node_b);
+ BLI_task_graph_edge_create(node_b, node_c);
+ BLI_task_graph_edge_create(node_c, node_d);
+ BLI_task_graph_edge_create(node_d, node_e);
+
+ EXPECT_TRUE(BLI_task_graph_node_push_work(node_a));
+ BLI_task_graph_work_and_wait(graph);
+
+ EXPECT_EQ(expected_value, data.value);
+ BLI_task_graph_free(graph);
+}
+
+TEST(task, GraphStartAtAnyNode)
+{
+ TaskData data = {4};
+ TaskGraph *graph = BLI_task_graph_create();
+
+ TaskNode *node_a = BLI_task_graph_node_create(graph, TaskData_increase_value, &data, NULL);
+ TaskNode *node_b = BLI_task_graph_node_create(
+ graph, TaskData_multiply_by_two_value, &data, NULL);
+ TaskNode *node_c = BLI_task_graph_node_create(graph, TaskData_decrease_value, &data, NULL);
+ TaskNode *node_d = BLI_task_graph_node_create(graph, TaskData_square_value, &data, NULL);
+ TaskNode *node_e = BLI_task_graph_node_create(graph, TaskData_increase_value, &data, NULL);
+
+ // ((4 - 1) * (4 - 1)) + 1
+ const int expected_value = 10;
+
+ BLI_task_graph_edge_create(node_a, node_b);
+ BLI_task_graph_edge_create(node_b, node_c);
+ BLI_task_graph_edge_create(node_c, node_d);
+ BLI_task_graph_edge_create(node_d, node_e);
+
+ EXPECT_TRUE(BLI_task_graph_node_push_work(node_c));
+ BLI_task_graph_work_and_wait(graph);
+
+ EXPECT_EQ(expected_value, data.value);
+ BLI_task_graph_free(graph);
+}
+
+TEST(task, GraphSplit)
+{
+ TaskData data = {1};
+
+ TaskGraph *graph = BLI_task_graph_create();
+ TaskNode *node_a = BLI_task_graph_node_create(graph, TaskData_increase_value, &data, NULL);
+ TaskNode *node_b = BLI_task_graph_node_create(graph, TaskData_store_value, &data, NULL);
+ TaskNode *node_c = BLI_task_graph_node_create(graph, TaskData_increase_value, &data, NULL);
+ TaskNode *node_d = BLI_task_graph_node_create(
+ graph, TaskData_multiply_by_two_store, &data, NULL);
+ BLI_task_graph_edge_create(node_a, node_b);
+ BLI_task_graph_edge_create(node_b, node_c);
+ BLI_task_graph_edge_create(node_b, node_d);
+ EXPECT_TRUE(BLI_task_graph_node_push_work(node_a));
+ BLI_task_graph_work_and_wait(graph);
+
+ EXPECT_EQ(3, data.value);
+ EXPECT_EQ(4, data.store);
+ BLI_task_graph_free(graph);
+}
+
+TEST(task, GraphForest)
+{
+ TaskData data1 = {1};
+ TaskData data2 = {3};
+
+ TaskGraph *graph = BLI_task_graph_create();
+
+ {
+ TaskNode *tree1_node_a = BLI_task_graph_node_create(
+ graph, TaskData_increase_value, &data1, NULL);
+ TaskNode *tree1_node_b = BLI_task_graph_node_create(graph, TaskData_store_value, &data1, NULL);
+ TaskNode *tree1_node_c = BLI_task_graph_node_create(
+ graph, TaskData_increase_value, &data1, NULL);
+ TaskNode *tree1_node_d = BLI_task_graph_node_create(
+ graph, TaskData_multiply_by_two_store, &data1, NULL);
+ BLI_task_graph_edge_create(tree1_node_a, tree1_node_b);
+ BLI_task_graph_edge_create(tree1_node_b, tree1_node_c);
+ BLI_task_graph_edge_create(tree1_node_b, tree1_node_d);
+ EXPECT_TRUE(BLI_task_graph_node_push_work(tree1_node_a));
+ }
+
+ {
+ TaskNode *tree2_node_a = BLI_task_graph_node_create(
+ graph, TaskData_increase_value, &data2, NULL);
+ TaskNode *tree2_node_b = BLI_task_graph_node_create(graph, TaskData_store_value, &data2, NULL);
+ TaskNode *tree2_node_c = BLI_task_graph_node_create(
+ graph, TaskData_increase_value, &data2, NULL);
+ TaskNode *tree2_node_d = BLI_task_graph_node_create(
+ graph, TaskData_multiply_by_two_store, &data2, NULL);
+ BLI_task_graph_edge_create(tree2_node_a, tree2_node_b);
+ BLI_task_graph_edge_create(tree2_node_b, tree2_node_c);
+ BLI_task_graph_edge_create(tree2_node_b, tree2_node_d);
+ EXPECT_TRUE(BLI_task_graph_node_push_work(tree2_node_a));
+ }
+
+ BLI_task_graph_work_and_wait(graph);
+
+ EXPECT_EQ(3, data1.value);
+ EXPECT_EQ(4, data1.store);
+ EXPECT_EQ(5, data2.value);
+ EXPECT_EQ(8, data2.store);
+ BLI_task_graph_free(graph);
+}
+
+TEST(task, GraphTaskData)
+{
+ TaskData data = {0};
+ TaskGraph *graph = BLI_task_graph_create();
+ TaskNode *node_a = BLI_task_graph_node_create(
+ graph, TaskData_store_value, &data, TaskData_increase_value);
+ TaskNode *node_b = BLI_task_graph_node_create(graph, TaskData_store_value, &data, NULL);
+ BLI_task_graph_edge_create(node_a, node_b);
+ EXPECT_TRUE(BLI_task_graph_node_push_work(node_a));
+ BLI_task_graph_work_and_wait(graph);
+ EXPECT_EQ(0, data.value);
+ EXPECT_EQ(0, data.store);
+ BLI_task_graph_free(graph);
+ /* data should be freed once */
+ EXPECT_EQ(1, data.value);
+ EXPECT_EQ(0, data.store);
+}
diff --git a/tests/gtests/blenlib/BLI_task_performance_test.cc b/tests/gtests/blenlib/BLI_task_performance_test.cc
index db596340464..06e832bdb5e 100644
--- a/tests/gtests/blenlib/BLI_task_performance_test.cc
+++ b/tests/gtests/blenlib/BLI_task_performance_test.cc
@@ -36,92 +36,6 @@ static uint gen_pseudo_random_number(uint num)
return ((num & 255) << 6) + 1;
}
-/* *** Parallel iterations over range of indices. *** */
-
-static void task_parallel_range_func(void *UNUSED(userdata),
- int index,
- const TaskParallelTLS *__restrict UNUSED(tls))
-{
- const uint limit = gen_pseudo_random_number((uint)index);
- for (uint i = (uint)index; i < limit;) {
- i += gen_pseudo_random_number(i);
- }
-}
-
-static void task_parallel_range_test_do(const char *id,
- const int num_items,
- const bool use_threads)
-{
- TaskParallelSettings settings;
- BLI_parallel_range_settings_defaults(&settings);
- settings.use_threading = use_threads;
-
- double averaged_timing = 0.0;
- for (int i = 0; i < NUM_RUN_AVERAGED; i++) {
- const double init_time = PIL_check_seconds_timer();
- for (int j = 0; j < 10; j++) {
- BLI_task_parallel_range(i + j, i + j + num_items, NULL, task_parallel_range_func, &settings);
- }
- averaged_timing += PIL_check_seconds_timer() - init_time;
- }
-
- printf("\t%s: non-pooled done in %fs on average over %d runs\n",
- id,
- averaged_timing / NUM_RUN_AVERAGED,
- NUM_RUN_AVERAGED);
-
- averaged_timing = 0.0;
- for (int i = 0; i < NUM_RUN_AVERAGED; i++) {
- const double init_time = PIL_check_seconds_timer();
- TaskParallelRangePool *range_pool = BLI_task_parallel_range_pool_init(&settings);
- for (int j = 0; j < 10; j++) {
- BLI_task_parallel_range_pool_push(
- range_pool, i + j, i + j + num_items, NULL, task_parallel_range_func, &settings);
- }
- BLI_task_parallel_range_pool_work_and_wait(range_pool);
- BLI_task_parallel_range_pool_free(range_pool);
- averaged_timing += PIL_check_seconds_timer() - init_time;
- }
-
- printf("\t%s: pooled done in %fs on average over %d runs\n",
- id,
- averaged_timing / NUM_RUN_AVERAGED,
- NUM_RUN_AVERAGED);
-}
-
-TEST(task, RangeIter10KNoThread)
-{
- task_parallel_range_test_do(
- "Range parallel iteration - Single thread - 10K items", 10000, false);
-}
-
-TEST(task, RangeIter10k)
-{
- task_parallel_range_test_do("Range parallel iteration - Threaded - 10K items", 10000, true);
-}
-
-TEST(task, RangeIter100KNoThread)
-{
- task_parallel_range_test_do(
- "Range parallel iteration - Single thread - 100K items", 100000, false);
-}
-
-TEST(task, RangeIter100k)
-{
- task_parallel_range_test_do("Range parallel iteration - Threaded - 100K items", 100000, true);
-}
-
-TEST(task, RangeIter1000KNoThread)
-{
- task_parallel_range_test_do(
- "Range parallel iteration - Single thread - 1000K items", 1000000, false);
-}
-
-TEST(task, RangeIter1000k)
-{
- task_parallel_range_test_do("Range parallel iteration - Threaded - 1000K items", 1000000, true);
-}
-
/* *** Parallel iterations over double-linked list items. *** */
static void task_listbase_light_iter_func(void *UNUSED(userdata),
diff --git a/tests/gtests/blenlib/BLI_task_test.cc b/tests/gtests/blenlib/BLI_task_test.cc
index d4ab9de13c4..ed300b3f238 100644
--- a/tests/gtests/blenlib/BLI_task_test.cc
+++ b/tests/gtests/blenlib/BLI_task_test.cc
@@ -27,17 +27,19 @@ static void task_range_iter_func(void *userdata, int index, const TaskParallelTL
// printf("%d, %d, %d\n", index, data[index], *((int *)tls->userdata_chunk));
}
-static void task_range_iter_finalize_func(void *__restrict userdata,
- void *__restrict userdata_chunk)
+static void task_range_iter_reduce_func(const void *__restrict UNUSED(userdata),
+ void *__restrict join_v,
+ void *__restrict userdata_chunk)
{
- int *data = (int *)userdata;
- data[NUM_ITEMS] += *(int *)userdata_chunk;
+ int *join = (int *)join_v;
+ int *chunk = (int *)userdata_chunk;
+ *join += *chunk;
// printf("%d, %d\n", data[NUM_ITEMS], *((int *)userdata_chunk));
}
TEST(task, RangeIter)
{
- int data[NUM_ITEMS + 1] = {0};
+ int data[NUM_ITEMS] = {0};
int sum = 0;
BLI_threadapi_init();
@@ -48,11 +50,11 @@ TEST(task, RangeIter)
settings.userdata_chunk = &sum;
settings.userdata_chunk_size = sizeof(sum);
- settings.func_finalize = task_range_iter_finalize_func;
+ settings.func_reduce = task_range_iter_reduce_func;
BLI_task_parallel_range(0, NUM_ITEMS, data, task_range_iter_func, &settings);
- /* Those checks should ensure us all items of the listbase were processed once, and only once -
+ /* Those checks should ensure us all items of the listbase were processed once, and only once
* as expected. */
int expected_sum = 0;
@@ -60,79 +62,7 @@ TEST(task, RangeIter)
EXPECT_EQ(data[i], i);
expected_sum += i;
}
- EXPECT_EQ(data[NUM_ITEMS], expected_sum);
-
- BLI_threadapi_exit();
-}
-
-TEST(task, RangeIterPool)
-{
- const int num_tasks = 10;
- int data[num_tasks][NUM_ITEMS + 1] = {{0}};
- int sum = 0;
-
- BLI_threadapi_init();
-
- TaskParallelSettings settings;
- BLI_parallel_range_settings_defaults(&settings);
- settings.min_iter_per_thread = 1;
-
- TaskParallelRangePool *range_pool = BLI_task_parallel_range_pool_init(&settings);
-
- for (int j = 0; j < num_tasks; j++) {
- settings.userdata_chunk = &sum;
- settings.userdata_chunk_size = sizeof(sum);
- settings.func_finalize = task_range_iter_finalize_func;
-
- BLI_task_parallel_range_pool_push(
- range_pool, 0, NUM_ITEMS, data[j], task_range_iter_func, &settings);
- }
-
- BLI_task_parallel_range_pool_work_and_wait(range_pool);
-
- /* Those checks should ensure us all items of the listbase were processed once, and only once -
- * as expected. */
-
- for (int j = 0; j < num_tasks; j++) {
- int expected_sum = 0;
- for (int i = 0; i < NUM_ITEMS; i++) {
- // EXPECT_EQ(data[j][i], i);
- expected_sum += i;
- }
- EXPECT_EQ(data[j][NUM_ITEMS], expected_sum);
- }
-
- /* A pool can be re-used untill it is freed. */
-
- for (int j = 0; j < num_tasks; j++) {
- memset(data[j], 0, sizeof(data[j]));
- }
- sum = 0;
-
- for (int j = 0; j < num_tasks; j++) {
- settings.userdata_chunk = &sum;
- settings.userdata_chunk_size = sizeof(sum);
- settings.func_finalize = task_range_iter_finalize_func;
-
- BLI_task_parallel_range_pool_push(
- range_pool, 0, NUM_ITEMS, data[j], task_range_iter_func, &settings);
- }
-
- BLI_task_parallel_range_pool_work_and_wait(range_pool);
-
- BLI_task_parallel_range_pool_free(range_pool);
-
- /* Those checks should ensure us all items of the listbase were processed once, and only once -
- * as expected. */
-
- for (int j = 0; j < num_tasks; j++) {
- int expected_sum = 0;
- for (int i = 0; i < NUM_ITEMS; i++) {
- // EXPECT_EQ(data[j][i], i);
- expected_sum += i;
- }
- EXPECT_EQ(data[j][NUM_ITEMS], expected_sum);
- }
+ EXPECT_EQ(sum, expected_sum);
BLI_threadapi_exit();
}
diff --git a/tests/gtests/blenlib/BLI_type_construct_mock.hh b/tests/gtests/blenlib/BLI_type_construct_mock.hh
new file mode 100644
index 00000000000..72767631608
--- /dev/null
+++ b/tests/gtests/blenlib/BLI_type_construct_mock.hh
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ */
+
+#ifndef __ANY_TYPE_MOCK_TEST_H__
+#define __ANY_TYPE_MOCK_TEST_H__
+
+#include "BLI_sys_types.h"
+
+class TypeConstructMock {
+ public:
+ bool default_constructed = false;
+ bool copy_constructed = false;
+ bool move_constructed = false;
+ bool copy_assigned = false;
+ bool move_assigned = false;
+
+ TypeConstructMock() : default_constructed(true)
+ {
+ }
+
+ TypeConstructMock(const TypeConstructMock &other) : copy_constructed(true)
+ {
+ }
+
+ TypeConstructMock(TypeConstructMock &&other) : move_constructed(true)
+ {
+ }
+
+ TypeConstructMock &operator=(const TypeConstructMock &other)
+ {
+ if (this == &other) {
+ return *this;
+ }
+
+ copy_assigned = true;
+ return *this;
+ }
+
+ TypeConstructMock &operator=(TypeConstructMock &&other)
+ {
+ if (this == &other) {
+ return *this;
+ }
+
+ move_assigned = true;
+ return *this;
+ }
+};
+
+#endif /* __ANY_TYPE_MOCK_TEST_H__ */
diff --git a/tests/gtests/blenlib/BLI_vector_set_test.cc b/tests/gtests/blenlib/BLI_vector_set_test.cc
index 5ec51337aa7..bfdd47ccb13 100644
--- a/tests/gtests/blenlib/BLI_vector_set_test.cc
+++ b/tests/gtests/blenlib/BLI_vector_set_test.cc
@@ -1,4 +1,4 @@
-#include "BLI_vector_set.h"
+#include "BLI_vector_set.hh"
#include "testing/testing.h"
using BLI::VectorSet;
@@ -8,6 +8,7 @@ TEST(vector_set, DefaultConstructor)
{
IntVectorSet set;
EXPECT_EQ(set.size(), 0);
+ EXPECT_TRUE(set.is_empty());
}
TEST(vector_set, InitializerListConstructor_WithoutDuplicates)
@@ -39,6 +40,17 @@ TEST(vector_set, Copy)
EXPECT_EQ(set2.index(2), 1);
}
+TEST(vector_set, CopyAssignment)
+{
+ IntVectorSet set1 = {1, 2, 3};
+ IntVectorSet set2 = {};
+ set2 = set1;
+ EXPECT_EQ(set1.size(), 3);
+ EXPECT_EQ(set2.size(), 3);
+ EXPECT_EQ(set1.index(2), 1);
+ EXPECT_EQ(set2.index(2), 1);
+}
+
TEST(vector_set, Move)
{
IntVectorSet set1 = {1, 2, 3};
@@ -47,11 +59,22 @@ TEST(vector_set, Move)
EXPECT_EQ(set2.size(), 3);
}
+TEST(vector_set, MoveAssignment)
+{
+ IntVectorSet set1 = {1, 2, 3};
+ IntVectorSet set2 = {};
+ set2 = std::move(set1);
+ EXPECT_EQ(set1.size(), 0);
+ EXPECT_EQ(set2.size(), 3);
+}
+
TEST(vector_set, AddNewIncreasesSize)
{
IntVectorSet set;
+ EXPECT_TRUE(set.is_empty());
EXPECT_EQ(set.size(), 0);
set.add(5);
+ EXPECT_FALSE(set.is_empty());
EXPECT_EQ(set.size(), 1);
}
diff --git a/tests/gtests/blenlib/BLI_vector_test.cc b/tests/gtests/blenlib/BLI_vector_test.cc
index 2402ee9627f..90180feba1f 100644
--- a/tests/gtests/blenlib/BLI_vector_test.cc
+++ b/tests/gtests/blenlib/BLI_vector_test.cc
@@ -1,19 +1,19 @@
-#include "BLI_vector.h"
+#include "BLI_type_construct_mock.hh"
+#include "BLI_vector.hh"
#include "testing/testing.h"
#include <forward_list>
using BLI::Vector;
-using IntVector = Vector<int>;
TEST(vector, DefaultConstructor)
{
- IntVector vec;
+ Vector<int> vec;
EXPECT_EQ(vec.size(), 0);
}
TEST(vector, SizeConstructor)
{
- IntVector vec(3);
+ Vector<int> vec(3);
EXPECT_EQ(vec.size(), 3);
EXPECT_EQ(vec[0], 0);
EXPECT_EQ(vec[1], 0);
@@ -22,7 +22,7 @@ TEST(vector, SizeConstructor)
TEST(vector, SizeValueConstructor)
{
- IntVector vec(4, 10);
+ Vector<int> vec(4, 10);
EXPECT_EQ(vec.size(), 4);
EXPECT_EQ(vec[0], 10);
EXPECT_EQ(vec[1], 10);
@@ -32,7 +32,7 @@ TEST(vector, SizeValueConstructor)
TEST(vector, InitializerListConstructor)
{
- IntVector vec = {1, 3, 4, 6};
+ Vector<int> vec = {1, 3, 4, 6};
EXPECT_EQ(vec.size(), 4);
EXPECT_EQ(vec[0], 1);
EXPECT_EQ(vec[1], 3);
@@ -45,7 +45,7 @@ struct TestListValue {
int value;
};
-TEST(vector, IntrusiveListBaseConstructor)
+TEST(vector, ListBaseConstructor)
{
TestListValue *value1 = new TestListValue{0, 0, 4};
TestListValue *value2 = new TestListValue{0, 0, 5};
@@ -55,7 +55,7 @@ TEST(vector, IntrusiveListBaseConstructor)
BLI_addtail(&list, value1);
BLI_addtail(&list, value2);
BLI_addtail(&list, value3);
- Vector<TestListValue *> vec(list, true);
+ Vector<TestListValue *> vec(list);
EXPECT_EQ(vec.size(), 3);
EXPECT_EQ(vec[0]->value, 4);
@@ -74,7 +74,7 @@ TEST(vector, ContainerConstructor)
list.push_front(1);
list.push_front(5);
- IntVector vec = IntVector::FromContainer(list);
+ Vector<int> vec = Vector<int>::FromContainer(list);
EXPECT_EQ(vec.size(), 3);
EXPECT_EQ(vec[0], 5);
EXPECT_EQ(vec[1], 1);
@@ -83,8 +83,8 @@ TEST(vector, ContainerConstructor)
TEST(vector, CopyConstructor)
{
- IntVector vec1 = {1, 2, 3};
- IntVector vec2(vec1);
+ Vector<int> vec1 = {1, 2, 3};
+ Vector<int> vec2(vec1);
EXPECT_EQ(vec2.size(), 3);
EXPECT_EQ(vec2[0], 1);
EXPECT_EQ(vec2[1], 2);
@@ -133,8 +133,8 @@ TEST(vector, CopyConstructor4)
TEST(vector, MoveConstructor)
{
- IntVector vec1 = {1, 2, 3, 4};
- IntVector vec2(std::move(vec1));
+ Vector<int> vec1 = {1, 2, 3, 4};
+ Vector<int> vec2(std::move(vec1));
EXPECT_EQ(vec1.size(), 0);
EXPECT_EQ(vec2.size(), 4);
@@ -179,20 +179,20 @@ TEST(vector, MoveConstructor4)
TEST(vector, MoveAssignment)
{
- IntVector vec = {1, 2};
+ Vector<int> vec = {1, 2};
EXPECT_EQ(vec.size(), 2);
EXPECT_EQ(vec[0], 1);
EXPECT_EQ(vec[1], 2);
- vec = IntVector({5});
+ vec = Vector<int>({5});
EXPECT_EQ(vec.size(), 1);
EXPECT_EQ(vec[0], 5);
}
TEST(vector, CopyAssignment)
{
- IntVector vec1 = {1, 2, 3};
- IntVector vec2 = {4, 5};
+ Vector<int> vec1 = {1, 2, 3};
+ Vector<int> vec2 = {4, 5};
EXPECT_EQ(vec1.size(), 3);
EXPECT_EQ(vec2.size(), 2);
@@ -206,7 +206,7 @@ TEST(vector, CopyAssignment)
TEST(vector, Append)
{
- IntVector vec;
+ Vector<int> vec;
vec.append(3);
vec.append(6);
vec.append(7);
@@ -218,7 +218,7 @@ TEST(vector, Append)
TEST(vector, AppendAndGetIndex)
{
- IntVector vec;
+ Vector<int> vec;
EXPECT_EQ(vec.append_and_get_index(10), 0);
EXPECT_EQ(vec.append_and_get_index(10), 1);
EXPECT_EQ(vec.append_and_get_index(10), 2);
@@ -228,7 +228,7 @@ TEST(vector, AppendAndGetIndex)
TEST(vector, AppendNonDuplicates)
{
- IntVector vec;
+ Vector<int> vec;
vec.append_non_duplicates(4);
EXPECT_EQ(vec.size(), 1);
vec.append_non_duplicates(5);
@@ -239,7 +239,7 @@ TEST(vector, AppendNonDuplicates)
TEST(vector, ExtendNonDuplicates)
{
- IntVector vec;
+ Vector<int> vec;
vec.extend_non_duplicates({1, 2});
EXPECT_EQ(vec.size(), 2);
vec.extend_non_duplicates({3, 4});
@@ -250,7 +250,7 @@ TEST(vector, ExtendNonDuplicates)
TEST(vector, Fill)
{
- IntVector vec(5);
+ Vector<int> vec(5);
vec.fill(3);
EXPECT_EQ(vec.size(), 5);
EXPECT_EQ(vec[0], 3);
@@ -262,7 +262,7 @@ TEST(vector, Fill)
TEST(vector, FillIndices)
{
- IntVector vec(5, 0);
+ Vector<int> vec(5, 0);
vec.fill_indices({1, 2}, 4);
EXPECT_EQ(vec[0], 0);
EXPECT_EQ(vec[1], 4);
@@ -273,7 +273,7 @@ TEST(vector, FillIndices)
TEST(vector, Iterator)
{
- IntVector vec({1, 4, 9, 16});
+ Vector<int> vec({1, 4, 9, 16});
int i = 1;
for (int value : vec) {
EXPECT_EQ(value, i * i);
@@ -293,14 +293,14 @@ TEST(vector, BecomeLarge)
}
}
-static IntVector return_by_value_helper()
+static Vector<int> return_by_value_helper()
{
- return IntVector({3, 5, 1});
+ return Vector<int>({3, 5, 1});
}
TEST(vector, ReturnByValue)
{
- IntVector vec = return_by_value_helper();
+ Vector<int> vec = return_by_value_helper();
EXPECT_EQ(vec.size(), 3);
EXPECT_EQ(vec[0], 3);
EXPECT_EQ(vec[1], 5);
@@ -309,10 +309,10 @@ TEST(vector, ReturnByValue)
TEST(vector, VectorOfVectors_Append)
{
- Vector<IntVector> vec;
+ Vector<Vector<int>> vec;
EXPECT_EQ(vec.size(), 0);
- IntVector v({1, 2});
+ Vector<int> v({1, 2});
vec.append(v);
vec.append({7, 8});
EXPECT_EQ(vec.size(), 2);
@@ -324,7 +324,7 @@ TEST(vector, VectorOfVectors_Append)
TEST(vector, VectorOfVectors_Fill)
{
- Vector<IntVector> vec(3);
+ Vector<Vector<int>> vec(3);
vec.fill({4, 5});
EXPECT_EQ(vec[0][0], 4);
@@ -337,7 +337,7 @@ TEST(vector, VectorOfVectors_Fill)
TEST(vector, RemoveLast)
{
- IntVector vec = {5, 6};
+ Vector<int> vec = {5, 6};
EXPECT_EQ(vec.size(), 2);
vec.remove_last();
EXPECT_EQ(vec.size(), 1);
@@ -345,19 +345,19 @@ TEST(vector, RemoveLast)
EXPECT_EQ(vec.size(), 0);
}
-TEST(vector, Empty)
+TEST(vector, IsEmpty)
{
- IntVector vec;
- EXPECT_TRUE(vec.empty());
+ Vector<int> vec;
+ EXPECT_TRUE(vec.is_empty());
vec.append(1);
- EXPECT_FALSE(vec.empty());
+ EXPECT_FALSE(vec.is_empty());
vec.remove_last();
- EXPECT_TRUE(vec.empty());
+ EXPECT_TRUE(vec.is_empty());
}
TEST(vector, RemoveReorder)
{
- IntVector vec = {4, 5, 6, 7};
+ Vector<int> vec = {4, 5, 6, 7};
vec.remove_and_reorder(1);
EXPECT_EQ(vec[0], 4);
EXPECT_EQ(vec[1], 7);
@@ -368,12 +368,12 @@ TEST(vector, RemoveReorder)
vec.remove_and_reorder(0);
EXPECT_EQ(vec[0], 7);
vec.remove_and_reorder(0);
- EXPECT_TRUE(vec.empty());
+ EXPECT_TRUE(vec.is_empty());
}
TEST(vector, RemoveFirstOccurrenceAndReorder)
{
- IntVector vec = {4, 5, 6, 7};
+ Vector<int> vec = {4, 5, 6, 7};
vec.remove_first_occurrence_and_reorder(5);
EXPECT_EQ(vec[0], 4);
EXPECT_EQ(vec[1], 7);
@@ -389,24 +389,24 @@ TEST(vector, RemoveFirstOccurrenceAndReorder)
TEST(vector, AllEqual_False)
{
- IntVector a = {1, 2, 3};
- IntVector b = {1, 2, 4};
- bool result = IntVector::all_equal(a, b);
+ Vector<int> a = {1, 2, 3};
+ Vector<int> b = {1, 2, 4};
+ bool result = Vector<int>::all_equal(a, b);
EXPECT_FALSE(result);
}
TEST(vector, AllEqual_True)
{
- IntVector a = {4, 5, 6};
- IntVector b = {4, 5, 6};
- bool result = IntVector::all_equal(a, b);
+ Vector<int> a = {4, 5, 6};
+ Vector<int> b = {4, 5, 6};
+ bool result = Vector<int>::all_equal(a, b);
EXPECT_TRUE(result);
}
TEST(vector, ExtendSmallVector)
{
- IntVector a = {2, 3, 4};
- IntVector b = {11, 12};
+ Vector<int> a = {2, 3, 4};
+ Vector<int> b = {11, 12};
b.extend(a);
EXPECT_EQ(b.size(), 5);
EXPECT_EQ(b[0], 11);
@@ -420,7 +420,7 @@ TEST(vector, ExtendArray)
{
int array[] = {3, 4, 5, 6};
- IntVector a;
+ Vector<int> a;
a.extend(array, 2);
EXPECT_EQ(a.size(), 2);
@@ -430,13 +430,13 @@ TEST(vector, ExtendArray)
TEST(vector, Last)
{
- IntVector a{3, 5, 7};
+ Vector<int> a{3, 5, 7};
EXPECT_EQ(a.last(), 7);
}
TEST(vector, AppendNTimes)
{
- IntVector a;
+ Vector<int> a;
a.append_n_times(5, 3);
a.append_n_times(2, 2);
EXPECT_EQ(a.size(), 5);
@@ -460,3 +460,68 @@ TEST(vector, UniquePtrValue)
UNUSED_VARS(a, b);
}
+
+TEST(vector, SizeConstructorCallsDefaultConstructor)
+{
+ Vector<TypeConstructMock> vec(3);
+ EXPECT_TRUE(vec[0].default_constructed);
+ EXPECT_TRUE(vec[1].default_constructed);
+ EXPECT_TRUE(vec[2].default_constructed);
+}
+
+TEST(vector, SizeValueConstructorCallsCopyConstructor)
+{
+ Vector<TypeConstructMock> vec(3, TypeConstructMock());
+ EXPECT_TRUE(vec[0].copy_constructed);
+ EXPECT_TRUE(vec[1].copy_constructed);
+ EXPECT_TRUE(vec[2].copy_constructed);
+}
+
+TEST(vector, AppendCallsCopyConstructor)
+{
+ Vector<TypeConstructMock> vec;
+ TypeConstructMock value;
+ vec.append(value);
+ EXPECT_TRUE(vec[0].copy_constructed);
+}
+
+TEST(vector, AppendCallsMoveConstructor)
+{
+ Vector<TypeConstructMock> vec;
+ vec.append(TypeConstructMock());
+ EXPECT_TRUE(vec[0].move_constructed);
+}
+
+TEST(vector, SmallVectorCopyCallsCopyConstructor)
+{
+ Vector<TypeConstructMock, 2> src(2);
+ Vector<TypeConstructMock, 2> dst(src);
+ EXPECT_TRUE(dst[0].copy_constructed);
+ EXPECT_TRUE(dst[1].copy_constructed);
+}
+
+TEST(vector, LargeVectorCopyCallsCopyConstructor)
+{
+ Vector<TypeConstructMock, 2> src(5);
+ Vector<TypeConstructMock, 2> dst(src);
+ EXPECT_TRUE(dst[0].copy_constructed);
+ EXPECT_TRUE(dst[1].copy_constructed);
+}
+
+TEST(vector, SmallVectorMoveCallsMoveConstructor)
+{
+ Vector<TypeConstructMock, 2> src(2);
+ Vector<TypeConstructMock, 2> dst(std::move(src));
+ EXPECT_TRUE(dst[0].move_constructed);
+ EXPECT_TRUE(dst[1].move_constructed);
+}
+
+TEST(vector, LargeVectorMoveCallsNoConstructor)
+{
+ Vector<TypeConstructMock, 2> src(5);
+ Vector<TypeConstructMock, 2> dst(std::move(src));
+
+ EXPECT_TRUE(dst[0].default_constructed);
+ EXPECT_FALSE(dst[0].move_constructed);
+ EXPECT_FALSE(dst[0].copy_constructed);
+}
diff --git a/tests/gtests/blenlib/CMakeLists.txt b/tests/gtests/blenlib/CMakeLists.txt
index 119b54fa0d4..6fbb304581d 100644
--- a/tests/gtests/blenlib/CMakeLists.txt
+++ b/tests/gtests/blenlib/CMakeLists.txt
@@ -52,6 +52,7 @@ BLENDER_TEST(BLI_heap "bf_blenlib")
BLENDER_TEST(BLI_heap_simple "bf_blenlib")
BLENDER_TEST(BLI_index_range "bf_blenlib")
BLENDER_TEST(BLI_kdopbvh "bf_blenlib;bf_intern_numaapi")
+BLENDER_TEST(BLI_linear_allocator "bf_blenlib")
BLENDER_TEST(BLI_linklist_lockfree "bf_blenlib;bf_intern_numaapi")
BLENDER_TEST(BLI_listbase "bf_blenlib")
BLENDER_TEST(BLI_map "bf_blenlib")
@@ -71,6 +72,7 @@ BLENDER_TEST(BLI_string_map "bf_blenlib")
BLENDER_TEST(BLI_string_ref "bf_blenlib")
BLENDER_TEST(BLI_string_utf8 "bf_blenlib")
BLENDER_TEST(BLI_task "bf_blenlib;bf_intern_numaapi")
+BLENDER_TEST(BLI_task_graph "bf_blenlib;bf_intern_numaapi")
BLENDER_TEST(BLI_vector "bf_blenlib")
BLENDER_TEST(BLI_vector_set "bf_blenlib")
diff --git a/tests/gtests/usd/abstract_hierarchy_iterator_test.cc b/tests/gtests/usd/abstract_hierarchy_iterator_test.cc
index 56d8100c30a..160dd52f39a 100644
--- a/tests/gtests/usd/abstract_hierarchy_iterator_test.cc
+++ b/tests/gtests/usd/abstract_hierarchy_iterator_test.cc
@@ -29,7 +29,7 @@ extern "C" {
#include <set>
/* Mapping from ID.name to set of export hierarchy path. Duplicated objects can be exported
- * multiple times, hence the set. */
+ * multiple times with different export paths, hence the set. */
typedef std::map<std::string, std::set<std::string>> created_writers;
using namespace USD;
diff --git a/tests/gtests/usd/hierarchy_context_order_test.cc b/tests/gtests/usd/hierarchy_context_order_test.cc
index 2068ea26227..4111fc7511e 100644
--- a/tests/gtests/usd/hierarchy_context_order_test.cc
+++ b/tests/gtests/usd/hierarchy_context_order_test.cc
@@ -44,9 +44,9 @@ TEST_F(HierarchyContextOrderTest, ObjectPointerTest)
ctx_b.object = fake_pointer(2);
ctx_b.duplicator = nullptr;
- EXPECT_EQ(true, ctx_a < ctx_b);
- EXPECT_EQ(false, ctx_b < ctx_a);
- EXPECT_EQ(false, ctx_a < ctx_a);
+ EXPECT_LT(ctx_a, ctx_b);
+ EXPECT_FALSE(ctx_b < ctx_a);
+ EXPECT_FALSE(ctx_a < ctx_a);
}
TEST_F(HierarchyContextOrderTest, DuplicatorPointerTest)
@@ -61,9 +61,9 @@ TEST_F(HierarchyContextOrderTest, DuplicatorPointerTest)
ctx_b.duplicator = fake_pointer(1);
ctx_b.export_name = "B";
- EXPECT_EQ(true, ctx_a < ctx_b);
- EXPECT_EQ(false, ctx_b < ctx_a);
- EXPECT_EQ(false, ctx_a < ctx_a);
+ EXPECT_LT(ctx_a, ctx_b);
+ EXPECT_FALSE(ctx_b < ctx_a);
+ EXPECT_FALSE(ctx_a < ctx_a);
}
TEST_F(HierarchyContextOrderTest, ExportParentTest)
@@ -76,9 +76,9 @@ TEST_F(HierarchyContextOrderTest, ExportParentTest)
ctx_b.object = fake_pointer(1);
ctx_b.export_parent = fake_pointer(2);
- EXPECT_EQ(true, ctx_a < ctx_b);
- EXPECT_EQ(false, ctx_b < ctx_a);
- EXPECT_EQ(false, ctx_a < ctx_a);
+ EXPECT_LT(ctx_a, ctx_b);
+ EXPECT_FALSE(ctx_b < ctx_a);
+ EXPECT_FALSE(ctx_a < ctx_a);
}
TEST_F(HierarchyContextOrderTest, TransitiveTest)
@@ -107,17 +107,17 @@ TEST_F(HierarchyContextOrderTest, TransitiveTest)
ctx_d.duplicator = nullptr;
ctx_d.export_name = "D";
- EXPECT_EQ(true, ctx_a < ctx_b);
- EXPECT_EQ(true, ctx_a < ctx_c);
- EXPECT_EQ(true, ctx_a < ctx_d);
- EXPECT_EQ(true, ctx_b < ctx_c);
- EXPECT_EQ(true, ctx_b < ctx_d);
- EXPECT_EQ(true, ctx_c < ctx_d);
-
- EXPECT_EQ(false, ctx_b < ctx_a);
- EXPECT_EQ(false, ctx_c < ctx_a);
- EXPECT_EQ(false, ctx_d < ctx_a);
- EXPECT_EQ(false, ctx_c < ctx_b);
- EXPECT_EQ(false, ctx_d < ctx_b);
- EXPECT_EQ(false, ctx_d < ctx_c);
+ EXPECT_LT(ctx_a, ctx_b);
+ EXPECT_LT(ctx_a, ctx_c);
+ EXPECT_LT(ctx_a, ctx_d);
+ EXPECT_LT(ctx_b, ctx_c);
+ EXPECT_LT(ctx_b, ctx_d);
+ EXPECT_LT(ctx_c, ctx_d);
+
+ EXPECT_FALSE(ctx_b < ctx_a);
+ EXPECT_FALSE(ctx_c < ctx_a);
+ EXPECT_FALSE(ctx_d < ctx_a);
+ EXPECT_FALSE(ctx_c < ctx_b);
+ EXPECT_FALSE(ctx_d < ctx_b);
+ EXPECT_FALSE(ctx_d < ctx_c);
}
diff --git a/tests/python/CMakeLists.txt b/tests/python/CMakeLists.txt
index 2d6dc4af40e..a3df01fdbe2 100644
--- a/tests/python/CMakeLists.txt
+++ b/tests/python/CMakeLists.txt
@@ -48,18 +48,14 @@ endfunction()
# Run Python script outside Blender.
function(add_python_test testname testscript)
- if(MSVC)
- add_test(
- NAME ${testname}
- COMMAND ${TEST_PYTHON_EXE} ${testscript} ${ARGN}
- )
- else()
- add_test(
- NAME ${testname}
- COMMAND ${testscript} ${ARGN}
- )
+ if(NOT TEST_PYTHON_EXE)
+ message(FATAL_ERROR "No Python configured for running tests, set TEST_PYTHON_EXE.")
endif()
+ add_test(
+ NAME ${testname}
+ COMMAND ${TEST_PYTHON_EXE} ${testscript} ${ARGN}
+ )
set_tests_properties(${testname} PROPERTIES ENVIRONMENT LSAN_OPTIONS=exitcode=0)
endfunction()
diff --git a/tests/python/alembic_tests.py b/tests/python/alembic_tests.py
index 9de1bc06d84..8c0315f1b68 100755..100644
--- a/tests/python/alembic_tests.py
+++ b/tests/python/alembic_tests.py
@@ -76,7 +76,7 @@ class AbstractAlembicTest(AbstractBlenderRunnerTest):
output = output.replace('\r\n', '\n').replace('\r', '\n')
if proc.returncode:
- raise AbcPropError('Error %d running abcls:\n%s' % (proc.returncode, output))
+ raise AbcPropError('Error %d running %s:\n%s' % (proc.returncode, ' '.join(command), output))
# Mapping from value type to callable that can convert a string to Python values.
converters = {
diff --git a/tests/python/cycles_render_tests.py b/tests/python/cycles_render_tests.py
index 79ba11fdd44..79ba11fdd44 100755..100644
--- a/tests/python/cycles_render_tests.py
+++ b/tests/python/cycles_render_tests.py
diff --git a/tests/python/eevee_render_tests.py b/tests/python/eevee_render_tests.py
index a7130136d0a..a7130136d0a 100755..100644
--- a/tests/python/eevee_render_tests.py
+++ b/tests/python/eevee_render_tests.py
diff --git a/tests/python/ffmpeg_tests.py b/tests/python/ffmpeg_tests.py
index 92734b5bc7d..92734b5bc7d 100755..100644
--- a/tests/python/ffmpeg_tests.py
+++ b/tests/python/ffmpeg_tests.py
diff --git a/tests/python/opengl_draw_tests.py b/tests/python/opengl_draw_tests.py
index ab4df63afd9..ab4df63afd9 100755..100644
--- a/tests/python/opengl_draw_tests.py
+++ b/tests/python/opengl_draw_tests.py
diff --git a/tests/python/workbench_render_tests.py b/tests/python/workbench_render_tests.py
index 155b54098a8..155b54098a8 100755..100644
--- a/tests/python/workbench_render_tests.py
+++ b/tests/python/workbench_render_tests.py