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:
authorCampbell Barton <ideasman42@gmail.com>2019-04-17 07:17:24 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-04-17 07:21:24 +0300
commite12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch)
tree8cf3453d12edb177a218ef8009357518ec6cab6a /tests
parentb3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff)
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211. For details on usage and instructions for migrating branches without conflicts, see: https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'tests')
-rw-r--r--tests/gtests/CMakeLists.txt26
-rw-r--r--tests/gtests/alembic/CMakeLists.txt30
-rw-r--r--tests/gtests/alembic/abc_export_test.cc256
-rw-r--r--tests/gtests/alembic/abc_matrix_test.cc514
-rw-r--r--tests/gtests/blenlib/BLI_array_store_test.cc1185
-rw-r--r--tests/gtests/blenlib/BLI_array_utils_test.cc182
-rw-r--r--tests/gtests/blenlib/BLI_edgehash_test.cc440
-rw-r--r--tests/gtests/blenlib/BLI_expr_pylike_eval_test.cc144
-rw-r--r--tests/gtests/blenlib/BLI_ghash_performance_test.cc574
-rw-r--r--tests/gtests/blenlib/BLI_ghash_test.cc247
-rw-r--r--tests/gtests/blenlib/BLI_hash_mm2a_test.cc74
-rw-r--r--tests/gtests/blenlib/BLI_heap_simple_test.cc151
-rw-r--r--tests/gtests/blenlib/BLI_heap_test.cc307
-rw-r--r--tests/gtests/blenlib/BLI_kdopbvh_test.cc141
-rw-r--r--tests/gtests/blenlib/BLI_linklist_lockfree_test.cc174
-rw-r--r--tests/gtests/blenlib/BLI_listbase_test.cc384
-rw-r--r--tests/gtests/blenlib/BLI_math_base_test.cc92
-rw-r--r--tests/gtests/blenlib/BLI_math_color_test.cc94
-rw-r--r--tests/gtests/blenlib/BLI_math_geom_test.cc16
-rw-r--r--tests/gtests/blenlib/BLI_memiter_test.cc340
-rw-r--r--tests/gtests/blenlib/BLI_path_util_test.cc681
-rw-r--r--tests/gtests/blenlib/BLI_polyfill_2d_test.cc714
-rw-r--r--tests/gtests/blenlib/BLI_ressource_strings.h2
-rw-r--r--tests/gtests/blenlib/BLI_stack_test.cc299
-rw-r--r--tests/gtests/blenlib/BLI_string_test.cc894
-rw-r--r--tests/gtests/blenlib/BLI_string_utf8_test.cc27
-rw-r--r--tests/gtests/blenlib/BLI_task_test.cc110
-rw-r--r--tests/gtests/blenlib/CMakeLists.txt16
-rw-r--r--tests/gtests/blenlib/stubs/bf_intern_eigen_stubs.h16
-rw-r--r--tests/gtests/bmesh/CMakeLists.txt20
-rw-r--r--tests/gtests/bmesh/bmesh_core_test.cc63
-rw-r--r--tests/gtests/guardedalloc/CMakeLists.txt8
-rw-r--r--tests/gtests/guardedalloc/guardedalloc_alignment_test.cc32
-rw-r--r--tests/gtests/guardedalloc/guardedalloc_overflow_test.cc56
-rw-r--r--tests/gtests/testing/CMakeLists.txt14
-rw-r--r--tests/gtests/testing/mock_log.h31
-rw-r--r--tests/gtests/testing/testing.h145
-rw-r--r--tests/gtests/testing/testing_main.cc3
38 files changed, 4407 insertions, 4095 deletions
diff --git a/tests/gtests/CMakeLists.txt b/tests/gtests/CMakeLists.txt
index 3ab64d87309..285b414e997 100644
--- a/tests/gtests/CMakeLists.txt
+++ b/tests/gtests/CMakeLists.txt
@@ -2,20 +2,20 @@
# GTest
if(WITH_GTESTS)
- include(GTestTesting)
+ include(GTestTesting)
- add_definitions(${GFLAGS_DEFINES})
- add_definitions(${GLOG_DEFINES})
- add_definitions(-DBLENDER_GFLAGS_NAMESPACE=${GFLAGS_NAMESPACE})
+ 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()
+ # Otherwise we get warnings here that we cant fix in external projects
+ remove_strict_flags()
- add_subdirectory(testing)
- add_subdirectory(blenlib)
- add_subdirectory(guardedalloc)
- add_subdirectory(bmesh)
- if(WITH_ALEMBIC)
- add_subdirectory(alembic)
- endif()
+ add_subdirectory(testing)
+ add_subdirectory(blenlib)
+ add_subdirectory(guardedalloc)
+ add_subdirectory(bmesh)
+ if(WITH_ALEMBIC)
+ add_subdirectory(alembic)
+ endif()
endif()
diff --git a/tests/gtests/alembic/CMakeLists.txt b/tests/gtests/alembic/CMakeLists.txt
index d401f57eff8..1eaefe6d91d 100644
--- a/tests/gtests/alembic/CMakeLists.txt
+++ b/tests/gtests/alembic/CMakeLists.txt
@@ -19,22 +19,22 @@
# ***** END GPL LICENSE BLOCK *****
set(INC
- .
- ..
- ../../../source/blender/blenlib
- ../../../source/blender/blenkernel
- ../../../source/blender/alembic
- ../../../source/blender/makesdna
- ../../../source/blender/depsgraph
- ${ALEMBIC_INCLUDE_DIRS}
- ${BOOST_INCLUDE_DIR}
- ${HDF5_INCLUDE_DIRS}
- ${OPENEXR_INCLUDE_DIRS}
+ .
+ ..
+ ../../../source/blender/blenlib
+ ../../../source/blender/blenkernel
+ ../../../source/blender/alembic
+ ../../../source/blender/makesdna
+ ../../../source/blender/depsgraph
+ ${ALEMBIC_INCLUDE_DIRS}
+ ${BOOST_INCLUDE_DIR}
+ ${HDF5_INCLUDE_DIRS}
+ ${OPENEXR_INCLUDE_DIRS}
)
set(LIB
- bf_blenloader # Should not be needed but gives linking error without it.
- bf_alembic
+ bf_blenloader # Should not be needed but gives linking error without it.
+ bf_alembic
)
include_directories(${INC})
@@ -43,9 +43,9 @@ setup_libdirs()
get_property(BLENDER_SORTED_LIBS GLOBAL PROPERTY BLENDER_SORTED_LIBS_PROP)
if(WITH_BUILDINFO)
- set(_buildinfo_src "$<TARGET_OBJECTS:buildinfoobj>")
+ set(_buildinfo_src "$<TARGET_OBJECTS:buildinfoobj>")
else()
- set(_buildinfo_src "")
+ set(_buildinfo_src "")
endif()
# For motivation on doubling BLENDER_SORTED_LIBS, see ../bmesh/CMakeLists.txt
diff --git a/tests/gtests/alembic/abc_export_test.cc b/tests/gtests/alembic/abc_export_test.cc
index ac7760d1541..f8010b02c96 100644
--- a/tests/gtests/alembic/abc_export_test.cc
+++ b/tests/gtests/alembic/abc_export_test.cc
@@ -14,139 +14,137 @@ extern "C" {
#include "DEG_depsgraph.h"
class TestableAbcExporter : public AbcExporter {
-public:
- TestableAbcExporter(Main *bmain,
- const char *filename, ExportSettings &settings)
- : AbcExporter(bmain, filename, settings)
- {
- }
-
- void getShutterSamples(unsigned int nr_of_samples,
- bool time_relative,
- std::vector<double> &samples)
- {
- AbcExporter::getShutterSamples(nr_of_samples, time_relative, samples);
- }
-
- void getFrameSet(unsigned int nr_of_samples,
- std::set<double> &frames) {
- AbcExporter::getFrameSet(nr_of_samples, frames);
- }
+ public:
+ TestableAbcExporter(Main *bmain, const char *filename, ExportSettings &settings)
+ : AbcExporter(bmain, filename, settings)
+ {
+ }
+
+ void getShutterSamples(unsigned int nr_of_samples,
+ bool time_relative,
+ std::vector<double> &samples)
+ {
+ AbcExporter::getShutterSamples(nr_of_samples, time_relative, samples);
+ }
+
+ void getFrameSet(unsigned int nr_of_samples, std::set<double> &frames)
+ {
+ AbcExporter::getFrameSet(nr_of_samples, frames);
+ }
};
-class AlembicExportTest : public testing::Test
-{
-protected:
- ExportSettings settings;
- Scene scene;
- Depsgraph *depsgraph;
- TestableAbcExporter *exporter;
- Main *bmain;
-
- virtual void SetUp()
- {
- settings.frame_start = 31.0;
- settings.frame_end = 223.0;
-
- /* Fake a 25 FPS scene with a nonzero base (because that's sometimes forgotten) */
- scene.r.frs_sec = 50;
- scene.r.frs_sec_base = 2;
-
- bmain = BKE_main_new();
-
- /* TODO(sergey): Pass scene layer somehow? */
- ViewLayer *view_layer = (ViewLayer *)scene.view_layers.first;
- settings.depsgraph = depsgraph = DEG_graph_new(&scene, view_layer, DAG_EVAL_VIEWPORT);
-
- settings.scene = &scene;
- settings.view_layer = view_layer;
-
- exporter = NULL;
- }
-
- virtual void TearDown()
- {
- BKE_main_free(bmain);
- DEG_graph_free(depsgraph);
- delete exporter;
- }
-
- // Call after setting up the settings.
- void createExporter()
- {
- exporter = new TestableAbcExporter(bmain, "somefile.abc", settings);
- }
+class AlembicExportTest : public testing::Test {
+ protected:
+ ExportSettings settings;
+ Scene scene;
+ Depsgraph *depsgraph;
+ TestableAbcExporter *exporter;
+ Main *bmain;
+
+ virtual void SetUp()
+ {
+ settings.frame_start = 31.0;
+ settings.frame_end = 223.0;
+
+ /* Fake a 25 FPS scene with a nonzero base (because that's sometimes forgotten) */
+ scene.r.frs_sec = 50;
+ scene.r.frs_sec_base = 2;
+
+ bmain = BKE_main_new();
+
+ /* TODO(sergey): Pass scene layer somehow? */
+ ViewLayer *view_layer = (ViewLayer *)scene.view_layers.first;
+ settings.depsgraph = depsgraph = DEG_graph_new(&scene, view_layer, DAG_EVAL_VIEWPORT);
+
+ settings.scene = &scene;
+ settings.view_layer = view_layer;
+
+ exporter = NULL;
+ }
+
+ virtual void TearDown()
+ {
+ BKE_main_free(bmain);
+ DEG_graph_free(depsgraph);
+ delete exporter;
+ }
+
+ // Call after setting up the settings.
+ void createExporter()
+ {
+ exporter = new TestableAbcExporter(bmain, "somefile.abc", settings);
+ }
};
-
-TEST_F(AlembicExportTest, TimeSamplesFullShutter) {
- settings.shutter_open = 0.0;
- settings.shutter_close = 1.0;
-
- createExporter();
- std::vector<double> samples;
-
- /* test 5 samples per frame */
- exporter->getShutterSamples(5, true, samples);
- EXPECT_EQ(5, samples.size());
- EXPECT_NEAR(1.240, samples[0], 1e-5f);
- EXPECT_NEAR(1.248, samples[1], 1e-5f);
- EXPECT_NEAR(1.256, samples[2], 1e-5f);
- EXPECT_NEAR(1.264, samples[3], 1e-5f);
- EXPECT_NEAR(1.272, samples[4], 1e-5f);
-
- /* test same, but using frame number offset instead of time */
- exporter->getShutterSamples(5, false, samples);
- EXPECT_EQ(5, samples.size());
- EXPECT_NEAR(0.0, samples[0], 1e-5f);
- EXPECT_NEAR(0.2, samples[1], 1e-5f);
- EXPECT_NEAR(0.4, samples[2], 1e-5f);
- EXPECT_NEAR(0.6, samples[3], 1e-5f);
- EXPECT_NEAR(0.8, samples[4], 1e-5f);
-
- /* use the same setup to test getFrameSet() */
- std::set<double> frames;
- exporter->getFrameSet(5, frames);
- EXPECT_EQ(965, frames.size());
- EXPECT_EQ(1, frames.count(31.0));
- EXPECT_EQ(1, frames.count(31.2));
- EXPECT_EQ(1, frames.count(31.4));
- EXPECT_EQ(1, frames.count(31.6));
- EXPECT_EQ(1, frames.count(31.8));
+TEST_F(AlembicExportTest, TimeSamplesFullShutter)
+{
+ settings.shutter_open = 0.0;
+ settings.shutter_close = 1.0;
+
+ createExporter();
+ std::vector<double> samples;
+
+ /* test 5 samples per frame */
+ exporter->getShutterSamples(5, true, samples);
+ EXPECT_EQ(5, samples.size());
+ EXPECT_NEAR(1.240, samples[0], 1e-5f);
+ EXPECT_NEAR(1.248, samples[1], 1e-5f);
+ EXPECT_NEAR(1.256, samples[2], 1e-5f);
+ EXPECT_NEAR(1.264, samples[3], 1e-5f);
+ EXPECT_NEAR(1.272, samples[4], 1e-5f);
+
+ /* test same, but using frame number offset instead of time */
+ exporter->getShutterSamples(5, false, samples);
+ EXPECT_EQ(5, samples.size());
+ EXPECT_NEAR(0.0, samples[0], 1e-5f);
+ EXPECT_NEAR(0.2, samples[1], 1e-5f);
+ EXPECT_NEAR(0.4, samples[2], 1e-5f);
+ EXPECT_NEAR(0.6, samples[3], 1e-5f);
+ EXPECT_NEAR(0.8, samples[4], 1e-5f);
+
+ /* use the same setup to test getFrameSet() */
+ std::set<double> frames;
+ exporter->getFrameSet(5, frames);
+ EXPECT_EQ(965, frames.size());
+ EXPECT_EQ(1, frames.count(31.0));
+ EXPECT_EQ(1, frames.count(31.2));
+ EXPECT_EQ(1, frames.count(31.4));
+ EXPECT_EQ(1, frames.count(31.6));
+ EXPECT_EQ(1, frames.count(31.8));
}
-
-TEST_F(AlembicExportTest, TimeSamples180degShutter) {
- settings.shutter_open = -0.25;
- settings.shutter_close = 0.25;
-
- createExporter();
- std::vector<double> samples;
-
- /* test 5 samples per frame */
- exporter->getShutterSamples(5, true, samples);
- EXPECT_EQ(5, samples.size());
- EXPECT_NEAR(1.230, samples[0], 1e-5f);
- EXPECT_NEAR(1.234, samples[1], 1e-5f);
- EXPECT_NEAR(1.238, samples[2], 1e-5f);
- EXPECT_NEAR(1.242, samples[3], 1e-5f);
- EXPECT_NEAR(1.246, samples[4], 1e-5f);
-
- /* test same, but using frame number offset instead of time */
- exporter->getShutterSamples(5, false, samples);
- EXPECT_EQ(5, samples.size());
- EXPECT_NEAR(-0.25, samples[0], 1e-5f);
- EXPECT_NEAR(-0.15, samples[1], 1e-5f);
- EXPECT_NEAR(-0.05, samples[2], 1e-5f);
- EXPECT_NEAR( 0.05, samples[3], 1e-5f);
- EXPECT_NEAR( 0.15, samples[4], 1e-5f);
-
- /* Use the same setup to test getFrameSet().
- * Here only a few numbers are tested, due to rounding issues. */
- std::set<double> frames;
- exporter->getFrameSet(5, frames);
- EXPECT_EQ(965, frames.size());
- EXPECT_EQ(1, frames.count(30.75));
- EXPECT_EQ(1, frames.count(30.95));
- EXPECT_EQ(1, frames.count(31.15));
+TEST_F(AlembicExportTest, TimeSamples180degShutter)
+{
+ settings.shutter_open = -0.25;
+ settings.shutter_close = 0.25;
+
+ createExporter();
+ std::vector<double> samples;
+
+ /* test 5 samples per frame */
+ exporter->getShutterSamples(5, true, samples);
+ EXPECT_EQ(5, samples.size());
+ EXPECT_NEAR(1.230, samples[0], 1e-5f);
+ EXPECT_NEAR(1.234, samples[1], 1e-5f);
+ EXPECT_NEAR(1.238, samples[2], 1e-5f);
+ EXPECT_NEAR(1.242, samples[3], 1e-5f);
+ EXPECT_NEAR(1.246, samples[4], 1e-5f);
+
+ /* test same, but using frame number offset instead of time */
+ exporter->getShutterSamples(5, false, samples);
+ EXPECT_EQ(5, samples.size());
+ EXPECT_NEAR(-0.25, samples[0], 1e-5f);
+ EXPECT_NEAR(-0.15, samples[1], 1e-5f);
+ EXPECT_NEAR(-0.05, samples[2], 1e-5f);
+ EXPECT_NEAR(0.05, samples[3], 1e-5f);
+ EXPECT_NEAR(0.15, samples[4], 1e-5f);
+
+ /* Use the same setup to test getFrameSet().
+ * Here only a few numbers are tested, due to rounding issues. */
+ std::set<double> frames;
+ exporter->getFrameSet(5, frames);
+ EXPECT_EQ(965, frames.size());
+ EXPECT_EQ(1, frames.count(30.75));
+ EXPECT_EQ(1, frames.count(30.95));
+ EXPECT_EQ(1, frames.count(31.15));
}
diff --git a/tests/gtests/alembic/abc_matrix_test.cc b/tests/gtests/alembic/abc_matrix_test.cc
index 49fb662c934..daffea15d0a 100644
--- a/tests/gtests/alembic/abc_matrix_test.cc
+++ b/tests/gtests/alembic/abc_matrix_test.cc
@@ -8,275 +8,279 @@ extern "C" {
#include "BLI_math.h"
}
-
-TEST(abc_matrix, CreateRotationMatrixY_YfromZ) {
- // Input variables
- float rot_x_mat[3][3];
- float rot_y_mat[3][3];
- float rot_z_mat[3][3];
- float euler[3] = {0.f, M_PI_4, 0.f};
-
- // Construct expected matrices
- float unit[3][3];
- float rot_z_min_quart_pi[3][3]; // rotation of -pi/4 radians over z-axis
-
- unit_m3(unit);
- unit_m3(rot_z_min_quart_pi);
- rot_z_min_quart_pi[0][0] = M_SQRT1_2;
- rot_z_min_quart_pi[0][1] = -M_SQRT1_2;
- rot_z_min_quart_pi[1][0] = M_SQRT1_2;
- rot_z_min_quart_pi[1][1] = M_SQRT1_2;
-
- // Run tests
- create_swapped_rotation_matrix(rot_x_mat, rot_y_mat, rot_z_mat, euler,
- ABC_YUP_FROM_ZUP);
-
- EXPECT_M3_NEAR(rot_x_mat, unit, 1e-5f);
- EXPECT_M3_NEAR(rot_y_mat, unit, 1e-5f);
- EXPECT_M3_NEAR(rot_z_mat, rot_z_min_quart_pi, 1e-5f);
+TEST(abc_matrix, CreateRotationMatrixY_YfromZ)
+{
+ // Input variables
+ float rot_x_mat[3][3];
+ float rot_y_mat[3][3];
+ float rot_z_mat[3][3];
+ float euler[3] = {0.f, M_PI_4, 0.f};
+
+ // Construct expected matrices
+ float unit[3][3];
+ float rot_z_min_quart_pi[3][3]; // rotation of -pi/4 radians over z-axis
+
+ unit_m3(unit);
+ unit_m3(rot_z_min_quart_pi);
+ rot_z_min_quart_pi[0][0] = M_SQRT1_2;
+ rot_z_min_quart_pi[0][1] = -M_SQRT1_2;
+ rot_z_min_quart_pi[1][0] = M_SQRT1_2;
+ rot_z_min_quart_pi[1][1] = M_SQRT1_2;
+
+ // Run tests
+ create_swapped_rotation_matrix(rot_x_mat, rot_y_mat, rot_z_mat, euler, ABC_YUP_FROM_ZUP);
+
+ EXPECT_M3_NEAR(rot_x_mat, unit, 1e-5f);
+ EXPECT_M3_NEAR(rot_y_mat, unit, 1e-5f);
+ EXPECT_M3_NEAR(rot_z_mat, rot_z_min_quart_pi, 1e-5f);
}
-TEST(abc_matrix, CreateRotationMatrixZ_YfromZ) {
- // Input variables
- float rot_x_mat[3][3];
- float rot_y_mat[3][3];
- float rot_z_mat[3][3];
- float euler[3] = {0.f, 0.f, M_PI_4};
-
- // Construct expected matrices
- float unit[3][3];
- float rot_y_quart_pi[3][3]; // rotation of pi/4 radians over y-axis
-
- unit_m3(unit);
- unit_m3(rot_y_quart_pi);
- rot_y_quart_pi[0][0] = M_SQRT1_2;
- rot_y_quart_pi[0][2] = -M_SQRT1_2;
- rot_y_quart_pi[2][0] = M_SQRT1_2;
- rot_y_quart_pi[2][2] = M_SQRT1_2;
-
- // Run tests
- create_swapped_rotation_matrix(rot_x_mat, rot_y_mat, rot_z_mat, euler,
- ABC_YUP_FROM_ZUP);
-
- EXPECT_M3_NEAR(rot_x_mat, unit, 1e-5f);
- EXPECT_M3_NEAR(rot_y_mat, rot_y_quart_pi, 1e-5f);
- EXPECT_M3_NEAR(rot_z_mat, unit, 1e-5f);
+TEST(abc_matrix, CreateRotationMatrixZ_YfromZ)
+{
+ // Input variables
+ float rot_x_mat[3][3];
+ float rot_y_mat[3][3];
+ float rot_z_mat[3][3];
+ float euler[3] = {0.f, 0.f, M_PI_4};
+
+ // Construct expected matrices
+ float unit[3][3];
+ float rot_y_quart_pi[3][3]; // rotation of pi/4 radians over y-axis
+
+ unit_m3(unit);
+ unit_m3(rot_y_quart_pi);
+ rot_y_quart_pi[0][0] = M_SQRT1_2;
+ rot_y_quart_pi[0][2] = -M_SQRT1_2;
+ rot_y_quart_pi[2][0] = M_SQRT1_2;
+ rot_y_quart_pi[2][2] = M_SQRT1_2;
+
+ // Run tests
+ create_swapped_rotation_matrix(rot_x_mat, rot_y_mat, rot_z_mat, euler, ABC_YUP_FROM_ZUP);
+
+ EXPECT_M3_NEAR(rot_x_mat, unit, 1e-5f);
+ EXPECT_M3_NEAR(rot_y_mat, rot_y_quart_pi, 1e-5f);
+ EXPECT_M3_NEAR(rot_z_mat, unit, 1e-5f);
}
-TEST(abc_matrix, CreateRotationMatrixXYZ_YfromZ) {
- // Input variables
- float rot_x_mat[3][3];
- float rot_y_mat[3][3];
- float rot_z_mat[3][3];
- // in degrees: X=10, Y=20, Z=30
- float euler[3] = {0.17453292012214f, 0.34906581044197f, 0.52359879016876f};
-
- // Construct expected matrices
- float rot_x_p10[3][3]; // rotation of +10 degrees over x-axis
- float rot_y_p30[3][3]; // rotation of +30 degrees over y-axis
- float rot_z_m20[3][3]; // rotation of -20 degrees over z-axis
-
- unit_m3(rot_x_p10);
- rot_x_p10[1][1] = 0.9848077297210693f;
- rot_x_p10[1][2] = 0.1736481785774231f;
- rot_x_p10[2][1] = -0.1736481785774231f;
- rot_x_p10[2][2] = 0.9848077297210693f;
-
- unit_m3(rot_y_p30);
- rot_y_p30[0][0] = 0.8660253882408142f;
- rot_y_p30[0][2] = -0.5f;
- rot_y_p30[2][0] = 0.5f;
- rot_y_p30[2][2] = 0.8660253882408142f;
-
- unit_m3(rot_z_m20);
- rot_z_m20[0][0] = 0.9396926164627075f;
- rot_z_m20[0][1] = -0.3420201241970062f;
- rot_z_m20[1][0] = 0.3420201241970062f;
- rot_z_m20[1][1] = 0.9396926164627075f;
-
- // Run tests
- create_swapped_rotation_matrix(rot_x_mat, rot_y_mat, rot_z_mat, euler,
- ABC_YUP_FROM_ZUP);
-
- EXPECT_M3_NEAR(rot_x_mat, rot_x_p10, 1e-5f);
- EXPECT_M3_NEAR(rot_y_mat, rot_y_p30, 1e-5f);
- EXPECT_M3_NEAR(rot_z_mat, rot_z_m20, 1e-5f);
+TEST(abc_matrix, CreateRotationMatrixXYZ_YfromZ)
+{
+ // Input variables
+ float rot_x_mat[3][3];
+ float rot_y_mat[3][3];
+ float rot_z_mat[3][3];
+ // in degrees: X=10, Y=20, Z=30
+ float euler[3] = {0.17453292012214f, 0.34906581044197f, 0.52359879016876f};
+
+ // Construct expected matrices
+ float rot_x_p10[3][3]; // rotation of +10 degrees over x-axis
+ float rot_y_p30[3][3]; // rotation of +30 degrees over y-axis
+ float rot_z_m20[3][3]; // rotation of -20 degrees over z-axis
+
+ unit_m3(rot_x_p10);
+ rot_x_p10[1][1] = 0.9848077297210693f;
+ rot_x_p10[1][2] = 0.1736481785774231f;
+ rot_x_p10[2][1] = -0.1736481785774231f;
+ rot_x_p10[2][2] = 0.9848077297210693f;
+
+ unit_m3(rot_y_p30);
+ rot_y_p30[0][0] = 0.8660253882408142f;
+ rot_y_p30[0][2] = -0.5f;
+ rot_y_p30[2][0] = 0.5f;
+ rot_y_p30[2][2] = 0.8660253882408142f;
+
+ unit_m3(rot_z_m20);
+ rot_z_m20[0][0] = 0.9396926164627075f;
+ rot_z_m20[0][1] = -0.3420201241970062f;
+ rot_z_m20[1][0] = 0.3420201241970062f;
+ rot_z_m20[1][1] = 0.9396926164627075f;
+
+ // Run tests
+ create_swapped_rotation_matrix(rot_x_mat, rot_y_mat, rot_z_mat, euler, ABC_YUP_FROM_ZUP);
+
+ EXPECT_M3_NEAR(rot_x_mat, rot_x_p10, 1e-5f);
+ EXPECT_M3_NEAR(rot_y_mat, rot_y_p30, 1e-5f);
+ EXPECT_M3_NEAR(rot_z_mat, rot_z_m20, 1e-5f);
}
-TEST(abc_matrix, CreateRotationMatrixXYZ_ZfromY) {
- // Input variables
- float rot_x_mat[3][3];
- float rot_y_mat[3][3];
- float rot_z_mat[3][3];
- // in degrees: X=10, Y=20, Z=30
- float euler[3] = {0.1745329201221466f, 0.3490658104419708f, 0.5235987901687622f};
-
- // Construct expected matrices
- float rot_x_p10[3][3]; // rotation of +10 degrees over x-axis
- float rot_y_m30[3][3]; // rotation of -30 degrees over y-axis
- float rot_z_p20[3][3]; // rotation of +20 degrees over z-axis
-
- unit_m3(rot_x_p10);
- rot_x_p10[1][1] = 0.9848077297210693f;
- rot_x_p10[1][2] = 0.1736481785774231f;
- rot_x_p10[2][1] = -0.1736481785774231f;
- rot_x_p10[2][2] = 0.9848077297210693f;
-
- unit_m3(rot_y_m30);
- rot_y_m30[0][0] = 0.8660253882408142f;
- rot_y_m30[0][2] = 0.5f;
- rot_y_m30[2][0] = -0.5f;
- rot_y_m30[2][2] = 0.8660253882408142f;
-
- unit_m3(rot_z_p20);
- rot_z_p20[0][0] = 0.9396926164627075f;
- rot_z_p20[0][1] = 0.3420201241970062f;
- rot_z_p20[1][0] = -0.3420201241970062f;
- rot_z_p20[1][1] = 0.9396926164627075f;
-
- // Run tests
- create_swapped_rotation_matrix(rot_x_mat, rot_y_mat, rot_z_mat, euler,
- ABC_ZUP_FROM_YUP);
-
- EXPECT_M3_NEAR(rot_x_mat, rot_x_p10, 1e-5f);
- EXPECT_M3_NEAR(rot_y_mat, rot_y_m30, 1e-5f);
- EXPECT_M3_NEAR(rot_z_mat, rot_z_p20, 1e-5f);
+TEST(abc_matrix, CreateRotationMatrixXYZ_ZfromY)
+{
+ // Input variables
+ float rot_x_mat[3][3];
+ float rot_y_mat[3][3];
+ float rot_z_mat[3][3];
+ // in degrees: X=10, Y=20, Z=30
+ float euler[3] = {0.1745329201221466f, 0.3490658104419708f, 0.5235987901687622f};
+
+ // Construct expected matrices
+ float rot_x_p10[3][3]; // rotation of +10 degrees over x-axis
+ float rot_y_m30[3][3]; // rotation of -30 degrees over y-axis
+ float rot_z_p20[3][3]; // rotation of +20 degrees over z-axis
+
+ unit_m3(rot_x_p10);
+ rot_x_p10[1][1] = 0.9848077297210693f;
+ rot_x_p10[1][2] = 0.1736481785774231f;
+ rot_x_p10[2][1] = -0.1736481785774231f;
+ rot_x_p10[2][2] = 0.9848077297210693f;
+
+ unit_m3(rot_y_m30);
+ rot_y_m30[0][0] = 0.8660253882408142f;
+ rot_y_m30[0][2] = 0.5f;
+ rot_y_m30[2][0] = -0.5f;
+ rot_y_m30[2][2] = 0.8660253882408142f;
+
+ unit_m3(rot_z_p20);
+ rot_z_p20[0][0] = 0.9396926164627075f;
+ rot_z_p20[0][1] = 0.3420201241970062f;
+ rot_z_p20[1][0] = -0.3420201241970062f;
+ rot_z_p20[1][1] = 0.9396926164627075f;
+
+ // Run tests
+ create_swapped_rotation_matrix(rot_x_mat, rot_y_mat, rot_z_mat, euler, ABC_ZUP_FROM_YUP);
+
+ EXPECT_M3_NEAR(rot_x_mat, rot_x_p10, 1e-5f);
+ EXPECT_M3_NEAR(rot_y_mat, rot_y_m30, 1e-5f);
+ EXPECT_M3_NEAR(rot_z_mat, rot_z_p20, 1e-5f);
}
-TEST(abc_matrix, CopyM44AxisSwap_YfromZ) {
- float result[4][4];
-
- /* Construct an input matrix that performs a rotation like the tests
- * above. This matrix was created by rotating a cube in Blender over
- * (X=10, Y=20, Z=30 degrees in XYZ order) and translating over (1, 2, 3) */
- float input[4][4] = {
- { 0.81379765272f, 0.4698463380336f, -0.342020124197f, 0.f},
- {-0.44096961617f, 0.8825641274452f, 0.163175910711f, 0.f},
- { 0.37852230668f, 0.0180283170193f, 0.925416588783f, 0.f},
- {1.f, 2.f, 3.f, 1.f},
- };
-
- copy_m44_axis_swap(result, input, ABC_YUP_FROM_ZUP);
-
- /* Check the resulting rotation & translation. */
- float trans[4] = {1.f, 3.f, -2.f, 1.f};
- EXPECT_V4_NEAR(trans, result[3], 1e-5f);
-
- /* This matrix was created by rotating a cube in Blender over
- * (X=10, Y=30, Z=-20 degrees in XZY order) and translating over (1, 3, -2) */
- float expect[4][4] = {
- {0.813797652721f, -0.342020124197f, -0.469846338033f, 0.f},
- {0.378522306680f, 0.925416588783f, -0.018028317019f, 0.f},
- {0.440969616174f, -0.163175910711f, 0.882564127445f, 0.f},
- {1.f, 3.f, -2.f, 1.f},
- };
- EXPECT_M4_NEAR(expect, result, 1e-5f);
+TEST(abc_matrix, CopyM44AxisSwap_YfromZ)
+{
+ float result[4][4];
+
+ /* Construct an input matrix that performs a rotation like the tests
+ * above. This matrix was created by rotating a cube in Blender over
+ * (X=10, Y=20, Z=30 degrees in XYZ order) and translating over (1, 2, 3) */
+ float input[4][4] = {
+ {0.81379765272f, 0.4698463380336f, -0.342020124197f, 0.f},
+ {-0.44096961617f, 0.8825641274452f, 0.163175910711f, 0.f},
+ {0.37852230668f, 0.0180283170193f, 0.925416588783f, 0.f},
+ {1.f, 2.f, 3.f, 1.f},
+ };
+
+ copy_m44_axis_swap(result, input, ABC_YUP_FROM_ZUP);
+
+ /* Check the resulting rotation & translation. */
+ float trans[4] = {1.f, 3.f, -2.f, 1.f};
+ EXPECT_V4_NEAR(trans, result[3], 1e-5f);
+
+ /* This matrix was created by rotating a cube in Blender over
+ * (X=10, Y=30, Z=-20 degrees in XZY order) and translating over (1, 3, -2) */
+ float expect[4][4] = {
+ {0.813797652721f, -0.342020124197f, -0.469846338033f, 0.f},
+ {0.378522306680f, 0.925416588783f, -0.018028317019f, 0.f},
+ {0.440969616174f, -0.163175910711f, 0.882564127445f, 0.f},
+ {1.f, 3.f, -2.f, 1.f},
+ };
+ EXPECT_M4_NEAR(expect, result, 1e-5f);
}
-TEST(abc_matrix, CopyM44AxisSwapWithScale_YfromZ) {
- float result[4][4];
-
- /* Construct an input matrix that performs a rotation like the tests
- * above. This matrix was created by rotating a cube in Blender over
- * (X=10, Y=20, Z=30 degrees in XYZ order), translating over (1, 2, 3),
- * and scaling by (4, 5, 6). */
- float input[4][4] = {
- { 3.25519061088f, 1.8793853521347f, -1.368080496788f, 0.f},
- {-2.20484805107f, 4.4128208160400f, 0.815879583358f, 0.f},
- { 2.27113389968f, 0.1081698983907f, 5.552499771118f, 0.f},
- {1.f, 2.f, 3.f, 1.f},
- };
-
- copy_m44_axis_swap(result, input, ABC_YUP_FROM_ZUP);
-
- /* This matrix was created by rotating a cube in Blender over
- * (X=10, Y=30, Z=-20 degrees in XZY order), translating over (1, 3, -2)
- * and scaling over (4, 6, 5). */
- float expect[4][4] = {
- {3.255190610885f, -1.368080496788f, -1.879385352134f, 0.f},
- {2.271133899688f, 5.552499771118f, -0.108169898390f, 0.f},
- {2.204848051071f, -0.815879583358f, 4.412820816040f, 0.f},
- {1.f, 3.f, -2.f, 1.f},
- };
- EXPECT_M4_NEAR(expect, result, 1e-5f);
+TEST(abc_matrix, CopyM44AxisSwapWithScale_YfromZ)
+{
+ float result[4][4];
+
+ /* Construct an input matrix that performs a rotation like the tests
+ * above. This matrix was created by rotating a cube in Blender over
+ * (X=10, Y=20, Z=30 degrees in XYZ order), translating over (1, 2, 3),
+ * and scaling by (4, 5, 6). */
+ float input[4][4] = {
+ {3.25519061088f, 1.8793853521347f, -1.368080496788f, 0.f},
+ {-2.20484805107f, 4.4128208160400f, 0.815879583358f, 0.f},
+ {2.27113389968f, 0.1081698983907f, 5.552499771118f, 0.f},
+ {1.f, 2.f, 3.f, 1.f},
+ };
+
+ copy_m44_axis_swap(result, input, ABC_YUP_FROM_ZUP);
+
+ /* This matrix was created by rotating a cube in Blender over
+ * (X=10, Y=30, Z=-20 degrees in XZY order), translating over (1, 3, -2)
+ * and scaling over (4, 6, 5). */
+ float expect[4][4] = {
+ {3.255190610885f, -1.368080496788f, -1.879385352134f, 0.f},
+ {2.271133899688f, 5.552499771118f, -0.108169898390f, 0.f},
+ {2.204848051071f, -0.815879583358f, 4.412820816040f, 0.f},
+ {1.f, 3.f, -2.f, 1.f},
+ };
+ EXPECT_M4_NEAR(expect, result, 1e-5f);
}
-TEST(abc_matrix, CopyM44AxisSwap_ZfromY) {
- float result[4][4];
-
- /* This matrix was created by rotating a cube in Blender over
- * (X=10, Y=30, Z=-20 degrees in XZY order) and translating over (1, 3, -2) */
- float input[4][4] = {
- {0.813797652721f, -0.342020124197f, -0.469846338033f, 0.f},
- {0.378522306680f, 0.925416588783f, -0.018028317019f, 0.f},
- {0.440969616174f, -0.163175910711f, 0.882564127445f, 0.f},
- {1.f, 3.f, -2.f, 1.f},
- };
-
- copy_m44_axis_swap(result, input, ABC_ZUP_FROM_YUP);
-
- /* This matrix was created by rotating a cube in Blender over
- * (X=10, Y=20, Z=30 degrees in XYZ order) and translating over (1, 2, 3) */
- float expect[4][4] = {
- {0.813797652721f, 0.469846338033f, -0.342020124197f, 0.f},
- {-0.44096961617f, 0.882564127445f, 0.163175910711f, 0.f},
- {0.378522306680f, 0.018028317019f, 0.925416588783f, 0.f},
- {1.f, 2.f, 3.f, 1.f},
- };
-
- EXPECT_M4_NEAR(expect, result, 1e-5f);
+TEST(abc_matrix, CopyM44AxisSwap_ZfromY)
+{
+ float result[4][4];
+
+ /* This matrix was created by rotating a cube in Blender over
+ * (X=10, Y=30, Z=-20 degrees in XZY order) and translating over (1, 3, -2) */
+ float input[4][4] = {
+ {0.813797652721f, -0.342020124197f, -0.469846338033f, 0.f},
+ {0.378522306680f, 0.925416588783f, -0.018028317019f, 0.f},
+ {0.440969616174f, -0.163175910711f, 0.882564127445f, 0.f},
+ {1.f, 3.f, -2.f, 1.f},
+ };
+
+ copy_m44_axis_swap(result, input, ABC_ZUP_FROM_YUP);
+
+ /* This matrix was created by rotating a cube in Blender over
+ * (X=10, Y=20, Z=30 degrees in XYZ order) and translating over (1, 2, 3) */
+ float expect[4][4] = {
+ {0.813797652721f, 0.469846338033f, -0.342020124197f, 0.f},
+ {-0.44096961617f, 0.882564127445f, 0.163175910711f, 0.f},
+ {0.378522306680f, 0.018028317019f, 0.925416588783f, 0.f},
+ {1.f, 2.f, 3.f, 1.f},
+ };
+
+ EXPECT_M4_NEAR(expect, result, 1e-5f);
}
-TEST(abc_matrix, CopyM44AxisSwapWithScale_ZfromY) {
- float result[4][4];
-
- /* This matrix was created by rotating a cube in Blender over
- * (X=10, Y=30, Z=-20 degrees in XZY order), translating over (1, 3, -2)
- * and scaling over (4, 6, 5). */
- float input[4][4] = {
- {3.2551906108f, -1.36808049678f, -1.879385352134f, 0.f},
- {2.2711338996f, 5.55249977111f, -0.108169898390f, 0.f},
- {2.2048480510f, -0.81587958335f, 4.412820816040f, 0.f},
- {1.f, 3.f, -2.f, 1.f},
- };
-
- copy_m44_axis_swap(result, input, ABC_ZUP_FROM_YUP);
-
- /* This matrix was created by rotating a cube in Blender over
- * (X=10, Y=20, Z=30 degrees in XYZ order), translating over (1, 2, 3),
- * and scaling by (4, 5, 6). */
- float expect[4][4] = {
- {3.25519061088f, 1.879385352134f, -1.36808049678f, 0.f},
- {-2.2048480510f, 4.412820816040f, 0.81587958335f, 0.f},
- {2.27113389968f, 0.108169898390f, 5.55249977111f, 0.f},
- {1.f, 2.f, 3.f, 1.f},
- };
-
- EXPECT_M4_NEAR(expect, result, 1e-5f);
+TEST(abc_matrix, CopyM44AxisSwapWithScale_ZfromY)
+{
+ float result[4][4];
+
+ /* This matrix was created by rotating a cube in Blender over
+ * (X=10, Y=30, Z=-20 degrees in XZY order), translating over (1, 3, -2)
+ * and scaling over (4, 6, 5). */
+ float input[4][4] = {
+ {3.2551906108f, -1.36808049678f, -1.879385352134f, 0.f},
+ {2.2711338996f, 5.55249977111f, -0.108169898390f, 0.f},
+ {2.2048480510f, -0.81587958335f, 4.412820816040f, 0.f},
+ {1.f, 3.f, -2.f, 1.f},
+ };
+
+ copy_m44_axis_swap(result, input, ABC_ZUP_FROM_YUP);
+
+ /* This matrix was created by rotating a cube in Blender over
+ * (X=10, Y=20, Z=30 degrees in XYZ order), translating over (1, 2, 3),
+ * and scaling by (4, 5, 6). */
+ float expect[4][4] = {
+ {3.25519061088f, 1.879385352134f, -1.36808049678f, 0.f},
+ {-2.2048480510f, 4.412820816040f, 0.81587958335f, 0.f},
+ {2.27113389968f, 0.108169898390f, 5.55249977111f, 0.f},
+ {1.f, 2.f, 3.f, 1.f},
+ };
+
+ EXPECT_M4_NEAR(expect, result, 1e-5f);
}
-TEST(abc_matrix, CopyM44AxisSwapWithScale_gimbal_ZfromY) {
- float result[4][4];
-
- /* This matrix represents a rotation over (-90, -0, -0) degrees,
- * and a translation over (-0, -0.1, -0). It is in Y=up. */
- float input[4][4] = {
- { 1.000f, 0.000f, 0.000f, 0.000f},
- { 0.000f, 0.000f,-1.000f, 0.000f},
- { 0.000f, 1.000f, 0.000f, 0.000f},
- {-0.000f,-0.100f,-0.000f, 1.000f},
- };
-
- copy_m44_axis_swap(result, input, ABC_ZUP_FROM_YUP);
-
- /* Since the rotation is only over the X-axis, it should not change.
- * The translation does change. */
- float expect[4][4] = {
- { 1.000f, 0.000f, 0.000f, 0.000f},
- { 0.000f, 0.000f,-1.000f, 0.000f},
- { 0.000f, 1.000f, 0.000f, 0.000f},
- {-0.000f, 0.000f,-0.100f, 1.000f},
- };
-
- EXPECT_M4_NEAR(expect, result, 1e-5f);
+TEST(abc_matrix, CopyM44AxisSwapWithScale_gimbal_ZfromY)
+{
+ float result[4][4];
+
+ /* This matrix represents a rotation over (-90, -0, -0) degrees,
+ * and a translation over (-0, -0.1, -0). It is in Y=up. */
+ float input[4][4] = {
+ {1.000f, 0.000f, 0.000f, 0.000f},
+ {0.000f, 0.000f, -1.000f, 0.000f},
+ {0.000f, 1.000f, 0.000f, 0.000f},
+ {-0.000f, -0.100f, -0.000f, 1.000f},
+ };
+
+ copy_m44_axis_swap(result, input, ABC_ZUP_FROM_YUP);
+
+ /* Since the rotation is only over the X-axis, it should not change.
+ * The translation does change. */
+ float expect[4][4] = {
+ {1.000f, 0.000f, 0.000f, 0.000f},
+ {0.000f, 0.000f, -1.000f, 0.000f},
+ {0.000f, 1.000f, 0.000f, 0.000f},
+ {-0.000f, 0.000f, -0.100f, 1.000f},
+ };
+
+ EXPECT_M4_NEAR(expect, result, 1e-5f);
}
diff --git a/tests/gtests/blenlib/BLI_array_store_test.cc b/tests/gtests/blenlib/BLI_array_store_test.cc
index 370a4111bae..c2fb16d12da 100644
--- a/tests/gtests/blenlib/BLI_array_store_test.cc
+++ b/tests/gtests/blenlib/BLI_array_store_test.cc
@@ -18,57 +18,55 @@ extern "C" {
/* print memory savings */
// #define DEBUG_PRINT
-
/* -------------------------------------------------------------------- */
/* Helper functions */
#ifdef DEBUG_PRINT
static void print_mem_saved(const char *id, const BArrayStore *bs)
{
- const double size_real = BLI_array_store_calc_size_compacted_get(bs);
- const double size_expand = BLI_array_store_calc_size_expanded_get(bs);
- const double percent = size_expand ? ((size_real / size_expand) * 100.0) : -1.0;
- printf("%s: %.8f%%\n", id, percent);
+ const double size_real = BLI_array_store_calc_size_compacted_get(bs);
+ const double size_expand = BLI_array_store_calc_size_expanded_get(bs);
+ const double percent = size_expand ? ((size_real / size_expand) * 100.0) : -1.0;
+ printf("%s: %.8f%%\n", id, percent);
}
#endif
-
/* -------------------------------------------------------------------- */
/* Test Chunks (building data from list of chunks) */
typedef struct TestChunk {
- struct TestChunk *next, *prev;
- const void *data;
- size_t data_len;
+ struct TestChunk *next, *prev;
+ const void *data;
+ size_t data_len;
} TestChunk;
static TestChunk *testchunk_list_add(ListBase *lb, const void *data, size_t data_len)
{
- TestChunk *tc = (TestChunk *)MEM_mallocN(sizeof(*tc), __func__);
- tc->data = data;
- tc->data_len = data_len;
- BLI_addtail(lb, tc);
+ TestChunk *tc = (TestChunk *)MEM_mallocN(sizeof(*tc), __func__);
+ tc->data = data;
+ tc->data_len = data_len;
+ BLI_addtail(lb, tc);
- return tc;
+ return tc;
}
#if 0
static TestChunk *testchunk_list_add_copydata(ListBase *lb, const void *data, size_t data_len)
{
- void *data_copy = MEM_mallocN(data_len, __func__);
- memcpy(data_copy, data, data_len);
- return testchunk_list_add(lb, data_copy, data_len);
+ void *data_copy = MEM_mallocN(data_len, __func__);
+ memcpy(data_copy, data, data_len);
+ return testchunk_list_add(lb, data_copy, data_len);
}
#endif
static void testchunk_list_free(ListBase *lb)
{
- for (TestChunk *tc = (TestChunk *)lb->first, *tb_next; tc; tc = tb_next) {
- tb_next = tc->next;
- MEM_freeN((void *)tc->data);
- MEM_freeN(tc);
- }
- BLI_listbase_clear(lb);
+ for (TestChunk *tc = (TestChunk *)lb->first, *tb_next; tc; tc = tb_next) {
+ tb_next = tc->next;
+ MEM_freeN((void *)tc->data);
+ MEM_freeN(tc);
+ }
+ BLI_listbase_clear(lb);
}
#if 0
@@ -76,374 +74,361 @@ static char *testchunk_as_data(
ListBase *lb,
size_t *r_data_len)
{
- size_t data_len = 0;
- for (TestChunk *tc = (TestChunk *)lb->first; tc; tc = tc->next) {
- data_len += tc->data_len;
- }
- char *data = (char *)MEM_mallocN(data_len, __func__);
- size_t i = 0;
- for (TestChunk *tc = (TestChunk *)lb->first; tc; tc = tc->next) {
- memcpy(&data[i], tc->data, tc->data_len);
- data_len += tc->data_len;
- i += tc->data_len;
- }
- if (r_data_len) {
- *r_data_len = i;
- }
- return data;
+ size_t data_len = 0;
+ for (TestChunk *tc = (TestChunk *)lb->first; tc; tc = tc->next) {
+ data_len += tc->data_len;
+ }
+ char *data = (char *)MEM_mallocN(data_len, __func__);
+ size_t i = 0;
+ for (TestChunk *tc = (TestChunk *)lb->first; tc; tc = tc->next) {
+ memcpy(&data[i], tc->data, tc->data_len);
+ data_len += tc->data_len;
+ i += tc->data_len;
+ }
+ if (r_data_len) {
+ *r_data_len = i;
+ }
+ return data;
}
#endif
-static char *testchunk_as_data_array(
- TestChunk **tc_array, int tc_array_len,
- size_t *r_data_len)
-{
- size_t data_len = 0;
- for (int tc_index = 0; tc_index < tc_array_len; tc_index++) {
- data_len += tc_array[tc_index]->data_len;
- }
- char *data = (char *)MEM_mallocN(data_len, __func__);
- size_t i = 0;
- for (int tc_index = 0; tc_index < tc_array_len; tc_index++) {
- TestChunk *tc = tc_array[tc_index];
- memcpy(&data[i], tc->data, tc->data_len);
- i += tc->data_len;
- }
- if (r_data_len) {
- *r_data_len = i;
- }
- return data;
+static char *testchunk_as_data_array(TestChunk **tc_array, int tc_array_len, size_t *r_data_len)
+{
+ size_t data_len = 0;
+ for (int tc_index = 0; tc_index < tc_array_len; tc_index++) {
+ data_len += tc_array[tc_index]->data_len;
+ }
+ char *data = (char *)MEM_mallocN(data_len, __func__);
+ size_t i = 0;
+ for (int tc_index = 0; tc_index < tc_array_len; tc_index++) {
+ TestChunk *tc = tc_array[tc_index];
+ memcpy(&data[i], tc->data, tc->data_len);
+ i += tc->data_len;
+ }
+ if (r_data_len) {
+ *r_data_len = i;
+ }
+ return data;
}
-
/* -------------------------------------------------------------------- */
/* Test Buffer */
/* API to handle local allocation of data so we can compare it with the data in the array_store */
typedef struct TestBuffer {
- struct TestBuffer *next, *prev;
- const void *data;
- size_t data_len;
+ struct TestBuffer *next, *prev;
+ const void *data;
+ size_t data_len;
- /* for reference */
- BArrayState *state;
+ /* for reference */
+ BArrayState *state;
} TestBuffer;
static TestBuffer *testbuffer_list_add(ListBase *lb, const void *data, size_t data_len)
{
- TestBuffer *tb = (TestBuffer *)MEM_mallocN(sizeof(*tb), __func__);
- tb->data = data;
- tb->data_len = data_len;
- tb->state = NULL;
- BLI_addtail(lb, tb);
- return tb;
+ TestBuffer *tb = (TestBuffer *)MEM_mallocN(sizeof(*tb), __func__);
+ tb->data = data;
+ tb->data_len = data_len;
+ tb->state = NULL;
+ BLI_addtail(lb, tb);
+ return tb;
}
static TestBuffer *testbuffer_list_add_copydata(ListBase *lb, const void *data, size_t data_len)
{
- void *data_copy = MEM_mallocN(data_len, __func__);
- memcpy(data_copy, data, data_len);
- return testbuffer_list_add(lb, data_copy, data_len);
+ void *data_copy = MEM_mallocN(data_len, __func__);
+ memcpy(data_copy, data, data_len);
+ return testbuffer_list_add(lb, data_copy, data_len);
}
-static void testbuffer_list_state_from_data(
- ListBase *lb,
- const char *data, const size_t data_len)
+static void testbuffer_list_state_from_data(ListBase *lb, const char *data, const size_t data_len)
{
- testbuffer_list_add_copydata(lb, (const void *)data, data_len);
+ testbuffer_list_add_copydata(lb, (const void *)data, data_len);
}
/**
* A version of testbuffer_list_state_from_data that expand data by stride,
* handy so we can test data at different strides.
*/
-static void testbuffer_list_state_from_data__stride_expand(
- ListBase *lb,
- const char *data, const size_t data_len,
- const size_t stride)
+static void testbuffer_list_state_from_data__stride_expand(ListBase *lb,
+ const char *data,
+ const size_t data_len,
+ const size_t stride)
{
- if (stride == 1) {
- testbuffer_list_state_from_data(lb, data, data_len);
- }
- else {
- const size_t data_stride_len = data_len * stride;
- char *data_stride = (char *)MEM_mallocN(data_stride_len, __func__);
+ if (stride == 1) {
+ testbuffer_list_state_from_data(lb, data, data_len);
+ }
+ else {
+ const size_t data_stride_len = data_len * stride;
+ char *data_stride = (char *)MEM_mallocN(data_stride_len, __func__);
- for (size_t i = 0, i_stride = 0; i < data_len; i += 1, i_stride += stride) {
- memset(&data_stride[i_stride], data[i], stride);
- }
+ for (size_t i = 0, i_stride = 0; i < data_len; i += 1, i_stride += stride) {
+ memset(&data_stride[i_stride], data[i], stride);
+ }
- testbuffer_list_add(lb, (const void *)data_stride, data_stride_len);
- }
+ testbuffer_list_add(lb, (const void *)data_stride, data_stride_len);
+ }
}
#define testbuffer_list_state_from_string_array(lb, data_array) \
-{ \
- unsigned int i_ = 0; \
- const char *data; \
- while ((data = data_array[i_++])) { \
- testbuffer_list_state_from_data(lb, data, strlen(data)); \
- } \
-} ((void)0)
+ { \
+ unsigned int i_ = 0; \
+ const char *data; \
+ while ((data = data_array[i_++])) { \
+ testbuffer_list_state_from_data(lb, data, strlen(data)); \
+ } \
+ } \
+ ((void)0)
//
#define TESTBUFFER_STRINGS_CREATE(lb, ...) \
-{ \
- BLI_listbase_clear(lb); \
- const char *data_array[] = {__VA_ARGS__ NULL}; \
- testbuffer_list_state_from_string_array((lb), data_array); \
-} ((void)0)
+ { \
+ BLI_listbase_clear(lb); \
+ const char *data_array[] = {__VA_ARGS__ NULL}; \
+ testbuffer_list_state_from_string_array((lb), data_array); \
+ } \
+ ((void)0)
/* test in both directions */
#define TESTBUFFER_STRINGS_EX(bs, ...) \
-{ \
- ListBase lb; \
- TESTBUFFER_STRINGS_CREATE(&lb, __VA_ARGS__); \
- \
- testbuffer_run_tests(bs, &lb); \
- \
- testbuffer_list_free(&lb); \
-} ((void)0)
+ { \
+ ListBase lb; \
+ TESTBUFFER_STRINGS_CREATE(&lb, __VA_ARGS__); \
+\
+ testbuffer_run_tests(bs, &lb); \
+\
+ testbuffer_list_free(&lb); \
+ } \
+ ((void)0)
#define TESTBUFFER_STRINGS(stride, chunk_count, ...) \
-{ \
- ListBase lb; \
- TESTBUFFER_STRINGS_CREATE(&lb, __VA_ARGS__); \
- \
- testbuffer_run_tests_simple(&lb, stride, chunk_count); \
- \
- testbuffer_list_free(&lb); \
-} ((void)0)
+ { \
+ ListBase lb; \
+ TESTBUFFER_STRINGS_CREATE(&lb, __VA_ARGS__); \
+\
+ testbuffer_run_tests_simple(&lb, stride, chunk_count); \
+\
+ testbuffer_list_free(&lb); \
+ } \
+ ((void)0)
static bool testbuffer_item_validate(TestBuffer *tb)
{
- size_t data_state_len;
- bool ok = true;
- void *data_state = BLI_array_store_state_data_get_alloc(tb->state, &data_state_len);
- if (tb->data_len != data_state_len) {
- ok = false;
- }
- else if (memcmp(data_state, tb->data, data_state_len) != 0) {
- ok = false;
- }
- MEM_freeN(data_state);
- return ok;
+ size_t data_state_len;
+ bool ok = true;
+ void *data_state = BLI_array_store_state_data_get_alloc(tb->state, &data_state_len);
+ if (tb->data_len != data_state_len) {
+ ok = false;
+ }
+ else if (memcmp(data_state, tb->data, data_state_len) != 0) {
+ ok = false;
+ }
+ MEM_freeN(data_state);
+ return ok;
}
static bool testbuffer_list_validate(const ListBase *lb)
{
- for (TestBuffer *tb = (TestBuffer *)lb->first; tb; tb = tb->next) {
- if (!testbuffer_item_validate(tb)) {
- return false;
- }
- }
+ for (TestBuffer *tb = (TestBuffer *)lb->first; tb; tb = tb->next) {
+ if (!testbuffer_item_validate(tb)) {
+ return false;
+ }
+ }
- return true;
+ return true;
}
static void testbuffer_list_data_randomize(ListBase *lb, unsigned int random_seed)
{
- for (TestBuffer *tb = (TestBuffer *)lb->first; tb; tb = tb->next) {
- BLI_array_randomize((void *)tb->data, 1, tb->data_len, random_seed++);
- }
+ for (TestBuffer *tb = (TestBuffer *)lb->first; tb; tb = tb->next) {
+ BLI_array_randomize((void *)tb->data, 1, tb->data_len, random_seed++);
+ }
}
-static void testbuffer_list_store_populate(
- BArrayStore *bs, ListBase *lb)
+static void testbuffer_list_store_populate(BArrayStore *bs, ListBase *lb)
{
- for (TestBuffer *tb = (TestBuffer *)lb->first, *tb_prev = NULL; tb; tb_prev = tb, tb = tb->next) {
- tb->state = BLI_array_store_state_add(bs, tb->data, tb->data_len, (tb_prev ? tb_prev->state : NULL));
- }
+ for (TestBuffer *tb = (TestBuffer *)lb->first, *tb_prev = NULL; tb;
+ tb_prev = tb, tb = tb->next) {
+ tb->state = BLI_array_store_state_add(
+ bs, tb->data, tb->data_len, (tb_prev ? tb_prev->state : NULL));
+ }
}
-static void testbuffer_list_store_clear(
- BArrayStore *bs, ListBase *lb)
+static void testbuffer_list_store_clear(BArrayStore *bs, ListBase *lb)
{
- for (TestBuffer *tb = (TestBuffer *)lb->first; tb; tb = tb->next) {
- BLI_array_store_state_remove(bs, tb->state);
- tb->state = NULL;
- }
+ for (TestBuffer *tb = (TestBuffer *)lb->first; tb; tb = tb->next) {
+ BLI_array_store_state_remove(bs, tb->state);
+ tb->state = NULL;
+ }
}
static void testbuffer_list_free(ListBase *lb)
{
- for (TestBuffer *tb = (TestBuffer *)lb->first, *tb_next; tb; tb = tb_next) {
- tb_next = tb->next;
- MEM_freeN((void *)tb->data);
- MEM_freeN(tb);
- }
- BLI_listbase_clear(lb);
+ for (TestBuffer *tb = (TestBuffer *)lb->first, *tb_next; tb; tb = tb_next) {
+ tb_next = tb->next;
+ MEM_freeN((void *)tb->data);
+ MEM_freeN(tb);
+ }
+ BLI_listbase_clear(lb);
}
-static void testbuffer_run_tests_single(
- BArrayStore *bs, ListBase *lb)
+static void testbuffer_run_tests_single(BArrayStore *bs, ListBase *lb)
{
- testbuffer_list_store_populate(bs, lb);
- EXPECT_TRUE(testbuffer_list_validate(lb));
- EXPECT_TRUE(BLI_array_store_is_valid(bs));
+ testbuffer_list_store_populate(bs, lb);
+ EXPECT_TRUE(testbuffer_list_validate(lb));
+ EXPECT_TRUE(BLI_array_store_is_valid(bs));
#ifdef DEBUG_PRINT
- print_mem_saved("data", bs);
+ print_mem_saved("data", bs);
#endif
}
/* avoid copy-paste code to run tests */
-static void testbuffer_run_tests(
- BArrayStore *bs, ListBase *lb)
+static void testbuffer_run_tests(BArrayStore *bs, ListBase *lb)
{
- /* forwards */
- testbuffer_run_tests_single(bs, lb);
- testbuffer_list_store_clear(bs, lb);
+ /* forwards */
+ testbuffer_run_tests_single(bs, lb);
+ testbuffer_list_store_clear(bs, lb);
- BLI_listbase_reverse(lb);
+ BLI_listbase_reverse(lb);
- /* backwards */
- testbuffer_run_tests_single(bs, lb);
- testbuffer_list_store_clear(bs, lb);
+ /* backwards */
+ testbuffer_run_tests_single(bs, lb);
+ testbuffer_list_store_clear(bs, lb);
}
-static void testbuffer_run_tests_simple(
- ListBase *lb,
- const int stride, const int chunk_count)
+static void testbuffer_run_tests_simple(ListBase *lb, const int stride, const int chunk_count)
{
- BArrayStore *bs = BLI_array_store_create(stride, chunk_count);
- testbuffer_run_tests(bs, lb);
- BLI_array_store_destroy(bs);
+ BArrayStore *bs = BLI_array_store_create(stride, chunk_count);
+ testbuffer_run_tests(bs, lb);
+ BLI_array_store_destroy(bs);
}
-
/* -------------------------------------------------------------------- */
/* Basic Tests */
TEST(array_store, Nop)
{
- BArrayStore *bs = BLI_array_store_create(1, 32);
- BLI_array_store_destroy(bs);
+ BArrayStore *bs = BLI_array_store_create(1, 32);
+ BLI_array_store_destroy(bs);
}
TEST(array_store, NopState)
{
- BArrayStore *bs = BLI_array_store_create(1, 32);
- const unsigned char data[] = "test";
- BArrayState *state = BLI_array_store_state_add(bs, data, sizeof(data) - 1, NULL);
- EXPECT_EQ(BLI_array_store_state_size_get(state), sizeof(data) - 1);
- BLI_array_store_state_remove(bs, state);
- BLI_array_store_destroy(bs);
+ BArrayStore *bs = BLI_array_store_create(1, 32);
+ const unsigned char data[] = "test";
+ BArrayState *state = BLI_array_store_state_add(bs, data, sizeof(data) - 1, NULL);
+ EXPECT_EQ(BLI_array_store_state_size_get(state), sizeof(data) - 1);
+ BLI_array_store_state_remove(bs, state);
+ BLI_array_store_destroy(bs);
}
TEST(array_store, Single)
{
- BArrayStore *bs = BLI_array_store_create(1, 32);
- const char data_src[] = "test";
- const char *data_dst;
- BArrayState *state = BLI_array_store_state_add(bs, data_src, sizeof(data_src), NULL);
- size_t data_dst_len;
- data_dst = (char *)BLI_array_store_state_data_get_alloc(state, &data_dst_len);
- EXPECT_STREQ(data_src, data_dst);
- EXPECT_EQ(data_dst_len, sizeof(data_src));
- BLI_array_store_destroy(bs);
- MEM_freeN((void *)data_dst);
+ BArrayStore *bs = BLI_array_store_create(1, 32);
+ const char data_src[] = "test";
+ const char *data_dst;
+ BArrayState *state = BLI_array_store_state_add(bs, data_src, sizeof(data_src), NULL);
+ size_t data_dst_len;
+ data_dst = (char *)BLI_array_store_state_data_get_alloc(state, &data_dst_len);
+ EXPECT_STREQ(data_src, data_dst);
+ EXPECT_EQ(data_dst_len, sizeof(data_src));
+ BLI_array_store_destroy(bs);
+ MEM_freeN((void *)data_dst);
}
TEST(array_store, DoubleNop)
{
- BArrayStore *bs = BLI_array_store_create(1, 32);
- const char data_src[] = "test";
- const char *data_dst;
+ BArrayStore *bs = BLI_array_store_create(1, 32);
+ const char data_src[] = "test";
+ const char *data_dst;
- BArrayState *state_a = BLI_array_store_state_add(bs, data_src, sizeof(data_src), NULL);
- BArrayState *state_b = BLI_array_store_state_add(bs, data_src, sizeof(data_src), state_a);
+ BArrayState *state_a = BLI_array_store_state_add(bs, data_src, sizeof(data_src), NULL);
+ BArrayState *state_b = BLI_array_store_state_add(bs, data_src, sizeof(data_src), state_a);
- EXPECT_EQ(BLI_array_store_calc_size_compacted_get(bs), sizeof(data_src));
- EXPECT_EQ(BLI_array_store_calc_size_expanded_get(bs), sizeof(data_src) * 2);
+ EXPECT_EQ(BLI_array_store_calc_size_compacted_get(bs), sizeof(data_src));
+ EXPECT_EQ(BLI_array_store_calc_size_expanded_get(bs), sizeof(data_src) * 2);
- size_t data_dst_len;
+ size_t data_dst_len;
- data_dst = (char *)BLI_array_store_state_data_get_alloc(state_a, &data_dst_len);
- EXPECT_STREQ(data_src, data_dst);
- MEM_freeN((void *)data_dst);
+ data_dst = (char *)BLI_array_store_state_data_get_alloc(state_a, &data_dst_len);
+ EXPECT_STREQ(data_src, data_dst);
+ MEM_freeN((void *)data_dst);
- data_dst = (char *)BLI_array_store_state_data_get_alloc(state_b, &data_dst_len);
- EXPECT_STREQ(data_src, data_dst);
- MEM_freeN((void *)data_dst);
+ data_dst = (char *)BLI_array_store_state_data_get_alloc(state_b, &data_dst_len);
+ EXPECT_STREQ(data_src, data_dst);
+ MEM_freeN((void *)data_dst);
- EXPECT_EQ(data_dst_len, sizeof(data_src));
- BLI_array_store_destroy(bs);
+ EXPECT_EQ(data_dst_len, sizeof(data_src));
+ BLI_array_store_destroy(bs);
}
TEST(array_store, DoubleDiff)
{
- BArrayStore *bs = BLI_array_store_create(1, 32);
- const char data_src_a[] = "test";
- const char data_src_b[] = "####";
- const char *data_dst;
+ BArrayStore *bs = BLI_array_store_create(1, 32);
+ const char data_src_a[] = "test";
+ const char data_src_b[] = "####";
+ const char *data_dst;
- BArrayState *state_a = BLI_array_store_state_add(bs, data_src_a, sizeof(data_src_a), NULL);
- BArrayState *state_b = BLI_array_store_state_add(bs, data_src_b, sizeof(data_src_b), state_a);
- size_t data_dst_len;
+ BArrayState *state_a = BLI_array_store_state_add(bs, data_src_a, sizeof(data_src_a), NULL);
+ BArrayState *state_b = BLI_array_store_state_add(bs, data_src_b, sizeof(data_src_b), state_a);
+ size_t data_dst_len;
- EXPECT_EQ(BLI_array_store_calc_size_compacted_get(bs), sizeof(data_src_a) * 2);
- EXPECT_EQ(BLI_array_store_calc_size_expanded_get(bs), sizeof(data_src_a) * 2);
+ EXPECT_EQ(BLI_array_store_calc_size_compacted_get(bs), sizeof(data_src_a) * 2);
+ EXPECT_EQ(BLI_array_store_calc_size_expanded_get(bs), sizeof(data_src_a) * 2);
- data_dst = (char *)BLI_array_store_state_data_get_alloc(state_a, &data_dst_len);
- EXPECT_STREQ(data_src_a, data_dst);
- MEM_freeN((void *)data_dst);
+ data_dst = (char *)BLI_array_store_state_data_get_alloc(state_a, &data_dst_len);
+ EXPECT_STREQ(data_src_a, data_dst);
+ MEM_freeN((void *)data_dst);
- data_dst = (char *)BLI_array_store_state_data_get_alloc(state_b, &data_dst_len);
- EXPECT_STREQ(data_src_b, data_dst);
- MEM_freeN((void *)data_dst);
+ data_dst = (char *)BLI_array_store_state_data_get_alloc(state_b, &data_dst_len);
+ EXPECT_STREQ(data_src_b, data_dst);
+ MEM_freeN((void *)data_dst);
- BLI_array_store_destroy(bs);
+ BLI_array_store_destroy(bs);
}
TEST(array_store, TextMixed)
{
- TESTBUFFER_STRINGS(1, 4, "",);
- TESTBUFFER_STRINGS(1, 4, "test",);
- TESTBUFFER_STRINGS(1, 4, "", "test",);
- TESTBUFFER_STRINGS(1, 4, "test", "",);
- TESTBUFFER_STRINGS(1, 4, "test", "", "test",);
- TESTBUFFER_STRINGS(1, 4, "", "test", "",);
+ TESTBUFFER_STRINGS(1, 4, "", );
+ TESTBUFFER_STRINGS(1, 4, "test", );
+ TESTBUFFER_STRINGS(1, 4, "", "test", );
+ TESTBUFFER_STRINGS(1, 4, "test", "", );
+ TESTBUFFER_STRINGS(1, 4, "test", "", "test", );
+ TESTBUFFER_STRINGS(1, 4, "", "test", "", );
}
TEST(array_store, TextDupeIncreaseDecrease)
{
- ListBase lb;
+ ListBase lb;
#define D "#1#2#3#4"
- TESTBUFFER_STRINGS_CREATE(
- &lb,
- D,
- D D,
- D D D,
- D D D D,
- );
-
- BArrayStore *bs = BLI_array_store_create(1, 8);
-
- /* forward */
- testbuffer_list_store_populate(bs, &lb);
- EXPECT_TRUE(testbuffer_list_validate(&lb));
- EXPECT_TRUE(BLI_array_store_is_valid(bs));
- EXPECT_EQ(BLI_array_store_calc_size_compacted_get(bs), strlen(D));
-
- testbuffer_list_store_clear(bs, &lb);
- BLI_listbase_reverse(&lb);
-
- /* backwards */
- testbuffer_list_store_populate(bs, &lb);
- EXPECT_TRUE(testbuffer_list_validate(&lb));
- EXPECT_TRUE(BLI_array_store_is_valid(bs));
- /* larger since first block doesn't de-duplicate */
- EXPECT_EQ(BLI_array_store_calc_size_compacted_get(bs), strlen(D) * 4);
+ TESTBUFFER_STRINGS_CREATE(&lb, D, D D, D D D, D D D D, );
+
+ BArrayStore *bs = BLI_array_store_create(1, 8);
+
+ /* forward */
+ testbuffer_list_store_populate(bs, &lb);
+ EXPECT_TRUE(testbuffer_list_validate(&lb));
+ EXPECT_TRUE(BLI_array_store_is_valid(bs));
+ EXPECT_EQ(BLI_array_store_calc_size_compacted_get(bs), strlen(D));
+
+ testbuffer_list_store_clear(bs, &lb);
+ BLI_listbase_reverse(&lb);
+
+ /* backwards */
+ testbuffer_list_store_populate(bs, &lb);
+ EXPECT_TRUE(testbuffer_list_validate(&lb));
+ EXPECT_TRUE(BLI_array_store_is_valid(bs));
+ /* larger since first block doesn't de-duplicate */
+ EXPECT_EQ(BLI_array_store_calc_size_compacted_get(bs), strlen(D) * 4);
#undef D
- testbuffer_list_free(&lb); \
+ testbuffer_list_free(&lb);
- BLI_array_store_destroy(bs);
+ BLI_array_store_destroy(bs);
}
-
/* -------------------------------------------------------------------- */
/* Plain Text Tests */
@@ -451,276 +436,374 @@ TEST(array_store, TextDupeIncreaseDecrease)
* Test that uses text input with different params for the array-store
* to ensure no corner cases fail.
*/
-static void plain_text_helper(
- const char *words, int words_len, const char word_delim,
- const int stride, const int chunk_count, const int random_seed)
+static void plain_text_helper(const char *words,
+ int words_len,
+ const char word_delim,
+ const int stride,
+ const int chunk_count,
+ const int random_seed)
{
- ListBase lb;
- BLI_listbase_clear(&lb);
+ ListBase lb;
+ BLI_listbase_clear(&lb);
- for (int i = 0, i_prev = 0; i < words_len; i++) {
- if (ELEM(words[i], word_delim, '\0')) {
- if (i != i_prev) {
- testbuffer_list_state_from_data__stride_expand(&lb, &words[i_prev], i - i_prev, stride);
- }
- i_prev = i;
- }
- }
+ for (int i = 0, i_prev = 0; i < words_len; i++) {
+ if (ELEM(words[i], word_delim, '\0')) {
+ if (i != i_prev) {
+ testbuffer_list_state_from_data__stride_expand(&lb, &words[i_prev], i - i_prev, stride);
+ }
+ i_prev = i;
+ }
+ }
- if (random_seed) {
- testbuffer_list_data_randomize(&lb, random_seed);
- }
+ if (random_seed) {
+ testbuffer_list_data_randomize(&lb, random_seed);
+ }
- testbuffer_run_tests_simple(&lb, stride, chunk_count);
+ testbuffer_run_tests_simple(&lb, stride, chunk_count);
- testbuffer_list_free(&lb);
+ testbuffer_list_free(&lb);
}
/* split by '.' (multiple words) */
#define WORDS words10k, sizeof(words10k)
-TEST(array_store, TextSentences_Chunk1) { plain_text_helper(WORDS, '.', 1, 1, 0); }
-TEST(array_store, TextSentences_Chunk2) { plain_text_helper(WORDS, '.', 1, 2, 0); }
-TEST(array_store, TextSentences_Chunk8) { plain_text_helper(WORDS, '.', 1, 8, 0); }
-TEST(array_store, TextSentences_Chunk32) { plain_text_helper(WORDS, '.', 1, 32, 0); }
-TEST(array_store, TextSentences_Chunk128) { plain_text_helper(WORDS, '.', 1, 128, 0); }
-TEST(array_store, TextSentences_Chunk1024) { plain_text_helper(WORDS, '.', 1, 1024, 0); }
+TEST(array_store, TextSentences_Chunk1)
+{
+ plain_text_helper(WORDS, '.', 1, 1, 0);
+}
+TEST(array_store, TextSentences_Chunk2)
+{
+ plain_text_helper(WORDS, '.', 1, 2, 0);
+}
+TEST(array_store, TextSentences_Chunk8)
+{
+ plain_text_helper(WORDS, '.', 1, 8, 0);
+}
+TEST(array_store, TextSentences_Chunk32)
+{
+ plain_text_helper(WORDS, '.', 1, 32, 0);
+}
+TEST(array_store, TextSentences_Chunk128)
+{
+ plain_text_helper(WORDS, '.', 1, 128, 0);
+}
+TEST(array_store, TextSentences_Chunk1024)
+{
+ plain_text_helper(WORDS, '.', 1, 1024, 0);
+}
/* odd numbers */
-TEST(array_store, TextSentences_Chunk3) { plain_text_helper(WORDS, '.', 1, 3, 0); }
-TEST(array_store, TextSentences_Chunk13) { plain_text_helper(WORDS, '.', 1, 13, 0); }
-TEST(array_store, TextSentences_Chunk131) { plain_text_helper(WORDS, '.', 1, 131, 0); }
+TEST(array_store, TextSentences_Chunk3)
+{
+ plain_text_helper(WORDS, '.', 1, 3, 0);
+}
+TEST(array_store, TextSentences_Chunk13)
+{
+ plain_text_helper(WORDS, '.', 1, 13, 0);
+}
+TEST(array_store, TextSentences_Chunk131)
+{
+ plain_text_helper(WORDS, '.', 1, 131, 0);
+}
/* split by ' ', individual words */
-TEST(array_store, TextWords_Chunk1) { plain_text_helper(WORDS, ' ', 1, 1, 0); }
-TEST(array_store, TextWords_Chunk2) { plain_text_helper(WORDS, ' ', 1, 2, 0); }
-TEST(array_store, TextWords_Chunk8) { plain_text_helper(WORDS, ' ', 1, 8, 0); }
-TEST(array_store, TextWords_Chunk32) { plain_text_helper(WORDS, ' ', 1, 32, 0); }
-TEST(array_store, TextWords_Chunk128) { plain_text_helper(WORDS, ' ', 1, 128, 0); }
-TEST(array_store, TextWords_Chunk1024) { plain_text_helper(WORDS, ' ', 1, 1024, 0); }
+TEST(array_store, TextWords_Chunk1)
+{
+ plain_text_helper(WORDS, ' ', 1, 1, 0);
+}
+TEST(array_store, TextWords_Chunk2)
+{
+ plain_text_helper(WORDS, ' ', 1, 2, 0);
+}
+TEST(array_store, TextWords_Chunk8)
+{
+ plain_text_helper(WORDS, ' ', 1, 8, 0);
+}
+TEST(array_store, TextWords_Chunk32)
+{
+ plain_text_helper(WORDS, ' ', 1, 32, 0);
+}
+TEST(array_store, TextWords_Chunk128)
+{
+ plain_text_helper(WORDS, ' ', 1, 128, 0);
+}
+TEST(array_store, TextWords_Chunk1024)
+{
+ plain_text_helper(WORDS, ' ', 1, 1024, 0);
+}
/* odd numbers */
-TEST(array_store, TextWords_Chunk3) { plain_text_helper(WORDS, ' ', 1, 3, 0); }
-TEST(array_store, TextWords_Chunk13) { plain_text_helper(WORDS, ' ', 1, 13, 0); }
-TEST(array_store, TextWords_Chunk131) { plain_text_helper(WORDS, ' ', 1, 131, 0); }
+TEST(array_store, TextWords_Chunk3)
+{
+ plain_text_helper(WORDS, ' ', 1, 3, 0);
+}
+TEST(array_store, TextWords_Chunk13)
+{
+ plain_text_helper(WORDS, ' ', 1, 13, 0);
+}
+TEST(array_store, TextWords_Chunk131)
+{
+ plain_text_helper(WORDS, ' ', 1, 131, 0);
+}
/* various tests with different strides & randomizing */
-TEST(array_store, TextSentencesRandom_Stride3_Chunk3) { plain_text_helper(WORDS, 'q', 3, 3, 7337); }
-TEST(array_store, TextSentencesRandom_Stride8_Chunk8) { plain_text_helper(WORDS, 'n', 8, 8, 5667); }
-TEST(array_store, TextSentencesRandom_Stride32_Chunk1) { plain_text_helper(WORDS, 'a', 1, 32, 1212); }
-TEST(array_store, TextSentencesRandom_Stride12_Chunk512) { plain_text_helper(WORDS, 'g', 12, 512, 9999); }
-TEST(array_store, TextSentencesRandom_Stride128_Chunk6) { plain_text_helper(WORDS, 'b', 20, 6, 1000); }
+TEST(array_store, TextSentencesRandom_Stride3_Chunk3)
+{
+ plain_text_helper(WORDS, 'q', 3, 3, 7337);
+}
+TEST(array_store, TextSentencesRandom_Stride8_Chunk8)
+{
+ plain_text_helper(WORDS, 'n', 8, 8, 5667);
+}
+TEST(array_store, TextSentencesRandom_Stride32_Chunk1)
+{
+ plain_text_helper(WORDS, 'a', 1, 32, 1212);
+}
+TEST(array_store, TextSentencesRandom_Stride12_Chunk512)
+{
+ plain_text_helper(WORDS, 'g', 12, 512, 9999);
+}
+TEST(array_store, TextSentencesRandom_Stride128_Chunk6)
+{
+ plain_text_helper(WORDS, 'b', 20, 6, 1000);
+}
#undef WORDS
-
/* -------------------------------------------------------------------- */
/* Random Data Tests */
-static unsigned int rand_range_i(RNG *rng, unsigned int min_i, unsigned int max_i, unsigned int step)
-{
- if (min_i == max_i) {
- return min_i;
- }
- BLI_assert(min_i <= max_i);
- BLI_assert(((min_i % step) == 0) && ((max_i % step) == 0));
- unsigned int range = (max_i - min_i);
- unsigned int value = BLI_rng_get_uint(rng) % range;
- value = (value / step) * step;
- return min_i + value;
+static unsigned int rand_range_i(RNG *rng,
+ unsigned int min_i,
+ unsigned int max_i,
+ unsigned int step)
+{
+ if (min_i == max_i) {
+ return min_i;
+ }
+ BLI_assert(min_i <= max_i);
+ BLI_assert(((min_i % step) == 0) && ((max_i % step) == 0));
+ unsigned int range = (max_i - min_i);
+ unsigned int value = BLI_rng_get_uint(rng) % range;
+ value = (value / step) * step;
+ return min_i + value;
+}
+
+static void testbuffer_list_state_random_data(ListBase *lb,
+ const size_t stride,
+ const size_t data_min_len,
+ const size_t data_max_len,
+
+ const unsigned int mutate,
+ RNG *rng)
+{
+ size_t data_len = rand_range_i(rng, data_min_len, data_max_len + stride, stride);
+ char *data = (char *)MEM_mallocN(data_len, __func__);
+
+ if (lb->last == NULL) {
+ BLI_rng_get_char_n(rng, data, data_len);
+ }
+ else {
+ TestBuffer *tb_last = (TestBuffer *)lb->last;
+ if (tb_last->data_len >= data_len) {
+ memcpy(data, tb_last->data, data_len);
+ }
+ else {
+ memcpy(data, tb_last->data, tb_last->data_len);
+ BLI_rng_get_char_n(rng, &data[tb_last->data_len], data_len - tb_last->data_len);
+ }
+
+ /* perform multiple small mutations to the array. */
+ for (int i = 0; i < mutate; i++) {
+ enum {
+ MUTATE_NOP = 0,
+ MUTATE_ADD,
+ MUTATE_REMOVE,
+ MUTATE_ROTATE,
+ MUTATE_RANDOMIZE,
+ MUTATE_TOTAL,
+ };
+
+ switch ((BLI_rng_get_uint(rng) % MUTATE_TOTAL)) {
+ case MUTATE_NOP: {
+ break;
+ }
+ case MUTATE_ADD: {
+ const unsigned int offset = rand_range_i(rng, 0, data_len, stride);
+ if (data_len < data_max_len) {
+ data_len += stride;
+ data = (char *)MEM_reallocN((void *)data, data_len);
+ memmove(&data[offset + stride], &data[offset], data_len - (offset + stride));
+ BLI_rng_get_char_n(rng, &data[offset], stride);
+ }
+ break;
+ }
+ case MUTATE_REMOVE: {
+ const unsigned int offset = rand_range_i(rng, 0, data_len, stride);
+ if (data_len > data_min_len) {
+ memmove(&data[offset], &data[offset + stride], data_len - (offset + stride));
+ data_len -= stride;
+ }
+ break;
+ }
+ case MUTATE_ROTATE: {
+ int items = data_len / stride;
+ if (items > 1) {
+ _bli_array_wrap(data, items, stride, (BLI_rng_get_uint(rng) % 2) ? -1 : 1);
+ }
+ break;
+ }
+ case MUTATE_RANDOMIZE: {
+ if (data_len > 0) {
+ const unsigned int offset = rand_range_i(rng, 0, data_len - stride, stride);
+ BLI_rng_get_char_n(rng, &data[offset], stride);
+ }
+ break;
+ }
+ default:
+ BLI_assert(0);
+ }
+ }
+ }
+
+ testbuffer_list_add(lb, (const void *)data, data_len);
+}
+
+static void random_data_mutate_helper(const int items_size_min,
+ const int items_size_max,
+ const int items_total,
+ const int stride,
+ const int chunk_count,
+ const int random_seed,
+ const int mutate)
+{
+
+ ListBase lb;
+ BLI_listbase_clear(&lb);
+
+ const size_t data_min_len = items_size_min * stride;
+ const size_t data_max_len = items_size_max * stride;
+
+ {
+ RNG *rng = BLI_rng_new(random_seed);
+ for (int i = 0; i < items_total; i++) {
+ testbuffer_list_state_random_data(&lb, stride, data_min_len, data_max_len, mutate, rng);
+ }
+ BLI_rng_free(rng);
+ }
+
+ testbuffer_run_tests_simple(&lb, stride, chunk_count);
+
+ testbuffer_list_free(&lb);
+}
+
+TEST(array_store, TestData_Stride1_Chunk32_Mutate2)
+{
+ random_data_mutate_helper(0, 100, 400, 1, 32, 9779, 2);
+}
+TEST(array_store, TestData_Stride8_Chunk512_Mutate2)
+{
+ random_data_mutate_helper(0, 128, 400, 8, 512, 1001, 2);
+}
+TEST(array_store, TestData_Stride12_Chunk48_Mutate2)
+{
+ random_data_mutate_helper(200, 256, 400, 12, 48, 1331, 2);
+}
+TEST(array_store, TestData_Stride32_Chunk64_Mutate1)
+{
+ random_data_mutate_helper(0, 256, 200, 32, 64, 3112, 1);
+}
+TEST(array_store, TestData_Stride32_Chunk64_Mutate8)
+{
+ random_data_mutate_helper(0, 256, 200, 32, 64, 7117, 8);
}
-static void testbuffer_list_state_random_data(
- ListBase *lb,
- const size_t stride,
- const size_t data_min_len, const size_t data_max_len,
-
- const unsigned int mutate, RNG *rng)
-{
- size_t data_len = rand_range_i(rng, data_min_len, data_max_len + stride, stride);
- char *data = (char *)MEM_mallocN(data_len, __func__);
-
- if (lb->last == NULL) {
- BLI_rng_get_char_n(rng, data, data_len);
- }
- else {
- TestBuffer *tb_last = (TestBuffer *)lb->last;
- if (tb_last->data_len >= data_len) {
- memcpy(data, tb_last->data, data_len);
- }
- else {
- memcpy(data, tb_last->data, tb_last->data_len);
- BLI_rng_get_char_n(rng, &data[tb_last->data_len], data_len - tb_last->data_len);
- }
-
- /* perform multiple small mutations to the array. */
- for (int i = 0; i < mutate; i++) {
- enum {
- MUTATE_NOP = 0,
- MUTATE_ADD,
- MUTATE_REMOVE,
- MUTATE_ROTATE,
- MUTATE_RANDOMIZE,
- MUTATE_TOTAL,
- };
-
- switch ((BLI_rng_get_uint(rng) % MUTATE_TOTAL)) {
- case MUTATE_NOP:
- {
- break;
- }
- case MUTATE_ADD:
- {
- const unsigned int offset = rand_range_i(rng, 0, data_len, stride);
- if (data_len < data_max_len) {
- data_len += stride;
- data = (char *)MEM_reallocN((void *)data, data_len);
- memmove(&data[offset + stride], &data[offset], data_len - (offset + stride));
- BLI_rng_get_char_n(rng, &data[offset], stride);
- }
- break;
- }
- case MUTATE_REMOVE:
- {
- const unsigned int offset = rand_range_i(rng, 0, data_len, stride);
- if (data_len > data_min_len) {
- memmove(&data[offset], &data[offset + stride], data_len - (offset + stride));
- data_len -= stride;
- }
- break;
- }
- case MUTATE_ROTATE:
- {
- int items = data_len / stride;
- if (items > 1) {
- _bli_array_wrap(data, items, stride, (BLI_rng_get_uint(rng) % 2) ? -1 : 1);
- }
- break;
- }
- case MUTATE_RANDOMIZE:
- {
- if (data_len > 0) {
- const unsigned int offset = rand_range_i(rng, 0, data_len - stride, stride);
- BLI_rng_get_char_n(rng, &data[offset], stride);
- }
- break;
- }
- default:
- BLI_assert(0);
- }
- }
- }
-
- testbuffer_list_add(lb, (const void *)data, data_len);
-}
-
-static void random_data_mutate_helper(
- const int items_size_min, const int items_size_max, const int items_total,
- const int stride, const int chunk_count,
- const int random_seed, const int mutate)
-{
-
-
- ListBase lb;
- BLI_listbase_clear(&lb);
-
- const size_t data_min_len = items_size_min * stride;
- const size_t data_max_len = items_size_max * stride;
-
- {
- RNG *rng = BLI_rng_new(random_seed);
- for (int i = 0; i < items_total; i++) {
- testbuffer_list_state_random_data(&lb, stride, data_min_len, data_max_len, mutate, rng);
- }
- BLI_rng_free(rng);
- }
-
- testbuffer_run_tests_simple(&lb, stride, chunk_count);
-
- testbuffer_list_free(&lb);
-}
-
-TEST(array_store, TestData_Stride1_Chunk32_Mutate2) { random_data_mutate_helper(0, 100, 400, 1, 32, 9779, 2); }
-TEST(array_store, TestData_Stride8_Chunk512_Mutate2) { random_data_mutate_helper(0, 128, 400, 8, 512, 1001, 2); }
-TEST(array_store, TestData_Stride12_Chunk48_Mutate2) { random_data_mutate_helper(200, 256, 400, 12, 48, 1331, 2); }
-TEST(array_store, TestData_Stride32_Chunk64_Mutate1) { random_data_mutate_helper(0, 256, 200, 32, 64, 3112, 1); }
-TEST(array_store, TestData_Stride32_Chunk64_Mutate8) { random_data_mutate_helper(0, 256, 200, 32, 64, 7117, 8); }
-
-
/* -------------------------------------------------------------------- */
/* Randomized Chunks Test */
-static void random_chunk_generate(
- ListBase *lb,
- const int chunks_per_buffer,
- const int stride, const int chunk_count,
- const int random_seed)
+static void random_chunk_generate(ListBase *lb,
+ const int chunks_per_buffer,
+ const int stride,
+ const int chunk_count,
+ const int random_seed)
{
- RNG *rng = BLI_rng_new(random_seed);
- const size_t chunk_size_bytes = stride * chunk_count;
- for (int i = 0; i < chunks_per_buffer; i++) {
- char *data_chunk = (char *)MEM_mallocN(chunk_size_bytes, __func__);
- BLI_rng_get_char_n(rng, data_chunk, chunk_size_bytes);
- testchunk_list_add(lb, data_chunk, chunk_size_bytes);
- }
- BLI_rng_free(rng);
+ RNG *rng = BLI_rng_new(random_seed);
+ const size_t chunk_size_bytes = stride * chunk_count;
+ for (int i = 0; i < chunks_per_buffer; i++) {
+ char *data_chunk = (char *)MEM_mallocN(chunk_size_bytes, __func__);
+ BLI_rng_get_char_n(rng, data_chunk, chunk_size_bytes);
+ testchunk_list_add(lb, data_chunk, chunk_size_bytes);
+ }
+ BLI_rng_free(rng);
}
/**
* Add random chunks, then re-order them to ensure chunk de-duplication is working.
*/
-static void random_chunk_mutate_helper(
- const int chunks_per_buffer, const int items_total,
- const int stride, const int chunk_count,
- const int random_seed)
+static void random_chunk_mutate_helper(const int chunks_per_buffer,
+ const int items_total,
+ const int stride,
+ const int chunk_count,
+ const int random_seed)
{
- /* generate random chunks */
+ /* generate random chunks */
- ListBase random_chunks;
- BLI_listbase_clear(&random_chunks);
- random_chunk_generate(&random_chunks, chunks_per_buffer, stride, chunk_count, random_seed);
- TestChunk **chunks_array = (TestChunk **)MEM_mallocN(chunks_per_buffer * sizeof(TestChunk *), __func__);
- {
- TestChunk *tc = (TestChunk *)random_chunks.first;
- for (int i = 0; i < chunks_per_buffer; i++, tc = tc->next) {
- chunks_array[i] = tc;
- }
- }
+ ListBase random_chunks;
+ BLI_listbase_clear(&random_chunks);
+ random_chunk_generate(&random_chunks, chunks_per_buffer, stride, chunk_count, random_seed);
+ TestChunk **chunks_array = (TestChunk **)MEM_mallocN(chunks_per_buffer * sizeof(TestChunk *),
+ __func__);
+ {
+ TestChunk *tc = (TestChunk *)random_chunks.first;
+ for (int i = 0; i < chunks_per_buffer; i++, tc = tc->next) {
+ chunks_array[i] = tc;
+ }
+ }
- /* add and re-order each time */
- ListBase lb;
- BLI_listbase_clear(&lb);
+ /* add and re-order each time */
+ ListBase lb;
+ BLI_listbase_clear(&lb);
- {
- RNG *rng = BLI_rng_new(random_seed);
- for (int i = 0; i < items_total; i++) {
- BLI_rng_shuffle_array(rng, chunks_array, sizeof(TestChunk *), chunks_per_buffer);
- size_t data_len;
- char *data = testchunk_as_data_array(chunks_array, chunks_per_buffer, &data_len);
- BLI_assert(data_len == chunks_per_buffer * chunk_count * stride);
- testbuffer_list_add(&lb, (const void *)data, data_len);
- }
- BLI_rng_free(rng);
- }
+ {
+ RNG *rng = BLI_rng_new(random_seed);
+ for (int i = 0; i < items_total; i++) {
+ BLI_rng_shuffle_array(rng, chunks_array, sizeof(TestChunk *), chunks_per_buffer);
+ size_t data_len;
+ char *data = testchunk_as_data_array(chunks_array, chunks_per_buffer, &data_len);
+ BLI_assert(data_len == chunks_per_buffer * chunk_count * stride);
+ testbuffer_list_add(&lb, (const void *)data, data_len);
+ }
+ BLI_rng_free(rng);
+ }
- testchunk_list_free(&random_chunks);
- MEM_freeN(chunks_array);
+ testchunk_list_free(&random_chunks);
+ MEM_freeN(chunks_array);
- BArrayStore *bs = BLI_array_store_create(stride, chunk_count);
- testbuffer_run_tests_single(bs, &lb);
+ BArrayStore *bs = BLI_array_store_create(stride, chunk_count);
+ testbuffer_run_tests_single(bs, &lb);
- size_t expected_size = chunks_per_buffer * chunk_count * stride;
- EXPECT_EQ(BLI_array_store_calc_size_compacted_get(bs), expected_size);
+ size_t expected_size = chunks_per_buffer * chunk_count * stride;
+ EXPECT_EQ(BLI_array_store_calc_size_compacted_get(bs), expected_size);
- BLI_array_store_destroy(bs);
-
- testbuffer_list_free(&lb);
+ BLI_array_store_destroy(bs);
+ testbuffer_list_free(&lb);
}
-TEST(array_store, TestChunk_Rand8_Stride1_Chunk64) { random_chunk_mutate_helper(8, 100, 1, 64, 9779); }
-TEST(array_store, TestChunk_Rand32_Stride1_Chunk64) { random_chunk_mutate_helper(32, 100, 1, 64, 1331); }
-TEST(array_store, TestChunk_Rand64_Stride8_Chunk32) { random_chunk_mutate_helper(64, 100, 8, 32, 2772); }
-TEST(array_store, TestChunk_Rand31_Stride11_Chunk21) { random_chunk_mutate_helper(31, 100, 11, 21, 7117); }
-
+TEST(array_store, TestChunk_Rand8_Stride1_Chunk64)
+{
+ random_chunk_mutate_helper(8, 100, 1, 64, 9779);
+}
+TEST(array_store, TestChunk_Rand32_Stride1_Chunk64)
+{
+ random_chunk_mutate_helper(32, 100, 1, 64, 1331);
+}
+TEST(array_store, TestChunk_Rand64_Stride8_Chunk32)
+{
+ random_chunk_mutate_helper(64, 100, 8, 32, 2772);
+}
+TEST(array_store, TestChunk_Rand31_Stride11_Chunk21)
+{
+ random_chunk_mutate_helper(31, 100, 11, 21, 7117);
+}
#if 0
/* -------------------------------------------------------------------- */
@@ -729,78 +812,78 @@ TEST(array_store, TestChunk_Rand31_Stride11_Chunk21) { random_chunk_mutate_helpe
void *file_read_binary_as_mem(const char *filepath, size_t pad_bytes, size_t *r_size)
{
- FILE *fp = fopen(filepath, "rb");
- void *mem = NULL;
+ FILE *fp = fopen(filepath, "rb");
+ void *mem = NULL;
- if (fp) {
- long int filelen_read;
- fseek(fp, 0L, SEEK_END);
- const long int filelen = ftell(fp);
- if (filelen == -1) {
- goto finally;
- }
- fseek(fp, 0L, SEEK_SET);
+ if (fp) {
+ long int filelen_read;
+ fseek(fp, 0L, SEEK_END);
+ const long int filelen = ftell(fp);
+ if (filelen == -1) {
+ goto finally;
+ }
+ fseek(fp, 0L, SEEK_SET);
- mem = MEM_mallocN(filelen + pad_bytes, __func__);
- if (mem == NULL) {
- goto finally;
- }
+ mem = MEM_mallocN(filelen + pad_bytes, __func__);
+ if (mem == NULL) {
+ goto finally;
+ }
- filelen_read = fread(mem, 1, filelen, fp);
- if ((filelen_read != filelen) || ferror(fp)) {
- MEM_freeN(mem);
- mem = NULL;
- goto finally;
- }
+ filelen_read = fread(mem, 1, filelen, fp);
+ if ((filelen_read != filelen) || ferror(fp)) {
+ MEM_freeN(mem);
+ mem = NULL;
+ goto finally;
+ }
- *r_size = filelen_read;
+ *r_size = filelen_read;
finally:
- fclose(fp);
- }
+ fclose(fp);
+ }
- return mem;
+ return mem;
}
TEST(array_store, PlainTextFiles)
-{ ListBase lb;
- BLI_listbase_clear(&lb);
- BArrayStore *bs = BLI_array_store_create(1, 128);
-
- for (int i = 0; i < 629; i++) {
- char str[512];
- BLI_snprintf(str, sizeof(str), "/src/py_array_cow/test_data/xz_data/%04d.c.xz", i);
- // BLI_snprintf(str, sizeof(str), "/src/py_array_cow/test_data/c_code/%04d.c", i);
- // printf("%s\n", str);
- size_t data_len;
- void *data;
- data = file_read_binary_as_mem(str, 0, &data_len);
-
- testbuffer_list_add(&lb, (const void *)data, data_len);
- }
-
- /* forwards */
- testbuffer_list_store_populate(bs, &lb);
- EXPECT_TRUE(testbuffer_list_validate(&lb));
- EXPECT_TRUE(BLI_array_store_is_valid(bs));
-#ifdef DEBUG_PRINT
- print_mem_saved("source code forward", bs);
-#endif
-
- testbuffer_list_store_clear(bs, &lb);
- BLI_listbase_reverse(&lb);
-
- /* backwards */
- testbuffer_list_store_populate(bs, &lb);
- EXPECT_TRUE(testbuffer_list_validate(&lb));
- EXPECT_TRUE(BLI_array_store_is_valid(bs));
-#ifdef DEBUG_PRINT
- print_mem_saved("source code backwards", bs);
-#endif
-
-
- testbuffer_list_free(&lb);
- BLI_array_store_destroy(bs);
+{ ListBase lb;
+ BLI_listbase_clear(&lb);
+ BArrayStore *bs = BLI_array_store_create(1, 128);
+
+ for (int i = 0; i < 629; i++) {
+ char str[512];
+ BLI_snprintf(str, sizeof(str), "/src/py_array_cow/test_data/xz_data/%04d.c.xz", i);
+ // BLI_snprintf(str, sizeof(str), "/src/py_array_cow/test_data/c_code/%04d.c", i);
+ // printf("%s\n", str);
+ size_t data_len;
+ void *data;
+ data = file_read_binary_as_mem(str, 0, &data_len);
+
+ testbuffer_list_add(&lb, (const void *)data, data_len);
+ }
+
+ /* forwards */
+ testbuffer_list_store_populate(bs, &lb);
+ EXPECT_TRUE(testbuffer_list_validate(&lb));
+ EXPECT_TRUE(BLI_array_store_is_valid(bs));
+# ifdef DEBUG_PRINT
+ print_mem_saved("source code forward", bs);
+# endif
+
+ testbuffer_list_store_clear(bs, &lb);
+ BLI_listbase_reverse(&lb);
+
+ /* backwards */
+ testbuffer_list_store_populate(bs, &lb);
+ EXPECT_TRUE(testbuffer_list_validate(&lb));
+ EXPECT_TRUE(BLI_array_store_is_valid(bs));
+# ifdef DEBUG_PRINT
+ print_mem_saved("source code backwards", bs);
+# endif
+
+
+ testbuffer_list_free(&lb);
+ BLI_array_store_destroy(bs);
}
#endif
diff --git a/tests/gtests/blenlib/BLI_array_utils_test.cc b/tests/gtests/blenlib/BLI_array_utils_test.cc
index 6daa400a478..fd9caed58f0 100644
--- a/tests/gtests/blenlib/BLI_array_utils_test.cc
+++ b/tests/gtests/blenlib/BLI_array_utils_test.cc
@@ -14,176 +14,180 @@ extern "C" {
/* BLI_array_reverse */
TEST(array_utils, ReverseStringEmpty)
{
- char data[] = "";
- BLI_array_reverse(data, ARRAY_SIZE(data) - 1);
- EXPECT_STREQ("", data);
+ char data[] = "";
+ BLI_array_reverse(data, ARRAY_SIZE(data) - 1);
+ EXPECT_STREQ("", data);
}
TEST(array_utils, ReverseStringSingle)
{
- char data[] = "0";
- BLI_array_reverse(data, ARRAY_SIZE(data) - 1);
- EXPECT_STREQ("0", data);
+ char data[] = "0";
+ BLI_array_reverse(data, ARRAY_SIZE(data) - 1);
+ EXPECT_STREQ("0", data);
}
TEST(array_utils, ReverseString4)
{
- char data[] = "0123";
- BLI_array_reverse(data, ARRAY_SIZE(data) - 1);
- EXPECT_STREQ("3210", data);
+ char data[] = "0123";
+ BLI_array_reverse(data, ARRAY_SIZE(data) - 1);
+ EXPECT_STREQ("3210", data);
}
TEST(array_utils, ReverseInt4)
{
- const int data_cmp[] = {3, 2, 1, 0};
- int data[] = {0, 1, 2, 3};
- BLI_array_reverse(data, ARRAY_SIZE(data));
- EXPECT_EQ_ARRAY(data_cmp, data, ARRAY_SIZE(data));
+ const int data_cmp[] = {3, 2, 1, 0};
+ int data[] = {0, 1, 2, 3};
+ BLI_array_reverse(data, ARRAY_SIZE(data));
+ EXPECT_EQ_ARRAY(data_cmp, data, ARRAY_SIZE(data));
}
/* BLI_array_findindex */
TEST(array_utils, FindIndexStringEmpty)
{
- char data[] = "", find = '0';
- EXPECT_EQ(BLI_array_findindex(data, ARRAY_SIZE(data) - 1, &find), -1);
- EXPECT_EQ(BLI_array_rfindindex(data, ARRAY_SIZE(data) - 1, &find), -1);
+ char data[] = "", find = '0';
+ EXPECT_EQ(BLI_array_findindex(data, ARRAY_SIZE(data) - 1, &find), -1);
+ EXPECT_EQ(BLI_array_rfindindex(data, ARRAY_SIZE(data) - 1, &find), -1);
}
TEST(array_utils, FindIndexStringSingle)
{
- char data[] = "0", find = '0';
- EXPECT_EQ(BLI_array_findindex(data, ARRAY_SIZE(data) - 1, &find), 0);
- EXPECT_EQ(BLI_array_rfindindex(data, ARRAY_SIZE(data) - 1, &find), 0);
+ char data[] = "0", find = '0';
+ EXPECT_EQ(BLI_array_findindex(data, ARRAY_SIZE(data) - 1, &find), 0);
+ EXPECT_EQ(BLI_array_rfindindex(data, ARRAY_SIZE(data) - 1, &find), 0);
}
TEST(array_utils, FindIndexStringSingleMissing)
{
- char data[] = "1", find = '0';
- EXPECT_EQ(BLI_array_findindex(data, ARRAY_SIZE(data) - 1, &find), -1);
- EXPECT_EQ(BLI_array_rfindindex(data, ARRAY_SIZE(data) - 1, &find), -1);
+ char data[] = "1", find = '0';
+ EXPECT_EQ(BLI_array_findindex(data, ARRAY_SIZE(data) - 1, &find), -1);
+ EXPECT_EQ(BLI_array_rfindindex(data, ARRAY_SIZE(data) - 1, &find), -1);
}
TEST(array_utils, FindIndexString4)
{
- char data[] = "0123", find = '3';
- EXPECT_EQ(BLI_array_findindex(data, ARRAY_SIZE(data) - 1, &find), 3);
- EXPECT_EQ(BLI_array_rfindindex(data, ARRAY_SIZE(data) - 1, &find), 3);
+ char data[] = "0123", find = '3';
+ EXPECT_EQ(BLI_array_findindex(data, ARRAY_SIZE(data) - 1, &find), 3);
+ EXPECT_EQ(BLI_array_rfindindex(data, ARRAY_SIZE(data) - 1, &find), 3);
}
TEST(array_utils, FindIndexInt4)
{
- int data[] = {0, 1, 2, 3}, find = 3;
- EXPECT_EQ(BLI_array_findindex(data, ARRAY_SIZE(data), &find), 3);
- EXPECT_EQ(BLI_array_rfindindex(data, ARRAY_SIZE(data), &find), 3);
+ int data[] = {0, 1, 2, 3}, find = 3;
+ EXPECT_EQ(BLI_array_findindex(data, ARRAY_SIZE(data), &find), 3);
+ EXPECT_EQ(BLI_array_rfindindex(data, ARRAY_SIZE(data), &find), 3);
}
TEST(array_utils, FindIndexInt4_DupeEnd)
{
- int data[] = {0, 1, 2, 0}, find = 0;
- EXPECT_EQ(BLI_array_findindex(data, ARRAY_SIZE(data), &find), 0);
- EXPECT_EQ(BLI_array_rfindindex(data, ARRAY_SIZE(data), &find), 3);
+ int data[] = {0, 1, 2, 0}, find = 0;
+ EXPECT_EQ(BLI_array_findindex(data, ARRAY_SIZE(data), &find), 0);
+ EXPECT_EQ(BLI_array_rfindindex(data, ARRAY_SIZE(data), &find), 3);
}
TEST(array_utils, FindIndexInt4_DupeMid)
{
- int data[] = {1, 0, 0, 3}, find = 0;
- EXPECT_EQ(BLI_array_findindex(data, ARRAY_SIZE(data), &find), 1);
- EXPECT_EQ(BLI_array_rfindindex(data, ARRAY_SIZE(data), &find), 2);
+ int data[] = {1, 0, 0, 3}, find = 0;
+ EXPECT_EQ(BLI_array_findindex(data, ARRAY_SIZE(data), &find), 1);
+ EXPECT_EQ(BLI_array_rfindindex(data, ARRAY_SIZE(data), &find), 2);
}
TEST(array_utils, FindIndexPointer)
{
- const char *data[4] = {NULL};
- STACK_DECLARE(data);
+ const char *data[4] = {NULL};
+ STACK_DECLARE(data);
- STACK_INIT(data, ARRAY_SIZE(data));
+ STACK_INIT(data, ARRAY_SIZE(data));
- const char *a = "a", *b = "b", *c = "c", *d = "d";
+ const char *a = "a", *b = "b", *c = "c", *d = "d";
-#define STACK_PUSH_AND_CHECK_FORWARD(v, i) { \
- STACK_PUSH(data, v); \
- EXPECT_EQ(BLI_array_findindex(data, STACK_SIZE(data), &(v)), i); \
-} ((void)0)
+#define STACK_PUSH_AND_CHECK_FORWARD(v, i) \
+ { \
+ STACK_PUSH(data, v); \
+ EXPECT_EQ(BLI_array_findindex(data, STACK_SIZE(data), &(v)), i); \
+ } \
+ ((void)0)
-#define STACK_PUSH_AND_CHECK_BACKWARD(v, i) { \
- STACK_PUSH(data, v); \
- EXPECT_EQ(BLI_array_rfindindex(data, STACK_SIZE(data), &(v)), i); \
-} ((void)0)
+#define STACK_PUSH_AND_CHECK_BACKWARD(v, i) \
+ { \
+ STACK_PUSH(data, v); \
+ EXPECT_EQ(BLI_array_rfindindex(data, STACK_SIZE(data), &(v)), i); \
+ } \
+ ((void)0)
-#define STACK_PUSH_AND_CHECK_BOTH(v, i) { \
- STACK_PUSH(data, v); \
- EXPECT_EQ(BLI_array_findindex(data, STACK_SIZE(data), &(v)), i); \
- EXPECT_EQ(BLI_array_rfindindex(data, STACK_SIZE(data), &(v)), i); \
-} ((void)0)
+#define STACK_PUSH_AND_CHECK_BOTH(v, i) \
+ { \
+ STACK_PUSH(data, v); \
+ EXPECT_EQ(BLI_array_findindex(data, STACK_SIZE(data), &(v)), i); \
+ EXPECT_EQ(BLI_array_rfindindex(data, STACK_SIZE(data), &(v)), i); \
+ } \
+ ((void)0)
- STACK_PUSH_AND_CHECK_BOTH(a, 0);
- STACK_PUSH_AND_CHECK_BOTH(b, 1);
- STACK_PUSH_AND_CHECK_BOTH(c, 2);
- STACK_PUSH_AND_CHECK_BOTH(d, 3);
+ STACK_PUSH_AND_CHECK_BOTH(a, 0);
+ STACK_PUSH_AND_CHECK_BOTH(b, 1);
+ STACK_PUSH_AND_CHECK_BOTH(c, 2);
+ STACK_PUSH_AND_CHECK_BOTH(d, 3);
- STACK_POP(data);
- STACK_PUSH_AND_CHECK_BACKWARD(a, 3);
+ STACK_POP(data);
+ STACK_PUSH_AND_CHECK_BACKWARD(a, 3);
- STACK_POP(data);
- STACK_PUSH_AND_CHECK_FORWARD(a, 0);
+ STACK_POP(data);
+ STACK_PUSH_AND_CHECK_FORWARD(a, 0);
- STACK_POP(data);
- STACK_POP(data);
+ STACK_POP(data);
+ STACK_POP(data);
- STACK_PUSH_AND_CHECK_BACKWARD(b, 2);
- STACK_PUSH_AND_CHECK_BACKWARD(a, 3);
+ STACK_PUSH_AND_CHECK_BACKWARD(b, 2);
+ STACK_PUSH_AND_CHECK_BACKWARD(a, 3);
#undef STACK_PUSH_AND_CHECK_FORWARD
#undef STACK_PUSH_AND_CHECK_BACKWARD
#undef STACK_PUSH_AND_CHECK_BOTH
-
}
-
-
/* BLI_array_binary_and */
#define BINARY_AND_TEST(data_cmp, data_a, data_b, data_combine, length) \
-{ \
- BLI_array_binary_and(data_combine, data_a, data_b, length); \
- EXPECT_EQ_ARRAY(data_cmp, data_combine, length); \
-} ((void)0)
+ { \
+ BLI_array_binary_and(data_combine, data_a, data_b, length); \
+ EXPECT_EQ_ARRAY(data_cmp, data_combine, length); \
+ } \
+ ((void)0)
TEST(array_utils, BinaryAndInt4Zero)
{
- const int data_cmp[] = {0, 0, 0, 0};
- int data_a[] = {0, 1, 0, 1}, data_b[] = {1, 0, 1, 0};
- int data_combine[ARRAY_SIZE(data_cmp)];
- BINARY_AND_TEST(data_cmp, data_a, data_b, data_combine, ARRAY_SIZE(data_cmp));
+ const int data_cmp[] = {0, 0, 0, 0};
+ int data_a[] = {0, 1, 0, 1}, data_b[] = {1, 0, 1, 0};
+ int data_combine[ARRAY_SIZE(data_cmp)];
+ BINARY_AND_TEST(data_cmp, data_a, data_b, data_combine, ARRAY_SIZE(data_cmp));
}
TEST(array_utils, BinaryAndInt4Mix)
{
- const int data_cmp[] = {1, 0, 1, 0};
- int data_a[] = {1, 1, 1, 1}, data_b[] = {1, 0, 1, 0};
- int data_combine[ARRAY_SIZE(data_cmp)];
- BINARY_AND_TEST(data_cmp, data_a, data_b, data_combine, ARRAY_SIZE(data_cmp));
+ const int data_cmp[] = {1, 0, 1, 0};
+ int data_a[] = {1, 1, 1, 1}, data_b[] = {1, 0, 1, 0};
+ int data_combine[ARRAY_SIZE(data_cmp)];
+ BINARY_AND_TEST(data_cmp, data_a, data_b, data_combine, ARRAY_SIZE(data_cmp));
}
#undef BINARY_AND_TEST
-
/* BLI_array_binary_or */
#define BINARY_OR_TEST(data_cmp, data_a, data_b, data_combine, length) \
-{ \
- BLI_array_binary_or(data_combine, data_a, data_b, length); \
- EXPECT_EQ_ARRAY(data_combine, data_cmp, length); \
-} ((void)0)
+ { \
+ BLI_array_binary_or(data_combine, data_a, data_b, length); \
+ EXPECT_EQ_ARRAY(data_combine, data_cmp, length); \
+ } \
+ ((void)0)
TEST(array_utils, BinaryOrInt4Alternate)
{
- int data_a[] = {0, 1, 0, 1}, data_b[] = {1, 0, 1, 0}, data_cmp[] = {1, 1, 1, 1};
- int data_combine[ARRAY_SIZE(data_cmp)];
- BINARY_OR_TEST(data_cmp, data_a, data_b, data_combine, ARRAY_SIZE(data_cmp));
+ int data_a[] = {0, 1, 0, 1}, data_b[] = {1, 0, 1, 0}, data_cmp[] = {1, 1, 1, 1};
+ int data_combine[ARRAY_SIZE(data_cmp)];
+ BINARY_OR_TEST(data_cmp, data_a, data_b, data_combine, ARRAY_SIZE(data_cmp));
}
TEST(array_utils, BinaryOrInt4Mix)
{
- int data_a[] = {1, 1, 0, 0}, data_b[] = {0, 0, 1, 0}, data_cmp[] = {1, 1, 1, 0};
- int data_combine[ARRAY_SIZE(data_cmp)];
- BINARY_OR_TEST(data_cmp, data_a, data_b, data_combine, ARRAY_SIZE(data_cmp));
+ int data_a[] = {1, 1, 0, 0}, data_b[] = {0, 0, 1, 0}, data_cmp[] = {1, 1, 1, 0};
+ int data_combine[ARRAY_SIZE(data_cmp)];
+ BINARY_OR_TEST(data_cmp, data_a, data_b, data_combine, ARRAY_SIZE(data_cmp));
}
#undef BINARY_OR_TEST
diff --git a/tests/gtests/blenlib/BLI_edgehash_test.cc b/tests/gtests/blenlib/BLI_edgehash_test.cc
index a9771d50c92..0ca251fee50 100644
--- a/tests/gtests/blenlib/BLI_edgehash_test.cc
+++ b/tests/gtests/blenlib/BLI_edgehash_test.cc
@@ -15,391 +15,393 @@ extern "C" {
TEST(edgehash, InsertIncreasesLength)
{
- EdgeHash *eh = BLI_edgehash_new(__func__);
+ EdgeHash *eh = BLI_edgehash_new(__func__);
- ASSERT_EQ(BLI_edgehash_len(eh), 0);
- BLI_edgehash_insert(eh, 1, 2, VALUE_1);
- ASSERT_EQ(BLI_edgehash_len(eh), 1);
+ ASSERT_EQ(BLI_edgehash_len(eh), 0);
+ BLI_edgehash_insert(eh, 1, 2, VALUE_1);
+ ASSERT_EQ(BLI_edgehash_len(eh), 1);
- BLI_edgehash_free(eh, nullptr);
+ BLI_edgehash_free(eh, nullptr);
}
TEST(edgehash, ReinsertNewIncreasesLength)
{
- EdgeHash *eh = BLI_edgehash_new(__func__);
+ EdgeHash *eh = BLI_edgehash_new(__func__);
- ASSERT_EQ(BLI_edgehash_len(eh), 0);
- BLI_edgehash_reinsert(eh, 1, 2, VALUE_1);
- ASSERT_EQ(BLI_edgehash_len(eh), 1);
+ ASSERT_EQ(BLI_edgehash_len(eh), 0);
+ BLI_edgehash_reinsert(eh, 1, 2, VALUE_1);
+ ASSERT_EQ(BLI_edgehash_len(eh), 1);
- BLI_edgehash_free(eh, nullptr);
+ BLI_edgehash_free(eh, nullptr);
}
TEST(edgehash, ReinsertExistingDoesNotIncreaseLength)
{
- EdgeHash *eh = BLI_edgehash_new(__func__);
+ EdgeHash *eh = BLI_edgehash_new(__func__);
- ASSERT_EQ(BLI_edgehash_len(eh), 0);
- BLI_edgehash_reinsert(eh, 1, 2, VALUE_1);
- ASSERT_EQ(BLI_edgehash_len(eh), 1);
- BLI_edgehash_reinsert(eh, 1, 2, VALUE_2);
- ASSERT_EQ(BLI_edgehash_len(eh), 1);
- BLI_edgehash_reinsert(eh, 2, 1, VALUE_2);
- ASSERT_EQ(BLI_edgehash_len(eh), 1);
+ ASSERT_EQ(BLI_edgehash_len(eh), 0);
+ BLI_edgehash_reinsert(eh, 1, 2, VALUE_1);
+ ASSERT_EQ(BLI_edgehash_len(eh), 1);
+ BLI_edgehash_reinsert(eh, 1, 2, VALUE_2);
+ ASSERT_EQ(BLI_edgehash_len(eh), 1);
+ BLI_edgehash_reinsert(eh, 2, 1, VALUE_2);
+ ASSERT_EQ(BLI_edgehash_len(eh), 1);
- BLI_edgehash_free(eh, nullptr);
+ BLI_edgehash_free(eh, nullptr);
}
TEST(edgehash, ReinsertCanChangeValue)
{
- EdgeHash *eh = BLI_edgehash_new(__func__);
+ EdgeHash *eh = BLI_edgehash_new(__func__);
- BLI_edgehash_insert(eh, 1, 2, VALUE_1);
- ASSERT_EQ(BLI_edgehash_lookup(eh, 1, 2), VALUE_1);
- BLI_edgehash_reinsert(eh, 2, 1, VALUE_2);
- ASSERT_EQ(BLI_edgehash_lookup(eh, 1, 2), VALUE_2);
- BLI_edgehash_reinsert(eh, 1, 2, VALUE_3);
- ASSERT_EQ(BLI_edgehash_lookup(eh, 2, 1), VALUE_3);
+ BLI_edgehash_insert(eh, 1, 2, VALUE_1);
+ ASSERT_EQ(BLI_edgehash_lookup(eh, 1, 2), VALUE_1);
+ BLI_edgehash_reinsert(eh, 2, 1, VALUE_2);
+ ASSERT_EQ(BLI_edgehash_lookup(eh, 1, 2), VALUE_2);
+ BLI_edgehash_reinsert(eh, 1, 2, VALUE_3);
+ ASSERT_EQ(BLI_edgehash_lookup(eh, 2, 1), VALUE_3);
- BLI_edgehash_free(eh, nullptr);
+ BLI_edgehash_free(eh, nullptr);
}
TEST(edgehash, LookupExisting)
{
- EdgeHash *eh = BLI_edgehash_new(__func__);
+ EdgeHash *eh = BLI_edgehash_new(__func__);
- BLI_edgehash_insert(eh, 1, 2, VALUE_1);
- ASSERT_EQ(BLI_edgehash_lookup(eh, 1, 2), VALUE_1);
- ASSERT_EQ(BLI_edgehash_lookup(eh, 2, 1), VALUE_1);
+ BLI_edgehash_insert(eh, 1, 2, VALUE_1);
+ ASSERT_EQ(BLI_edgehash_lookup(eh, 1, 2), VALUE_1);
+ ASSERT_EQ(BLI_edgehash_lookup(eh, 2, 1), VALUE_1);
- BLI_edgehash_free(eh, nullptr);
+ BLI_edgehash_free(eh, nullptr);
}
TEST(edgehash, LookupNonExisting)
{
- EdgeHash *eh = BLI_edgehash_new(__func__);
+ EdgeHash *eh = BLI_edgehash_new(__func__);
- ASSERT_EQ(BLI_edgehash_lookup(eh, 1, 2), nullptr);
+ ASSERT_EQ(BLI_edgehash_lookup(eh, 1, 2), nullptr);
- BLI_edgehash_free(eh, nullptr);
+ BLI_edgehash_free(eh, nullptr);
}
TEST(edgehash, LookupNonExistingWithDefault)
{
- EdgeHash *eh = BLI_edgehash_new(__func__);
+ EdgeHash *eh = BLI_edgehash_new(__func__);
- ASSERT_EQ(BLI_edgehash_lookup_default(eh, 1, 2, VALUE_1), VALUE_1);
+ ASSERT_EQ(BLI_edgehash_lookup_default(eh, 1, 2, VALUE_1), VALUE_1);
- BLI_edgehash_free(eh, nullptr);
+ BLI_edgehash_free(eh, nullptr);
}
TEST(edgehash, LookupExistingWithDefault)
{
- EdgeHash *eh = BLI_edgehash_new(__func__);
+ EdgeHash *eh = BLI_edgehash_new(__func__);
- BLI_edgehash_insert(eh, 1, 2, VALUE_1);
- ASSERT_EQ(BLI_edgehash_lookup_default(eh, 1, 2, VALUE_2), VALUE_1);
+ BLI_edgehash_insert(eh, 1, 2, VALUE_1);
+ ASSERT_EQ(BLI_edgehash_lookup_default(eh, 1, 2, VALUE_2), VALUE_1);
- BLI_edgehash_free(eh, nullptr);
+ BLI_edgehash_free(eh, nullptr);
}
TEST(edgehash, LookupPExisting)
{
- EdgeHash *eh = BLI_edgehash_new(__func__);
+ EdgeHash *eh = BLI_edgehash_new(__func__);
- void *value = VALUE_1;
- BLI_edgehash_insert(eh, 1, 2, value);
- void **value_p = BLI_edgehash_lookup_p(eh, 1, 2);
- ASSERT_EQ(*value_p, VALUE_1);
- *value_p = VALUE_2;
- ASSERT_EQ(BLI_edgehash_lookup(eh, 1, 2), VALUE_2);
+ void *value = VALUE_1;
+ BLI_edgehash_insert(eh, 1, 2, value);
+ void **value_p = BLI_edgehash_lookup_p(eh, 1, 2);
+ ASSERT_EQ(*value_p, VALUE_1);
+ *value_p = VALUE_2;
+ ASSERT_EQ(BLI_edgehash_lookup(eh, 1, 2), VALUE_2);
- BLI_edgehash_free(eh, nullptr);
+ BLI_edgehash_free(eh, nullptr);
}
TEST(edgehash, LookupPNonExisting)
{
- EdgeHash *eh = BLI_edgehash_new(__func__);
+ EdgeHash *eh = BLI_edgehash_new(__func__);
- ASSERT_EQ(BLI_edgehash_lookup_p(eh, 1, 2), nullptr);
+ ASSERT_EQ(BLI_edgehash_lookup_p(eh, 1, 2), nullptr);
- BLI_edgehash_free(eh, nullptr);
+ BLI_edgehash_free(eh, nullptr);
}
TEST(edgehash, EnsurePNonExisting)
{
- EdgeHash *eh = BLI_edgehash_new(__func__);
+ EdgeHash *eh = BLI_edgehash_new(__func__);
- void **value_p;
- bool existed = BLI_edgehash_ensure_p(eh, 1, 2, &value_p);
- ASSERT_FALSE(existed);
- *value_p = VALUE_1;
- ASSERT_EQ(BLI_edgehash_lookup(eh, 1, 2), VALUE_1);
+ void **value_p;
+ bool existed = BLI_edgehash_ensure_p(eh, 1, 2, &value_p);
+ ASSERT_FALSE(existed);
+ *value_p = VALUE_1;
+ ASSERT_EQ(BLI_edgehash_lookup(eh, 1, 2), VALUE_1);
- BLI_edgehash_free(eh, nullptr);
+ BLI_edgehash_free(eh, nullptr);
}
TEST(edgehash, EnsurePExisting)
{
- EdgeHash *eh = BLI_edgehash_new(__func__);
+ EdgeHash *eh = BLI_edgehash_new(__func__);
- BLI_edgehash_insert(eh, 1, 2, VALUE_1);
- void **value_p;
- bool existed = BLI_edgehash_ensure_p(eh, 1, 2, &value_p);
- ASSERT_TRUE(existed);
- ASSERT_EQ(*value_p, VALUE_1);
- *value_p = VALUE_2;
- ASSERT_EQ(BLI_edgehash_lookup(eh, 1, 2), VALUE_2);
+ BLI_edgehash_insert(eh, 1, 2, VALUE_1);
+ void **value_p;
+ bool existed = BLI_edgehash_ensure_p(eh, 1, 2, &value_p);
+ ASSERT_TRUE(existed);
+ ASSERT_EQ(*value_p, VALUE_1);
+ *value_p = VALUE_2;
+ ASSERT_EQ(BLI_edgehash_lookup(eh, 1, 2), VALUE_2);
- BLI_edgehash_free(eh, nullptr);
+ BLI_edgehash_free(eh, nullptr);
}
TEST(edgehash, RemoveExistingDecreasesLength)
{
- EdgeHash *eh = BLI_edgehash_new(__func__);
+ EdgeHash *eh = BLI_edgehash_new(__func__);
- BLI_edgehash_insert(eh, 1, 2, VALUE_1);
- ASSERT_EQ(BLI_edgehash_len(eh), 1);
- bool has_been_removed = BLI_edgehash_remove(eh, 1, 2, nullptr);
- ASSERT_EQ(BLI_edgehash_len(eh), 0);
- ASSERT_TRUE(has_been_removed);
+ BLI_edgehash_insert(eh, 1, 2, VALUE_1);
+ ASSERT_EQ(BLI_edgehash_len(eh), 1);
+ bool has_been_removed = BLI_edgehash_remove(eh, 1, 2, nullptr);
+ ASSERT_EQ(BLI_edgehash_len(eh), 0);
+ ASSERT_TRUE(has_been_removed);
- BLI_edgehash_free(eh, nullptr);
+ BLI_edgehash_free(eh, nullptr);
}
TEST(edgehash, RemoveNonExistingDoesNotDecreaseLength)
{
- EdgeHash *eh = BLI_edgehash_new(__func__);
+ EdgeHash *eh = BLI_edgehash_new(__func__);
- BLI_edgehash_insert(eh, 1, 2, VALUE_1);
- ASSERT_EQ(BLI_edgehash_len(eh), 1);
- bool has_been_removed = BLI_edgehash_remove(eh, 4, 5, nullptr);
- ASSERT_EQ(BLI_edgehash_len(eh), 1);
- ASSERT_FALSE(has_been_removed);
+ BLI_edgehash_insert(eh, 1, 2, VALUE_1);
+ ASSERT_EQ(BLI_edgehash_len(eh), 1);
+ bool has_been_removed = BLI_edgehash_remove(eh, 4, 5, nullptr);
+ ASSERT_EQ(BLI_edgehash_len(eh), 1);
+ ASSERT_FALSE(has_been_removed);
- BLI_edgehash_free(eh, nullptr);
+ BLI_edgehash_free(eh, nullptr);
}
TEST(edgehash, PopKeyTwice)
{
- EdgeHash *eh = BLI_edgehash_new(__func__);
+ EdgeHash *eh = BLI_edgehash_new(__func__);
- BLI_edgehash_insert(eh, 1, 2, VALUE_1);
- ASSERT_EQ(BLI_edgehash_popkey(eh, 1, 2), VALUE_1);
- ASSERT_EQ(BLI_edgehash_popkey(eh, 1, 2), nullptr);
+ BLI_edgehash_insert(eh, 1, 2, VALUE_1);
+ ASSERT_EQ(BLI_edgehash_popkey(eh, 1, 2), VALUE_1);
+ ASSERT_EQ(BLI_edgehash_popkey(eh, 1, 2), nullptr);
- BLI_edgehash_free(eh, nullptr);
+ BLI_edgehash_free(eh, nullptr);
}
TEST(edgehash, LookupInvertedIndices)
{
- EdgeHash *eh = BLI_edgehash_new(__func__);
+ EdgeHash *eh = BLI_edgehash_new(__func__);
- BLI_edgehash_insert(eh, 1, 2, VALUE_1);
- ASSERT_EQ(BLI_edgehash_lookup(eh, 2, 1), VALUE_1);
+ BLI_edgehash_insert(eh, 1, 2, VALUE_1);
+ ASSERT_EQ(BLI_edgehash_lookup(eh, 2, 1), VALUE_1);
- BLI_edgehash_free(eh, nullptr);
+ BLI_edgehash_free(eh, nullptr);
}
TEST(edgehash, HasKeyExisting)
{
- EdgeHash *eh = BLI_edgehash_new(__func__);
+ EdgeHash *eh = BLI_edgehash_new(__func__);
- BLI_edgehash_insert(eh, 1, 2, VALUE_1);
- ASSERT_TRUE(BLI_edgehash_haskey(eh, 1, 2));
- ASSERT_TRUE(BLI_edgehash_haskey(eh, 2, 1));
+ BLI_edgehash_insert(eh, 1, 2, VALUE_1);
+ ASSERT_TRUE(BLI_edgehash_haskey(eh, 1, 2));
+ ASSERT_TRUE(BLI_edgehash_haskey(eh, 2, 1));
- BLI_edgehash_free(eh, nullptr);
+ BLI_edgehash_free(eh, nullptr);
}
TEST(edgehash, HasKeyNonExisting)
{
- EdgeHash *eh = BLI_edgehash_new(__func__);
+ EdgeHash *eh = BLI_edgehash_new(__func__);
- ASSERT_FALSE(BLI_edgehash_haskey(eh, 1, 2));
+ ASSERT_FALSE(BLI_edgehash_haskey(eh, 1, 2));
- BLI_edgehash_free(eh, nullptr);
+ BLI_edgehash_free(eh, nullptr);
}
TEST(edgehash, ClearSetsLengthToZero)
{
- EdgeHash *eh = BLI_edgehash_new(__func__);
+ EdgeHash *eh = BLI_edgehash_new(__func__);
- BLI_edgehash_insert(eh, 1, 2, VALUE_1);
- BLI_edgehash_insert(eh, 1, 2, VALUE_2);
- ASSERT_EQ(BLI_edgehash_len(eh), 2);
- BLI_edgehash_clear(eh, nullptr);
- ASSERT_EQ(BLI_edgehash_len(eh), 0);
+ BLI_edgehash_insert(eh, 1, 2, VALUE_1);
+ BLI_edgehash_insert(eh, 1, 2, VALUE_2);
+ ASSERT_EQ(BLI_edgehash_len(eh), 2);
+ BLI_edgehash_clear(eh, nullptr);
+ ASSERT_EQ(BLI_edgehash_len(eh), 0);
- BLI_edgehash_free(eh, nullptr);
+ BLI_edgehash_free(eh, nullptr);
}
TEST(edgehash, IteratorFindsAllValues)
{
- EdgeHash *eh = BLI_edgehash_new(__func__);
-
- BLI_edgehash_insert(eh, 1, 2, VALUE_1);
- BLI_edgehash_insert(eh, 1, 3, VALUE_2);
- BLI_edgehash_insert(eh, 1, 4, VALUE_3);
-
- EdgeHashIterator *ehi = BLI_edgehashIterator_new(eh);
- auto a = BLI_edgehashIterator_getValue(ehi);
- BLI_edgehashIterator_step(ehi);
- auto b = BLI_edgehashIterator_getValue(ehi);
- BLI_edgehashIterator_step(ehi);
- auto c = BLI_edgehashIterator_getValue(ehi);
- BLI_edgehashIterator_step(ehi);
-
- ASSERT_NE(a, b);
- ASSERT_NE(b, c);
- ASSERT_NE(a, c);
- ASSERT_TRUE(ELEM(a, VALUE_1, VALUE_2, VALUE_3));
- ASSERT_TRUE(ELEM(b, VALUE_1, VALUE_2, VALUE_3));
- ASSERT_TRUE(ELEM(c, VALUE_1, VALUE_2, VALUE_3));
-
- BLI_edgehashIterator_free(ehi);
- BLI_edgehash_free(eh, nullptr);
+ EdgeHash *eh = BLI_edgehash_new(__func__);
+
+ BLI_edgehash_insert(eh, 1, 2, VALUE_1);
+ BLI_edgehash_insert(eh, 1, 3, VALUE_2);
+ BLI_edgehash_insert(eh, 1, 4, VALUE_3);
+
+ EdgeHashIterator *ehi = BLI_edgehashIterator_new(eh);
+ auto a = BLI_edgehashIterator_getValue(ehi);
+ BLI_edgehashIterator_step(ehi);
+ auto b = BLI_edgehashIterator_getValue(ehi);
+ BLI_edgehashIterator_step(ehi);
+ auto c = BLI_edgehashIterator_getValue(ehi);
+ BLI_edgehashIterator_step(ehi);
+
+ ASSERT_NE(a, b);
+ ASSERT_NE(b, c);
+ ASSERT_NE(a, c);
+ ASSERT_TRUE(ELEM(a, VALUE_1, VALUE_2, VALUE_3));
+ ASSERT_TRUE(ELEM(b, VALUE_1, VALUE_2, VALUE_3));
+ ASSERT_TRUE(ELEM(c, VALUE_1, VALUE_2, VALUE_3));
+
+ BLI_edgehashIterator_free(ehi);
+ BLI_edgehash_free(eh, nullptr);
}
TEST(edgehash, IterateIsDone)
{
- EdgeHash *eh = BLI_edgehash_new(__func__);
-
- BLI_edgehash_insert(eh, 1, 2, VALUE_1);
- BLI_edgehash_insert(eh, 1, 3, VALUE_2);
- BLI_edgehash_insert(eh, 1, 4, VALUE_3);
-
- EdgeHashIterator *ehi = BLI_edgehashIterator_new(eh);
- ASSERT_FALSE(BLI_edgehashIterator_isDone(ehi));
- BLI_edgehashIterator_step(ehi);
- ASSERT_FALSE(BLI_edgehashIterator_isDone(ehi));
- BLI_edgehashIterator_step(ehi);
- ASSERT_FALSE(BLI_edgehashIterator_isDone(ehi));
- BLI_edgehashIterator_step(ehi);
- ASSERT_TRUE(BLI_edgehashIterator_isDone(ehi));
-
- BLI_edgehashIterator_free(ehi);
- BLI_edgehash_free(eh, nullptr);
+ EdgeHash *eh = BLI_edgehash_new(__func__);
+
+ BLI_edgehash_insert(eh, 1, 2, VALUE_1);
+ BLI_edgehash_insert(eh, 1, 3, VALUE_2);
+ BLI_edgehash_insert(eh, 1, 4, VALUE_3);
+
+ EdgeHashIterator *ehi = BLI_edgehashIterator_new(eh);
+ ASSERT_FALSE(BLI_edgehashIterator_isDone(ehi));
+ BLI_edgehashIterator_step(ehi);
+ ASSERT_FALSE(BLI_edgehashIterator_isDone(ehi));
+ BLI_edgehashIterator_step(ehi);
+ ASSERT_FALSE(BLI_edgehashIterator_isDone(ehi));
+ BLI_edgehashIterator_step(ehi);
+ ASSERT_TRUE(BLI_edgehashIterator_isDone(ehi));
+
+ BLI_edgehashIterator_free(ehi);
+ BLI_edgehash_free(eh, nullptr);
}
TEST(edgehash, DoubleRemove)
{
- EdgeHash *eh = BLI_edgehash_new(__func__);
+ EdgeHash *eh = BLI_edgehash_new(__func__);
- BLI_edgehash_insert(eh, 1, 2, VALUE_1);
- BLI_edgehash_insert(eh, 1, 3, VALUE_2);
- BLI_edgehash_insert(eh, 1, 4, VALUE_3);
- ASSERT_EQ(BLI_edgehash_len(eh), 3);
+ BLI_edgehash_insert(eh, 1, 2, VALUE_1);
+ BLI_edgehash_insert(eh, 1, 3, VALUE_2);
+ BLI_edgehash_insert(eh, 1, 4, VALUE_3);
+ ASSERT_EQ(BLI_edgehash_len(eh), 3);
- BLI_edgehash_remove(eh, 1, 2, nullptr);
- BLI_edgehash_remove(eh, 1, 3, nullptr);
- ASSERT_EQ(BLI_edgehash_len(eh), 1);
+ BLI_edgehash_remove(eh, 1, 2, nullptr);
+ BLI_edgehash_remove(eh, 1, 3, nullptr);
+ ASSERT_EQ(BLI_edgehash_len(eh), 1);
- BLI_edgehash_free(eh, nullptr);
+ BLI_edgehash_free(eh, nullptr);
}
struct Edge {
- uint v1, v2;
+ uint v1, v2;
};
TEST(edgehash, StressTest)
{
- std::srand(0);
- int amount = 10000;
+ std::srand(0);
+ int amount = 10000;
- std::vector<Edge> edges;
- for (int i = 0; i < amount; i++) {
- edges.push_back({(uint)i, amount + (uint)std::rand() % 12345});
- }
+ std::vector<Edge> edges;
+ for (int i = 0; i < amount; i++) {
+ edges.push_back({(uint)i, amount + (uint)std::rand() % 12345});
+ }
- EdgeHash *eh = BLI_edgehash_new(__func__);
+ EdgeHash *eh = BLI_edgehash_new(__func__);
- /* first insert all the edges */
- for (int i = 0; i < edges.size(); i++) {
- BLI_edgehash_insert(eh, edges[i].v1, edges[i].v2, POINTER_FROM_INT(i));
- }
+ /* first insert all the edges */
+ for (int i = 0; i < edges.size(); i++) {
+ BLI_edgehash_insert(eh, edges[i].v1, edges[i].v2, POINTER_FROM_INT(i));
+ }
- std::vector<Edge> shuffled = edges;
- std::random_shuffle(shuffled.begin(), shuffled.end());
+ std::vector<Edge> shuffled = edges;
+ std::random_shuffle(shuffled.begin(), shuffled.end());
- /* then remove half of them */
- int remove_until = shuffled.size() / 2;
- for (int i = 0; i < remove_until; i++) {
- BLI_edgehash_remove(eh, shuffled[i].v2, shuffled[i].v1, nullptr);
- }
+ /* then remove half of them */
+ int remove_until = shuffled.size() / 2;
+ for (int i = 0; i < remove_until; i++) {
+ BLI_edgehash_remove(eh, shuffled[i].v2, shuffled[i].v1, nullptr);
+ }
- ASSERT_EQ(BLI_edgehash_len(eh), edges.size() - remove_until);
+ ASSERT_EQ(BLI_edgehash_len(eh), edges.size() - remove_until);
- /* check if the right ones have been removed */
- for (int i = 0; i < shuffled.size(); i++) {
- bool haskey = BLI_edgehash_haskey(eh, shuffled[i].v1, shuffled[i].v2);
- if (i < remove_until) ASSERT_FALSE(haskey);
- else ASSERT_TRUE(haskey);
- }
+ /* check if the right ones have been removed */
+ for (int i = 0; i < shuffled.size(); i++) {
+ bool haskey = BLI_edgehash_haskey(eh, shuffled[i].v1, shuffled[i].v2);
+ if (i < remove_until)
+ ASSERT_FALSE(haskey);
+ else
+ ASSERT_TRUE(haskey);
+ }
- /* reinsert all edges */
- for (int i = 0; i < edges.size(); i++) {
- BLI_edgehash_reinsert(eh, edges[i].v1, edges[i].v2, POINTER_FROM_INT(i));
- }
+ /* reinsert all edges */
+ for (int i = 0; i < edges.size(); i++) {
+ BLI_edgehash_reinsert(eh, edges[i].v1, edges[i].v2, POINTER_FROM_INT(i));
+ }
- ASSERT_EQ(BLI_edgehash_len(eh), edges.size());
+ ASSERT_EQ(BLI_edgehash_len(eh), edges.size());
- /* pop all edges */
- for (int i = 0; i < edges.size(); i++) {
- int value = POINTER_AS_INT(BLI_edgehash_popkey(eh, edges[i].v1, edges[i].v2));
- ASSERT_EQ(i, value);
- }
+ /* pop all edges */
+ for (int i = 0; i < edges.size(); i++) {
+ int value = POINTER_AS_INT(BLI_edgehash_popkey(eh, edges[i].v1, edges[i].v2));
+ ASSERT_EQ(i, value);
+ }
- ASSERT_EQ(BLI_edgehash_len(eh), 0);
+ ASSERT_EQ(BLI_edgehash_len(eh), 0);
- BLI_edgehash_free(eh, nullptr);
+ BLI_edgehash_free(eh, nullptr);
}
TEST(edgeset, AddNonExistingIncreasesLength)
{
- EdgeSet *es = BLI_edgeset_new(__func__);
+ EdgeSet *es = BLI_edgeset_new(__func__);
- ASSERT_EQ(BLI_edgeset_len(es), 0);
- BLI_edgeset_add(es, 1, 2);
- ASSERT_EQ(BLI_edgeset_len(es), 1);
- BLI_edgeset_add(es, 1, 3);
- ASSERT_EQ(BLI_edgeset_len(es), 2);
- BLI_edgeset_add(es, 1, 4);
- ASSERT_EQ(BLI_edgeset_len(es), 3);
+ ASSERT_EQ(BLI_edgeset_len(es), 0);
+ BLI_edgeset_add(es, 1, 2);
+ ASSERT_EQ(BLI_edgeset_len(es), 1);
+ BLI_edgeset_add(es, 1, 3);
+ ASSERT_EQ(BLI_edgeset_len(es), 2);
+ BLI_edgeset_add(es, 1, 4);
+ ASSERT_EQ(BLI_edgeset_len(es), 3);
- BLI_edgeset_free(es);
+ BLI_edgeset_free(es);
}
TEST(edgeset, AddExistingDoesNotIncreaseLength)
{
- EdgeSet *es = BLI_edgeset_new(__func__);
+ EdgeSet *es = BLI_edgeset_new(__func__);
- ASSERT_EQ(BLI_edgeset_len(es), 0);
- BLI_edgeset_add(es, 1, 2);
- ASSERT_EQ(BLI_edgeset_len(es), 1);
- BLI_edgeset_add(es, 2, 1);
- ASSERT_EQ(BLI_edgeset_len(es), 1);
- BLI_edgeset_add(es, 1, 2);
- ASSERT_EQ(BLI_edgeset_len(es), 1);
+ ASSERT_EQ(BLI_edgeset_len(es), 0);
+ BLI_edgeset_add(es, 1, 2);
+ ASSERT_EQ(BLI_edgeset_len(es), 1);
+ BLI_edgeset_add(es, 2, 1);
+ ASSERT_EQ(BLI_edgeset_len(es), 1);
+ BLI_edgeset_add(es, 1, 2);
+ ASSERT_EQ(BLI_edgeset_len(es), 1);
- BLI_edgeset_free(es);
+ BLI_edgeset_free(es);
}
TEST(edgeset, HasKeyNonExisting)
{
- EdgeSet *es = BLI_edgeset_new(__func__);
+ EdgeSet *es = BLI_edgeset_new(__func__);
- ASSERT_FALSE(BLI_edgeset_haskey(es, 1, 2));
+ ASSERT_FALSE(BLI_edgeset_haskey(es, 1, 2));
- BLI_edgeset_free(es);
+ BLI_edgeset_free(es);
}
TEST(edgeset, HasKeyExisting)
{
- EdgeSet *es = BLI_edgeset_new(__func__);
+ EdgeSet *es = BLI_edgeset_new(__func__);
- BLI_edgeset_insert(es, 1, 2);
- ASSERT_TRUE(BLI_edgeset_haskey(es, 1, 2));
+ BLI_edgeset_insert(es, 1, 2);
+ ASSERT_TRUE(BLI_edgeset_haskey(es, 1, 2));
- BLI_edgeset_free(es);
+ BLI_edgeset_free(es);
}
diff --git a/tests/gtests/blenlib/BLI_expr_pylike_eval_test.cc b/tests/gtests/blenlib/BLI_expr_pylike_eval_test.cc
index 51e5b02232b..32e33e2e118 100644
--- a/tests/gtests/blenlib/BLI_expr_pylike_eval_test.cc
+++ b/tests/gtests/blenlib/BLI_expr_pylike_eval_test.cc
@@ -14,78 +14,81 @@ extern "C" {
static void expr_pylike_parse_fail_test(const char *str)
{
- ExprPyLike_Parsed *expr = BLI_expr_pylike_parse(str, NULL, 0);
+ ExprPyLike_Parsed *expr = BLI_expr_pylike_parse(str, NULL, 0);
- EXPECT_FALSE(BLI_expr_pylike_is_valid(expr));
+ EXPECT_FALSE(BLI_expr_pylike_is_valid(expr));
- BLI_expr_pylike_free(expr);
+ BLI_expr_pylike_free(expr);
}
static void expr_pylike_const_test(const char *str, double value, bool force_const)
{
- ExprPyLike_Parsed *expr = BLI_expr_pylike_parse(str, NULL, 0);
+ ExprPyLike_Parsed *expr = BLI_expr_pylike_parse(str, NULL, 0);
- if (force_const) {
- EXPECT_TRUE(BLI_expr_pylike_is_constant(expr));
- }
- else {
- EXPECT_TRUE(BLI_expr_pylike_is_valid(expr));
- EXPECT_FALSE(BLI_expr_pylike_is_constant(expr));
- }
+ if (force_const) {
+ EXPECT_TRUE(BLI_expr_pylike_is_constant(expr));
+ }
+ else {
+ EXPECT_TRUE(BLI_expr_pylike_is_valid(expr));
+ EXPECT_FALSE(BLI_expr_pylike_is_constant(expr));
+ }
- double result;
- eExprPyLike_EvalStatus status = BLI_expr_pylike_eval(expr, NULL, 0, &result);
+ double result;
+ eExprPyLike_EvalStatus status = BLI_expr_pylike_eval(expr, NULL, 0, &result);
- EXPECT_EQ(status, EXPR_PYLIKE_SUCCESS);
- EXPECT_EQ(result, value);
+ EXPECT_EQ(status, EXPR_PYLIKE_SUCCESS);
+ EXPECT_EQ(result, value);
- BLI_expr_pylike_free(expr);
+ BLI_expr_pylike_free(expr);
}
static ExprPyLike_Parsed *parse_for_eval(const char *str, bool nonconst)
{
- const char *names[1] = {"x"};
- ExprPyLike_Parsed *expr = BLI_expr_pylike_parse(str, names, ARRAY_SIZE(names));
+ const char *names[1] = {"x"};
+ ExprPyLike_Parsed *expr = BLI_expr_pylike_parse(str, names, ARRAY_SIZE(names));
- EXPECT_TRUE(BLI_expr_pylike_is_valid(expr));
+ EXPECT_TRUE(BLI_expr_pylike_is_valid(expr));
- if (nonconst) {
- EXPECT_FALSE(BLI_expr_pylike_is_constant(expr));
- }
+ if (nonconst) {
+ EXPECT_FALSE(BLI_expr_pylike_is_constant(expr));
+ }
- return expr;
+ return expr;
}
static void verify_eval_result(ExprPyLike_Parsed *expr, double x, double value)
{
- double result;
- eExprPyLike_EvalStatus status = BLI_expr_pylike_eval(expr, &x, 1, &result);
+ double result;
+ eExprPyLike_EvalStatus status = BLI_expr_pylike_eval(expr, &x, 1, &result);
- EXPECT_EQ(status, EXPR_PYLIKE_SUCCESS);
- EXPECT_EQ(result, value);
+ EXPECT_EQ(status, EXPR_PYLIKE_SUCCESS);
+ EXPECT_EQ(result, value);
}
static void expr_pylike_eval_test(const char *str, double x, double value)
{
- ExprPyLike_Parsed *expr = parse_for_eval(str, true);
- verify_eval_result(expr, x, value);
- BLI_expr_pylike_free(expr);
+ ExprPyLike_Parsed *expr = parse_for_eval(str, true);
+ verify_eval_result(expr, x, value);
+ BLI_expr_pylike_free(expr);
}
static void expr_pylike_error_test(const char *str, double x, eExprPyLike_EvalStatus error)
{
- ExprPyLike_Parsed *expr = parse_for_eval(str, false);
+ ExprPyLike_Parsed *expr = parse_for_eval(str, false);
- double result;
- eExprPyLike_EvalStatus status = BLI_expr_pylike_eval(expr, &x, 1, &result);
+ double result;
+ eExprPyLike_EvalStatus status = BLI_expr_pylike_eval(expr, &x, 1, &result);
- EXPECT_EQ(status, error);
+ EXPECT_EQ(status, error);
- BLI_expr_pylike_free(expr);
+ BLI_expr_pylike_free(expr);
}
#define TEST_PARSE_FAIL(name, str) \
- TEST(expr_pylike, ParseFail_##name) { expr_pylike_parse_fail_test(str); }
+ TEST(expr_pylike, ParseFail_##name) \
+ { \
+ expr_pylike_parse_fail_test(str); \
+ }
TEST_PARSE_FAIL(Empty, "")
TEST_PARSE_FAIL(ConstHex, "0x0")
@@ -113,15 +116,24 @@ TEST_PARSE_FAIL(Truncated10, "fmod(1,")
/* Constant expression with working constant folding */
#define TEST_CONST(name, str, value) \
- TEST(expr_pylike, Const_##name) { expr_pylike_const_test(str, value, true); }
+ TEST(expr_pylike, Const_##name) \
+ { \
+ expr_pylike_const_test(str, value, true); \
+ }
/* Constant expression but constant folding is not supported */
#define TEST_RESULT(name, str, value) \
- TEST(expr_pylike, Result_##name) { expr_pylike_const_test(str, value, false); }
+ TEST(expr_pylike, Result_##name) \
+ { \
+ expr_pylike_const_test(str, value, false); \
+ }
/* Expression with an argument */
#define TEST_EVAL(name, str, x, value) \
- TEST(expr_pylike, Eval_##name) { expr_pylike_eval_test(str, x, value); }
+ TEST(expr_pylike, Eval_##name) \
+ { \
+ expr_pylike_eval_test(str, x, value); \
+ }
TEST_CONST(Zero, "0", 0.0)
TEST_CONST(Zero2, "00", 0.0)
@@ -239,38 +251,42 @@ TEST_RESULT(Bool2, "not 2 or 3 and 4", 4.0)
TEST(expr_pylike, Eval_Ternary1)
{
- ExprPyLike_Parsed *expr = parse_for_eval("x / 2 if x < 4 else x - 2 if x < 8 else x*2 - 12", true);
+ ExprPyLike_Parsed *expr = parse_for_eval("x / 2 if x < 4 else x - 2 if x < 8 else x*2 - 12",
+ true);
- for (int i = 0; i <= 10; i++) {
- double x = i;
- double v = (x < 4) ? (x / 2) : (x < 8) ? (x - 2) : (x*2 - 12);
+ for (int i = 0; i <= 10; i++) {
+ double x = i;
+ double v = (x < 4) ? (x / 2) : (x < 8) ? (x - 2) : (x * 2 - 12);
- verify_eval_result(expr, x, v);
- }
+ verify_eval_result(expr, x, v);
+ }
- BLI_expr_pylike_free(expr);
+ BLI_expr_pylike_free(expr);
}
TEST(expr_pylike, MultipleArgs)
{
- const char* names[3] = {"x", "y", "x"};
- double values[3] = {1.0, 2.0, 3.0};
+ const char *names[3] = {"x", "y", "x"};
+ double values[3] = {1.0, 2.0, 3.0};
- ExprPyLike_Parsed *expr = BLI_expr_pylike_parse("x*10 + y", names, ARRAY_SIZE(names));
+ ExprPyLike_Parsed *expr = BLI_expr_pylike_parse("x*10 + y", names, ARRAY_SIZE(names));
- EXPECT_TRUE(BLI_expr_pylike_is_valid(expr));
+ EXPECT_TRUE(BLI_expr_pylike_is_valid(expr));
- double result;
- eExprPyLike_EvalStatus status = BLI_expr_pylike_eval(expr, values, 3, &result);
+ double result;
+ eExprPyLike_EvalStatus status = BLI_expr_pylike_eval(expr, values, 3, &result);
- EXPECT_EQ(status, EXPR_PYLIKE_SUCCESS);
- EXPECT_EQ(result, 32.0);
+ EXPECT_EQ(status, EXPR_PYLIKE_SUCCESS);
+ EXPECT_EQ(result, 32.0);
- BLI_expr_pylike_free(expr);
+ BLI_expr_pylike_free(expr);
}
#define TEST_ERROR(name, str, x, code) \
- TEST(expr_pylike, Error_##name) { expr_pylike_error_test(str, x, code); }
+ TEST(expr_pylike, Error_##name) \
+ { \
+ expr_pylike_error_test(str, x, code); \
+ }
TEST_ERROR(DivZero1, "0 / 0", 0.0, EXPR_PYLIKE_MATH_ERROR)
TEST_ERROR(DivZero2, "1 / 0", 0.0, EXPR_PYLIKE_DIV_BY_ZERO)
@@ -291,20 +307,20 @@ TEST_ERROR(Mixed3, "sqrt(x) + 1 / max(0, x)", 1.0, EXPR_PYLIKE_SUCCESS)
TEST(expr_pylike, Error_Invalid)
{
- ExprPyLike_Parsed *expr = BLI_expr_pylike_parse("", NULL, 0);
- double result;
+ ExprPyLike_Parsed *expr = BLI_expr_pylike_parse("", NULL, 0);
+ double result;
- EXPECT_EQ(BLI_expr_pylike_eval(expr, NULL, 0, &result), EXPR_PYLIKE_INVALID);
+ EXPECT_EQ(BLI_expr_pylike_eval(expr, NULL, 0, &result), EXPR_PYLIKE_INVALID);
- BLI_expr_pylike_free(expr);
+ BLI_expr_pylike_free(expr);
}
TEST(expr_pylike, Error_ArgumentCount)
{
- ExprPyLike_Parsed *expr = parse_for_eval("x", false);
- double result;
+ ExprPyLike_Parsed *expr = parse_for_eval("x", false);
+ double result;
- EXPECT_EQ(BLI_expr_pylike_eval(expr, NULL, 0, &result), EXPR_PYLIKE_FATAL_ERROR);
+ EXPECT_EQ(BLI_expr_pylike_eval(expr, NULL, 0, &result), EXPR_PYLIKE_FATAL_ERROR);
- BLI_expr_pylike_free(expr);
+ BLI_expr_pylike_free(expr);
}
diff --git a/tests/gtests/blenlib/BLI_ghash_performance_test.cc b/tests/gtests/blenlib/BLI_ghash_performance_test.cc
index 18a1f121e47..b7a6e16e42a 100644
--- a/tests/gtests/blenlib/BLI_ghash_performance_test.cc
+++ b/tests/gtests/blenlib/BLI_ghash_performance_test.cc
@@ -28,228 +28,236 @@ extern "C" {
#define TESTCASE_SIZE_SMALL 17
#define PRINTF_GHASH_STATS(_gh) \
-{ \
- double q, lf, var, pempty, poverloaded; \
- int bigb; \
- q = BLI_ghash_calc_quality_ex((_gh), &lf, &var, &pempty, &poverloaded, &bigb); \
- printf("GHash stats (%u entries):\n\t" \
- "Quality (the lower the better): %f\n\tVariance (the lower the better): %f\n\tLoad: %f\n\t" \
- "Empty buckets: %.2f%%\n\tOverloaded buckets: %.2f%% (biggest bucket: %d)\n", \
- BLI_ghash_len(_gh), q, var, lf, pempty * 100.0, poverloaded * 100.0, bigb); \
-} void (0)
+ { \
+ double q, lf, var, pempty, poverloaded; \
+ int bigb; \
+ q = BLI_ghash_calc_quality_ex((_gh), &lf, &var, &pempty, &poverloaded, &bigb); \
+ printf( \
+ "GHash stats (%u entries):\n\t" \
+ "Quality (the lower the better): %f\n\tVariance (the lower the better): %f\n\tLoad: " \
+ "%f\n\t" \
+ "Empty buckets: %.2f%%\n\tOverloaded buckets: %.2f%% (biggest bucket: %d)\n", \
+ BLI_ghash_len(_gh), \
+ q, \
+ var, \
+ lf, \
+ pempty * 100.0, \
+ poverloaded * 100.0, \
+ bigb); \
+ } \
+ void(0)
/* Str: whole text, lines and words from a 'corpus' text. */
static void str_ghash_tests(GHash *ghash, const char *id)
{
- printf("\n========== STARTING %s ==========\n", id);
+ printf("\n========== STARTING %s ==========\n", id);
#ifdef TEXT_CORPUS_PATH
- size_t sz = 0;
- char *data;
- {
- struct stat st;
- if (stat(TEXT_CORPUS_PATH, &st) == 0)
- sz = st.st_size;
- }
- if (sz != 0) {
- FILE *f = fopen(TEXT_CORPUS_PATH, "r");
-
- data = (char *)MEM_mallocN(sz + 1, __func__);
- if (fread(data, sizeof(*data), sz, f) != sz) {
- printf("ERROR in reading file %s!", TEXT_CORPUS_PATH);
- MEM_freeN(data);
- data = BLI_strdup(words10k);
- }
- data[sz] = '\0';
- fclose(f);
- }
- else {
- data = BLI_strdup(words10k);
- }
+ size_t sz = 0;
+ char *data;
+ {
+ struct stat st;
+ if (stat(TEXT_CORPUS_PATH, &st) == 0)
+ sz = st.st_size;
+ }
+ if (sz != 0) {
+ FILE *f = fopen(TEXT_CORPUS_PATH, "r");
+
+ data = (char *)MEM_mallocN(sz + 1, __func__);
+ if (fread(data, sizeof(*data), sz, f) != sz) {
+ printf("ERROR in reading file %s!", TEXT_CORPUS_PATH);
+ MEM_freeN(data);
+ data = BLI_strdup(words10k);
+ }
+ data[sz] = '\0';
+ fclose(f);
+ }
+ else {
+ data = BLI_strdup(words10k);
+ }
#else
- char *data = BLI_strdup(words10k);
+ char *data = BLI_strdup(words10k);
#endif
- char *data_p = BLI_strdup(data);
- char *data_w = BLI_strdup(data);
- char *data_bis = BLI_strdup(data);
+ char *data_p = BLI_strdup(data);
+ char *data_w = BLI_strdup(data);
+ char *data_bis = BLI_strdup(data);
- {
- char *p, *w, *c_p, *c_w;
+ {
+ char *p, *w, *c_p, *c_w;
- TIMEIT_START(string_insert);
+ TIMEIT_START(string_insert);
#ifdef GHASH_RESERVE
- BLI_ghash_reserve(ghash, strlen(data) / 32); /* rough estimation... */
+ BLI_ghash_reserve(ghash, strlen(data) / 32); /* rough estimation... */
#endif
- BLI_ghash_insert(ghash, data, POINTER_FROM_INT(data[0]));
-
- for (p = c_p = data_p, w = c_w = data_w; *c_w; c_w++, c_p++) {
- if (*c_p == '.') {
- *c_p = *c_w = '\0';
- if (!BLI_ghash_haskey(ghash, p)) {
- BLI_ghash_insert(ghash, p, POINTER_FROM_INT(p[0]));
- }
- if (!BLI_ghash_haskey(ghash, w)) {
- BLI_ghash_insert(ghash, w, POINTER_FROM_INT(w[0]));
- }
- p = c_p + 1;
- w = c_w + 1;
- }
- else if (*c_w == ' ') {
- *c_w = '\0';
- if (!BLI_ghash_haskey(ghash, w)) {
- BLI_ghash_insert(ghash, w, POINTER_FROM_INT(w[0]));
- }
- w = c_w + 1;
- }
- }
-
- TIMEIT_END(string_insert);
- }
-
- PRINTF_GHASH_STATS(ghash);
-
- {
- char *p, *w, *c;
- void *v;
-
- TIMEIT_START(string_lookup);
-
- v = BLI_ghash_lookup(ghash, data_bis);
- EXPECT_EQ(POINTER_AS_INT(v), data_bis[0]);
-
- for (p = w = c = data_bis; *c; c++) {
- if (*c == '.') {
- *c = '\0';
- v = BLI_ghash_lookup(ghash, w);
- EXPECT_EQ(POINTER_AS_INT(v), w[0]);
- v = BLI_ghash_lookup(ghash, p);
- EXPECT_EQ(POINTER_AS_INT(v), p[0]);
- p = w = c + 1;
- }
- else if (*c == ' ') {
- *c = '\0';
- v = BLI_ghash_lookup(ghash, w);
- EXPECT_EQ(POINTER_AS_INT(v), w[0]);
- w = c + 1;
- }
- }
-
- TIMEIT_END(string_lookup);
- }
-
- BLI_ghash_free(ghash, NULL, NULL);
- MEM_freeN(data);
- MEM_freeN(data_p);
- MEM_freeN(data_w);
- MEM_freeN(data_bis);
-
- printf("========== ENDED %s ==========\n\n", id);
+ BLI_ghash_insert(ghash, data, POINTER_FROM_INT(data[0]));
+
+ for (p = c_p = data_p, w = c_w = data_w; *c_w; c_w++, c_p++) {
+ if (*c_p == '.') {
+ *c_p = *c_w = '\0';
+ if (!BLI_ghash_haskey(ghash, p)) {
+ BLI_ghash_insert(ghash, p, POINTER_FROM_INT(p[0]));
+ }
+ if (!BLI_ghash_haskey(ghash, w)) {
+ BLI_ghash_insert(ghash, w, POINTER_FROM_INT(w[0]));
+ }
+ p = c_p + 1;
+ w = c_w + 1;
+ }
+ else if (*c_w == ' ') {
+ *c_w = '\0';
+ if (!BLI_ghash_haskey(ghash, w)) {
+ BLI_ghash_insert(ghash, w, POINTER_FROM_INT(w[0]));
+ }
+ w = c_w + 1;
+ }
+ }
+
+ TIMEIT_END(string_insert);
+ }
+
+ PRINTF_GHASH_STATS(ghash);
+
+ {
+ char *p, *w, *c;
+ void *v;
+
+ TIMEIT_START(string_lookup);
+
+ v = BLI_ghash_lookup(ghash, data_bis);
+ EXPECT_EQ(POINTER_AS_INT(v), data_bis[0]);
+
+ for (p = w = c = data_bis; *c; c++) {
+ if (*c == '.') {
+ *c = '\0';
+ v = BLI_ghash_lookup(ghash, w);
+ EXPECT_EQ(POINTER_AS_INT(v), w[0]);
+ v = BLI_ghash_lookup(ghash, p);
+ EXPECT_EQ(POINTER_AS_INT(v), p[0]);
+ p = w = c + 1;
+ }
+ else if (*c == ' ') {
+ *c = '\0';
+ v = BLI_ghash_lookup(ghash, w);
+ EXPECT_EQ(POINTER_AS_INT(v), w[0]);
+ w = c + 1;
+ }
+ }
+
+ TIMEIT_END(string_lookup);
+ }
+
+ BLI_ghash_free(ghash, NULL, NULL);
+ MEM_freeN(data);
+ MEM_freeN(data_p);
+ MEM_freeN(data_w);
+ MEM_freeN(data_bis);
+
+ printf("========== ENDED %s ==========\n\n", id);
}
TEST(ghash, TextGHash)
{
- GHash *ghash = BLI_ghash_new(BLI_ghashutil_strhash_p, BLI_ghashutil_strcmp, __func__);
+ GHash *ghash = BLI_ghash_new(BLI_ghashutil_strhash_p, BLI_ghashutil_strcmp, __func__);
- str_ghash_tests(ghash, "StrGHash - GHash");
+ str_ghash_tests(ghash, "StrGHash - GHash");
}
TEST(ghash, TextMurmur2a)
{
- GHash *ghash = BLI_ghash_new(BLI_ghashutil_strhash_p_murmur, BLI_ghashutil_strcmp, __func__);
+ GHash *ghash = BLI_ghash_new(BLI_ghashutil_strhash_p_murmur, BLI_ghashutil_strcmp, __func__);
- str_ghash_tests(ghash, "StrGHash - Murmur");
+ str_ghash_tests(ghash, "StrGHash - Murmur");
}
-
/* Int: uniform 100M first integers. */
static void int_ghash_tests(GHash *ghash, const char *id, const unsigned int nbr)
{
- printf("\n========== STARTING %s ==========\n", id);
+ printf("\n========== STARTING %s ==========\n", id);
- {
- unsigned int i = nbr;
+ {
+ unsigned int i = nbr;
- TIMEIT_START(int_insert);
+ TIMEIT_START(int_insert);
#ifdef GHASH_RESERVE
- BLI_ghash_reserve(ghash, nbr);
+ BLI_ghash_reserve(ghash, nbr);
#endif
- while (i--) {
- BLI_ghash_insert(ghash, POINTER_FROM_UINT(i), POINTER_FROM_UINT(i));
- }
+ while (i--) {
+ BLI_ghash_insert(ghash, POINTER_FROM_UINT(i), POINTER_FROM_UINT(i));
+ }
- TIMEIT_END(int_insert);
- }
+ TIMEIT_END(int_insert);
+ }
- PRINTF_GHASH_STATS(ghash);
+ PRINTF_GHASH_STATS(ghash);
- {
- unsigned int i = nbr;
+ {
+ unsigned int i = nbr;
- TIMEIT_START(int_lookup);
+ TIMEIT_START(int_lookup);
- while (i--) {
- void *v = BLI_ghash_lookup(ghash, POINTER_FROM_UINT(i));
- EXPECT_EQ(POINTER_AS_UINT(v), i);
- }
+ while (i--) {
+ void *v = BLI_ghash_lookup(ghash, POINTER_FROM_UINT(i));
+ EXPECT_EQ(POINTER_AS_UINT(v), i);
+ }
- TIMEIT_END(int_lookup);
- }
+ TIMEIT_END(int_lookup);
+ }
- {
- void *k, *v;
+ {
+ void *k, *v;
- TIMEIT_START(int_pop);
+ TIMEIT_START(int_pop);
- GHashIterState pop_state = {0};
+ GHashIterState pop_state = {0};
- while (BLI_ghash_pop(ghash, &pop_state, &k, &v)) {
- EXPECT_EQ(k, v);
- }
+ while (BLI_ghash_pop(ghash, &pop_state, &k, &v)) {
+ EXPECT_EQ(k, v);
+ }
- TIMEIT_END(int_pop);
- }
- EXPECT_EQ(BLI_ghash_len(ghash), 0);
+ TIMEIT_END(int_pop);
+ }
+ EXPECT_EQ(BLI_ghash_len(ghash), 0);
- BLI_ghash_free(ghash, NULL, NULL);
+ BLI_ghash_free(ghash, NULL, NULL);
- printf("========== ENDED %s ==========\n\n", id);
+ printf("========== ENDED %s ==========\n\n", id);
}
TEST(ghash, IntGHash12000)
{
- GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
+ GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
- int_ghash_tests(ghash, "IntGHash - GHash - 12000", 12000);
+ int_ghash_tests(ghash, "IntGHash - GHash - 12000", 12000);
}
#ifdef GHASH_RUN_BIG
TEST(ghash, IntGHash100000000)
{
- GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
+ GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
- int_ghash_tests(ghash, "IntGHash - GHash - 100000000", 100000000);
+ int_ghash_tests(ghash, "IntGHash - GHash - 100000000", 100000000);
}
#endif
TEST(ghash, IntMurmur2a12000)
{
- GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p_murmur, BLI_ghashutil_intcmp, __func__);
+ GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p_murmur, BLI_ghashutil_intcmp, __func__);
- int_ghash_tests(ghash, "IntGHash - Murmur - 12000", 12000);
+ int_ghash_tests(ghash, "IntGHash - Murmur - 12000", 12000);
}
#ifdef GHASH_RUN_BIG
TEST(ghash, IntMurmur2a100000000)
{
- GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p_murmur, BLI_ghashutil_intcmp, __func__);
+ GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p_murmur, BLI_ghashutil_intcmp, __func__);
- int_ghash_tests(ghash, "IntGHash - Murmur - 100000000", 100000000);
+ int_ghash_tests(ghash, "IntGHash - Murmur - 100000000", 100000000);
}
#endif
@@ -257,107 +265,107 @@ TEST(ghash, IntMurmur2a100000000)
static void randint_ghash_tests(GHash *ghash, const char *id, const unsigned int nbr)
{
- printf("\n========== STARTING %s ==========\n", id);
+ printf("\n========== STARTING %s ==========\n", id);
- unsigned int *data = (unsigned int *)MEM_mallocN(sizeof(*data) * (size_t)nbr, __func__);
- unsigned int *dt;
- unsigned int i;
+ unsigned int *data = (unsigned int *)MEM_mallocN(sizeof(*data) * (size_t)nbr, __func__);
+ unsigned int *dt;
+ unsigned int i;
- {
- RNG *rng = BLI_rng_new(0);
- for (i = nbr, dt = data; i--; dt++) {
- *dt = BLI_rng_get_uint(rng);
- }
- BLI_rng_free(rng);
- }
+ {
+ RNG *rng = BLI_rng_new(0);
+ for (i = nbr, dt = data; i--; dt++) {
+ *dt = BLI_rng_get_uint(rng);
+ }
+ BLI_rng_free(rng);
+ }
- {
- TIMEIT_START(int_insert);
+ {
+ TIMEIT_START(int_insert);
#ifdef GHASH_RESERVE
- BLI_ghash_reserve(ghash, nbr);
+ BLI_ghash_reserve(ghash, nbr);
#endif
- for (i = nbr, dt = data; i--; dt++) {
- BLI_ghash_insert(ghash, POINTER_FROM_UINT(*dt), POINTER_FROM_UINT(*dt));
- }
+ for (i = nbr, dt = data; i--; dt++) {
+ BLI_ghash_insert(ghash, POINTER_FROM_UINT(*dt), POINTER_FROM_UINT(*dt));
+ }
- TIMEIT_END(int_insert);
- }
+ TIMEIT_END(int_insert);
+ }
- PRINTF_GHASH_STATS(ghash);
+ PRINTF_GHASH_STATS(ghash);
- {
- TIMEIT_START(int_lookup);
+ {
+ TIMEIT_START(int_lookup);
- for (i = nbr, dt = data; i--; dt++) {
- void *v = BLI_ghash_lookup(ghash, POINTER_FROM_UINT(*dt));
- EXPECT_EQ(POINTER_AS_UINT(v), *dt);
- }
+ for (i = nbr, dt = data; i--; dt++) {
+ void *v = BLI_ghash_lookup(ghash, POINTER_FROM_UINT(*dt));
+ EXPECT_EQ(POINTER_AS_UINT(v), *dt);
+ }
- TIMEIT_END(int_lookup);
- }
+ TIMEIT_END(int_lookup);
+ }
- BLI_ghash_free(ghash, NULL, NULL);
+ BLI_ghash_free(ghash, NULL, NULL);
- printf("========== ENDED %s ==========\n\n", id);
+ printf("========== ENDED %s ==========\n\n", id);
}
TEST(ghash, IntRandGHash12000)
{
- GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
+ GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
- randint_ghash_tests(ghash, "RandIntGHash - GHash - 12000", 12000);
+ randint_ghash_tests(ghash, "RandIntGHash - GHash - 12000", 12000);
}
#ifdef GHASH_RUN_BIG
TEST(ghash, IntRandGHash50000000)
{
- GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
+ GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
- randint_ghash_tests(ghash, "RandIntGHash - GHash - 50000000", 50000000);
+ randint_ghash_tests(ghash, "RandIntGHash - GHash - 50000000", 50000000);
}
#endif
TEST(ghash, IntRandMurmur2a12000)
{
- GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p_murmur, BLI_ghashutil_intcmp, __func__);
+ GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p_murmur, BLI_ghashutil_intcmp, __func__);
- randint_ghash_tests(ghash, "RandIntGHash - Murmur - 12000", 12000);
+ randint_ghash_tests(ghash, "RandIntGHash - Murmur - 12000", 12000);
}
#ifdef GHASH_RUN_BIG
TEST(ghash, IntRandMurmur2a50000000)
{
- GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p_murmur, BLI_ghashutil_intcmp, __func__);
+ GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p_murmur, BLI_ghashutil_intcmp, __func__);
- randint_ghash_tests(ghash, "RandIntGHash - Murmur - 50000000", 50000000);
+ randint_ghash_tests(ghash, "RandIntGHash - Murmur - 50000000", 50000000);
}
#endif
static unsigned int ghashutil_tests_nohash_p(const void *p)
{
- return POINTER_AS_UINT(p);
+ return POINTER_AS_UINT(p);
}
static bool ghashutil_tests_cmp_p(const void *a, const void *b)
{
- return a != b;
+ return a != b;
}
TEST(ghash, Int4NoHash12000)
{
- GHash *ghash = BLI_ghash_new(ghashutil_tests_nohash_p, ghashutil_tests_cmp_p, __func__);
+ GHash *ghash = BLI_ghash_new(ghashutil_tests_nohash_p, ghashutil_tests_cmp_p, __func__);
- randint_ghash_tests(ghash, "RandIntGHash - No Hash - 12000", 12000);
+ randint_ghash_tests(ghash, "RandIntGHash - No Hash - 12000", 12000);
}
#ifdef GHASH_RUN_BIG
TEST(ghash, Int4NoHash50000000)
{
- GHash *ghash = BLI_ghash_new(ghashutil_tests_nohash_p, ghashutil_tests_cmp_p, __func__);
+ GHash *ghash = BLI_ghash_new(ghashutil_tests_nohash_p, ghashutil_tests_cmp_p, __func__);
- randint_ghash_tests(ghash, "RandIntGHash - No Hash - 50000000", 50000000);
+ randint_ghash_tests(ghash, "RandIntGHash - No Hash - 50000000", 50000000);
}
#endif
@@ -365,85 +373,89 @@ TEST(ghash, Int4NoHash50000000)
static void int4_ghash_tests(GHash *ghash, const char *id, const unsigned int nbr)
{
- printf("\n========== STARTING %s ==========\n", id);
-
- void *data_v = MEM_mallocN(sizeof(unsigned int[4]) * (size_t)nbr, __func__);
- unsigned int (*data)[4] = (unsigned int (*)[4])data_v;
- unsigned int (*dt)[4];
- unsigned int i, j;
-
- {
- RNG *rng = BLI_rng_new(0);
- for (i = nbr, dt = data; i--; dt++) {
- for (j = 4; j--; ) {
- (*dt)[j] = BLI_rng_get_uint(rng);
- }
- }
- BLI_rng_free(rng);
- }
-
- {
- TIMEIT_START(int_v4_insert);
+ printf("\n========== STARTING %s ==========\n", id);
+
+ void *data_v = MEM_mallocN(sizeof(unsigned int[4]) * (size_t)nbr, __func__);
+ unsigned int(*data)[4] = (unsigned int(*)[4])data_v;
+ unsigned int(*dt)[4];
+ unsigned int i, j;
+
+ {
+ RNG *rng = BLI_rng_new(0);
+ for (i = nbr, dt = data; i--; dt++) {
+ for (j = 4; j--;) {
+ (*dt)[j] = BLI_rng_get_uint(rng);
+ }
+ }
+ BLI_rng_free(rng);
+ }
+
+ {
+ TIMEIT_START(int_v4_insert);
#ifdef GHASH_RESERVE
- BLI_ghash_reserve(ghash, nbr);
+ BLI_ghash_reserve(ghash, nbr);
#endif
- for (i = nbr, dt = data; i--; dt++) {
- BLI_ghash_insert(ghash, *dt, POINTER_FROM_UINT(i));
- }
+ for (i = nbr, dt = data; i--; dt++) {
+ BLI_ghash_insert(ghash, *dt, POINTER_FROM_UINT(i));
+ }
- TIMEIT_END(int_v4_insert);
- }
+ TIMEIT_END(int_v4_insert);
+ }
- PRINTF_GHASH_STATS(ghash);
+ PRINTF_GHASH_STATS(ghash);
- {
- TIMEIT_START(int_v4_lookup);
+ {
+ TIMEIT_START(int_v4_lookup);
- for (i = nbr, dt = data; i--; dt++) {
- void *v = BLI_ghash_lookup(ghash, (void *)(*dt));
- EXPECT_EQ(POINTER_AS_UINT(v), i);
- }
+ for (i = nbr, dt = data; i--; dt++) {
+ void *v = BLI_ghash_lookup(ghash, (void *)(*dt));
+ EXPECT_EQ(POINTER_AS_UINT(v), i);
+ }
- TIMEIT_END(int_v4_lookup);
- }
+ TIMEIT_END(int_v4_lookup);
+ }
- BLI_ghash_free(ghash, NULL, NULL);
- MEM_freeN(data);
+ BLI_ghash_free(ghash, NULL, NULL);
+ MEM_freeN(data);
- printf("========== ENDED %s ==========\n\n", id);
+ printf("========== ENDED %s ==========\n\n", id);
}
TEST(ghash, Int4GHash2000)
{
- GHash *ghash = BLI_ghash_new(BLI_ghashutil_uinthash_v4_p, BLI_ghashutil_uinthash_v4_cmp, __func__);
+ GHash *ghash = BLI_ghash_new(
+ BLI_ghashutil_uinthash_v4_p, BLI_ghashutil_uinthash_v4_cmp, __func__);
- int4_ghash_tests(ghash, "Int4GHash - GHash - 2000", 2000);
+ int4_ghash_tests(ghash, "Int4GHash - GHash - 2000", 2000);
}
#ifdef GHASH_RUN_BIG
TEST(ghash, Int4GHash20000000)
{
- GHash *ghash = BLI_ghash_new(BLI_ghashutil_uinthash_v4_p, BLI_ghashutil_uinthash_v4_cmp, __func__);
+ GHash *ghash = BLI_ghash_new(
+ BLI_ghashutil_uinthash_v4_p, BLI_ghashutil_uinthash_v4_cmp, __func__);
- int4_ghash_tests(ghash, "Int4GHash - GHash - 20000000", 20000000);
+ int4_ghash_tests(ghash, "Int4GHash - GHash - 20000000", 20000000);
}
#endif
TEST(ghash, Int4Murmur2a2000)
{
- GHash *ghash = BLI_ghash_new(BLI_ghashutil_uinthash_v4_p_murmur, BLI_ghashutil_uinthash_v4_cmp, __func__);
+ GHash *ghash = BLI_ghash_new(
+ BLI_ghashutil_uinthash_v4_p_murmur, BLI_ghashutil_uinthash_v4_cmp, __func__);
- int4_ghash_tests(ghash, "Int4GHash - Murmur - 2000", 2000);
+ int4_ghash_tests(ghash, "Int4GHash - Murmur - 2000", 2000);
}
#ifdef GHASH_RUN_BIG
TEST(ghash, Int4Murmur2a20000000)
{
- GHash *ghash = BLI_ghash_new(BLI_ghashutil_uinthash_v4_p_murmur, BLI_ghashutil_uinthash_v4_cmp, __func__);
+ GHash *ghash = BLI_ghash_new(
+ BLI_ghashutil_uinthash_v4_p_murmur, BLI_ghashutil_uinthash_v4_cmp, __func__);
- int4_ghash_tests(ghash, "Int4GHash - Murmur - 20000000", 20000000);
+ int4_ghash_tests(ghash, "Int4GHash - Murmur - 20000000", 20000000);
}
#endif
@@ -451,86 +463,88 @@ TEST(ghash, Int4Murmur2a20000000)
static void multi_small_ghash_tests_one(GHash *ghash, RNG *rng, const unsigned int nbr)
{
- unsigned int *data = (unsigned int *)MEM_mallocN(sizeof(*data) * (size_t)nbr, __func__);
- unsigned int *dt;
- unsigned int i;
+ unsigned int *data = (unsigned int *)MEM_mallocN(sizeof(*data) * (size_t)nbr, __func__);
+ unsigned int *dt;
+ unsigned int i;
- for (i = nbr, dt = data; i--; dt++) {
- *dt = BLI_rng_get_uint(rng);
- }
+ for (i = nbr, dt = data; i--; dt++) {
+ *dt = BLI_rng_get_uint(rng);
+ }
#ifdef GHASH_RESERVE
- BLI_ghash_reserve(ghash, nbr);
+ BLI_ghash_reserve(ghash, nbr);
#endif
- for (i = nbr, dt = data; i--; dt++) {
- BLI_ghash_insert(ghash, POINTER_FROM_UINT(*dt), POINTER_FROM_UINT(*dt));
- }
+ for (i = nbr, dt = data; i--; dt++) {
+ BLI_ghash_insert(ghash, POINTER_FROM_UINT(*dt), POINTER_FROM_UINT(*dt));
+ }
- for (i = nbr, dt = data; i--; dt++) {
- void *v = BLI_ghash_lookup(ghash, POINTER_FROM_UINT(*dt));
- EXPECT_EQ(POINTER_AS_UINT(v), *dt);
- }
+ for (i = nbr, dt = data; i--; dt++) {
+ void *v = BLI_ghash_lookup(ghash, POINTER_FROM_UINT(*dt));
+ EXPECT_EQ(POINTER_AS_UINT(v), *dt);
+ }
- BLI_ghash_clear(ghash, NULL, NULL);
+ BLI_ghash_clear(ghash, NULL, NULL);
}
static void multi_small_ghash_tests(GHash *ghash, const char *id, const unsigned int nbr)
{
- printf("\n========== STARTING %s ==========\n", id);
+ printf("\n========== STARTING %s ==========\n", id);
- RNG *rng = BLI_rng_new(0);
+ RNG *rng = BLI_rng_new(0);
- TIMEIT_START(multi_small_ghash);
+ TIMEIT_START(multi_small_ghash);
- unsigned int i = nbr;
- while (i--) {
- const int nbr = 1 + (BLI_rng_get_int(rng) % TESTCASE_SIZE_SMALL) * (!(i % 100) ? 100 : (!(i % 10) ? 10 : 1));
- multi_small_ghash_tests_one(ghash, rng, nbr);
- }
+ unsigned int i = nbr;
+ while (i--) {
+ const int nbr = 1 + (BLI_rng_get_int(rng) % TESTCASE_SIZE_SMALL) *
+ (!(i % 100) ? 100 : (!(i % 10) ? 10 : 1));
+ multi_small_ghash_tests_one(ghash, rng, nbr);
+ }
- TIMEIT_END(multi_small_ghash);
+ TIMEIT_END(multi_small_ghash);
- TIMEIT_START(multi_small2_ghash);
+ TIMEIT_START(multi_small2_ghash);
- unsigned int i = nbr;
- while (i--) {
- const int nbr = 1 + (BLI_rng_get_int(rng) % TESTCASE_SIZE_SMALL) / 2 * (!(i % 100) ? 100 : (!(i % 10) ? 10 : 1));
- multi_small_ghash_tests_one(ghash, rng, nbr);
- }
+ unsigned int i = nbr;
+ while (i--) {
+ const int nbr = 1 + (BLI_rng_get_int(rng) % TESTCASE_SIZE_SMALL) / 2 *
+ (!(i % 100) ? 100 : (!(i % 10) ? 10 : 1));
+ multi_small_ghash_tests_one(ghash, rng, nbr);
+ }
- TIMEIT_END(multi_small2_ghash);
+ TIMEIT_END(multi_small2_ghash);
- BLI_ghash_free(ghash, NULL, NULL);
- BLI_rng_free(rng);
+ BLI_ghash_free(ghash, NULL, NULL);
+ BLI_rng_free(rng);
- printf("========== ENDED %s ==========\n\n", id);
+ printf("========== ENDED %s ==========\n\n", id);
}
TEST(ghash, MultiRandIntGHash2000)
{
- GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
+ GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
- multi_small_ghash_tests(ghash, "MultiSmall RandIntGHash - GHash - 2000", 2000);
+ multi_small_ghash_tests(ghash, "MultiSmall RandIntGHash - GHash - 2000", 2000);
}
TEST(ghash, MultiRandIntGHash200000)
{
- GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
+ GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
- multi_small_ghash_tests(ghash, "MultiSmall RandIntGHash - GHash - 200000", 200000);
+ multi_small_ghash_tests(ghash, "MultiSmall RandIntGHash - GHash - 200000", 200000);
}
TEST(ghash, MultiRandIntMurmur2a2000)
{
- GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p_murmur, BLI_ghashutil_intcmp, __func__);
+ GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p_murmur, BLI_ghashutil_intcmp, __func__);
- multi_small_ghash_tests(ghash, "MultiSmall RandIntGHash - Murmur2a - 2000", 2000);
+ multi_small_ghash_tests(ghash, "MultiSmall RandIntGHash - Murmur2a - 2000", 2000);
}
TEST(ghash, MultiRandIntMurmur2a200000)
{
- GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p_murmur, BLI_ghashutil_intcmp, __func__);
+ GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p_murmur, BLI_ghashutil_intcmp, __func__);
- multi_small_ghash_tests(ghash, "MultiSmall RandIntGHash - Murmur2a - 200000", 200000);
+ multi_small_ghash_tests(ghash, "MultiSmall RandIntGHash - Murmur2a - 200000", 200000);
}
diff --git a/tests/gtests/blenlib/BLI_ghash_test.cc b/tests/gtests/blenlib/BLI_ghash_test.cc
index a219d3ec21a..c2ef064c8c9 100644
--- a/tests/gtests/blenlib/BLI_ghash_test.cc
+++ b/tests/gtests/blenlib/BLI_ghash_test.cc
@@ -14,187 +14,196 @@ extern "C" {
/* Only keeping this in case here, for now. */
#define PRINTF_GHASH_STATS(_gh) \
-{ \
- double q, lf, var, pempty, poverloaded; \
- int bigb; \
- q = BLI_ghash_calc_quality_ex((_gh), &lf, &var, &pempty, &poverloaded, &bigb); \
- printf("GHash stats (%d entries):\n\t" \
- "Quality (the lower the better): %f\n\tVariance (the lower the better): %f\n\tLoad: %f\n\t" \
- "Empty buckets: %.2f%%\n\tOverloaded buckets: %.2f%% (biggest bucket: %d)\n", \
- BLI_ghash_len(_gh), q, var, lf, pempty * 100.0, poverloaded * 100.0, bigb); \
-} void (0)
+ { \
+ double q, lf, var, pempty, poverloaded; \
+ int bigb; \
+ q = BLI_ghash_calc_quality_ex((_gh), &lf, &var, &pempty, &poverloaded, &bigb); \
+ printf( \
+ "GHash stats (%d entries):\n\t" \
+ "Quality (the lower the better): %f\n\tVariance (the lower the better): %f\n\tLoad: " \
+ "%f\n\t" \
+ "Empty buckets: %.2f%%\n\tOverloaded buckets: %.2f%% (biggest bucket: %d)\n", \
+ BLI_ghash_len(_gh), \
+ q, \
+ var, \
+ lf, \
+ pempty * 100.0, \
+ poverloaded * 100.0, \
+ bigb); \
+ } \
+ void(0)
/* Note: for pure-ghash testing, nature of the keys and data have absolutely no importance! So here we just use mere
* random integers stored in pointers. */
static void init_keys(unsigned int keys[TESTCASE_SIZE], const int seed)
{
- RNG *rng = BLI_rng_new(seed);
- unsigned int *k;
- int i;
-
- for (i = 0, k = keys; i < TESTCASE_SIZE; ) {
- /* Risks of collision are low, but they do exist.
- * And we cannot use a GSet, since we test that here! */
- int j, t = BLI_rng_get_uint(rng);
- for (j = i; j--; ) {
- if (keys[j] == t) {
- continue;
- }
- }
- *k = t;
- i++;
- k++;
- }
- BLI_rng_free(rng);
+ RNG *rng = BLI_rng_new(seed);
+ unsigned int *k;
+ int i;
+
+ for (i = 0, k = keys; i < TESTCASE_SIZE;) {
+ /* Risks of collision are low, but they do exist.
+ * And we cannot use a GSet, since we test that here! */
+ int j, t = BLI_rng_get_uint(rng);
+ for (j = i; j--;) {
+ if (keys[j] == t) {
+ continue;
+ }
+ }
+ *k = t;
+ i++;
+ k++;
+ }
+ BLI_rng_free(rng);
}
/* Here we simply insert and then lookup all keys, ensuring we do get back the expected stored 'data'. */
TEST(ghash, InsertLookup)
{
- GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
- unsigned int keys[TESTCASE_SIZE], *k;
- int i;
+ GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
+ unsigned int keys[TESTCASE_SIZE], *k;
+ int i;
- init_keys(keys, 0);
+ init_keys(keys, 0);
- for (i = TESTCASE_SIZE, k = keys; i--; k++) {
- BLI_ghash_insert(ghash, POINTER_FROM_UINT(*k), POINTER_FROM_UINT(*k));
- }
+ for (i = TESTCASE_SIZE, k = keys; i--; k++) {
+ BLI_ghash_insert(ghash, POINTER_FROM_UINT(*k), POINTER_FROM_UINT(*k));
+ }
- EXPECT_EQ(BLI_ghash_len(ghash), TESTCASE_SIZE);
+ EXPECT_EQ(BLI_ghash_len(ghash), TESTCASE_SIZE);
- for (i = TESTCASE_SIZE, k = keys; i--; k++) {
- void *v = BLI_ghash_lookup(ghash, POINTER_FROM_UINT(*k));
- EXPECT_EQ(POINTER_AS_UINT(v), *k);
- }
+ for (i = TESTCASE_SIZE, k = keys; i--; k++) {
+ void *v = BLI_ghash_lookup(ghash, POINTER_FROM_UINT(*k));
+ EXPECT_EQ(POINTER_AS_UINT(v), *k);
+ }
- BLI_ghash_free(ghash, NULL, NULL);
+ BLI_ghash_free(ghash, NULL, NULL);
}
/* Here we simply insert and then remove all keys, ensuring we do get an empty, unshrinked ghash. */
TEST(ghash, InsertRemove)
{
- GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
- unsigned int keys[TESTCASE_SIZE], *k;
- int i, bkt_size;
+ GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
+ unsigned int keys[TESTCASE_SIZE], *k;
+ int i, bkt_size;
- init_keys(keys, 10);
+ init_keys(keys, 10);
- for (i = TESTCASE_SIZE, k = keys; i--; k++) {
- BLI_ghash_insert(ghash, POINTER_FROM_UINT(*k), POINTER_FROM_UINT(*k));
- }
+ for (i = TESTCASE_SIZE, k = keys; i--; k++) {
+ BLI_ghash_insert(ghash, POINTER_FROM_UINT(*k), POINTER_FROM_UINT(*k));
+ }
- EXPECT_EQ(BLI_ghash_len(ghash), TESTCASE_SIZE);
- bkt_size = BLI_ghash_buckets_len(ghash);
+ EXPECT_EQ(BLI_ghash_len(ghash), TESTCASE_SIZE);
+ bkt_size = BLI_ghash_buckets_len(ghash);
- for (i = TESTCASE_SIZE, k = keys; i--; k++) {
- void *v = BLI_ghash_popkey(ghash, POINTER_FROM_UINT(*k), NULL);
- EXPECT_EQ(POINTER_AS_UINT(v), *k);
- }
+ for (i = TESTCASE_SIZE, k = keys; i--; k++) {
+ void *v = BLI_ghash_popkey(ghash, POINTER_FROM_UINT(*k), NULL);
+ EXPECT_EQ(POINTER_AS_UINT(v), *k);
+ }
- EXPECT_EQ(BLI_ghash_len(ghash), 0);
- EXPECT_EQ(BLI_ghash_buckets_len(ghash), bkt_size);
+ EXPECT_EQ(BLI_ghash_len(ghash), 0);
+ EXPECT_EQ(BLI_ghash_buckets_len(ghash), bkt_size);
- BLI_ghash_free(ghash, NULL, NULL);
+ BLI_ghash_free(ghash, NULL, NULL);
}
/* Same as above, but this time we allow ghash to shrink. */
TEST(ghash, InsertRemoveShrink)
{
- GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
- unsigned int keys[TESTCASE_SIZE], *k;
- int i, bkt_size;
+ GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
+ unsigned int keys[TESTCASE_SIZE], *k;
+ int i, bkt_size;
- BLI_ghash_flag_set(ghash, GHASH_FLAG_ALLOW_SHRINK);
- init_keys(keys, 20);
+ BLI_ghash_flag_set(ghash, GHASH_FLAG_ALLOW_SHRINK);
+ init_keys(keys, 20);
- for (i = TESTCASE_SIZE, k = keys; i--; k++) {
- BLI_ghash_insert(ghash, POINTER_FROM_UINT(*k), POINTER_FROM_UINT(*k));
- }
+ for (i = TESTCASE_SIZE, k = keys; i--; k++) {
+ BLI_ghash_insert(ghash, POINTER_FROM_UINT(*k), POINTER_FROM_UINT(*k));
+ }
- EXPECT_EQ(BLI_ghash_len(ghash), TESTCASE_SIZE);
- bkt_size = BLI_ghash_buckets_len(ghash);
+ EXPECT_EQ(BLI_ghash_len(ghash), TESTCASE_SIZE);
+ bkt_size = BLI_ghash_buckets_len(ghash);
- for (i = TESTCASE_SIZE, k = keys; i--; k++) {
- void *v = BLI_ghash_popkey(ghash, POINTER_FROM_UINT(*k), NULL);
- EXPECT_EQ(POINTER_AS_UINT(v), *k);
- }
+ for (i = TESTCASE_SIZE, k = keys; i--; k++) {
+ void *v = BLI_ghash_popkey(ghash, POINTER_FROM_UINT(*k), NULL);
+ EXPECT_EQ(POINTER_AS_UINT(v), *k);
+ }
- EXPECT_EQ(BLI_ghash_len(ghash), 0);
- EXPECT_LT(BLI_ghash_buckets_len(ghash), bkt_size);
+ EXPECT_EQ(BLI_ghash_len(ghash), 0);
+ EXPECT_LT(BLI_ghash_buckets_len(ghash), bkt_size);
- BLI_ghash_free(ghash, NULL, NULL);
+ BLI_ghash_free(ghash, NULL, NULL);
}
/* Check copy. */
TEST(ghash, Copy)
{
- GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
- GHash *ghash_copy;
- unsigned int keys[TESTCASE_SIZE], *k;
- int i;
+ GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
+ GHash *ghash_copy;
+ unsigned int keys[TESTCASE_SIZE], *k;
+ int i;
- init_keys(keys, 30);
+ init_keys(keys, 30);
- for (i = TESTCASE_SIZE, k = keys; i--; k++) {
- BLI_ghash_insert(ghash, POINTER_FROM_UINT(*k), POINTER_FROM_UINT(*k));
- }
+ for (i = TESTCASE_SIZE, k = keys; i--; k++) {
+ BLI_ghash_insert(ghash, POINTER_FROM_UINT(*k), POINTER_FROM_UINT(*k));
+ }
- EXPECT_EQ(BLI_ghash_len(ghash), TESTCASE_SIZE);
+ EXPECT_EQ(BLI_ghash_len(ghash), TESTCASE_SIZE);
- ghash_copy = BLI_ghash_copy(ghash, NULL, NULL);
+ ghash_copy = BLI_ghash_copy(ghash, NULL, NULL);
- EXPECT_EQ(BLI_ghash_len(ghash_copy), TESTCASE_SIZE);
- EXPECT_EQ(BLI_ghash_buckets_len(ghash_copy), BLI_ghash_buckets_len(ghash));
+ EXPECT_EQ(BLI_ghash_len(ghash_copy), TESTCASE_SIZE);
+ EXPECT_EQ(BLI_ghash_buckets_len(ghash_copy), BLI_ghash_buckets_len(ghash));
- for (i = TESTCASE_SIZE, k = keys; i--; k++) {
- void *v = BLI_ghash_lookup(ghash_copy, POINTER_FROM_UINT(*k));
- EXPECT_EQ(POINTER_AS_UINT(v), *k);
- }
+ for (i = TESTCASE_SIZE, k = keys; i--; k++) {
+ void *v = BLI_ghash_lookup(ghash_copy, POINTER_FROM_UINT(*k));
+ EXPECT_EQ(POINTER_AS_UINT(v), *k);
+ }
- BLI_ghash_free(ghash, NULL, NULL);
- BLI_ghash_free(ghash_copy, NULL, NULL);
+ BLI_ghash_free(ghash, NULL, NULL);
+ BLI_ghash_free(ghash_copy, NULL, NULL);
}
/* Check pop. */
TEST(ghash, Pop)
{
- GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
- unsigned int keys[TESTCASE_SIZE], *k;
- int i;
+ GHash *ghash = BLI_ghash_new(BLI_ghashutil_inthash_p, BLI_ghashutil_intcmp, __func__);
+ unsigned int keys[TESTCASE_SIZE], *k;
+ int i;
- BLI_ghash_flag_set(ghash, GHASH_FLAG_ALLOW_SHRINK);
- init_keys(keys, 30);
+ BLI_ghash_flag_set(ghash, GHASH_FLAG_ALLOW_SHRINK);
+ init_keys(keys, 30);
- for (i = TESTCASE_SIZE, k = keys; i--; k++) {
- BLI_ghash_insert(ghash, POINTER_FROM_UINT(*k), POINTER_FROM_UINT(*k));
- }
+ for (i = TESTCASE_SIZE, k = keys; i--; k++) {
+ BLI_ghash_insert(ghash, POINTER_FROM_UINT(*k), POINTER_FROM_UINT(*k));
+ }
- EXPECT_EQ(BLI_ghash_len(ghash), TESTCASE_SIZE);
+ EXPECT_EQ(BLI_ghash_len(ghash), TESTCASE_SIZE);
- GHashIterState pop_state = {0};
+ GHashIterState pop_state = {0};
- for (i = TESTCASE_SIZE / 2; i--; ) {
- void *k, *v;
- bool success = BLI_ghash_pop(ghash, &pop_state, &k, &v);
- EXPECT_EQ(k, v);
- EXPECT_TRUE(success);
+ for (i = TESTCASE_SIZE / 2; i--;) {
+ void *k, *v;
+ bool success = BLI_ghash_pop(ghash, &pop_state, &k, &v);
+ EXPECT_EQ(k, v);
+ EXPECT_TRUE(success);
- if (i % 2) {
- BLI_ghash_insert(ghash, POINTER_FROM_UINT(i * 4), POINTER_FROM_UINT(i * 4));
- }
- }
+ if (i % 2) {
+ BLI_ghash_insert(ghash, POINTER_FROM_UINT(i * 4), POINTER_FROM_UINT(i * 4));
+ }
+ }
- EXPECT_EQ(BLI_ghash_len(ghash), (TESTCASE_SIZE - TESTCASE_SIZE / 2 + TESTCASE_SIZE / 4));
+ EXPECT_EQ(BLI_ghash_len(ghash), (TESTCASE_SIZE - TESTCASE_SIZE / 2 + TESTCASE_SIZE / 4));
- {
- void *k, *v;
- while (BLI_ghash_pop(ghash, &pop_state, &k, &v)) {
- EXPECT_EQ(k, v);
- }
- }
- EXPECT_EQ(BLI_ghash_len(ghash), 0);
+ {
+ void *k, *v;
+ while (BLI_ghash_pop(ghash, &pop_state, &k, &v)) {
+ EXPECT_EQ(k, v);
+ }
+ }
+ EXPECT_EQ(BLI_ghash_len(ghash), 0);
- BLI_ghash_free(ghash, NULL, NULL);
+ BLI_ghash_free(ghash, NULL, NULL);
}
diff --git a/tests/gtests/blenlib/BLI_hash_mm2a_test.cc b/tests/gtests/blenlib/BLI_hash_mm2a_test.cc
index 109c925af4c..16a2db6af56 100644
--- a/tests/gtests/blenlib/BLI_hash_mm2a_test.cc
+++ b/tests/gtests/blenlib/BLI_hash_mm2a_test.cc
@@ -12,64 +12,64 @@ extern "C" {
TEST(hash_mm2a, MM2ABasic)
{
- BLI_HashMurmur2A mm2;
+ BLI_HashMurmur2A mm2;
- const char *data = "Blender";
+ const char *data = "Blender";
- BLI_hash_mm2a_init(&mm2, 0);
- BLI_hash_mm2a_add(&mm2, (const unsigned char *)data, strlen(data));
+ BLI_hash_mm2a_init(&mm2, 0);
+ BLI_hash_mm2a_add(&mm2, (const unsigned char *)data, strlen(data));
#ifdef __LITTLE_ENDIAN__
- EXPECT_EQ(BLI_hash_mm2a_end(&mm2), 1633988145);
+ EXPECT_EQ(BLI_hash_mm2a_end(&mm2), 1633988145);
#else
- EXPECT_EQ(BLI_hash_mm2a_end(&mm2), 959283772);
+ EXPECT_EQ(BLI_hash_mm2a_end(&mm2), 959283772);
#endif
}
TEST(hash_mm2a, MM2AConcatenateStrings)
{
- BLI_HashMurmur2A mm2;
- uint32_t hash;
+ BLI_HashMurmur2A mm2;
+ uint32_t hash;
- const char *data1 = "Blender";
- const char *data2 = " is ";
- const char *data3 = "FaNtAsTiC";
- const char *data123 = "Blender is FaNtAsTiC";
+ const char *data1 = "Blender";
+ const char *data2 = " is ";
+ const char *data3 = "FaNtAsTiC";
+ const char *data123 = "Blender is FaNtAsTiC";
- BLI_hash_mm2a_init(&mm2, 0);
- BLI_hash_mm2a_add(&mm2, (const unsigned char *)data1, strlen(data1));
- BLI_hash_mm2a_add(&mm2, (const unsigned char *)data2, strlen(data2));
- BLI_hash_mm2a_add(&mm2, (const unsigned char *)data3, strlen(data3));
- hash = BLI_hash_mm2a_end(&mm2);
- BLI_hash_mm2a_init(&mm2, 0);
- BLI_hash_mm2a_add(&mm2, (const unsigned char *)data123, strlen(data123));
+ BLI_hash_mm2a_init(&mm2, 0);
+ BLI_hash_mm2a_add(&mm2, (const unsigned char *)data1, strlen(data1));
+ BLI_hash_mm2a_add(&mm2, (const unsigned char *)data2, strlen(data2));
+ BLI_hash_mm2a_add(&mm2, (const unsigned char *)data3, strlen(data3));
+ hash = BLI_hash_mm2a_end(&mm2);
+ BLI_hash_mm2a_init(&mm2, 0);
+ BLI_hash_mm2a_add(&mm2, (const unsigned char *)data123, strlen(data123));
#ifdef __LITTLE_ENDIAN__
- EXPECT_EQ(hash, 1545105348);
+ EXPECT_EQ(hash, 1545105348);
#else
- EXPECT_EQ(hash, 2604964730);
+ EXPECT_EQ(hash, 2604964730);
#endif
- EXPECT_EQ(BLI_hash_mm2a_end(&mm2), hash);
+ EXPECT_EQ(BLI_hash_mm2a_end(&mm2), hash);
}
TEST(hash_mm2a, MM2AIntegers)
{
- BLI_HashMurmur2A mm2;
- uint32_t hash;
+ BLI_HashMurmur2A mm2;
+ uint32_t hash;
- const int ints[4] = {1, 2, 3, 4};
+ const int ints[4] = {1, 2, 3, 4};
- BLI_hash_mm2a_init(&mm2, 0);
- BLI_hash_mm2a_add_int(&mm2, ints[0]);
- BLI_hash_mm2a_add_int(&mm2, ints[1]);
- BLI_hash_mm2a_add_int(&mm2, ints[2]);
- BLI_hash_mm2a_add_int(&mm2, ints[3]);
- hash = BLI_hash_mm2a_end(&mm2);
- BLI_hash_mm2a_init(&mm2, 0);
- BLI_hash_mm2a_add(&mm2, (const unsigned char *)ints, sizeof(ints));
- /* Yes, same hash here on little and big endian. */
+ BLI_hash_mm2a_init(&mm2, 0);
+ BLI_hash_mm2a_add_int(&mm2, ints[0]);
+ BLI_hash_mm2a_add_int(&mm2, ints[1]);
+ BLI_hash_mm2a_add_int(&mm2, ints[2]);
+ BLI_hash_mm2a_add_int(&mm2, ints[3]);
+ hash = BLI_hash_mm2a_end(&mm2);
+ BLI_hash_mm2a_init(&mm2, 0);
+ BLI_hash_mm2a_add(&mm2, (const unsigned char *)ints, sizeof(ints));
+ /* Yes, same hash here on little and big endian. */
#ifdef __LITTLE_ENDIAN__
- EXPECT_EQ(hash, 405493096);
+ EXPECT_EQ(hash, 405493096);
#else
- EXPECT_EQ(hash, 405493096);
+ EXPECT_EQ(hash, 405493096);
#endif
- EXPECT_EQ(BLI_hash_mm2a_end(&mm2), hash);
+ EXPECT_EQ(BLI_hash_mm2a_end(&mm2), hash);
}
diff --git a/tests/gtests/blenlib/BLI_heap_simple_test.cc b/tests/gtests/blenlib/BLI_heap_simple_test.cc
index 9c97163f337..16e1ecbf9cf 100644
--- a/tests/gtests/blenlib/BLI_heap_simple_test.cc
+++ b/tests/gtests/blenlib/BLI_heap_simple_test.cc
@@ -15,104 +15,109 @@ extern "C" {
#define SIZE 1024
-
static void range_fl(float *array_tar, const int size)
{
- float *array_pt = array_tar + (size - 1);
- int i = size;
- while (i--) {
- *(array_pt--) = (float)i;
- }
+ float *array_pt = array_tar + (size - 1);
+ int i = size;
+ while (i--) {
+ *(array_pt--) = (float)i;
+ }
}
TEST(heap, SimpleEmpty)
{
- HeapSimple *heap;
+ HeapSimple *heap;
- heap = BLI_heapsimple_new();
- EXPECT_TRUE(BLI_heapsimple_is_empty(heap));
- EXPECT_EQ(BLI_heapsimple_len(heap), 0);
- BLI_heapsimple_free(heap, NULL);
+ heap = BLI_heapsimple_new();
+ EXPECT_TRUE(BLI_heapsimple_is_empty(heap));
+ EXPECT_EQ(BLI_heapsimple_len(heap), 0);
+ BLI_heapsimple_free(heap, NULL);
}
TEST(heap, SimpleOne)
{
- HeapSimple *heap;
- const char *in = "test";
-
- heap = BLI_heapsimple_new();
-
- BLI_heapsimple_insert(heap, 0.0f, (void *)in);
- EXPECT_FALSE(BLI_heapsimple_is_empty(heap));
- EXPECT_EQ(BLI_heapsimple_len(heap), 1);
- EXPECT_EQ(in, BLI_heapsimple_pop_min(heap));
- EXPECT_TRUE(BLI_heapsimple_is_empty(heap));
- EXPECT_EQ(BLI_heapsimple_len(heap), 0);
- BLI_heapsimple_free(heap, NULL);
+ HeapSimple *heap;
+ const char *in = "test";
+
+ heap = BLI_heapsimple_new();
+
+ BLI_heapsimple_insert(heap, 0.0f, (void *)in);
+ EXPECT_FALSE(BLI_heapsimple_is_empty(heap));
+ EXPECT_EQ(BLI_heapsimple_len(heap), 1);
+ EXPECT_EQ(in, BLI_heapsimple_pop_min(heap));
+ EXPECT_TRUE(BLI_heapsimple_is_empty(heap));
+ EXPECT_EQ(BLI_heapsimple_len(heap), 0);
+ BLI_heapsimple_free(heap, NULL);
}
TEST(heap, SimpleRange)
{
- const int items_total = SIZE;
- HeapSimple *heap = BLI_heapsimple_new();
- for (int in = 0; in < items_total; in++) {
- BLI_heapsimple_insert(heap, (float)in, POINTER_FROM_INT(in));
- }
- for (int out_test = 0; out_test < items_total; out_test++) {
- EXPECT_EQ(out_test, POINTER_AS_INT(BLI_heapsimple_pop_min(heap)));
-
- }
- EXPECT_TRUE(BLI_heapsimple_is_empty(heap));
- BLI_heapsimple_free(heap, NULL);
+ const int items_total = SIZE;
+ HeapSimple *heap = BLI_heapsimple_new();
+ for (int in = 0; in < items_total; in++) {
+ BLI_heapsimple_insert(heap, (float)in, POINTER_FROM_INT(in));
+ }
+ for (int out_test = 0; out_test < items_total; out_test++) {
+ EXPECT_EQ(out_test, POINTER_AS_INT(BLI_heapsimple_pop_min(heap)));
+ }
+ EXPECT_TRUE(BLI_heapsimple_is_empty(heap));
+ BLI_heapsimple_free(heap, NULL);
}
TEST(heap, SimpleRangeReverse)
{
- const int items_total = SIZE;
- HeapSimple *heap = BLI_heapsimple_new();
- for (int in = 0; in < items_total; in++) {
- BLI_heapsimple_insert(heap, (float)-in, POINTER_FROM_INT(-in));
- }
- for (int out_test = items_total - 1; out_test >= 0; out_test--) {
- EXPECT_EQ(-out_test, POINTER_AS_INT(BLI_heapsimple_pop_min(heap)));
- }
- EXPECT_TRUE(BLI_heapsimple_is_empty(heap));
- BLI_heapsimple_free(heap, NULL);
+ const int items_total = SIZE;
+ HeapSimple *heap = BLI_heapsimple_new();
+ for (int in = 0; in < items_total; in++) {
+ BLI_heapsimple_insert(heap, (float)-in, POINTER_FROM_INT(-in));
+ }
+ for (int out_test = items_total - 1; out_test >= 0; out_test--) {
+ EXPECT_EQ(-out_test, POINTER_AS_INT(BLI_heapsimple_pop_min(heap)));
+ }
+ EXPECT_TRUE(BLI_heapsimple_is_empty(heap));
+ BLI_heapsimple_free(heap, NULL);
}
TEST(heap, SimpleDuplicates)
{
- const int items_total = SIZE;
- HeapSimple *heap = BLI_heapsimple_new();
- for (int in = 0; in < items_total; in++) {
- BLI_heapsimple_insert(heap, 1.0f, 0);
- }
- for (int out_test = 0; out_test < items_total; out_test++) {
- EXPECT_EQ(0, POINTER_AS_INT(BLI_heapsimple_pop_min(heap)));
- }
- EXPECT_TRUE(BLI_heapsimple_is_empty(heap));
- BLI_heapsimple_free(heap, NULL);
+ const int items_total = SIZE;
+ HeapSimple *heap = BLI_heapsimple_new();
+ for (int in = 0; in < items_total; in++) {
+ BLI_heapsimple_insert(heap, 1.0f, 0);
+ }
+ for (int out_test = 0; out_test < items_total; out_test++) {
+ EXPECT_EQ(0, POINTER_AS_INT(BLI_heapsimple_pop_min(heap)));
+ }
+ EXPECT_TRUE(BLI_heapsimple_is_empty(heap));
+ BLI_heapsimple_free(heap, NULL);
}
-static void random_heapsimple_helper(
- const int items_total,
- const int random_seed)
+static void random_heapsimple_helper(const int items_total, const int random_seed)
{
- HeapSimple *heap = BLI_heapsimple_new();
- float *values = (float *)MEM_mallocN(sizeof(float) * items_total, __func__);
- range_fl(values, items_total);
- BLI_array_randomize(values, sizeof(float), items_total, random_seed);
- for (int i = 0; i < items_total; i++) {
- BLI_heapsimple_insert(heap, values[i], POINTER_FROM_INT((int)values[i]));
- }
- for (int out_test = 0; out_test < items_total; out_test++) {
- EXPECT_EQ(out_test, POINTER_AS_INT(BLI_heapsimple_pop_min(heap)));
- }
- EXPECT_TRUE(BLI_heapsimple_is_empty(heap));
- BLI_heapsimple_free(heap, NULL);
- MEM_freeN(values);
+ HeapSimple *heap = BLI_heapsimple_new();
+ float *values = (float *)MEM_mallocN(sizeof(float) * items_total, __func__);
+ range_fl(values, items_total);
+ BLI_array_randomize(values, sizeof(float), items_total, random_seed);
+ for (int i = 0; i < items_total; i++) {
+ BLI_heapsimple_insert(heap, values[i], POINTER_FROM_INT((int)values[i]));
+ }
+ for (int out_test = 0; out_test < items_total; out_test++) {
+ EXPECT_EQ(out_test, POINTER_AS_INT(BLI_heapsimple_pop_min(heap)));
+ }
+ EXPECT_TRUE(BLI_heapsimple_is_empty(heap));
+ BLI_heapsimple_free(heap, NULL);
+ MEM_freeN(values);
}
-TEST(heap, SimpleRand1) { random_heapsimple_helper(1, 1234); }
-TEST(heap, SimpleRand2) { random_heapsimple_helper(2, 1234); }
-TEST(heap, SimpleRand100) { random_heapsimple_helper(100, 4321); }
+TEST(heap, SimpleRand1)
+{
+ random_heapsimple_helper(1, 1234);
+}
+TEST(heap, SimpleRand2)
+{
+ random_heapsimple_helper(2, 1234);
+}
+TEST(heap, SimpleRand100)
+{
+ random_heapsimple_helper(100, 4321);
+}
diff --git a/tests/gtests/blenlib/BLI_heap_test.cc b/tests/gtests/blenlib/BLI_heap_test.cc
index 26f3aa19b9f..884093435e4 100644
--- a/tests/gtests/blenlib/BLI_heap_test.cc
+++ b/tests/gtests/blenlib/BLI_heap_test.cc
@@ -14,179 +14,196 @@ extern "C" {
#define SIZE 1024
-
static void range_fl(float *array_tar, const int size)
{
- float *array_pt = array_tar + (size - 1);
- int i = size;
- while (i--) {
- *(array_pt--) = (float)i;
- }
+ float *array_pt = array_tar + (size - 1);
+ int i = size;
+ while (i--) {
+ *(array_pt--) = (float)i;
+ }
}
TEST(heap, Empty)
{
- Heap *heap;
+ Heap *heap;
- heap = BLI_heap_new();
- EXPECT_TRUE(BLI_heap_is_empty(heap));
- EXPECT_EQ(BLI_heap_len(heap), 0);
- BLI_heap_free(heap, NULL);
+ heap = BLI_heap_new();
+ EXPECT_TRUE(BLI_heap_is_empty(heap));
+ EXPECT_EQ(BLI_heap_len(heap), 0);
+ BLI_heap_free(heap, NULL);
}
TEST(heap, One)
{
- Heap *heap;
- const char *in = "test";
-
- heap = BLI_heap_new();
-
- BLI_heap_insert(heap, 0.0f, (void *)in);
- EXPECT_FALSE(BLI_heap_is_empty(heap));
- EXPECT_EQ(BLI_heap_len(heap), 1);
- EXPECT_EQ(in, BLI_heap_pop_min(heap));
- EXPECT_TRUE(BLI_heap_is_empty(heap));
- EXPECT_EQ(BLI_heap_len(heap), 0);
- BLI_heap_free(heap, NULL);
+ Heap *heap;
+ const char *in = "test";
+
+ heap = BLI_heap_new();
+
+ BLI_heap_insert(heap, 0.0f, (void *)in);
+ EXPECT_FALSE(BLI_heap_is_empty(heap));
+ EXPECT_EQ(BLI_heap_len(heap), 1);
+ EXPECT_EQ(in, BLI_heap_pop_min(heap));
+ EXPECT_TRUE(BLI_heap_is_empty(heap));
+ EXPECT_EQ(BLI_heap_len(heap), 0);
+ BLI_heap_free(heap, NULL);
}
TEST(heap, Range)
{
- const int items_total = SIZE;
- Heap *heap = BLI_heap_new();
- for (int in = 0; in < items_total; in++) {
- BLI_heap_insert(heap, (float)in, POINTER_FROM_INT(in));
- }
- for (int out_test = 0; out_test < items_total; out_test++) {
- EXPECT_EQ(out_test, POINTER_AS_INT(BLI_heap_pop_min(heap)));
-
- }
- EXPECT_TRUE(BLI_heap_is_empty(heap));
- BLI_heap_free(heap, NULL);
+ const int items_total = SIZE;
+ Heap *heap = BLI_heap_new();
+ for (int in = 0; in < items_total; in++) {
+ BLI_heap_insert(heap, (float)in, POINTER_FROM_INT(in));
+ }
+ for (int out_test = 0; out_test < items_total; out_test++) {
+ EXPECT_EQ(out_test, POINTER_AS_INT(BLI_heap_pop_min(heap)));
+ }
+ EXPECT_TRUE(BLI_heap_is_empty(heap));
+ BLI_heap_free(heap, NULL);
}
TEST(heap, RangeReverse)
{
- const int items_total = SIZE;
- Heap *heap = BLI_heap_new();
- for (int in = 0; in < items_total; in++) {
- BLI_heap_insert(heap, (float)-in, POINTER_FROM_INT(-in));
- }
- for (int out_test = items_total - 1; out_test >= 0; out_test--) {
- EXPECT_EQ(-out_test, POINTER_AS_INT(BLI_heap_pop_min(heap)));
- }
- EXPECT_TRUE(BLI_heap_is_empty(heap));
- BLI_heap_free(heap, NULL);
+ const int items_total = SIZE;
+ Heap *heap = BLI_heap_new();
+ for (int in = 0; in < items_total; in++) {
+ BLI_heap_insert(heap, (float)-in, POINTER_FROM_INT(-in));
+ }
+ for (int out_test = items_total - 1; out_test >= 0; out_test--) {
+ EXPECT_EQ(-out_test, POINTER_AS_INT(BLI_heap_pop_min(heap)));
+ }
+ EXPECT_TRUE(BLI_heap_is_empty(heap));
+ BLI_heap_free(heap, NULL);
}
TEST(heap, RangeRemove)
{
- const int items_total = SIZE;
- Heap *heap = BLI_heap_new();
- HeapNode **nodes = (HeapNode **)MEM_mallocN(sizeof(HeapNode *) * items_total, __func__);
- for (int in = 0; in < items_total; in++) {
- nodes[in] = BLI_heap_insert(heap, (float)in, POINTER_FROM_INT(in));
- }
- for (int i = 0; i < items_total; i += 2) {
- BLI_heap_remove(heap, nodes[i]);
- nodes[i] = NULL;
- }
- for (int out_test = 1; out_test < items_total; out_test += 2) {
- EXPECT_EQ(out_test, POINTER_AS_INT(BLI_heap_pop_min(heap)));
- }
- EXPECT_TRUE(BLI_heap_is_empty(heap));
- BLI_heap_free(heap, NULL);
- MEM_freeN(nodes);
+ const int items_total = SIZE;
+ Heap *heap = BLI_heap_new();
+ HeapNode **nodes = (HeapNode **)MEM_mallocN(sizeof(HeapNode *) * items_total, __func__);
+ for (int in = 0; in < items_total; in++) {
+ nodes[in] = BLI_heap_insert(heap, (float)in, POINTER_FROM_INT(in));
+ }
+ for (int i = 0; i < items_total; i += 2) {
+ BLI_heap_remove(heap, nodes[i]);
+ nodes[i] = NULL;
+ }
+ for (int out_test = 1; out_test < items_total; out_test += 2) {
+ EXPECT_EQ(out_test, POINTER_AS_INT(BLI_heap_pop_min(heap)));
+ }
+ EXPECT_TRUE(BLI_heap_is_empty(heap));
+ BLI_heap_free(heap, NULL);
+ MEM_freeN(nodes);
}
TEST(heap, Duplicates)
{
- const int items_total = SIZE;
- Heap *heap = BLI_heap_new();
- for (int in = 0; in < items_total; in++) {
- BLI_heap_insert(heap, 1.0f, 0);
- }
- for (int out_test = 0; out_test < items_total; out_test++) {
- EXPECT_EQ(0, POINTER_AS_INT(BLI_heap_pop_min(heap)));
- }
- EXPECT_TRUE(BLI_heap_is_empty(heap));
- BLI_heap_free(heap, NULL);
-}
-
-static void random_heap_helper(
- const int items_total,
- const int random_seed)
-{
- Heap *heap = BLI_heap_new();
- float *values = (float *)MEM_mallocN(sizeof(float) * items_total, __func__);
- range_fl(values, items_total);
- BLI_array_randomize(values, sizeof(float), items_total, random_seed);
- for (int i = 0; i < items_total; i++) {
- BLI_heap_insert(heap, values[i], POINTER_FROM_INT((int)values[i]));
- }
- for (int out_test = 0; out_test < items_total; out_test++) {
- EXPECT_EQ(out_test, POINTER_AS_INT(BLI_heap_pop_min(heap)));
- }
- EXPECT_TRUE(BLI_heap_is_empty(heap));
- BLI_heap_free(heap, NULL);
- MEM_freeN(values);
-}
-
-TEST(heap, Rand1) { random_heap_helper(1, 1234); }
-TEST(heap, Rand2) { random_heap_helper(2, 1234); }
-TEST(heap, Rand100) { random_heap_helper(100, 4321); }
+ const int items_total = SIZE;
+ Heap *heap = BLI_heap_new();
+ for (int in = 0; in < items_total; in++) {
+ BLI_heap_insert(heap, 1.0f, 0);
+ }
+ for (int out_test = 0; out_test < items_total; out_test++) {
+ EXPECT_EQ(0, POINTER_AS_INT(BLI_heap_pop_min(heap)));
+ }
+ EXPECT_TRUE(BLI_heap_is_empty(heap));
+ BLI_heap_free(heap, NULL);
+}
+static void random_heap_helper(const int items_total, const int random_seed)
+{
+ Heap *heap = BLI_heap_new();
+ float *values = (float *)MEM_mallocN(sizeof(float) * items_total, __func__);
+ range_fl(values, items_total);
+ BLI_array_randomize(values, sizeof(float), items_total, random_seed);
+ for (int i = 0; i < items_total; i++) {
+ BLI_heap_insert(heap, values[i], POINTER_FROM_INT((int)values[i]));
+ }
+ for (int out_test = 0; out_test < items_total; out_test++) {
+ EXPECT_EQ(out_test, POINTER_AS_INT(BLI_heap_pop_min(heap)));
+ }
+ EXPECT_TRUE(BLI_heap_is_empty(heap));
+ BLI_heap_free(heap, NULL);
+ MEM_freeN(values);
+}
+
+TEST(heap, Rand1)
+{
+ random_heap_helper(1, 1234);
+}
+TEST(heap, Rand2)
+{
+ random_heap_helper(2, 1234);
+}
+TEST(heap, Rand100)
+{
+ random_heap_helper(100, 4321);
+}
TEST(heap, ReInsertSimple)
{
- const int items_total = SIZE;
- Heap *heap = BLI_heap_new();
- HeapNode **nodes = (HeapNode **)MEM_mallocN(sizeof(HeapNode *) * items_total, __func__);
- for (int in = 0; in < items_total; in++) {
- nodes[in] = BLI_heap_insert(heap, (float)in, POINTER_FROM_INT(in));
- }
- for (int i = 0; i < items_total; i++) {
- BLI_heap_node_value_update(heap, nodes[i], (float)(items_total + i));
- }
-
- for (int out_test = 0; out_test < items_total; out_test++) {
- EXPECT_EQ(out_test, POINTER_AS_INT(BLI_heap_pop_min(heap)));
- }
-
- EXPECT_TRUE(BLI_heap_is_empty(heap));
- BLI_heap_free(heap, NULL);
- MEM_freeN(nodes);
-}
-
-static void random_heap_reinsert_helper(
- const int items_total,
- const int random_seed)
-{
- Heap *heap = BLI_heap_new();
- HeapNode **nodes = (HeapNode **)MEM_mallocN(sizeof(HeapNode *) * items_total, __func__);
- for (int in = 0; in < items_total; in++) {
- nodes[in] = BLI_heap_insert(heap, (float)in, POINTER_FROM_INT(in));
- }
- BLI_array_randomize(nodes, sizeof(HeapNode *), items_total, random_seed);
- for (int i = 0; i < items_total; i++) {
- BLI_heap_node_value_update(heap, nodes[i], (float)i);
- }
- EXPECT_TRUE(BLI_heap_is_valid(heap));
-
- for (int out_test = 0; out_test < items_total; out_test++) {
- HeapNode *node_top = BLI_heap_top(heap);
- float out = BLI_heap_node_value(node_top);
- EXPECT_EQ(out, BLI_heap_top_value(heap));
- EXPECT_EQ((float)out_test, out);
- BLI_heap_pop_min(heap);
- }
- EXPECT_TRUE(BLI_heap_is_empty(heap));
- BLI_heap_free(heap, NULL);
- MEM_freeN(nodes);
-}
-
-TEST(heap, ReInsertRandom1) { random_heap_reinsert_helper(1, 1234); }
-TEST(heap, ReInsertRandom2) { random_heap_reinsert_helper(2, 1234); }
-TEST(heap, ReInsertRandom100) { random_heap_reinsert_helper(100, 4321); }
-TEST(heap, ReInsertRandom1024) { random_heap_reinsert_helper(1024, 9876); }
-TEST(heap, ReInsertRandom2048) { random_heap_reinsert_helper(2048, 5321); }
+ const int items_total = SIZE;
+ Heap *heap = BLI_heap_new();
+ HeapNode **nodes = (HeapNode **)MEM_mallocN(sizeof(HeapNode *) * items_total, __func__);
+ for (int in = 0; in < items_total; in++) {
+ nodes[in] = BLI_heap_insert(heap, (float)in, POINTER_FROM_INT(in));
+ }
+ for (int i = 0; i < items_total; i++) {
+ BLI_heap_node_value_update(heap, nodes[i], (float)(items_total + i));
+ }
+
+ for (int out_test = 0; out_test < items_total; out_test++) {
+ EXPECT_EQ(out_test, POINTER_AS_INT(BLI_heap_pop_min(heap)));
+ }
+
+ EXPECT_TRUE(BLI_heap_is_empty(heap));
+ BLI_heap_free(heap, NULL);
+ MEM_freeN(nodes);
+}
+
+static void random_heap_reinsert_helper(const int items_total, const int random_seed)
+{
+ Heap *heap = BLI_heap_new();
+ HeapNode **nodes = (HeapNode **)MEM_mallocN(sizeof(HeapNode *) * items_total, __func__);
+ for (int in = 0; in < items_total; in++) {
+ nodes[in] = BLI_heap_insert(heap, (float)in, POINTER_FROM_INT(in));
+ }
+ BLI_array_randomize(nodes, sizeof(HeapNode *), items_total, random_seed);
+ for (int i = 0; i < items_total; i++) {
+ BLI_heap_node_value_update(heap, nodes[i], (float)i);
+ }
+ EXPECT_TRUE(BLI_heap_is_valid(heap));
+
+ for (int out_test = 0; out_test < items_total; out_test++) {
+ HeapNode *node_top = BLI_heap_top(heap);
+ float out = BLI_heap_node_value(node_top);
+ EXPECT_EQ(out, BLI_heap_top_value(heap));
+ EXPECT_EQ((float)out_test, out);
+ BLI_heap_pop_min(heap);
+ }
+ EXPECT_TRUE(BLI_heap_is_empty(heap));
+ BLI_heap_free(heap, NULL);
+ MEM_freeN(nodes);
+}
+
+TEST(heap, ReInsertRandom1)
+{
+ random_heap_reinsert_helper(1, 1234);
+}
+TEST(heap, ReInsertRandom2)
+{
+ random_heap_reinsert_helper(2, 1234);
+}
+TEST(heap, ReInsertRandom100)
+{
+ random_heap_reinsert_helper(100, 4321);
+}
+TEST(heap, ReInsertRandom1024)
+{
+ random_heap_reinsert_helper(1024, 9876);
+}
+TEST(heap, ReInsertRandom2048)
+{
+ random_heap_reinsert_helper(2048, 5321);
+}
diff --git a/tests/gtests/blenlib/BLI_kdopbvh_test.cc b/tests/gtests/blenlib/BLI_kdopbvh_test.cc
index ff4a74b8be8..bd35a491550 100644
--- a/tests/gtests/blenlib/BLI_kdopbvh_test.cc
+++ b/tests/gtests/blenlib/BLI_kdopbvh_test.cc
@@ -17,14 +17,12 @@ extern "C" {
/* -------------------------------------------------------------------- */
/* Helper Functions */
-static void rng_v3_round(
- float *coords, int coords_len,
- struct RNG *rng, int round, float scale)
+static void rng_v3_round(float *coords, int coords_len, struct RNG *rng, int round, float scale)
{
- for (int i = 0; i < coords_len; i++) {
- float f = BLI_rng_get_float(rng) * 2.0f - 1.0f;
- coords[i] = ((float)((int)(f * round)) / (float)round) * scale;
- }
+ for (int i = 0; i < coords_len; i++) {
+ float f = BLI_rng_get_float(rng) * 2.0f - 1.0f;
+ coords[i] = ((float)((int)(f * round)) / (float)round) * scale;
+ }
}
/* -------------------------------------------------------------------- */
@@ -32,86 +30,105 @@ static void rng_v3_round(
TEST(kdopbvh, Empty)
{
- BVHTree *tree = BLI_bvhtree_new(0, 0.0, 8, 8);
- BLI_bvhtree_balance(tree);
- EXPECT_EQ(0, BLI_bvhtree_get_len(tree));
- BLI_bvhtree_free(tree);
+ BVHTree *tree = BLI_bvhtree_new(0, 0.0, 8, 8);
+ BLI_bvhtree_balance(tree);
+ EXPECT_EQ(0, BLI_bvhtree_get_len(tree));
+ BLI_bvhtree_free(tree);
}
TEST(kdopbvh, Single)
{
- BVHTree *tree = BLI_bvhtree_new(1, 0.0, 8, 8);
- {
- float co[3] = {0};
- BLI_bvhtree_insert(tree, 0, co, 1);
- }
+ BVHTree *tree = BLI_bvhtree_new(1, 0.0, 8, 8);
+ {
+ float co[3] = {0};
+ BLI_bvhtree_insert(tree, 0, co, 1);
+ }
- EXPECT_EQ(BLI_bvhtree_get_len(tree), 1);
+ EXPECT_EQ(BLI_bvhtree_get_len(tree), 1);
- BLI_bvhtree_balance(tree);
- BLI_bvhtree_free(tree);
+ BLI_bvhtree_balance(tree);
+ BLI_bvhtree_free(tree);
}
void optimal_check_callback(void *userdata, int index, const float co[3], BVHTreeNearest *nearest)
{
- float (*points)[3] = (float (*)[3])userdata;
+ float(*points)[3] = (float(*)[3])userdata;
- /* BVH_NEAREST_OPTIMAL_ORDER should hit the right node on the first try */
- EXPECT_EQ(nearest->index, -1);
- EXPECT_EQ_ARRAY(co, points[index], 3);
+ /* BVH_NEAREST_OPTIMAL_ORDER should hit the right node on the first try */
+ EXPECT_EQ(nearest->index, -1);
+ EXPECT_EQ_ARRAY(co, points[index], 3);
- nearest->index = index;
- nearest->dist_sq = len_squared_v3v3(co, points[index]);
+ nearest->index = index;
+ nearest->dist_sq = len_squared_v3v3(co, points[index]);
}
/**
* Note that a small epsilon is added to the BVH nodes bounds, even if we pass in zero.
* Use rounding to ensure very close nodes don't cause the wrong node to be found as nearest.
*/
-static void find_nearest_points_test(int points_len, float scale, int round, int random_seed, bool optimal = false)
+static void find_nearest_points_test(
+ int points_len, float scale, int round, int random_seed, bool optimal = false)
{
- struct RNG *rng = BLI_rng_new(random_seed);
- BVHTree *tree = BLI_bvhtree_new(points_len, 0.0, 8, 8);
+ struct RNG *rng = BLI_rng_new(random_seed);
+ BVHTree *tree = BLI_bvhtree_new(points_len, 0.0, 8, 8);
- void *mem = MEM_mallocN(sizeof(float[3]) * points_len, __func__);
- float (*points)[3] = (float (*)[3])mem;
+ void *mem = MEM_mallocN(sizeof(float[3]) * points_len, __func__);
+ float(*points)[3] = (float(*)[3])mem;
- for (int i = 0; i < points_len; i++) {
- rng_v3_round(points[i], 3, rng, round, scale);
- BLI_bvhtree_insert(tree, i, points[i], 1);
- }
- BLI_bvhtree_balance(tree);
+ for (int i = 0; i < points_len; i++) {
+ rng_v3_round(points[i], 3, rng, round, scale);
+ BLI_bvhtree_insert(tree, i, points[i], 1);
+ }
+ BLI_bvhtree_balance(tree);
- /* first find each point */
- BVHTree_NearestPointCallback callback = optimal ? optimal_check_callback : NULL;
- int flags = optimal ? BVH_NEAREST_OPTIMAL_ORDER : 0;
+ /* first find each point */
+ BVHTree_NearestPointCallback callback = optimal ? optimal_check_callback : NULL;
+ int flags = optimal ? BVH_NEAREST_OPTIMAL_ORDER : 0;
- for (int i = 0; i < points_len; i++) {
- const int j = BLI_bvhtree_find_nearest_ex(tree, points[i], NULL, callback, points, flags);
- if (j != i) {
+ for (int i = 0; i < points_len; i++) {
+ const int j = BLI_bvhtree_find_nearest_ex(tree, points[i], NULL, callback, points, flags);
+ if (j != i) {
#if 0
- const float dist = len_v3v3(points[i], points[j]);
- if (dist > (1.0f / (float)round)) {
- printf("%.15f (%d %d)\n", dist, i, j);
- print_v3_id(points[i]);
- print_v3_id(points[j]);
- fflush(stdout);
- }
+ const float dist = len_v3v3(points[i], points[j]);
+ if (dist > (1.0f / (float)round)) {
+ printf("%.15f (%d %d)\n", dist, i, j);
+ print_v3_id(points[i]);
+ print_v3_id(points[j]);
+ fflush(stdout);
+ }
#endif
- EXPECT_GE(j, 0);
- EXPECT_LT(j, points_len);
- EXPECT_EQ_ARRAY(points[i], points[j], 3);
- }
- }
- BLI_bvhtree_free(tree);
- BLI_rng_free(rng);
- MEM_freeN(points);
+ EXPECT_GE(j, 0);
+ EXPECT_LT(j, points_len);
+ EXPECT_EQ_ARRAY(points[i], points[j], 3);
+ }
+ }
+ BLI_bvhtree_free(tree);
+ BLI_rng_free(rng);
+ MEM_freeN(points);
}
-TEST(kdopbvh, FindNearest_1) { find_nearest_points_test(1, 1.0, 1000, 1234); }
-TEST(kdopbvh, FindNearest_2) { find_nearest_points_test(2, 1.0, 1000, 123); }
-TEST(kdopbvh, FindNearest_500) { find_nearest_points_test(500, 1.0, 1000, 12); }
+TEST(kdopbvh, FindNearest_1)
+{
+ find_nearest_points_test(1, 1.0, 1000, 1234);
+}
+TEST(kdopbvh, FindNearest_2)
+{
+ find_nearest_points_test(2, 1.0, 1000, 123);
+}
+TEST(kdopbvh, FindNearest_500)
+{
+ find_nearest_points_test(500, 1.0, 1000, 12);
+}
-TEST(kdopbvh, OptimalFindNearest_1) { find_nearest_points_test(1, 1.0, 1000, 1234, true); }
-TEST(kdopbvh, OptimalFindNearest_2) { find_nearest_points_test(2, 1.0, 1000, 123, true); }
-TEST(kdopbvh, OptimalFindNearest_500) { find_nearest_points_test(500, 1.0, 1000, 12, true); }
+TEST(kdopbvh, OptimalFindNearest_1)
+{
+ find_nearest_points_test(1, 1.0, 1000, 1234, true);
+}
+TEST(kdopbvh, OptimalFindNearest_2)
+{
+ find_nearest_points_test(2, 1.0, 1000, 123, true);
+}
+TEST(kdopbvh, OptimalFindNearest_500)
+{
+ find_nearest_points_test(500, 1.0, 1000, 12, true);
+}
diff --git a/tests/gtests/blenlib/BLI_linklist_lockfree_test.cc b/tests/gtests/blenlib/BLI_linklist_lockfree_test.cc
index 309efaee00e..265637ef32c 100644
--- a/tests/gtests/blenlib/BLI_linklist_lockfree_test.cc
+++ b/tests/gtests/blenlib/BLI_linklist_lockfree_test.cc
@@ -9,122 +9,108 @@
#include "BLI_task.h"
#include "BLI_threads.h"
-
TEST(LockfreeLinkList, Init)
{
- LockfreeLinkList list;
- BLI_linklist_lockfree_init(&list);
- EXPECT_EQ(list.head, &list.dummy_node);
- EXPECT_EQ(list.tail, &list.dummy_node);
- BLI_linklist_lockfree_free(&list, NULL);
+ LockfreeLinkList list;
+ BLI_linklist_lockfree_init(&list);
+ EXPECT_EQ(list.head, &list.dummy_node);
+ EXPECT_EQ(list.tail, &list.dummy_node);
+ BLI_linklist_lockfree_free(&list, NULL);
}
TEST(LockfreeLinkList, InsertSingle)
{
- LockfreeLinkList list;
- LockfreeLinkNode node;
- BLI_linklist_lockfree_init(&list);
- BLI_linklist_lockfree_insert(&list, &node);
- EXPECT_EQ(list.head, &list.dummy_node);
- EXPECT_EQ(list.head->next, &node);
- EXPECT_EQ(list.tail, &node);
- BLI_linklist_lockfree_free(&list, NULL);
+ LockfreeLinkList list;
+ LockfreeLinkNode node;
+ BLI_linklist_lockfree_init(&list);
+ BLI_linklist_lockfree_insert(&list, &node);
+ EXPECT_EQ(list.head, &list.dummy_node);
+ EXPECT_EQ(list.head->next, &node);
+ EXPECT_EQ(list.tail, &node);
+ BLI_linklist_lockfree_free(&list, NULL);
}
TEST(LockfreeLinkList, InsertMultiple)
{
- static const int num_nodes = 128;
- LockfreeLinkList list;
- LockfreeLinkNode nodes[num_nodes];
- BLI_linklist_lockfree_init(&list);
- /* Insert all the nodes. */
- for (int i = 0; i < num_nodes; ++i) {
- BLI_linklist_lockfree_insert(&list, &nodes[i]);
- }
- /* Check head and tail. */
- EXPECT_EQ(list.head, &list.dummy_node);
- EXPECT_EQ(list.tail, &nodes[num_nodes - 1]);
- /* Check rest of the nodes. */
- int node_index = 0;
- for (LockfreeLinkNode *node = BLI_linklist_lockfree_begin(&list);
- node != NULL;
- node = node->next, ++node_index)
- {
- EXPECT_EQ(node, &nodes[node_index]);
- if (node_index != num_nodes - 1) {
- EXPECT_EQ(node->next, &nodes[node_index + 1]);
- }
- }
- /* Free list. */
- BLI_linklist_lockfree_free(&list, NULL);
+ static const int num_nodes = 128;
+ LockfreeLinkList list;
+ LockfreeLinkNode nodes[num_nodes];
+ BLI_linklist_lockfree_init(&list);
+ /* Insert all the nodes. */
+ for (int i = 0; i < num_nodes; ++i) {
+ BLI_linklist_lockfree_insert(&list, &nodes[i]);
+ }
+ /* Check head and tail. */
+ EXPECT_EQ(list.head, &list.dummy_node);
+ EXPECT_EQ(list.tail, &nodes[num_nodes - 1]);
+ /* Check rest of the nodes. */
+ int node_index = 0;
+ for (LockfreeLinkNode *node = BLI_linklist_lockfree_begin(&list); node != NULL;
+ node = node->next, ++node_index) {
+ EXPECT_EQ(node, &nodes[node_index]);
+ if (node_index != num_nodes - 1) {
+ EXPECT_EQ(node->next, &nodes[node_index + 1]);
+ }
+ }
+ /* Free list. */
+ BLI_linklist_lockfree_free(&list, NULL);
}
namespace {
struct IndexedNode {
- IndexedNode *next;
- int index;
+ IndexedNode *next;
+ int index;
};
-void concurrent_insert(TaskPool *__restrict pool,
- void *taskdata,
- int /*threadid*/)
+void concurrent_insert(TaskPool *__restrict pool, void *taskdata, int /*threadid*/)
{
- LockfreeLinkList *list = (LockfreeLinkList *)BLI_task_pool_userdata(pool);
- CHECK_NOTNULL(list);
- IndexedNode *node = (IndexedNode *)MEM_mallocN(sizeof(IndexedNode),
- "test node");
- node->index = POINTER_AS_INT(taskdata);
- BLI_linklist_lockfree_insert(list, (LockfreeLinkNode *)node);
+ LockfreeLinkList *list = (LockfreeLinkList *)BLI_task_pool_userdata(pool);
+ CHECK_NOTNULL(list);
+ IndexedNode *node = (IndexedNode *)MEM_mallocN(sizeof(IndexedNode), "test node");
+ node->index = POINTER_AS_INT(taskdata);
+ BLI_linklist_lockfree_insert(list, (LockfreeLinkNode *)node);
}
-
} // namespace
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);
- /* 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,
- TASK_PRIORITY_HIGH);
- }
- /* 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");
- /* First, we make sure that none of the nodes are added twice. */
- for (LockfreeLinkNode *node_v = BLI_linklist_lockfree_begin(&list);
- node_v != NULL;
- node_v = node_v->next)
- {
- IndexedNode *node = (IndexedNode *)node_v;
- EXPECT_GE(node->index, 0);
- EXPECT_LT(node->index, num_nodes);
- EXPECT_FALSE(visited_nodes[node->index]);
- visited_nodes[node->index] = true;
- }
- /* Then we make sure node was added. */
- for (int node_index = 0; node_index < num_nodes; ++node_index) {
- EXPECT_TRUE(visited_nodes[node_index]);
- }
- MEM_freeN(visited_nodes);
- /* Cleanup data. */
- BLI_linklist_lockfree_free(&list, MEM_freeN);
- BLI_task_pool_free(pool);
- BLI_task_scheduler_free(scheduler);
+ 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);
+ /* 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, TASK_PRIORITY_HIGH);
+ }
+ /* 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");
+ /* First, we make sure that none of the nodes are added twice. */
+ for (LockfreeLinkNode *node_v = BLI_linklist_lockfree_begin(&list); node_v != NULL;
+ node_v = node_v->next) {
+ IndexedNode *node = (IndexedNode *)node_v;
+ EXPECT_GE(node->index, 0);
+ EXPECT_LT(node->index, num_nodes);
+ EXPECT_FALSE(visited_nodes[node->index]);
+ visited_nodes[node->index] = true;
+ }
+ /* Then we make sure node was added. */
+ for (int node_index = 0; node_index < num_nodes; ++node_index) {
+ EXPECT_TRUE(visited_nodes[node_index]);
+ }
+ MEM_freeN(visited_nodes);
+ /* 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_listbase_test.cc b/tests/gtests/blenlib/BLI_listbase_test.cc
index 4dac2d05bd8..76d173c9604 100644
--- a/tests/gtests/blenlib/BLI_listbase_test.cc
+++ b/tests/gtests/blenlib/BLI_listbase_test.cc
@@ -12,246 +12,244 @@ extern "C" {
#include "BLI_ressource_strings.h"
}
-
/* local validation function */
static bool listbase_is_valid(const ListBase *listbase)
{
#define TESTFAIL(test) \
- if (!(test)) goto fail;
-
- if (listbase->first) {
- const Link *prev, *link;
- link = (Link *)listbase->first;
- TESTFAIL(link->prev == NULL);
-
- link = (Link *)listbase->last;
- TESTFAIL(link->next == NULL);
-
- prev = NULL;
- link = (Link *)listbase->first;
- do {
- TESTFAIL(link->prev == prev);
- } while ((prev = link), (link = link->next));
- TESTFAIL(prev == listbase->last);
-
- prev = NULL;
- link = (Link *)listbase->last;
- do {
- TESTFAIL(link->next == prev);
- } while ((prev = link), (link = link->prev));
- TESTFAIL(prev == listbase->first);
- }
- else {
- TESTFAIL(listbase->last == NULL);
- }
+ if (!(test)) \
+ goto fail;
+
+ if (listbase->first) {
+ const Link *prev, *link;
+ link = (Link *)listbase->first;
+ TESTFAIL(link->prev == NULL);
+
+ link = (Link *)listbase->last;
+ TESTFAIL(link->next == NULL);
+
+ prev = NULL;
+ link = (Link *)listbase->first;
+ do {
+ TESTFAIL(link->prev == prev);
+ } while ((prev = link), (link = link->next));
+ TESTFAIL(prev == listbase->last);
+
+ prev = NULL;
+ link = (Link *)listbase->last;
+ do {
+ TESTFAIL(link->next == prev);
+ } while ((prev = link), (link = link->prev));
+ TESTFAIL(prev == listbase->first);
+ }
+ else {
+ TESTFAIL(listbase->last == NULL);
+ }
#undef TESTFAIL
- return true;
+ return true;
fail:
- return false;
+ return false;
}
static int char_switch(char *string, char ch_src, char ch_dst)
{
- int tot = 0;
- while (*string != 0) {
- if (*string == ch_src) {
- *string = ch_dst;
- tot++;
- }
- string++;
- }
- return tot;
+ int tot = 0;
+ while (*string != 0) {
+ if (*string == ch_src) {
+ *string = ch_dst;
+ tot++;
+ }
+ string++;
+ }
+ return tot;
}
-
TEST(listbase, FindLinkOrIndex)
{
- ListBase lb;
- void *link1 = MEM_callocN(sizeof(Link), "link1");
- void *link2 = MEM_callocN(sizeof(Link), "link2");
-
- /* Empty list */
- BLI_listbase_clear(&lb);
- EXPECT_EQ(BLI_findlink(&lb, -1), (void*)NULL);
- EXPECT_EQ(BLI_findlink(&lb, 0), (void*)NULL);
- EXPECT_EQ(BLI_findlink(&lb, 1), (void*)NULL);
- EXPECT_EQ(BLI_rfindlink(&lb, -1), (void*)NULL);
- EXPECT_EQ(BLI_rfindlink(&lb, 0), (void*)NULL);
- EXPECT_EQ(BLI_rfindlink(&lb, 1), (void*)NULL);
- EXPECT_EQ(BLI_findindex(&lb, link1), -1);
-
- /* One link */
- BLI_addtail(&lb, link1);
- EXPECT_EQ(BLI_findlink(&lb, 0), link1);
- EXPECT_EQ(BLI_rfindlink(&lb, 0), link1);
- EXPECT_EQ(BLI_findindex(&lb, link1), 0);
-
- /* Two links */
- BLI_addtail(&lb, link2);
- EXPECT_EQ(BLI_findlink(&lb, 1), link2);
- EXPECT_EQ(BLI_rfindlink(&lb, 0), link2);
- EXPECT_EQ(BLI_findindex(&lb, link2), 1);
-
- BLI_freelistN(&lb);
+ ListBase lb;
+ void *link1 = MEM_callocN(sizeof(Link), "link1");
+ void *link2 = MEM_callocN(sizeof(Link), "link2");
+
+ /* Empty list */
+ BLI_listbase_clear(&lb);
+ EXPECT_EQ(BLI_findlink(&lb, -1), (void *)NULL);
+ EXPECT_EQ(BLI_findlink(&lb, 0), (void *)NULL);
+ EXPECT_EQ(BLI_findlink(&lb, 1), (void *)NULL);
+ EXPECT_EQ(BLI_rfindlink(&lb, -1), (void *)NULL);
+ EXPECT_EQ(BLI_rfindlink(&lb, 0), (void *)NULL);
+ EXPECT_EQ(BLI_rfindlink(&lb, 1), (void *)NULL);
+ EXPECT_EQ(BLI_findindex(&lb, link1), -1);
+
+ /* One link */
+ BLI_addtail(&lb, link1);
+ EXPECT_EQ(BLI_findlink(&lb, 0), link1);
+ EXPECT_EQ(BLI_rfindlink(&lb, 0), link1);
+ EXPECT_EQ(BLI_findindex(&lb, link1), 0);
+
+ /* Two links */
+ BLI_addtail(&lb, link2);
+ EXPECT_EQ(BLI_findlink(&lb, 1), link2);
+ EXPECT_EQ(BLI_rfindlink(&lb, 0), link2);
+ EXPECT_EQ(BLI_findindex(&lb, link2), 1);
+
+ BLI_freelistN(&lb);
}
-
/* -------------------------------------------------------------------- */
/* Sort utilities & test */
static int testsort_array_str_cmp(const void *a, const void *b)
{
- int i = strcmp(*(const char **)a, *(const char **)b);
- return (i > 0) ? 1 : (i < 0) ? -1 : 0;
+ int i = strcmp(*(const char **)a, *(const char **)b);
+ return (i > 0) ? 1 : (i < 0) ? -1 : 0;
}
static int testsort_listbase_str_cmp(const void *a, const void *b)
{
- const LinkData *link_a = (LinkData *)a;
- const LinkData *link_b = (LinkData *)b;
- int i = strcmp((const char *)link_a->data, (const char *)link_b->data);
- return (i > 0) ? 1 : (i < 0) ? -1 : 0;
+ const LinkData *link_a = (LinkData *)a;
+ const LinkData *link_b = (LinkData *)b;
+ int i = strcmp((const char *)link_a->data, (const char *)link_b->data);
+ return (i > 0) ? 1 : (i < 0) ? -1 : 0;
}
static int testsort_array_str_cmp_reverse(const void *a, const void *b)
{
- return -testsort_array_str_cmp(a, b);
+ return -testsort_array_str_cmp(a, b);
}
static int testsort_listbase_str_cmp_reverse(const void *a, const void *b)
{
- return -testsort_listbase_str_cmp(a, b);
+ return -testsort_listbase_str_cmp(a, b);
}
/* check array and listbase compare */
static bool testsort_listbase_array_str_cmp(ListBase *lb, char **arr, int arr_tot)
{
- LinkData *link_step;
- int i;
-
- link_step = (LinkData *)lb->first;
- for (i = 0; i < arr_tot; i++) {
- if (strcmp(arr[i], (char *)link_step->data) != 0) {
- return false;
- }
- link_step = link_step->next;
- }
- if (link_step) {
- return false;
- }
-
- return true;
+ LinkData *link_step;
+ int i;
+
+ link_step = (LinkData *)lb->first;
+ for (i = 0; i < arr_tot; i++) {
+ if (strcmp(arr[i], (char *)link_step->data) != 0) {
+ return false;
+ }
+ link_step = link_step->next;
+ }
+ if (link_step) {
+ return false;
+ }
+
+ return true;
}
/* assumes nodes are allocated in-order */
static bool testsort_listbase_sort_is_stable(ListBase *lb, bool forward)
{
- LinkData *link_step;
-
- link_step = (LinkData *)lb->first;
- while (link_step && link_step->next) {
- if (strcmp((const char *)link_step->data, (const char *)link_step->next->data) == 0) {
- if ((link_step < link_step->next) != forward) {
- return false;
- }
- }
- link_step = link_step->next;
- }
- return true;
+ LinkData *link_step;
+
+ link_step = (LinkData *)lb->first;
+ while (link_step && link_step->next) {
+ if (strcmp((const char *)link_step->data, (const char *)link_step->next->data) == 0) {
+ if ((link_step < link_step->next) != forward) {
+ return false;
+ }
+ }
+ link_step = link_step->next;
+ }
+ return true;
}
TEST(listbase, Sort)
{
- const int words_len = sizeof(words10k) - 1;
- char *words = BLI_strdupn(words10k, words_len);
- int words_tot;
- char **words_arr; /* qsort for comparison */
- int i;
- char *w_step;
- ListBase words_lb;
- LinkData *words_linkdata_arr;
-
- /* delimit words */
- words_tot = 1 + char_switch(words, ' ', '\0');
-
- words_arr = (char **)MEM_mallocN(sizeof(*words_arr) * words_tot, __func__);
-
- words_linkdata_arr = (LinkData *)MEM_mallocN(sizeof(*words_linkdata_arr) * words_tot, __func__);
-
- /* create array */
- w_step = words;
- for (i = 0; i < words_tot; i++) {
- words_arr[i] = w_step;
- w_step += strlen(w_step) + 1;
- }
-
- /* sort empty list */
- {
- BLI_listbase_clear(&words_lb);
- BLI_listbase_sort(&words_lb, testsort_listbase_str_cmp);
- EXPECT_TRUE(listbase_is_valid(&words_lb));
- }
-
- /* sort single single */
- {
- LinkData link;
- link.data = words;
- BLI_addtail(&words_lb, &link);
- BLI_listbase_sort(&words_lb, testsort_listbase_str_cmp);
- EXPECT_TRUE(listbase_is_valid(&words_lb));
- BLI_listbase_clear(&words_lb);
- }
-
- /* create listbase */
- BLI_listbase_clear(&words_lb);
- w_step = words;
- for (i = 0; i < words_tot; i++) {
- LinkData *link = &words_linkdata_arr[i];
- link->data = w_step;
- BLI_addtail(&words_lb, link);
- w_step += strlen(w_step) + 1;
- }
- EXPECT_TRUE(listbase_is_valid(&words_lb));
-
- /* sort (forward) */
- {
- qsort(words_arr, words_tot, sizeof(*words_arr), testsort_array_str_cmp);
-
- BLI_listbase_sort(&words_lb, testsort_listbase_str_cmp);
- EXPECT_TRUE(listbase_is_valid(&words_lb));
- EXPECT_TRUE(testsort_listbase_array_str_cmp(&words_lb, words_arr, words_tot));
- EXPECT_TRUE(testsort_listbase_sort_is_stable(&words_lb, true));
- }
-
- /* sort (reverse) */
- {
- qsort(words_arr, words_tot, sizeof(*words_arr), testsort_array_str_cmp_reverse);
-
- BLI_listbase_sort(&words_lb, testsort_listbase_str_cmp_reverse);
- EXPECT_TRUE(listbase_is_valid(&words_lb));
- EXPECT_TRUE(testsort_listbase_array_str_cmp(&words_lb, words_arr, words_tot));
- EXPECT_TRUE(testsort_listbase_sort_is_stable(&words_lb, true));
- }
-
- /* sort (forward but after reversing, test stability in alternate direction) */
- {
- BLI_array_reverse(words_arr, words_tot);
- BLI_listbase_reverse(&words_lb);
-
- EXPECT_TRUE(listbase_is_valid(&words_lb));
- EXPECT_TRUE(testsort_listbase_array_str_cmp(&words_lb, words_arr, words_tot));
- EXPECT_TRUE(testsort_listbase_sort_is_stable(&words_lb, false));
-
- /* and again */
- BLI_array_reverse(words_arr, words_tot);
- BLI_listbase_sort(&words_lb, testsort_listbase_str_cmp_reverse);
- EXPECT_TRUE(testsort_listbase_array_str_cmp(&words_lb, words_arr, words_tot));
- EXPECT_TRUE(testsort_listbase_sort_is_stable(&words_lb, false));
- }
-
- MEM_freeN(words);
- MEM_freeN(words_arr);
- MEM_freeN(words_linkdata_arr);
+ const int words_len = sizeof(words10k) - 1;
+ char *words = BLI_strdupn(words10k, words_len);
+ int words_tot;
+ char **words_arr; /* qsort for comparison */
+ int i;
+ char *w_step;
+ ListBase words_lb;
+ LinkData *words_linkdata_arr;
+
+ /* delimit words */
+ words_tot = 1 + char_switch(words, ' ', '\0');
+
+ words_arr = (char **)MEM_mallocN(sizeof(*words_arr) * words_tot, __func__);
+
+ words_linkdata_arr = (LinkData *)MEM_mallocN(sizeof(*words_linkdata_arr) * words_tot, __func__);
+
+ /* create array */
+ w_step = words;
+ for (i = 0; i < words_tot; i++) {
+ words_arr[i] = w_step;
+ w_step += strlen(w_step) + 1;
+ }
+
+ /* sort empty list */
+ {
+ BLI_listbase_clear(&words_lb);
+ BLI_listbase_sort(&words_lb, testsort_listbase_str_cmp);
+ EXPECT_TRUE(listbase_is_valid(&words_lb));
+ }
+
+ /* sort single single */
+ {
+ LinkData link;
+ link.data = words;
+ BLI_addtail(&words_lb, &link);
+ BLI_listbase_sort(&words_lb, testsort_listbase_str_cmp);
+ EXPECT_TRUE(listbase_is_valid(&words_lb));
+ BLI_listbase_clear(&words_lb);
+ }
+
+ /* create listbase */
+ BLI_listbase_clear(&words_lb);
+ w_step = words;
+ for (i = 0; i < words_tot; i++) {
+ LinkData *link = &words_linkdata_arr[i];
+ link->data = w_step;
+ BLI_addtail(&words_lb, link);
+ w_step += strlen(w_step) + 1;
+ }
+ EXPECT_TRUE(listbase_is_valid(&words_lb));
+
+ /* sort (forward) */
+ {
+ qsort(words_arr, words_tot, sizeof(*words_arr), testsort_array_str_cmp);
+
+ BLI_listbase_sort(&words_lb, testsort_listbase_str_cmp);
+ EXPECT_TRUE(listbase_is_valid(&words_lb));
+ EXPECT_TRUE(testsort_listbase_array_str_cmp(&words_lb, words_arr, words_tot));
+ EXPECT_TRUE(testsort_listbase_sort_is_stable(&words_lb, true));
+ }
+
+ /* sort (reverse) */
+ {
+ qsort(words_arr, words_tot, sizeof(*words_arr), testsort_array_str_cmp_reverse);
+
+ BLI_listbase_sort(&words_lb, testsort_listbase_str_cmp_reverse);
+ EXPECT_TRUE(listbase_is_valid(&words_lb));
+ EXPECT_TRUE(testsort_listbase_array_str_cmp(&words_lb, words_arr, words_tot));
+ EXPECT_TRUE(testsort_listbase_sort_is_stable(&words_lb, true));
+ }
+
+ /* sort (forward but after reversing, test stability in alternate direction) */
+ {
+ BLI_array_reverse(words_arr, words_tot);
+ BLI_listbase_reverse(&words_lb);
+
+ EXPECT_TRUE(listbase_is_valid(&words_lb));
+ EXPECT_TRUE(testsort_listbase_array_str_cmp(&words_lb, words_arr, words_tot));
+ EXPECT_TRUE(testsort_listbase_sort_is_stable(&words_lb, false));
+
+ /* and again */
+ BLI_array_reverse(words_arr, words_tot);
+ BLI_listbase_sort(&words_lb, testsort_listbase_str_cmp_reverse);
+ EXPECT_TRUE(testsort_listbase_array_str_cmp(&words_lb, words_arr, words_tot));
+ EXPECT_TRUE(testsort_listbase_sort_is_stable(&words_lb, false));
+ }
+
+ MEM_freeN(words);
+ MEM_freeN(words_arr);
+ MEM_freeN(words_linkdata_arr);
}
diff --git a/tests/gtests/blenlib/BLI_math_base_test.cc b/tests/gtests/blenlib/BLI_math_base_test.cc
index d8c01459179..89903e1759c 100644
--- a/tests/gtests/blenlib/BLI_math_base_test.cc
+++ b/tests/gtests/blenlib/BLI_math_base_test.cc
@@ -9,79 +9,75 @@
/* Put this here, since we cannot use BLI_assert() in inline math files it seems... */
TEST(math_base, CompareFFRelativeValid)
{
- EXPECT_TRUE(sizeof(float) == sizeof(int));
+ EXPECT_TRUE(sizeof(float) == sizeof(int));
}
TEST(math_base, CompareFFRelativeNormal)
{
- float f1 = 1.99999988f; /* *(float *)&(*(int *)&f2 - 1) */
- float f2 = 2.00000000f;
- float f3 = 2.00000048f; /* *(float *)&(*(int *)&f2 + 2) */
- float f4 = 2.10000000f; /* *(float *)&(*(int *)&f2 + 419430) */
+ float f1 = 1.99999988f; /* *(float *)&(*(int *)&f2 - 1) */
+ float f2 = 2.00000000f;
+ float f3 = 2.00000048f; /* *(float *)&(*(int *)&f2 + 2) */
+ float f4 = 2.10000000f; /* *(float *)&(*(int *)&f2 + 419430) */
- const float max_diff = FLT_EPSILON * 0.1f;
+ const float max_diff = FLT_EPSILON * 0.1f;
- EXPECT_TRUE(compare_ff_relative(f1, f2, max_diff, 1));
- EXPECT_TRUE(compare_ff_relative(f2, f1, max_diff, 1));
+ EXPECT_TRUE(compare_ff_relative(f1, f2, max_diff, 1));
+ EXPECT_TRUE(compare_ff_relative(f2, f1, max_diff, 1));
- EXPECT_TRUE(compare_ff_relative(f3, f2, max_diff, 2));
- EXPECT_TRUE(compare_ff_relative(f2, f3, max_diff, 2));
+ EXPECT_TRUE(compare_ff_relative(f3, f2, max_diff, 2));
+ EXPECT_TRUE(compare_ff_relative(f2, f3, max_diff, 2));
- EXPECT_FALSE(compare_ff_relative(f3, f2, max_diff, 1));
- EXPECT_FALSE(compare_ff_relative(f2, f3, max_diff, 1));
+ EXPECT_FALSE(compare_ff_relative(f3, f2, max_diff, 1));
+ EXPECT_FALSE(compare_ff_relative(f2, f3, max_diff, 1));
+ EXPECT_FALSE(compare_ff_relative(f3, f2, -1.0f, 1));
+ EXPECT_FALSE(compare_ff_relative(f2, f3, -1.0f, 1));
- EXPECT_FALSE(compare_ff_relative(f3, f2, -1.0f, 1));
- EXPECT_FALSE(compare_ff_relative(f2, f3, -1.0f, 1));
+ EXPECT_TRUE(compare_ff_relative(f3, f2, -1.0f, 2));
+ EXPECT_TRUE(compare_ff_relative(f2, f3, -1.0f, 2));
- EXPECT_TRUE(compare_ff_relative(f3, f2, -1.0f, 2));
- EXPECT_TRUE(compare_ff_relative(f2, f3, -1.0f, 2));
+ EXPECT_FALSE(compare_ff_relative(f4, f2, max_diff, 64));
+ EXPECT_FALSE(compare_ff_relative(f2, f4, max_diff, 64));
-
- EXPECT_FALSE(compare_ff_relative(f4, f2, max_diff, 64));
- EXPECT_FALSE(compare_ff_relative(f2, f4, max_diff, 64));
-
- EXPECT_TRUE(compare_ff_relative(f1, f3, max_diff, 64));
- EXPECT_TRUE(compare_ff_relative(f3, f1, max_diff, 64));
+ EXPECT_TRUE(compare_ff_relative(f1, f3, max_diff, 64));
+ EXPECT_TRUE(compare_ff_relative(f3, f1, max_diff, 64));
}
TEST(math_base, CompareFFRelativeZero)
{
- float f0 = 0.0f;
- float f1 = 4.2038954e-045f; /* *(float *)&(*(int *)&f0 + 3) */
-
- float fn0 = -0.0f;
- float fn1 = -2.8025969e-045f; /* *(float *)&(*(int *)&fn0 - 2) */
-
- const float max_diff = FLT_EPSILON * 0.1f;
+ float f0 = 0.0f;
+ float f1 = 4.2038954e-045f; /* *(float *)&(*(int *)&f0 + 3) */
- EXPECT_TRUE(compare_ff_relative(f0, f1, -1.0f, 3));
- EXPECT_TRUE(compare_ff_relative(f1, f0, -1.0f, 3));
+ float fn0 = -0.0f;
+ float fn1 = -2.8025969e-045f; /* *(float *)&(*(int *)&fn0 - 2) */
- EXPECT_FALSE(compare_ff_relative(f0, f1, -1.0f, 1));
- EXPECT_FALSE(compare_ff_relative(f1, f0, -1.0f, 1));
+ const float max_diff = FLT_EPSILON * 0.1f;
- EXPECT_TRUE(compare_ff_relative(fn0, fn1, -1.0f, 8));
- EXPECT_TRUE(compare_ff_relative(fn1, fn0, -1.0f, 8));
+ EXPECT_TRUE(compare_ff_relative(f0, f1, -1.0f, 3));
+ EXPECT_TRUE(compare_ff_relative(f1, f0, -1.0f, 3));
+ EXPECT_FALSE(compare_ff_relative(f0, f1, -1.0f, 1));
+ EXPECT_FALSE(compare_ff_relative(f1, f0, -1.0f, 1));
- EXPECT_TRUE(compare_ff_relative(f0, f1, max_diff, 1));
- EXPECT_TRUE(compare_ff_relative(f1, f0, max_diff, 1));
+ EXPECT_TRUE(compare_ff_relative(fn0, fn1, -1.0f, 8));
+ EXPECT_TRUE(compare_ff_relative(fn1, fn0, -1.0f, 8));
- EXPECT_TRUE(compare_ff_relative(fn0, f0, max_diff, 1));
- EXPECT_TRUE(compare_ff_relative(f0, fn0, max_diff, 1));
+ EXPECT_TRUE(compare_ff_relative(f0, f1, max_diff, 1));
+ EXPECT_TRUE(compare_ff_relative(f1, f0, max_diff, 1));
- EXPECT_TRUE(compare_ff_relative(f0, fn1, max_diff, 1));
- EXPECT_TRUE(compare_ff_relative(fn1, f0, max_diff, 1));
+ EXPECT_TRUE(compare_ff_relative(fn0, f0, max_diff, 1));
+ EXPECT_TRUE(compare_ff_relative(f0, fn0, max_diff, 1));
+ EXPECT_TRUE(compare_ff_relative(f0, fn1, max_diff, 1));
+ EXPECT_TRUE(compare_ff_relative(fn1, f0, max_diff, 1));
- /* Note: in theory, this should return false, since 0.0f and -0.0f have 0x80000000 diff,
- * but overflow in subtraction seems to break something here
- * (abs(*(int *)&fn0 - *(int *)&f0) == 0x80000000 == fn0), probably because int32 cannot hold this abs value.
+ /* Note: in theory, this should return false, since 0.0f and -0.0f have 0x80000000 diff,
+ * but overflow in subtraction seems to break something here
+ * (abs(*(int *)&fn0 - *(int *)&f0) == 0x80000000 == fn0), probably because int32 cannot hold this abs value.
* this is yet another illustration of why one shall never use (near-)zero floats in pure-ULP comparison. */
-// EXPECT_FALSE(compare_ff_relative(fn0, f0, -1.0f, 1024));
-// EXPECT_FALSE(compare_ff_relative(f0, fn0, -1.0f, 1024));
+ // EXPECT_FALSE(compare_ff_relative(fn0, f0, -1.0f, 1024));
+ // EXPECT_FALSE(compare_ff_relative(f0, fn0, -1.0f, 1024));
- EXPECT_FALSE(compare_ff_relative(fn0, f1, -1.0f, 1024));
- EXPECT_FALSE(compare_ff_relative(f1, fn0, -1.0f, 1024));
+ EXPECT_FALSE(compare_ff_relative(fn0, f1, -1.0f, 1024));
+ EXPECT_FALSE(compare_ff_relative(f1, fn0, -1.0f, 1024));
}
diff --git a/tests/gtests/blenlib/BLI_math_color_test.cc b/tests/gtests/blenlib/BLI_math_color_test.cc
index 8989e6740a5..7df47e74eb0 100644
--- a/tests/gtests/blenlib/BLI_math_color_test.cc
+++ b/tests/gtests/blenlib/BLI_math_color_test.cc
@@ -6,85 +6,71 @@
TEST(math_color, RGBToHSVRoundtrip)
{
- float orig_rgb[3] = {0.1f, 0.2f, 0.3f};
- float hsv[3], rgb[3];
- rgb_to_hsv_v(orig_rgb, hsv);
- hsv_to_rgb_v(hsv, rgb);
- EXPECT_V3_NEAR(orig_rgb, rgb, 1e-5);
+ float orig_rgb[3] = {0.1f, 0.2f, 0.3f};
+ float hsv[3], rgb[3];
+ rgb_to_hsv_v(orig_rgb, hsv);
+ hsv_to_rgb_v(hsv, rgb);
+ EXPECT_V3_NEAR(orig_rgb, rgb, 1e-5);
}
TEST(math_color, RGBToHSLRoundtrip)
{
- float orig_rgb[3] = {0.1f, 0.2f, 0.3f};
- float hsl[3], rgb[3];
- rgb_to_hsl_v(orig_rgb, hsl);
- hsl_to_rgb_v(hsl, rgb);
- EXPECT_V3_NEAR(orig_rgb, rgb, 1e-5);
+ float orig_rgb[3] = {0.1f, 0.2f, 0.3f};
+ float hsl[3], rgb[3];
+ rgb_to_hsl_v(orig_rgb, hsl);
+ hsl_to_rgb_v(hsl, rgb);
+ EXPECT_V3_NEAR(orig_rgb, rgb, 1e-5);
}
TEST(math_color, RGBToYUVRoundtrip)
{
- float orig_rgb[3] = {0.1f, 0.2f, 0.3f};
- float yuv[3], rgb[3];
- rgb_to_yuv(orig_rgb[0], orig_rgb[1], orig_rgb[2],
- &yuv[0], &yuv[1], &yuv[2], BLI_YUV_ITU_BT709);
- yuv_to_rgb(yuv[0], yuv[1], yuv[2],
- &rgb[0], &rgb[1], &rgb[2], BLI_YUV_ITU_BT709);
- EXPECT_V3_NEAR(orig_rgb, rgb, 1e-4);
+ float orig_rgb[3] = {0.1f, 0.2f, 0.3f};
+ float yuv[3], rgb[3];
+ rgb_to_yuv(orig_rgb[0], orig_rgb[1], orig_rgb[2], &yuv[0], &yuv[1], &yuv[2], BLI_YUV_ITU_BT709);
+ yuv_to_rgb(yuv[0], yuv[1], yuv[2], &rgb[0], &rgb[1], &rgb[2], BLI_YUV_ITU_BT709);
+ EXPECT_V3_NEAR(orig_rgb, rgb, 1e-4);
}
TEST(math_color, RGBToYCCRoundtrip)
{
- float orig_rgb[3] = {0.1f, 0.2f, 0.3f};
- float ycc[3], rgb[3];
+ float orig_rgb[3] = {0.1f, 0.2f, 0.3f};
+ float ycc[3], rgb[3];
- rgb_to_ycc(orig_rgb[0], orig_rgb[1], orig_rgb[2],
- &ycc[0], &ycc[1], &ycc[2],
- BLI_YCC_ITU_BT601);
- ycc_to_rgb(ycc[0], ycc[1], ycc[2],
- &rgb[0], &rgb[1], &rgb[2],
- BLI_YCC_ITU_BT601);
- EXPECT_V3_NEAR(orig_rgb, rgb, 1e-3);
+ rgb_to_ycc(orig_rgb[0], orig_rgb[1], orig_rgb[2], &ycc[0], &ycc[1], &ycc[2], BLI_YCC_ITU_BT601);
+ ycc_to_rgb(ycc[0], ycc[1], ycc[2], &rgb[0], &rgb[1], &rgb[2], BLI_YCC_ITU_BT601);
+ EXPECT_V3_NEAR(orig_rgb, rgb, 1e-3);
- rgb_to_ycc(orig_rgb[0], orig_rgb[1], orig_rgb[2],
- &ycc[0], &ycc[1], &ycc[2],
- BLI_YCC_ITU_BT709);
- ycc_to_rgb(ycc[0], ycc[1], ycc[2],
- &rgb[0], &rgb[1], &rgb[2],
- BLI_YCC_ITU_BT709);
- EXPECT_V3_NEAR(orig_rgb, rgb, 1e-3);
+ rgb_to_ycc(orig_rgb[0], orig_rgb[1], orig_rgb[2], &ycc[0], &ycc[1], &ycc[2], BLI_YCC_ITU_BT709);
+ ycc_to_rgb(ycc[0], ycc[1], ycc[2], &rgb[0], &rgb[1], &rgb[2], BLI_YCC_ITU_BT709);
+ EXPECT_V3_NEAR(orig_rgb, rgb, 1e-3);
- rgb_to_ycc(orig_rgb[0], orig_rgb[1], orig_rgb[2],
- &ycc[0], &ycc[1], &ycc[2],
- BLI_YCC_JFIF_0_255);
- ycc_to_rgb(ycc[0], ycc[1], ycc[2],
- &rgb[0], &rgb[1], &rgb[2],
- BLI_YCC_JFIF_0_255);
- EXPECT_V3_NEAR(orig_rgb, rgb, 1e-3);
+ rgb_to_ycc(orig_rgb[0], orig_rgb[1], orig_rgb[2], &ycc[0], &ycc[1], &ycc[2], BLI_YCC_JFIF_0_255);
+ ycc_to_rgb(ycc[0], ycc[1], ycc[2], &rgb[0], &rgb[1], &rgb[2], BLI_YCC_JFIF_0_255);
+ EXPECT_V3_NEAR(orig_rgb, rgb, 1e-3);
}
TEST(math_color, LinearRGBTosRGBNearZero)
{
- float linear_color = 0.002f;
- float srgb_color = linearrgb_to_srgb(linear_color);
- EXPECT_NEAR(0.02584f, srgb_color, 1e-5);
+ float linear_color = 0.002f;
+ float srgb_color = linearrgb_to_srgb(linear_color);
+ EXPECT_NEAR(0.02584f, srgb_color, 1e-5);
}
TEST(math_color, LinearRGBTosRGB)
{
- float linear_color = 0.75f;
- float srgb_color = linearrgb_to_srgb(linear_color);
- EXPECT_NEAR(0.880824f, srgb_color, 1e-5);
+ float linear_color = 0.75f;
+ float srgb_color = linearrgb_to_srgb(linear_color);
+ EXPECT_NEAR(0.880824f, srgb_color, 1e-5);
}
TEST(math_color, LinearRGBTosRGBRoundtrip)
{
- const int N = 50;
- int i;
- for (i = 0; i < N; ++i) {
- float orig_linear_color = (float) i / N;
- float srgb_color = linearrgb_to_srgb(orig_linear_color);
- float linear_color = srgb_to_linearrgb(srgb_color);
- EXPECT_NEAR(orig_linear_color, linear_color, 1e-5);
- }
+ const int N = 50;
+ int i;
+ for (i = 0; i < N; ++i) {
+ float orig_linear_color = (float)i / N;
+ float srgb_color = linearrgb_to_srgb(orig_linear_color);
+ float linear_color = srgb_to_linearrgb(srgb_color);
+ EXPECT_NEAR(orig_linear_color, linear_color, 1e-5);
+ }
}
diff --git a/tests/gtests/blenlib/BLI_math_geom_test.cc b/tests/gtests/blenlib/BLI_math_geom_test.cc
index 92e2532392e..ea86e5aa97e 100644
--- a/tests/gtests/blenlib/BLI_math_geom_test.cc
+++ b/tests/gtests/blenlib/BLI_math_geom_test.cc
@@ -8,18 +8,14 @@
TEST(math_geom, DistToLine2DSimple)
{
- float p[2] = {5.0f, 1.0f},
- a[2] = {0.0f, 0.0f},
- b[2] = {2.0f, 0.0f};
- float distance = dist_to_line_v2(p, a, b);
- EXPECT_NEAR(1.0f, distance, 1e-6);
+ float p[2] = {5.0f, 1.0f}, a[2] = {0.0f, 0.0f}, b[2] = {2.0f, 0.0f};
+ float distance = dist_to_line_v2(p, a, b);
+ EXPECT_NEAR(1.0f, distance, 1e-6);
}
TEST(math_geom, DistToLineSegment2DSimple)
{
- float p[2] = {3.0f, 1.0f},
- a[2] = {0.0f, 0.0f},
- b[2] = {2.0f, 0.0f};
- float distance = dist_to_line_segment_v2(p, a, b);
- EXPECT_NEAR(sqrtf(2.0f), distance, 1e-6);
+ float p[2] = {3.0f, 1.0f}, a[2] = {0.0f, 0.0f}, b[2] = {2.0f, 0.0f};
+ float distance = dist_to_line_segment_v2(p, a, b);
+ EXPECT_NEAR(sqrtf(2.0f), distance, 1e-6);
}
diff --git a/tests/gtests/blenlib/BLI_memiter_test.cc b/tests/gtests/blenlib/BLI_memiter_test.cc
index 601eadea267..c1c07dc7540 100644
--- a/tests/gtests/blenlib/BLI_memiter_test.cc
+++ b/tests/gtests/blenlib/BLI_memiter_test.cc
@@ -13,51 +13,51 @@ extern "C" {
TEST(memiter, Nop)
{
- BLI_memiter *mi = BLI_memiter_create(64);
- BLI_memiter_destroy(mi);
+ BLI_memiter *mi = BLI_memiter_create(64);
+ BLI_memiter_destroy(mi);
}
void memiter_empty_test(int num_elems, const int chunk_size)
{
- BLI_memiter *mi = BLI_memiter_create(chunk_size);
- void *data;
- for (int index = 0; index < num_elems; index++) {
- data = BLI_memiter_alloc(mi, 0);
- }
- int index = 0, total_size = 0;
- BLI_memiter_handle it;
- BLI_memiter_iter_init(mi, &it);
- uint elem_size;
- while ((data = BLI_memiter_iter_step_size(&it, &elem_size))) {
- index += 1;
- total_size += elem_size;
- }
- EXPECT_EQ(0, total_size);
- EXPECT_EQ(num_elems, index);
-
- BLI_memiter_destroy(mi);
+ BLI_memiter *mi = BLI_memiter_create(chunk_size);
+ void *data;
+ for (int index = 0; index < num_elems; index++) {
+ data = BLI_memiter_alloc(mi, 0);
+ }
+ int index = 0, total_size = 0;
+ BLI_memiter_handle it;
+ BLI_memiter_iter_init(mi, &it);
+ uint elem_size;
+ while ((data = BLI_memiter_iter_step_size(&it, &elem_size))) {
+ index += 1;
+ total_size += elem_size;
+ }
+ EXPECT_EQ(0, total_size);
+ EXPECT_EQ(num_elems, index);
+
+ BLI_memiter_destroy(mi);
}
#define MEMITER_NUMBER_TEST_FN(fn, number_type) \
-void fn(int num_elems, const int chunk_size) \
-{ \
- BLI_memiter *mi = BLI_memiter_create(chunk_size); \
- number_type *data; \
- for (int index = 0; index < num_elems; index++) { \
- data = (number_type *)BLI_memiter_alloc(mi, sizeof(number_type)); \
- *data = index; \
- } \
- BLI_memiter_handle it; \
- BLI_memiter_iter_init(mi, &it); \
- uint elem_size; \
- int index = 0; \
- while ((data = (number_type *)BLI_memiter_iter_step_size(&it, &elem_size))) { \
- EXPECT_EQ(sizeof(number_type), elem_size); \
- EXPECT_EQ(index, *data); \
- index += 1; \
- } \
- BLI_memiter_destroy(mi); \
-}
+ void fn(int num_elems, const int chunk_size) \
+ { \
+ BLI_memiter *mi = BLI_memiter_create(chunk_size); \
+ number_type *data; \
+ for (int index = 0; index < num_elems; index++) { \
+ data = (number_type *)BLI_memiter_alloc(mi, sizeof(number_type)); \
+ *data = index; \
+ } \
+ BLI_memiter_handle it; \
+ BLI_memiter_iter_init(mi, &it); \
+ uint elem_size; \
+ int index = 0; \
+ while ((data = (number_type *)BLI_memiter_iter_step_size(&it, &elem_size))) { \
+ EXPECT_EQ(sizeof(number_type), elem_size); \
+ EXPECT_EQ(index, *data); \
+ index += 1; \
+ } \
+ BLI_memiter_destroy(mi); \
+ }
/* generate number functions */
MEMITER_NUMBER_TEST_FN(memiter_char_test, char)
@@ -67,81 +67,98 @@ MEMITER_NUMBER_TEST_FN(memiter_long_test, int64_t)
void memiter_string_test(const char *strings[], const int chunk_size)
{
- BLI_memiter *mi = BLI_memiter_create(chunk_size);
- char *data;
- int index = 0;
- int total_size_expect = 0;
- while (strings[index]) {
- const int size = strlen(strings[index]) + 1;
- BLI_memiter_alloc_from(mi, size, strings[index]);
- total_size_expect += size;
- index += 1;
- }
- const int strings_len = index;
- int total_size = 0;
- BLI_memiter_handle it;
- BLI_memiter_iter_init(mi, &it);
- uint elem_size;
- index = 0;
- while ((data = (char *)BLI_memiter_iter_step_size(&it, &elem_size))) {
- EXPECT_EQ(strlen(strings[index]) + 1, elem_size);
- EXPECT_STREQ(strings[index], data);
- total_size += elem_size;
- index += 1;
- }
- EXPECT_EQ(total_size_expect, total_size);
- EXPECT_EQ(strings_len, index);
-
- BLI_memiter_destroy(mi);
+ BLI_memiter *mi = BLI_memiter_create(chunk_size);
+ char *data;
+ int index = 0;
+ int total_size_expect = 0;
+ while (strings[index]) {
+ const int size = strlen(strings[index]) + 1;
+ BLI_memiter_alloc_from(mi, size, strings[index]);
+ total_size_expect += size;
+ index += 1;
+ }
+ const int strings_len = index;
+ int total_size = 0;
+ BLI_memiter_handle it;
+ BLI_memiter_iter_init(mi, &it);
+ uint elem_size;
+ index = 0;
+ while ((data = (char *)BLI_memiter_iter_step_size(&it, &elem_size))) {
+ EXPECT_EQ(strlen(strings[index]) + 1, elem_size);
+ EXPECT_STREQ(strings[index], data);
+ total_size += elem_size;
+ index += 1;
+ }
+ EXPECT_EQ(total_size_expect, total_size);
+ EXPECT_EQ(strings_len, index);
+
+ BLI_memiter_destroy(mi);
}
void memiter_words10k_test(const char split_char, const int chunk_size)
{
- const int words_len = sizeof(words10k) - 1;
- char *words = BLI_strdupn(words10k, words_len);
- BLI_str_replace_char(words, split_char, '\0');
-
- BLI_memiter *mi = BLI_memiter_create(chunk_size);
-
- char *data;
- int index;
- char *c_end, *c;
- c_end = words + words_len;
- c = words;
- index = 0;
- while (c < c_end) {
- int elem_size = strlen(c) + 1;
- data = (char *)BLI_memiter_alloc(mi, elem_size);
- memcpy(data, c, elem_size);
- c += elem_size;
- index += 1;
- }
- const int len_expect = index;
- c = words;
- uint size;
- BLI_memiter_handle it;
- BLI_memiter_iter_init(mi, &it);
- index = 0;
- while ((data = (char *)BLI_memiter_iter_step_size(&it, &size))) {
- int size_expect = strlen(c) + 1;
- EXPECT_EQ(size_expect, size);
- EXPECT_STREQ(c, data);
- c += size;
- index += 1;
- }
- EXPECT_EQ(len_expect, index);
- BLI_memiter_destroy(mi);
- MEM_freeN(words);
-}
+ const int words_len = sizeof(words10k) - 1;
+ char *words = BLI_strdupn(words10k, words_len);
+ BLI_str_replace_char(words, split_char, '\0');
+ BLI_memiter *mi = BLI_memiter_create(chunk_size);
+
+ char *data;
+ int index;
+ char *c_end, *c;
+ c_end = words + words_len;
+ c = words;
+ index = 0;
+ while (c < c_end) {
+ int elem_size = strlen(c) + 1;
+ data = (char *)BLI_memiter_alloc(mi, elem_size);
+ memcpy(data, c, elem_size);
+ c += elem_size;
+ index += 1;
+ }
+ const int len_expect = index;
+ c = words;
+ uint size;
+ BLI_memiter_handle it;
+ BLI_memiter_iter_init(mi, &it);
+ index = 0;
+ while ((data = (char *)BLI_memiter_iter_step_size(&it, &size))) {
+ int size_expect = strlen(c) + 1;
+ EXPECT_EQ(size_expect, size);
+ EXPECT_STREQ(c, data);
+ c += size;
+ index += 1;
+ }
+ EXPECT_EQ(len_expect, index);
+ BLI_memiter_destroy(mi);
+ MEM_freeN(words);
+}
#define TEST_EMPTY_AT_CHUNK_SIZE(chunk_size) \
-TEST(memiter, Empty0_##chunk_size) { memiter_empty_test(0, chunk_size); } \
-TEST(memiter, Empty1_##chunk_size) { memiter_empty_test(1, chunk_size); } \
-TEST(memiter, Empty2_##chunk_size) { memiter_empty_test(2, chunk_size); } \
-TEST(memiter, Empty3_##chunk_size) { memiter_empty_test(3, chunk_size); } \
-TEST(memiter, Empty13_##chunk_size) { memiter_empty_test(13, chunk_size); } \
-TEST(memiter, Empty256_##chunk_size) { memiter_empty_test(256, chunk_size); } \
+ TEST(memiter, Empty0_##chunk_size) \
+ { \
+ memiter_empty_test(0, chunk_size); \
+ } \
+ TEST(memiter, Empty1_##chunk_size) \
+ { \
+ memiter_empty_test(1, chunk_size); \
+ } \
+ TEST(memiter, Empty2_##chunk_size) \
+ { \
+ memiter_empty_test(2, chunk_size); \
+ } \
+ TEST(memiter, Empty3_##chunk_size) \
+ { \
+ memiter_empty_test(3, chunk_size); \
+ } \
+ TEST(memiter, Empty13_##chunk_size) \
+ { \
+ memiter_empty_test(13, chunk_size); \
+ } \
+ TEST(memiter, Empty256_##chunk_size) \
+ { \
+ memiter_empty_test(256, chunk_size); \
+ }
TEST_EMPTY_AT_CHUNK_SIZE(1)
TEST_EMPTY_AT_CHUNK_SIZE(2)
@@ -150,25 +167,73 @@ TEST_EMPTY_AT_CHUNK_SIZE(13)
TEST_EMPTY_AT_CHUNK_SIZE(256)
#define TEST_NUMBER_AT_CHUNK_SIZE(chunk_size) \
-TEST(memiter, Char1_##chunk_size) { memiter_char_test(1, chunk_size); } \
-TEST(memiter, Short1_##chunk_size) { memiter_short_test(1, chunk_size); } \
-TEST(memiter, Int1_##chunk_size) { memiter_int_test(1, chunk_size); } \
-TEST(memiter, Long1_##chunk_size) { memiter_long_test(1, chunk_size); } \
+ TEST(memiter, Char1_##chunk_size) \
+ { \
+ memiter_char_test(1, chunk_size); \
+ } \
+ TEST(memiter, Short1_##chunk_size) \
+ { \
+ memiter_short_test(1, chunk_size); \
+ } \
+ TEST(memiter, Int1_##chunk_size) \
+ { \
+ memiter_int_test(1, chunk_size); \
+ } \
+ TEST(memiter, Long1_##chunk_size) \
+ { \
+ memiter_long_test(1, chunk_size); \
+ } \
\
-TEST(memiter, Char2_##chunk_size) { memiter_char_test(2, chunk_size); } \
-TEST(memiter, Short2_##chunk_size) { memiter_short_test(2, chunk_size); } \
-TEST(memiter, Int2_##chunk_size) { memiter_int_test(2, chunk_size); } \
-TEST(memiter, Long2_##chunk_size) { memiter_long_test(2, chunk_size); } \
+ TEST(memiter, Char2_##chunk_size) \
+ { \
+ memiter_char_test(2, chunk_size); \
+ } \
+ TEST(memiter, Short2_##chunk_size) \
+ { \
+ memiter_short_test(2, chunk_size); \
+ } \
+ TEST(memiter, Int2_##chunk_size) \
+ { \
+ memiter_int_test(2, chunk_size); \
+ } \
+ TEST(memiter, Long2_##chunk_size) \
+ { \
+ memiter_long_test(2, chunk_size); \
+ } \
\
-TEST(memiter, Char3_##chunk_size) { memiter_char_test(3, chunk_size); } \
-TEST(memiter, Short3_##chunk_size) { memiter_short_test(3, chunk_size); } \
-TEST(memiter, Int3_##chunk_size) { memiter_int_test(3, chunk_size); } \
-TEST(memiter, Long3_##chunk_size) { memiter_long_test(3, chunk_size); } \
+ TEST(memiter, Char3_##chunk_size) \
+ { \
+ memiter_char_test(3, chunk_size); \
+ } \
+ TEST(memiter, Short3_##chunk_size) \
+ { \
+ memiter_short_test(3, chunk_size); \
+ } \
+ TEST(memiter, Int3_##chunk_size) \
+ { \
+ memiter_int_test(3, chunk_size); \
+ } \
+ TEST(memiter, Long3_##chunk_size) \
+ { \
+ memiter_long_test(3, chunk_size); \
+ } \
\
-TEST(memiter, Char256_##chunk_size) { memiter_char_test(256, chunk_size); } \
-TEST(memiter, Short256_##chunk_size) { memiter_short_test(256, chunk_size); } \
-TEST(memiter, Int256_##chunk_size) { memiter_int_test(256, chunk_size); } \
-TEST(memiter, Long256_##chunk_size) { memiter_long_test(256, chunk_size); } \
+ TEST(memiter, Char256_##chunk_size) \
+ { \
+ memiter_char_test(256, chunk_size); \
+ } \
+ TEST(memiter, Short256_##chunk_size) \
+ { \
+ memiter_short_test(256, chunk_size); \
+ } \
+ TEST(memiter, Int256_##chunk_size) \
+ { \
+ memiter_int_test(256, chunk_size); \
+ } \
+ TEST(memiter, Long256_##chunk_size) \
+ { \
+ memiter_long_test(256, chunk_size); \
+ }
TEST_NUMBER_AT_CHUNK_SIZE(1)
TEST_NUMBER_AT_CHUNK_SIZE(2)
@@ -176,17 +241,19 @@ TEST_NUMBER_AT_CHUNK_SIZE(3)
TEST_NUMBER_AT_CHUNK_SIZE(13)
TEST_NUMBER_AT_CHUNK_SIZE(256)
-#define STRINGS_TEST(chunk_size, ...) { \
- const char *data[] = {__VA_ARGS__, NULL}; \
- memiter_string_test(data, chunk_size); \
-}
+#define STRINGS_TEST(chunk_size, ...) \
+ { \
+ const char *data[] = {__VA_ARGS__, NULL}; \
+ memiter_string_test(data, chunk_size); \
+ }
#define TEST_STRINGS_AT_CHUNK_SIZE(chunk_size) \
-TEST(memiter, Strings_##chunk_size) { \
- STRINGS_TEST(chunk_size, ""); \
- STRINGS_TEST(chunk_size, "test", "me"); \
- STRINGS_TEST(chunk_size, "more", "test", "data", "to", "follow"); \
-}
+ TEST(memiter, Strings_##chunk_size) \
+ { \
+ STRINGS_TEST(chunk_size, ""); \
+ STRINGS_TEST(chunk_size, "test", "me"); \
+ STRINGS_TEST(chunk_size, "more", "test", "data", "to", "follow"); \
+ }
TEST_STRINGS_AT_CHUNK_SIZE(1)
TEST_STRINGS_AT_CHUNK_SIZE(2)
@@ -194,10 +261,15 @@ TEST_STRINGS_AT_CHUNK_SIZE(3)
TEST_STRINGS_AT_CHUNK_SIZE(13)
TEST_STRINGS_AT_CHUNK_SIZE(256)
-
#define TEST_WORDS10K_AT_CHUNK_SIZE(chunk_size) \
-TEST(memiter, Words10kSentence_##chunk_size) { memiter_words10k_test('.', chunk_size); } \
-TEST(memiter, Words10kWords_##chunk_size) { memiter_words10k_test(' ', chunk_size); } \
+ TEST(memiter, Words10kSentence_##chunk_size) \
+ { \
+ memiter_words10k_test('.', chunk_size); \
+ } \
+ TEST(memiter, Words10kWords_##chunk_size) \
+ { \
+ memiter_words10k_test(' ', chunk_size); \
+ }
TEST_WORDS10K_AT_CHUNK_SIZE(1)
TEST_WORDS10K_AT_CHUNK_SIZE(2)
diff --git a/tests/gtests/blenlib/BLI_path_util_test.cc b/tests/gtests/blenlib/BLI_path_util_test.cc
index 1cd1cbc345d..a9ac5816380 100644
--- a/tests/gtests/blenlib/BLI_path_util_test.cc
+++ b/tests/gtests/blenlib/BLI_path_util_test.cc
@@ -11,7 +11,6 @@ extern "C" {
#ifdef _WIN32
# include "../../../source/blender/blenkernel/BKE_global.h"
#endif
-
}
/* -------------------------------------------------------------------- */
@@ -31,28 +30,31 @@ char *zLhm65070058860608_br_find_exe(const char *default_exe);
const char *GHOST_getUserDir(int version, const char *versionstr)
{
- return "/home/user";
+ return "/home/user";
}
const char *GHOST_getSystemDir(int version, const char *versionstr)
{
- return "/system/path";
+ return "/system/path";
}
struct ImBuf;
-void IMB_freeImBuf(struct ImBuf *ibuf) {}
-struct ImBuf *IMB_dupImBuf(const ImBuf *ibuf) {return NULL;}
+void IMB_freeImBuf(struct ImBuf *ibuf)
+{
+}
+struct ImBuf *IMB_dupImBuf(const ImBuf *ibuf)
+{
+ return NULL;
+}
#ifdef __linux__
char *zLhm65070058860608_br_find_exe(const char *default_exe)
{
- return NULL;
+ return NULL;
}
#endif
-
}
-
/* -------------------------------------------------------------------- */
/* tests */
@@ -60,286 +62,287 @@ char *zLhm65070058860608_br_find_exe(const char *default_exe)
#ifndef _WIN32
TEST(path_util, Clean)
{
- /* "/./" -> "/" */
- {
- char path[FILE_MAX] = "/a/./b/./c/./";
- BLI_cleanup_path(NULL, path);
- EXPECT_STREQ("/a/b/c/", path);
- }
-
- {
- char path[FILE_MAX] = "/./././";
- BLI_cleanup_path(NULL, path);
- EXPECT_STREQ("/", path);
- }
-
- {
- char path[FILE_MAX] = "/a/./././b/";
- BLI_cleanup_path(NULL, path);
- EXPECT_STREQ("/a/b/", path);
- }
-
- /* "//" -> "/" */
- {
- char path[FILE_MAX] = "a////";
- BLI_cleanup_path(NULL, path);
- EXPECT_STREQ("a/", path);
- }
-
- if (0) /* FIXME */
- {
- char path[FILE_MAX] = "./a////";
- BLI_cleanup_path(NULL, path);
- EXPECT_STREQ("./a/", path);
- }
-
- /* "foo/bar/../" -> "foo/" */
- {
- char path[FILE_MAX] = "/a/b/c/../../../";
- BLI_cleanup_path(NULL, path);
- EXPECT_STREQ("/", path);
- }
-
- {
- char path[FILE_MAX] = "/a/../a/b/../b/c/../c/";
- BLI_cleanup_path(NULL, path);
- EXPECT_STREQ("/a/b/c/", path);
- }
-
- {
- char path[FILE_MAX] = "//../";
- BLI_cleanup_path("/a/b/c/", path);
- EXPECT_STREQ("/a/b/", path);
- }
+ /* "/./" -> "/" */
+ {
+ char path[FILE_MAX] = "/a/./b/./c/./";
+ BLI_cleanup_path(NULL, path);
+ EXPECT_STREQ("/a/b/c/", path);
+ }
+
+ {
+ char path[FILE_MAX] = "/./././";
+ BLI_cleanup_path(NULL, path);
+ EXPECT_STREQ("/", path);
+ }
+
+ {
+ char path[FILE_MAX] = "/a/./././b/";
+ BLI_cleanup_path(NULL, path);
+ EXPECT_STREQ("/a/b/", path);
+ }
+
+ /* "//" -> "/" */
+ {
+ char path[FILE_MAX] = "a////";
+ BLI_cleanup_path(NULL, path);
+ EXPECT_STREQ("a/", path);
+ }
+
+ if (0) /* FIXME */
+ {
+ char path[FILE_MAX] = "./a////";
+ BLI_cleanup_path(NULL, path);
+ EXPECT_STREQ("./a/", path);
+ }
+
+ /* "foo/bar/../" -> "foo/" */
+ {
+ char path[FILE_MAX] = "/a/b/c/../../../";
+ BLI_cleanup_path(NULL, path);
+ EXPECT_STREQ("/", path);
+ }
+
+ {
+ char path[FILE_MAX] = "/a/../a/b/../b/c/../c/";
+ BLI_cleanup_path(NULL, path);
+ EXPECT_STREQ("/a/b/c/", path);
+ }
+
+ {
+ char path[FILE_MAX] = "//../";
+ BLI_cleanup_path("/a/b/c/", path);
+ EXPECT_STREQ("/a/b/", path);
+ }
}
#endif
-
#define AT_INDEX(str_input, index_input, str_expect) \
- { \
- char path[] = str_input; \
- const char *expect = str_expect; \
- int index_output, len_output; \
- const bool ret = BLI_path_name_at_index(path, index_input, &index_output, &len_output); \
- if (expect == NULL) { \
- EXPECT_EQ(ret, false); \
- } \
- else { \
- EXPECT_EQ(ret, true); \
- EXPECT_EQ(strlen(expect), len_output); \
- path[index_output + len_output] = '\0'; \
- EXPECT_STREQ(&path[index_output], expect); \
- } \
- }((void)0)
+ { \
+ char path[] = str_input; \
+ const char *expect = str_expect; \
+ int index_output, len_output; \
+ const bool ret = BLI_path_name_at_index(path, index_input, &index_output, &len_output); \
+ if (expect == NULL) { \
+ EXPECT_EQ(ret, false); \
+ } \
+ else { \
+ EXPECT_EQ(ret, true); \
+ EXPECT_EQ(strlen(expect), len_output); \
+ path[index_output + len_output] = '\0'; \
+ EXPECT_STREQ(&path[index_output], expect); \
+ } \
+ } \
+ ((void)0)
/* BLI_path_name_at_index */
TEST(path_util, NameAtIndex_Single)
{
- AT_INDEX("/a", 0, "a");
- AT_INDEX("/a/", 0, "a");
- AT_INDEX("a/", 0, "a");
- AT_INDEX("//a//", 0, "a");
- AT_INDEX("a/b", 0, "a");
-
- AT_INDEX("/a", 1, NULL);
- AT_INDEX("/a/", 1, NULL);
- AT_INDEX("a/", 1, NULL);
- AT_INDEX("//a//", 1, NULL);
+ AT_INDEX("/a", 0, "a");
+ AT_INDEX("/a/", 0, "a");
+ AT_INDEX("a/", 0, "a");
+ AT_INDEX("//a//", 0, "a");
+ AT_INDEX("a/b", 0, "a");
+
+ AT_INDEX("/a", 1, NULL);
+ AT_INDEX("/a/", 1, NULL);
+ AT_INDEX("a/", 1, NULL);
+ AT_INDEX("//a//", 1, NULL);
}
TEST(path_util, NameAtIndex_SingleNeg)
{
- AT_INDEX("/a", -1, "a");
- AT_INDEX("/a/", -1, "a");
- AT_INDEX("a/", -1, "a");
- AT_INDEX("//a//", -1, "a");
- AT_INDEX("a/b", -1, "b");
-
- AT_INDEX("/a", -2, NULL);
- AT_INDEX("/a/", -2, NULL);
- AT_INDEX("a/", -2, NULL);
- AT_INDEX("//a//", -2, NULL);
+ AT_INDEX("/a", -1, "a");
+ AT_INDEX("/a/", -1, "a");
+ AT_INDEX("a/", -1, "a");
+ AT_INDEX("//a//", -1, "a");
+ AT_INDEX("a/b", -1, "b");
+
+ AT_INDEX("/a", -2, NULL);
+ AT_INDEX("/a/", -2, NULL);
+ AT_INDEX("a/", -2, NULL);
+ AT_INDEX("//a//", -2, NULL);
}
TEST(path_util, NameAtIndex_Double)
{
- AT_INDEX("/ab", 0, "ab");
- AT_INDEX("/ab/", 0, "ab");
- AT_INDEX("ab/", 0, "ab");
- AT_INDEX("//ab//", 0, "ab");
- AT_INDEX("ab/c", 0, "ab");
-
- AT_INDEX("/ab", 1, NULL);
- AT_INDEX("/ab/", 1, NULL);
- AT_INDEX("ab/", 1, NULL);
- AT_INDEX("//ab//", 1, NULL);
+ AT_INDEX("/ab", 0, "ab");
+ AT_INDEX("/ab/", 0, "ab");
+ AT_INDEX("ab/", 0, "ab");
+ AT_INDEX("//ab//", 0, "ab");
+ AT_INDEX("ab/c", 0, "ab");
+
+ AT_INDEX("/ab", 1, NULL);
+ AT_INDEX("/ab/", 1, NULL);
+ AT_INDEX("ab/", 1, NULL);
+ AT_INDEX("//ab//", 1, NULL);
}
TEST(path_util, NameAtIndex_DoublNeg)
{
- AT_INDEX("/ab", -1, "ab");
- AT_INDEX("/ab/", -1, "ab");
- AT_INDEX("ab/", -1, "ab");
- AT_INDEX("//ab//", -1, "ab");
- AT_INDEX("ab/c", -1, "c");
-
- AT_INDEX("/ab", -2, NULL);
- AT_INDEX("/ab/", -2, NULL);
- AT_INDEX("ab/", -2, NULL);
- AT_INDEX("//ab//", -2, NULL);
+ AT_INDEX("/ab", -1, "ab");
+ AT_INDEX("/ab/", -1, "ab");
+ AT_INDEX("ab/", -1, "ab");
+ AT_INDEX("//ab//", -1, "ab");
+ AT_INDEX("ab/c", -1, "c");
+
+ AT_INDEX("/ab", -2, NULL);
+ AT_INDEX("/ab/", -2, NULL);
+ AT_INDEX("ab/", -2, NULL);
+ AT_INDEX("//ab//", -2, NULL);
}
TEST(path_util, NameAtIndex_Misc)
{
- AT_INDEX("/how/now/brown/cow", 0, "how");
- AT_INDEX("/how/now/brown/cow", 1, "now");
- AT_INDEX("/how/now/brown/cow", 2, "brown");
- AT_INDEX("/how/now/brown/cow", 3, "cow");
- AT_INDEX("/how/now/brown/cow", 4, NULL);
- AT_INDEX("/how/now/brown/cow/", 4, NULL);
+ AT_INDEX("/how/now/brown/cow", 0, "how");
+ AT_INDEX("/how/now/brown/cow", 1, "now");
+ AT_INDEX("/how/now/brown/cow", 2, "brown");
+ AT_INDEX("/how/now/brown/cow", 3, "cow");
+ AT_INDEX("/how/now/brown/cow", 4, NULL);
+ AT_INDEX("/how/now/brown/cow/", 4, NULL);
}
TEST(path_util, NameAtIndex_MiscNeg)
{
- AT_INDEX("/how/now/brown/cow", 0, "how");
- AT_INDEX("/how/now/brown/cow", 1, "now");
- AT_INDEX("/how/now/brown/cow", 2, "brown");
- AT_INDEX("/how/now/brown/cow", 3, "cow");
- AT_INDEX("/how/now/brown/cow", 4, NULL);
- AT_INDEX("/how/now/brown/cow/", 4, NULL);
+ AT_INDEX("/how/now/brown/cow", 0, "how");
+ AT_INDEX("/how/now/brown/cow", 1, "now");
+ AT_INDEX("/how/now/brown/cow", 2, "brown");
+ AT_INDEX("/how/now/brown/cow", 3, "cow");
+ AT_INDEX("/how/now/brown/cow", 4, NULL);
+ AT_INDEX("/how/now/brown/cow/", 4, NULL);
}
TEST(path_util, NameAtIndex_MiscComplex)
{
- AT_INDEX("how//now/brown/cow", 0, "how");
- AT_INDEX("//how///now\\/brown/cow", 1, "now");
- AT_INDEX("/how/now\\//brown\\/cow", 2, "brown");
- AT_INDEX("/how/now/brown/cow//\\", 3, "cow");
- AT_INDEX("/how/now/brown/\\cow", 4, NULL);
- AT_INDEX("how/now/brown/\\cow\\", 4, NULL);
+ AT_INDEX("how//now/brown/cow", 0, "how");
+ AT_INDEX("//how///now\\/brown/cow", 1, "now");
+ AT_INDEX("/how/now\\//brown\\/cow", 2, "brown");
+ AT_INDEX("/how/now/brown/cow//\\", 3, "cow");
+ AT_INDEX("/how/now/brown/\\cow", 4, NULL);
+ AT_INDEX("how/now/brown/\\cow\\", 4, NULL);
}
TEST(path_util, NameAtIndex_MiscComplexNeg)
{
- AT_INDEX("how//now/brown/cow", -4, "how");
- AT_INDEX("//how///now\\/brown/cow", -3, "now");
- AT_INDEX("/how/now\\//brown\\/cow", -2, "brown");
- AT_INDEX("/how/now/brown/cow//\\", -1, "cow");
- AT_INDEX("/how/now/brown/\\cow", -5, NULL);
- AT_INDEX("how/now/brown/\\cow\\", -5, NULL);
+ AT_INDEX("how//now/brown/cow", -4, "how");
+ AT_INDEX("//how///now\\/brown/cow", -3, "now");
+ AT_INDEX("/how/now\\//brown\\/cow", -2, "brown");
+ AT_INDEX("/how/now/brown/cow//\\", -1, "cow");
+ AT_INDEX("/how/now/brown/\\cow", -5, NULL);
+ AT_INDEX("how/now/brown/\\cow\\", -5, NULL);
}
TEST(path_util, NameAtIndex_NoneComplex)
{
- AT_INDEX("", 0, NULL);
- AT_INDEX("/", 0, NULL);
- AT_INDEX("//", 0, NULL);
- AT_INDEX("///", 0, NULL);
+ AT_INDEX("", 0, NULL);
+ AT_INDEX("/", 0, NULL);
+ AT_INDEX("//", 0, NULL);
+ AT_INDEX("///", 0, NULL);
}
TEST(path_util, NameAtIndex_NoneComplexNeg)
{
- AT_INDEX("", -1, NULL);
- AT_INDEX("/", -1, NULL);
- AT_INDEX("//", -1, NULL);
- AT_INDEX("///", -1, NULL);
+ AT_INDEX("", -1, NULL);
+ AT_INDEX("/", -1, NULL);
+ AT_INDEX("//", -1, NULL);
+ AT_INDEX("///", -1, NULL);
}
#undef AT_INDEX
#define JOIN(str_expect, out_size, ...) \
- { \
- const char *expect = str_expect; \
- char result[(out_size) + 1024]; \
- /* check we don't write past the last byte */ \
- result[out_size] = '\0'; \
- BLI_path_join(result, out_size, __VA_ARGS__, NULL); \
- /* simplify expected string */ \
- BLI_str_replace_char(result, '\\', '/'); \
- EXPECT_STREQ(result, expect); \
- EXPECT_EQ(result[out_size], '\0'); \
- } ((void)0)
+ { \
+ const char *expect = str_expect; \
+ char result[(out_size) + 1024]; \
+ /* check we don't write past the last byte */ \
+ result[out_size] = '\0'; \
+ BLI_path_join(result, out_size, __VA_ARGS__, NULL); \
+ /* simplify expected string */ \
+ BLI_str_replace_char(result, '\\', '/'); \
+ EXPECT_STREQ(result, expect); \
+ EXPECT_EQ(result[out_size], '\0'); \
+ } \
+ ((void)0)
/* BLI_path_join */
TEST(path_util, JoinNop)
{
- JOIN("", 100, "");
- JOIN("", 100, "", "");
- JOIN("", 100, "", "", "");
- JOIN("/", 100, "/", "", "");
- JOIN("/", 100, "/", "/");
- JOIN("/", 100, "/", "", "/");
- JOIN("/", 100, "/", "", "/", "");
+ JOIN("", 100, "");
+ JOIN("", 100, "", "");
+ JOIN("", 100, "", "", "");
+ JOIN("/", 100, "/", "", "");
+ JOIN("/", 100, "/", "/");
+ JOIN("/", 100, "/", "", "/");
+ JOIN("/", 100, "/", "", "/", "");
}
TEST(path_util, JoinSingle)
{
- JOIN("test", 100, "test");
- JOIN("", 100, "");
- JOIN("a", 100, "a");
- JOIN("/a", 100, "/a");
- JOIN("a/", 100, "a/");
- JOIN("/a/", 100, "/a/");
- JOIN("/a/", 100, "/a//");
- JOIN("//a/", 100, "//a//");
+ JOIN("test", 100, "test");
+ JOIN("", 100, "");
+ JOIN("a", 100, "a");
+ JOIN("/a", 100, "/a");
+ JOIN("a/", 100, "a/");
+ JOIN("/a/", 100, "/a/");
+ JOIN("/a/", 100, "/a//");
+ JOIN("//a/", 100, "//a//");
}
TEST(path_util, JoinTriple)
{
- JOIN("/a/b/c", 100, "/a", "b", "c");
- JOIN("/a/b/c", 100, "/a/", "/b/", "/c");
- JOIN("/a/b/c", 100, "/a/b/", "/c");
- JOIN("/a/b/c", 100, "/a/b/c");
- JOIN("/a/b/c", 100, "/", "a/b/c");
-
- JOIN("/a/b/c/", 100, "/a/", "/b/", "/c/");
- JOIN("/a/b/c/", 100, "/a/b/c/");
- JOIN("/a/b/c/", 100, "/a/b/", "/c/");
- JOIN("/a/b/c/", 100, "/a/b/c", "/");
- JOIN("/a/b/c/", 100, "/", "a/b/c", "/");
+ JOIN("/a/b/c", 100, "/a", "b", "c");
+ JOIN("/a/b/c", 100, "/a/", "/b/", "/c");
+ JOIN("/a/b/c", 100, "/a/b/", "/c");
+ JOIN("/a/b/c", 100, "/a/b/c");
+ JOIN("/a/b/c", 100, "/", "a/b/c");
+
+ JOIN("/a/b/c/", 100, "/a/", "/b/", "/c/");
+ JOIN("/a/b/c/", 100, "/a/b/c/");
+ JOIN("/a/b/c/", 100, "/a/b/", "/c/");
+ JOIN("/a/b/c/", 100, "/a/b/c", "/");
+ JOIN("/a/b/c/", 100, "/", "a/b/c", "/");
}
TEST(path_util, JoinTruncateShort)
{
- JOIN("", 1, "/");
- JOIN("/", 2, "/");
- JOIN("a", 2, "", "aa");
- JOIN("a", 2, "", "a/");
- JOIN("a/b", 4, "a", "bc");
- JOIN("ab/", 4, "ab", "c");
- JOIN("/a/", 4, "/a", "b");
- JOIN("/a/", 4, "/a/", "b/");
- JOIN("/a/", 4, "/a", "/b/");
- JOIN("/a/", 4, "/", "a/b/");
- JOIN("//a", 4, "//", "a/b/");
-
- JOIN("/a/b", 5, "/a", "b", "c");
+ JOIN("", 1, "/");
+ JOIN("/", 2, "/");
+ JOIN("a", 2, "", "aa");
+ JOIN("a", 2, "", "a/");
+ JOIN("a/b", 4, "a", "bc");
+ JOIN("ab/", 4, "ab", "c");
+ JOIN("/a/", 4, "/a", "b");
+ JOIN("/a/", 4, "/a/", "b/");
+ JOIN("/a/", 4, "/a", "/b/");
+ JOIN("/a/", 4, "/", "a/b/");
+ JOIN("//a", 4, "//", "a/b/");
+
+ JOIN("/a/b", 5, "/a", "b", "c");
}
TEST(path_util, JoinTruncateLong)
{
- JOIN("", 1, "//", "//longer", "path");
- JOIN("/", 2, "//", "//longer", "path");
- JOIN("//", 3, "//", "//longer", "path");
- JOIN("//l", 4, "//", "//longer", "path");
- /* snip */
- JOIN("//longe", 8, "//", "//longer", "path");
- JOIN("//longer", 9, "//", "//longer", "path");
- JOIN("//longer/", 10, "//", "//longer", "path");
- JOIN("//longer/p", 11, "//", "//longer", "path");
- JOIN("//longer/pa", 12, "//", "//longer", "path");
- JOIN("//longer/pat", 13, "//", "//longer", "path");
- JOIN("//longer/path", 14, "//", "//longer", "path"); // not truncated
- JOIN("//longer/path", 14, "//", "//longer", "path/");
- JOIN("//longer/path/", 15, "//", "//longer", "path/"); // not truncated
- JOIN("//longer/path/", 15, "//", "//longer", "path/", "trunc");
- JOIN("//longer/path/t", 16, "//", "//longer", "path/", "trunc");
+ JOIN("", 1, "//", "//longer", "path");
+ JOIN("/", 2, "//", "//longer", "path");
+ JOIN("//", 3, "//", "//longer", "path");
+ JOIN("//l", 4, "//", "//longer", "path");
+ /* snip */
+ JOIN("//longe", 8, "//", "//longer", "path");
+ JOIN("//longer", 9, "//", "//longer", "path");
+ JOIN("//longer/", 10, "//", "//longer", "path");
+ JOIN("//longer/p", 11, "//", "//longer", "path");
+ JOIN("//longer/pa", 12, "//", "//longer", "path");
+ JOIN("//longer/pat", 13, "//", "//longer", "path");
+ JOIN("//longer/path", 14, "//", "//longer", "path"); // not truncated
+ JOIN("//longer/path", 14, "//", "//longer", "path/");
+ JOIN("//longer/path/", 15, "//", "//longer", "path/"); // not truncated
+ JOIN("//longer/path/", 15, "//", "//longer", "path/", "trunc");
+ JOIN("//longer/path/t", 16, "//", "//longer", "path/", "trunc");
}
TEST(path_util, JoinComplex)
{
- JOIN("/a/b/c/d/e/f/g/", 100, "/", "\\a/b", "//////c/d", "", "e\\\\", "f", "g//");
- JOIN("/aa/bb/cc/dd/ee/ff/gg/", 100, "/", "\\aa/bb", "//////cc/dd", "", "ee\\\\", "ff", "gg//");
- JOIN("1/2/3/", 100, "1", "////////", "", "2", "3\\");
+ JOIN("/a/b/c/d/e/f/g/", 100, "/", "\\a/b", "//////c/d", "", "e\\\\", "f", "g//");
+ JOIN("/aa/bb/cc/dd/ee/ff/gg/", 100, "/", "\\aa/bb", "//////cc/dd", "", "ee\\\\", "ff", "gg//");
+ JOIN("1/2/3/", 100, "1", "////////", "", "2", "3\\");
}
#undef JOIN
@@ -347,140 +350,140 @@ TEST(path_util, JoinComplex)
/* BLI_path_frame */
TEST(path_util, Frame)
{
- bool ret;
-
- {
- char path[FILE_MAX] = "";
- ret = BLI_path_frame(path, 123, 1);
- EXPECT_EQ(ret, 1);
- EXPECT_STREQ("123", path);
- }
-
- {
- char path[FILE_MAX] = "";
- ret = BLI_path_frame(path, 123, 12);
- EXPECT_EQ(ret, 1);
- EXPECT_STREQ("000000000123", path);
- }
-
- {
- char path[FILE_MAX] = "test_";
- ret = BLI_path_frame(path, 123, 1);
- EXPECT_EQ(ret, 1);
- EXPECT_STREQ("test_123", path);
- }
-
- {
- char path[FILE_MAX] = "test_";
- ret = BLI_path_frame(path, 1, 12);
- EXPECT_EQ(ret, 1);
- EXPECT_STREQ("test_000000000001", path);
- }
-
- {
- char path[FILE_MAX] = "test_############";
- ret = BLI_path_frame(path, 1, 0);
- EXPECT_EQ(ret, 1);
- EXPECT_STREQ("test_000000000001", path);
- }
-
- {
- char path[FILE_MAX] = "test_#_#_middle";
- ret = BLI_path_frame(path, 123, 0);
- EXPECT_EQ(ret, 1);
- EXPECT_STREQ("test_#_123_middle", path);
- }
-
- /* intentionally fail */
- {
- char path[FILE_MAX] = "";
- ret = BLI_path_frame(path, 123, 0);
- EXPECT_EQ(ret, 0);
- EXPECT_STREQ("", path);
- }
-
- {
- char path[FILE_MAX] = "test_middle";
- ret = BLI_path_frame(path, 123, 0);
- EXPECT_EQ(ret, 0);
- EXPECT_STREQ("test_middle", path);
- }
+ bool ret;
+
+ {
+ char path[FILE_MAX] = "";
+ ret = BLI_path_frame(path, 123, 1);
+ EXPECT_EQ(ret, 1);
+ EXPECT_STREQ("123", path);
+ }
+
+ {
+ char path[FILE_MAX] = "";
+ ret = BLI_path_frame(path, 123, 12);
+ EXPECT_EQ(ret, 1);
+ EXPECT_STREQ("000000000123", path);
+ }
+
+ {
+ char path[FILE_MAX] = "test_";
+ ret = BLI_path_frame(path, 123, 1);
+ EXPECT_EQ(ret, 1);
+ EXPECT_STREQ("test_123", path);
+ }
+
+ {
+ char path[FILE_MAX] = "test_";
+ ret = BLI_path_frame(path, 1, 12);
+ EXPECT_EQ(ret, 1);
+ EXPECT_STREQ("test_000000000001", path);
+ }
+
+ {
+ char path[FILE_MAX] = "test_############";
+ ret = BLI_path_frame(path, 1, 0);
+ EXPECT_EQ(ret, 1);
+ EXPECT_STREQ("test_000000000001", path);
+ }
+
+ {
+ char path[FILE_MAX] = "test_#_#_middle";
+ ret = BLI_path_frame(path, 123, 0);
+ EXPECT_EQ(ret, 1);
+ EXPECT_STREQ("test_#_123_middle", path);
+ }
+
+ /* intentionally fail */
+ {
+ char path[FILE_MAX] = "";
+ ret = BLI_path_frame(path, 123, 0);
+ EXPECT_EQ(ret, 0);
+ EXPECT_STREQ("", path);
+ }
+
+ {
+ char path[FILE_MAX] = "test_middle";
+ ret = BLI_path_frame(path, 123, 0);
+ EXPECT_EQ(ret, 0);
+ EXPECT_STREQ("test_middle", path);
+ }
}
/* BLI_split_dirfile */
TEST(path_util, SplitDirfile)
{
- {
- const char *path = "";
- char dir[FILE_MAX], file[FILE_MAX];
- BLI_split_dirfile(path, dir, file, sizeof(dir), sizeof(file));
- EXPECT_STREQ("", dir);
- EXPECT_STREQ("", file);
- }
-
- {
- const char *path = "/";
- char dir[FILE_MAX], file[FILE_MAX];
- BLI_split_dirfile(path, dir, file, sizeof(dir), sizeof(file));
- EXPECT_STREQ("/", dir);
- EXPECT_STREQ("", file);
- }
-
- {
- const char *path = "fileonly";
- char dir[FILE_MAX], file[FILE_MAX];
- BLI_split_dirfile(path, dir, file, sizeof(dir), sizeof(file));
- EXPECT_STREQ("", dir);
- EXPECT_STREQ("fileonly", file);
- }
-
- {
- const char *path = "dironly/";
- char dir[FILE_MAX], file[FILE_MAX];
- BLI_split_dirfile(path, dir, file, sizeof(dir), sizeof(file));
- EXPECT_STREQ("dironly/", dir);
- EXPECT_STREQ("", file);
- }
-
- {
- const char *path = "/a/b";
- char dir[FILE_MAX], file[FILE_MAX];
- BLI_split_dirfile(path, dir, file, sizeof(dir), sizeof(file));
- EXPECT_STREQ("/a/", dir);
- EXPECT_STREQ("b", file);
- }
-
- {
- const char *path = "/dirtoobig/filetoobig";
- char dir[5], file[5];
- BLI_split_dirfile(path, dir, file, sizeof(dir), sizeof(file));
- EXPECT_STREQ("/dir", dir);
- EXPECT_STREQ("file", file);
-
- BLI_split_dirfile(path, dir, file, 1, 1);
- EXPECT_STREQ("", dir);
- EXPECT_STREQ("", file);
- }
+ {
+ const char *path = "";
+ char dir[FILE_MAX], file[FILE_MAX];
+ BLI_split_dirfile(path, dir, file, sizeof(dir), sizeof(file));
+ EXPECT_STREQ("", dir);
+ EXPECT_STREQ("", file);
+ }
+
+ {
+ const char *path = "/";
+ char dir[FILE_MAX], file[FILE_MAX];
+ BLI_split_dirfile(path, dir, file, sizeof(dir), sizeof(file));
+ EXPECT_STREQ("/", dir);
+ EXPECT_STREQ("", file);
+ }
+
+ {
+ const char *path = "fileonly";
+ char dir[FILE_MAX], file[FILE_MAX];
+ BLI_split_dirfile(path, dir, file, sizeof(dir), sizeof(file));
+ EXPECT_STREQ("", dir);
+ EXPECT_STREQ("fileonly", file);
+ }
+
+ {
+ const char *path = "dironly/";
+ char dir[FILE_MAX], file[FILE_MAX];
+ BLI_split_dirfile(path, dir, file, sizeof(dir), sizeof(file));
+ EXPECT_STREQ("dironly/", dir);
+ EXPECT_STREQ("", file);
+ }
+
+ {
+ const char *path = "/a/b";
+ char dir[FILE_MAX], file[FILE_MAX];
+ BLI_split_dirfile(path, dir, file, sizeof(dir), sizeof(file));
+ EXPECT_STREQ("/a/", dir);
+ EXPECT_STREQ("b", file);
+ }
+
+ {
+ const char *path = "/dirtoobig/filetoobig";
+ char dir[5], file[5];
+ BLI_split_dirfile(path, dir, file, sizeof(dir), sizeof(file));
+ EXPECT_STREQ("/dir", dir);
+ EXPECT_STREQ("file", file);
+
+ BLI_split_dirfile(path, dir, file, 1, 1);
+ EXPECT_STREQ("", dir);
+ EXPECT_STREQ("", file);
+ }
}
#define PATH_FRAME_STRIP(input_path, expect_path, expect_ext) \
-{ \
- char path[FILE_MAX]; \
- char ext[FILE_MAX]; \
- BLI_strncpy(path, (input_path), FILE_MAX); \
- BLI_path_frame_strip(path, ext); \
- EXPECT_STREQ(path, expect_path); \
- EXPECT_STREQ(ext, expect_ext); \
-}
+ { \
+ char path[FILE_MAX]; \
+ char ext[FILE_MAX]; \
+ BLI_strncpy(path, (input_path), FILE_MAX); \
+ BLI_path_frame_strip(path, ext); \
+ EXPECT_STREQ(path, expect_path); \
+ EXPECT_STREQ(ext, expect_ext); \
+ }
/* BLI_path_frame_strip */
TEST(path_util, PathFrameStrip)
{
- PATH_FRAME_STRIP("", "", "");
- PATH_FRAME_STRIP("nonum.abc", "nonum", ".abc");
- PATH_FRAME_STRIP("fileonly.001.abc", "fileonly.###", ".abc");
- PATH_FRAME_STRIP("/abspath/to/somefile.001.abc", "/abspath/to/somefile.###", ".abc");
- PATH_FRAME_STRIP("/ext/longer/somefile.001.alembic", "/ext/longer/somefile.###", ".alembic");
- PATH_FRAME_STRIP("/ext/shorter/somefile.123001.abc", "/ext/shorter/somefile.######", ".abc");
+ PATH_FRAME_STRIP("", "", "");
+ PATH_FRAME_STRIP("nonum.abc", "nonum", ".abc");
+ PATH_FRAME_STRIP("fileonly.001.abc", "fileonly.###", ".abc");
+ PATH_FRAME_STRIP("/abspath/to/somefile.001.abc", "/abspath/to/somefile.###", ".abc");
+ PATH_FRAME_STRIP("/ext/longer/somefile.001.alembic", "/ext/longer/somefile.###", ".alembic");
+ PATH_FRAME_STRIP("/ext/shorter/somefile.123001.abc", "/ext/shorter/somefile.######", ".abc");
}
#undef PATH_FRAME_STRIP
diff --git a/tests/gtests/blenlib/BLI_polyfill_2d_test.cc b/tests/gtests/blenlib/BLI_polyfill_2d_test.cc
index a8c7eff4626..d4878238a1c 100644
--- a/tests/gtests/blenlib/BLI_polyfill_2d_test.cc
+++ b/tests/gtests/blenlib/BLI_polyfill_2d_test.cc
@@ -22,18 +22,19 @@ extern "C" {
#endif
#ifdef USE_BEAUTIFY
-#include "BLI_polyfill_2d_beautify.h"
-#include "BLI_memarena.h"
-#include "BLI_heap.h"
+# include "BLI_polyfill_2d_beautify.h"
+# include "BLI_memarena.h"
+# include "BLI_heap.h"
#endif
}
#include "stubs/bf_intern_eigen_stubs.h"
-static void polyfill_to_obj(
- const char *id,
- const float poly[][2], const unsigned int poly_tot,
- const unsigned int tris[][3], const unsigned int tris_tot);
+static void polyfill_to_obj(const char *id,
+ const float poly[][2],
+ const unsigned int poly_tot,
+ const unsigned int tris[][3],
+ const unsigned int tris_tot);
/* -------------------------------------------------------------------- */
/* test utility functions */
@@ -42,13 +43,13 @@ static void polyfill_to_obj(
static void test_valid_polyfill_prepare(unsigned int tris[][3], unsigned int tris_tot)
{
- unsigned int i;
- for (i = 0; i < tris_tot; i++) {
- unsigned int j;
- for (j = 0; j < 3; j++) {
- tris[i][j] = TRI_ERROR_VALUE;
- }
- }
+ unsigned int i;
+ for (i = 0; i < tris_tot; i++) {
+ unsigned int j;
+ for (j = 0; j < 3; j++) {
+ tris[i][j] = TRI_ERROR_VALUE;
+ }
+ }
}
/**
@@ -58,272 +59,283 @@ static void test_valid_polyfill_prepare(unsigned int tris[][3], unsigned int tri
* - all tris set.
* - all verts used at least once.
*/
-static void test_polyfill_simple(
- const float poly[][2], const unsigned int poly_tot,
- const unsigned int tris[][3], const unsigned int tris_tot)
-{
- unsigned int i;
- int *tot_used = (int *)MEM_callocN(poly_tot * sizeof(int), __func__);
- for (i = 0; i < tris_tot; i++) {
- unsigned int j;
- for (j = 0; j < 3; j++) {
- EXPECT_NE(TRI_ERROR_VALUE, tris[i][j]);
- tot_used[tris[i][j]] += 1;
- }
- EXPECT_NE(tris[i][0], tris[i][1]);
- EXPECT_NE(tris[i][1], tris[i][2]);
- EXPECT_NE(tris[i][2], tris[i][0]);
- }
- for (i = 0; i < poly_tot; i++) {
- EXPECT_NE(0, tot_used[i]);
- }
- MEM_freeN(tot_used);
-}
-
-static void test_polyfill_topology(
- const float poly[][2], const unsigned int poly_tot,
- const unsigned int tris[][3], const unsigned int tris_tot)
-{
- EdgeHash *edgehash = BLI_edgehash_new(__func__);
- EdgeHashIterator *ehi;
- unsigned int i;
- for (i = 0; i < tris_tot; i++) {
- unsigned int j;
- for (j = 0; j < 3; j++) {
- const unsigned int v1 = tris[i][j];
- const unsigned int v2 = tris[i][(j + 1) % 3];
- void **p = BLI_edgehash_lookup_p(edgehash, v1, v2);
- if (p) {
- *p = (void *)((intptr_t)*p + (intptr_t)1);
- }
- else {
- BLI_edgehash_insert(edgehash, v1, v2, (void *)(intptr_t)1);
- }
- }
- }
- EXPECT_EQ(BLI_edgehash_len(edgehash), poly_tot + (poly_tot - 3));
-
- for (i = 0; i < poly_tot; i++) {
- const unsigned int v1 = i;
- const unsigned int v2 = (i + 1) % poly_tot;
- void **p = BLI_edgehash_lookup_p(edgehash, v1, v2);
- EXPECT_EQ((void *)p != NULL, 1);
- EXPECT_EQ((intptr_t)*p, 1);
- }
-
- for (ehi = BLI_edgehashIterator_new(edgehash), i = 0;
- BLI_edgehashIterator_isDone(ehi) == false;
- BLI_edgehashIterator_step(ehi), i++)
- {
- void **p = BLI_edgehashIterator_getValue_p(ehi);
- EXPECT_TRUE(ELEM((intptr_t)*p, 1, 2));
- }
-
- BLI_edgehashIterator_free(ehi);
- BLI_edgehash_free(edgehash, NULL);
+static void test_polyfill_simple(const float poly[][2],
+ const unsigned int poly_tot,
+ const unsigned int tris[][3],
+ const unsigned int tris_tot)
+{
+ unsigned int i;
+ int *tot_used = (int *)MEM_callocN(poly_tot * sizeof(int), __func__);
+ for (i = 0; i < tris_tot; i++) {
+ unsigned int j;
+ for (j = 0; j < 3; j++) {
+ EXPECT_NE(TRI_ERROR_VALUE, tris[i][j]);
+ tot_used[tris[i][j]] += 1;
+ }
+ EXPECT_NE(tris[i][0], tris[i][1]);
+ EXPECT_NE(tris[i][1], tris[i][2]);
+ EXPECT_NE(tris[i][2], tris[i][0]);
+ }
+ for (i = 0; i < poly_tot; i++) {
+ EXPECT_NE(0, tot_used[i]);
+ }
+ MEM_freeN(tot_used);
+}
+
+static void test_polyfill_topology(const float poly[][2],
+ const unsigned int poly_tot,
+ const unsigned int tris[][3],
+ const unsigned int tris_tot)
+{
+ EdgeHash *edgehash = BLI_edgehash_new(__func__);
+ EdgeHashIterator *ehi;
+ unsigned int i;
+ for (i = 0; i < tris_tot; i++) {
+ unsigned int j;
+ for (j = 0; j < 3; j++) {
+ const unsigned int v1 = tris[i][j];
+ const unsigned int v2 = tris[i][(j + 1) % 3];
+ void **p = BLI_edgehash_lookup_p(edgehash, v1, v2);
+ if (p) {
+ *p = (void *)((intptr_t)*p + (intptr_t)1);
+ }
+ else {
+ BLI_edgehash_insert(edgehash, v1, v2, (void *)(intptr_t)1);
+ }
+ }
+ }
+ EXPECT_EQ(BLI_edgehash_len(edgehash), poly_tot + (poly_tot - 3));
+
+ for (i = 0; i < poly_tot; i++) {
+ const unsigned int v1 = i;
+ const unsigned int v2 = (i + 1) % poly_tot;
+ void **p = BLI_edgehash_lookup_p(edgehash, v1, v2);
+ EXPECT_EQ((void *)p != NULL, 1);
+ EXPECT_EQ((intptr_t)*p, 1);
+ }
+
+ for (ehi = BLI_edgehashIterator_new(edgehash), i = 0; BLI_edgehashIterator_isDone(ehi) == false;
+ BLI_edgehashIterator_step(ehi), i++) {
+ void **p = BLI_edgehashIterator_getValue_p(ehi);
+ EXPECT_TRUE(ELEM((intptr_t)*p, 1, 2));
+ }
+
+ BLI_edgehashIterator_free(ehi);
+ BLI_edgehash_free(edgehash, NULL);
}
/**
* Check all faces are flipped the same way
*/
-static void test_polyfill_winding(
- const float poly[][2], const unsigned int poly_tot,
- const unsigned int tris[][3], const unsigned int tris_tot)
-{
- unsigned int i;
- unsigned int count[2] = {0, 0};
- for (i = 0; i < tris_tot; i++) {
- float winding_test = cross_tri_v2(poly[tris[i][0]], poly[tris[i][1]], poly[tris[i][2]]);
- if (fabsf(winding_test) > FLT_EPSILON) {
- count[winding_test < 0.0f] += 1;
- }
- }
- EXPECT_TRUE(ELEM(0, count[0], count[1]));
+static void test_polyfill_winding(const float poly[][2],
+ const unsigned int poly_tot,
+ const unsigned int tris[][3],
+ const unsigned int tris_tot)
+{
+ unsigned int i;
+ unsigned int count[2] = {0, 0};
+ for (i = 0; i < tris_tot; i++) {
+ float winding_test = cross_tri_v2(poly[tris[i][0]], poly[tris[i][1]], poly[tris[i][2]]);
+ if (fabsf(winding_test) > FLT_EPSILON) {
+ count[winding_test < 0.0f] += 1;
+ }
+ }
+ EXPECT_TRUE(ELEM(0, count[0], count[1]));
}
/**
* Check the accumulated triangle area is close to the original area.
*/
-static void test_polyfill_area(
- const float poly[][2], const unsigned int poly_tot,
- const unsigned int tris[][3], const unsigned int tris_tot)
-{
- unsigned int i;
- const float area_tot = area_poly_v2(poly, poly_tot);
- float area_tot_tris = 0.0f;
- const float eps_abs = 0.00001f;
- const float eps = area_tot > 1.0f ? (area_tot * eps_abs) : eps_abs;
- for (i = 0; i < tris_tot; i++) {
- area_tot_tris += area_tri_v2(poly[tris[i][0]], poly[tris[i][1]], poly[tris[i][2]]);
- }
- EXPECT_NEAR(area_tot, area_tot_tris, eps);
+static void test_polyfill_area(const float poly[][2],
+ const unsigned int poly_tot,
+ const unsigned int tris[][3],
+ const unsigned int tris_tot)
+{
+ unsigned int i;
+ const float area_tot = area_poly_v2(poly, poly_tot);
+ float area_tot_tris = 0.0f;
+ const float eps_abs = 0.00001f;
+ const float eps = area_tot > 1.0f ? (area_tot * eps_abs) : eps_abs;
+ for (i = 0; i < tris_tot; i++) {
+ area_tot_tris += area_tri_v2(poly[tris[i][0]], poly[tris[i][1]], poly[tris[i][2]]);
+ }
+ EXPECT_NEAR(area_tot, area_tot_tris, eps);
}
-
/* -------------------------------------------------------------------- */
/* Macro and helpers to manage checking */
/**
* Main template for polyfill testing.
*/
-static void test_polyfill_template_check(
- const char *id, bool is_degenerate,
- const float poly[][2], const unsigned int poly_tot,
- const unsigned int tris[][3], const unsigned int tris_tot)
+static void test_polyfill_template_check(const char *id,
+ bool is_degenerate,
+ const float poly[][2],
+ const unsigned int poly_tot,
+ const unsigned int tris[][3],
+ const unsigned int tris_tot)
{
- test_polyfill_simple(poly, poly_tot, tris, tris_tot);
- test_polyfill_topology(poly, poly_tot, tris, tris_tot);
- if (!is_degenerate) {
- test_polyfill_winding(poly, poly_tot, tris, tris_tot);
+ test_polyfill_simple(poly, poly_tot, tris, tris_tot);
+ test_polyfill_topology(poly, poly_tot, tris, tris_tot);
+ if (!is_degenerate) {
+ test_polyfill_winding(poly, poly_tot, tris, tris_tot);
- test_polyfill_area(poly, poly_tot, tris, tris_tot);
- }
- polyfill_to_obj(id, poly, poly_tot, tris, tris_tot);
+ test_polyfill_area(poly, poly_tot, tris, tris_tot);
+ }
+ polyfill_to_obj(id, poly, poly_tot, tris, tris_tot);
}
-static void test_polyfill_template(
- const char *id, bool is_degenerate,
- const float poly[][2], const unsigned int poly_tot,
- unsigned int tris[][3], const unsigned int tris_tot)
+static void test_polyfill_template(const char *id,
+ bool is_degenerate,
+ const float poly[][2],
+ const unsigned int poly_tot,
+ unsigned int tris[][3],
+ const unsigned int tris_tot)
{
- test_valid_polyfill_prepare(tris, tris_tot);
- BLI_polyfill_calc(poly, poly_tot, 0, tris);
+ test_valid_polyfill_prepare(tris, tris_tot);
+ BLI_polyfill_calc(poly, poly_tot, 0, tris);
- /* check all went well */
- test_polyfill_template_check(id, is_degenerate, poly, poly_tot, tris, tris_tot);
+ /* check all went well */
+ test_polyfill_template_check(id, is_degenerate, poly, poly_tot, tris, tris_tot);
#ifdef USE_BEAUTIFY
- /* check beautify gives good results too */
- {
- MemArena *pf_arena = BLI_memarena_new(BLI_POLYFILL_ARENA_SIZE, __func__);
- Heap *pf_heap = BLI_heap_new_ex(BLI_POLYFILL_ALLOC_NGON_RESERVE);
+ /* check beautify gives good results too */
+ {
+ MemArena *pf_arena = BLI_memarena_new(BLI_POLYFILL_ARENA_SIZE, __func__);
+ Heap *pf_heap = BLI_heap_new_ex(BLI_POLYFILL_ALLOC_NGON_RESERVE);
- BLI_polyfill_beautify(
- poly, poly_tot, tris,
- pf_arena, pf_heap);
+ BLI_polyfill_beautify(poly, poly_tot, tris, pf_arena, pf_heap);
- test_polyfill_template_check(id, is_degenerate, poly, poly_tot, tris, tris_tot);
+ test_polyfill_template_check(id, is_degenerate, poly, poly_tot, tris, tris_tot);
- BLI_memarena_free(pf_arena);
- BLI_heap_free(pf_heap, NULL);
- }
+ BLI_memarena_free(pf_arena);
+ BLI_heap_free(pf_heap, NULL);
+ }
#endif
}
-static void test_polyfill_template_flip_sign(
- const char *id, bool is_degenerate,
- const float poly[][2], const unsigned int poly_tot,
- unsigned int tris[][3], const unsigned int tris_tot)
-{
- float (*poly_copy)[2] = (float (*)[2])MEM_mallocN(sizeof(float[2]) * poly_tot, id);
- for (int flip_x = 0; flip_x < 2; flip_x++) {
- for (int flip_y = 0; flip_y < 2; flip_y++) {
- float sign_x = flip_x ? -1.0f : 1.0f;
- float sign_y = flip_y ? -1.0f : 1.0f;
- for (int i = 0; i < poly_tot; i++) {
- poly_copy[i][0] = poly[i][0] * sign_x;
- poly_copy[i][1] = poly[i][1] * sign_y;
- }
- test_polyfill_template(id, is_degenerate, poly_copy, poly_tot, tris, tris_tot);
- }
- }
- MEM_freeN(poly_copy);
+static void test_polyfill_template_flip_sign(const char *id,
+ bool is_degenerate,
+ const float poly[][2],
+ const unsigned int poly_tot,
+ unsigned int tris[][3],
+ const unsigned int tris_tot)
+{
+ float(*poly_copy)[2] = (float(*)[2])MEM_mallocN(sizeof(float[2]) * poly_tot, id);
+ for (int flip_x = 0; flip_x < 2; flip_x++) {
+ for (int flip_y = 0; flip_y < 2; flip_y++) {
+ float sign_x = flip_x ? -1.0f : 1.0f;
+ float sign_y = flip_y ? -1.0f : 1.0f;
+ for (int i = 0; i < poly_tot; i++) {
+ poly_copy[i][0] = poly[i][0] * sign_x;
+ poly_copy[i][1] = poly[i][1] * sign_y;
+ }
+ test_polyfill_template(id, is_degenerate, poly_copy, poly_tot, tris, tris_tot);
+ }
+ }
+ MEM_freeN(poly_copy);
}
#ifdef USE_COMBINATIONS_ALL
-static void test_polyfill_template_main(
- const char *id, bool is_degenerate,
- const float poly[][2], const unsigned int poly_tot,
- unsigned int tris[][3], const unsigned int tris_tot)
+static void test_polyfill_template_main(const char *id,
+ bool is_degenerate,
+ const float poly[][2],
+ const unsigned int poly_tot,
+ unsigned int tris[][3],
+ const unsigned int tris_tot)
{
- /* overkill? - try at _every_ offset & reverse */
- unsigned int poly_reverse;
- float (*poly_copy)[2] = (float (*)[2])MEM_mallocN(sizeof(float[2]) * poly_tot, id);
- float tmp[2];
+ /* overkill? - try at _every_ offset & reverse */
+ unsigned int poly_reverse;
+ float(*poly_copy)[2] = (float(*)[2])MEM_mallocN(sizeof(float[2]) * poly_tot, id);
+ float tmp[2];
- memcpy(poly_copy, poly, sizeof(float[2]) * poly_tot);
+ memcpy(poly_copy, poly, sizeof(float[2]) * poly_tot);
- for (poly_reverse = 0; poly_reverse < 2; poly_reverse++) {
- unsigned int poly_cycle;
+ for (poly_reverse = 0; poly_reverse < 2; poly_reverse++) {
+ unsigned int poly_cycle;
- if (poly_reverse) {
- BLI_array_reverse(poly_copy, poly_tot);
- }
+ if (poly_reverse) {
+ BLI_array_reverse(poly_copy, poly_tot);
+ }
- for (poly_cycle = 0; poly_cycle < poly_tot; poly_cycle++) {
- // printf("polytest %s ofs=%d, reverse=%d\n", id, poly_cycle, poly_reverse);
- test_polyfill_template_flip_sign(id, is_degenerate, poly, poly_tot, tris, tris_tot);
+ for (poly_cycle = 0; poly_cycle < poly_tot; poly_cycle++) {
+ // printf("polytest %s ofs=%d, reverse=%d\n", id, poly_cycle, poly_reverse);
+ test_polyfill_template_flip_sign(id, is_degenerate, poly, poly_tot, tris, tris_tot);
- /* cycle */
- copy_v2_v2(tmp, poly_copy[0]);
- memmove(&poly_copy[0], &poly_copy[1], (poly_tot - 1) * sizeof(float[2]));
- copy_v2_v2(poly_copy[poly_tot - 1], tmp);
- }
- }
+ /* cycle */
+ copy_v2_v2(tmp, poly_copy[0]);
+ memmove(&poly_copy[0], &poly_copy[1], (poly_tot - 1) * sizeof(float[2]));
+ copy_v2_v2(poly_copy[poly_tot - 1], tmp);
+ }
+ }
- MEM_freeN(poly_copy);
+ MEM_freeN(poly_copy);
}
#else /* USE_COMBINATIONS_ALL */
-static void test_polyfill_template_main(
- const char *id, bool is_degenerate,
- const float poly[][2], const unsigned int poly_tot,
- unsigned int tris[][3], const unsigned int tris_tot)
+static void test_polyfill_template_main(const char *id,
+ bool is_degenerate,
+ const float poly[][2],
+ const unsigned int poly_tot,
+ unsigned int tris[][3],
+ const unsigned int tris_tot)
{
- test_polyfill_template_flip_sign(id, is_degenerate, poly, poly_tot, tris, tris_tot);
+ test_polyfill_template_flip_sign(id, is_degenerate, poly, poly_tot, tris, tris_tot);
}
-#endif /* USE_COMBINATIONS_ALL */
+#endif /* USE_COMBINATIONS_ALL */
#define TEST_POLYFILL_TEMPLATE_STATIC(poly, is_degenerate) \
-{ \
- unsigned int tris[POLY_TRI_COUNT(ARRAY_SIZE(poly))][3]; \
- const unsigned int poly_tot = ARRAY_SIZE(poly); \
- const unsigned int tris_tot = ARRAY_SIZE(tris); \
- const char *id = typeid(*this).name(); \
- \
- test_polyfill_template_main(id, is_degenerate, poly, poly_tot, tris, tris_tot); \
-} (void)0
+ { \
+ unsigned int tris[POLY_TRI_COUNT(ARRAY_SIZE(poly))][3]; \
+ const unsigned int poly_tot = ARRAY_SIZE(poly); \
+ const unsigned int tris_tot = ARRAY_SIZE(tris); \
+ const char *id = typeid(*this).name(); \
+\
+ test_polyfill_template_main(id, is_degenerate, poly, poly_tot, tris, tris_tot); \
+ } \
+ (void)0
/* -------------------------------------------------------------------- */
/* visualisation functions (not needed for testing) */
#ifdef USE_OBJ_PREVIEW
-static void polyfill_to_obj(
- const char *id,
- const float poly[][2], const unsigned int poly_tot,
- const unsigned int tris[][3], const unsigned int tris_tot)
+static void polyfill_to_obj(const char *id,
+ const float poly[][2],
+ const unsigned int poly_tot,
+ const unsigned int tris[][3],
+ const unsigned int tris_tot)
{
- char path[1024];
- FILE *f;
- unsigned int i;
+ char path[1024];
+ FILE *f;
+ unsigned int i;
- BLI_snprintf(path, sizeof(path), "%s.obj", id);
+ BLI_snprintf(path, sizeof(path), "%s.obj", id);
- f = fopen(path, "w");
- if (!f) {
- return;
- }
+ f = fopen(path, "w");
+ if (!f) {
+ return;
+ }
- for (i = 0; i < poly_tot; i++) {
- fprintf(f, "v %f %f 0.0\n", UNPACK2(poly[i]));
- }
+ for (i = 0; i < poly_tot; i++) {
+ fprintf(f, "v %f %f 0.0\n", UNPACK2(poly[i]));
+ }
- for (i = 0; i < tris_tot; i++) {
- fprintf(f, "f %u %u %u\n", UNPACK3_EX(1 +, tris[i], ));
- }
+ for (i = 0; i < tris_tot; i++) {
+ fprintf(f, "f %u %u %u\n", UNPACK3_EX(1 +, tris[i], ));
+ }
- fclose(f);
+ fclose(f);
}
#else
-static void polyfill_to_obj(
- const char *id,
- const float poly[][2], const unsigned int poly_tot,
- const unsigned int tris[][3], const unsigned int tris_tot)
+static void polyfill_to_obj(const char *id,
+ const float poly[][2],
+ const unsigned int poly_tot,
+ const unsigned int tris[][3],
+ const unsigned int tris_tot)
{
- (void)id;
- (void)poly, (void)poly_tot;
- (void)tris, (void)tris_tot;
+ (void)id;
+ (void)poly, (void)poly_tot;
+ (void)tris, (void)tris_tot;
}
-#endif /* USE_OBJ_PREVIEW */
-
+#endif /* USE_OBJ_PREVIEW */
/* -------------------------------------------------------------------- */
/* tests */
@@ -365,227 +377,303 @@ static void polyfill_to_obj(
* \endcode
*/
-#define POLY_TRI_COUNT(len) ((len) - 2)
-
+#define POLY_TRI_COUNT(len) ((len)-2)
/* A counterclockwise triangle */
TEST(polyfill2d, TriangleCCW)
{
- const float poly[][2] = {{0, 0}, {0, 1}, {1, 0}};
- TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
+ const float poly[][2] = {{0, 0}, {0, 1}, {1, 0}};
+ TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
}
/* A counterclockwise square */
TEST(polyfill2d, SquareCCW)
{
- const float poly[][2] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}};
- TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
+ const float poly[][2] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}};
+ TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
}
/* A clockwise square */
TEST(polyfill2d, SquareCW)
{
- const float poly[][2] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
- TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
+ const float poly[][2] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
+ TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
}
/* Starfleet insigna */
TEST(polyfill2d, Starfleet)
{
- const float poly[][2] = {{0, 0}, {0.6f, 0.4f}, {1, 0}, {0.5f, 1}};
- TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
+ const float poly[][2] = {{0, 0}, {0.6f, 0.4f}, {1, 0}, {0.5f, 1}};
+ TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
}
/* Starfleet insigna with repeated point */
TEST(polyfill2d, StarfleetDegenerate)
{
- const float poly[][2] = {{0, 0}, {0.6f, 0.4f}, {0.6f, 0.4f}, {1, 0}, {0.5f, 1}};
- TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
+ const float poly[][2] = {{0, 0}, {0.6f, 0.4f}, {0.6f, 0.4f}, {1, 0}, {0.5f, 1}};
+ TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
}
/* Three collinear points */
TEST(polyfill2d, 3Colinear)
{
- const float poly[][2] = {{0, 0}, {1, 0}, {2, 0}};
- TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
+ const float poly[][2] = {{0, 0}, {1, 0}, {2, 0}};
+ TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
}
/* Four collinear points */
TEST(polyfill2d, 4Colinear)
{
- const float poly[][2] = {{0, 0}, {1, 0}, {2, 0}, {3, 0}};
- TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
+ const float poly[][2] = {{0, 0}, {1, 0}, {2, 0}, {3, 0}};
+ TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
}
/* Non-consecutive collinear points */
TEST(polyfill2d, UnorderedColinear)
{
- const float poly[][2] = {{0, 0}, {1, 1}, {2, 0}, {3, 1}, {4, 0}};
- TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
+ const float poly[][2] = {{0, 0}, {1, 1}, {2, 0}, {3, 1}, {4, 0}};
+ TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
}
/* Plus shape */
TEST(polyfill2d, PlusShape)
{
- const float poly[][2] = {
- {1, 0}, {2, 0}, {2, 1}, {3, 1}, {3, 2}, {2, 2}, {2, 3}, {1, 3}, {1, 2}, {0, 2}, {0, 1}, {1, 1}};
- TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
+ const float poly[][2] = {{1, 0},
+ {2, 0},
+ {2, 1},
+ {3, 1},
+ {3, 2},
+ {2, 2},
+ {2, 3},
+ {1, 3},
+ {1, 2},
+ {0, 2},
+ {0, 1},
+ {1, 1}};
+ TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
}
/* Star shape */
TEST(polyfill2d, StarShape)
{
- const float poly[][2] = {
- {4, 0}, {5, 3}, {8, 4}, {5, 5}, {4, 8}, {3, 5}, {0, 4}, {3, 3}};
- TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
+ const float poly[][2] = {{4, 0}, {5, 3}, {8, 4}, {5, 5}, {4, 8}, {3, 5}, {0, 4}, {3, 3}};
+ TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
}
/* U shape */
TEST(polyfill2d, UShape)
{
- const float poly[][2] = {
- {1, 0}, {2, 0}, {3, 1}, {3, 3}, {2, 3}, {2, 1}, {1, 1}, {1, 3}, {0, 3}, {0, 1}};
- TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
+ const float poly[][2] = {
+ {1, 0}, {2, 0}, {3, 1}, {3, 3}, {2, 3}, {2, 1}, {1, 1}, {1, 3}, {0, 3}, {0, 1}};
+ TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
}
/* Spiral */
TEST(polyfill2d, Spiral)
{
- const float poly[][2] = {
- {1, 0}, {4, 0}, {5, 1}, {5, 4}, {4, 5}, {1, 5}, {0, 4}, {0, 3},
- {1, 2}, {2, 2}, {3, 3}, {1, 3}, {1, 4}, {4, 4}, {4, 1}, {0, 1}};
- TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
+ const float poly[][2] = {{1, 0},
+ {4, 0},
+ {5, 1},
+ {5, 4},
+ {4, 5},
+ {1, 5},
+ {0, 4},
+ {0, 3},
+ {1, 2},
+ {2, 2},
+ {3, 3},
+ {1, 3},
+ {1, 4},
+ {4, 4},
+ {4, 1},
+ {0, 1}};
+ TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
}
/* Test case from http:# www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml */
TEST(polyfill2d, TestFlipCode)
{
- const float poly[][2] = {
- {0, 6}, {0, 0}, {3, 0}, {4, 1}, {6, 1}, {8, 0}, {12, 0}, {13, 2},
- {8, 2}, {8, 4}, {11, 4}, {11, 6}, {6, 6}, {4, 3}, {2, 6}};
- TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
+ const float poly[][2] = {{0, 6},
+ {0, 0},
+ {3, 0},
+ {4, 1},
+ {6, 1},
+ {8, 0},
+ {12, 0},
+ {13, 2},
+ {8, 2},
+ {8, 4},
+ {11, 4},
+ {11, 6},
+ {6, 6},
+ {4, 3},
+ {2, 6}};
+ TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
}
/* Self-intersection */
TEST(polyfill2d, SelfIntersect)
{
- const float poly[][2] = {{0, 0}, {1, 1}, {2, -1}, {3, 1}, {4, 0}};
- TEST_POLYFILL_TEMPLATE_STATIC(poly, true);
+ const float poly[][2] = {{0, 0}, {1, 1}, {2, -1}, {3, 1}, {4, 0}};
+ TEST_POLYFILL_TEMPLATE_STATIC(poly, true);
}
/* Self-touching */
TEST(polyfill2d, SelfTouch)
{
- const float poly[][2] = {
- {0, 0}, {4, 0}, {4, 4}, {2, 4}, {2, 3}, {3, 3}, {3, 1}, {1, 1}, {1, 3}, {2, 3}, {2, 4}, {0, 4}};
- TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
+ const float poly[][2] = {{0, 0},
+ {4, 0},
+ {4, 4},
+ {2, 4},
+ {2, 3},
+ {3, 3},
+ {3, 1},
+ {1, 1},
+ {1, 3},
+ {2, 3},
+ {2, 4},
+ {0, 4}};
+ TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
}
/* Self-overlapping */
TEST(polyfill2d, SelfOverlap)
{
- const float poly[][2] = {
- {0, 0}, {4, 0}, {4, 4}, {1, 4}, {1, 3}, {3, 3}, {3, 1}, {1, 1}, {1, 3}, {3, 3}, {3, 4}, {0, 4}};
- TEST_POLYFILL_TEMPLATE_STATIC(poly, true);
+ const float poly[][2] = {{0, 0},
+ {4, 0},
+ {4, 4},
+ {1, 4},
+ {1, 3},
+ {3, 3},
+ {3, 1},
+ {1, 1},
+ {1, 3},
+ {3, 3},
+ {3, 4},
+ {0, 4}};
+ TEST_POLYFILL_TEMPLATE_STATIC(poly, true);
}
/* Test case from http:# www.davdata.nl/math/polygons.html */
TEST(polyfill2d, TestDavData)
{
- const float poly[][2] = {
- {190, 480}, {140, 180}, {310, 100}, {330, 390}, {290, 390}, {280, 260}, {220, 260}, {220, 430}, {370, 430},
- {350, 30}, {50, 30}, {160, 560}, {730, 510}, {710, 20}, {410, 30}, {470, 440}, {640, 410}, {630, 140},
- {590, 140}, {580, 360}, {510, 370}, {510, 60}, {650, 70}, {660, 450}, {190, 480}};
- TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
+ const float poly[][2] = {{190, 480}, {140, 180}, {310, 100}, {330, 390}, {290, 390},
+ {280, 260}, {220, 260}, {220, 430}, {370, 430}, {350, 30},
+ {50, 30}, {160, 560}, {730, 510}, {710, 20}, {410, 30},
+ {470, 440}, {640, 410}, {630, 140}, {590, 140}, {580, 360},
+ {510, 370}, {510, 60}, {650, 70}, {660, 450}, {190, 480}};
+ TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
}
/* Issue 815, http:# code.google.com/p/libgdx/issues/detail?id=815 */
TEST(polyfill2d, Issue815)
{
- const float poly[][2] = {
- {-2.0f, 0.0f}, {-2.0f, 0.5f}, {0.0f, 1.0f}, {0.5f, 2.875f},
- {1.0f, 0.5f}, {1.5f, 1.0f}, {2.0f, 1.0f}, {2.0f, 0.0f}};
- TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
+ const float poly[][2] = {{-2.0f, 0.0f},
+ {-2.0f, 0.5f},
+ {0.0f, 1.0f},
+ {0.5f, 2.875f},
+ {1.0f, 0.5f},
+ {1.5f, 1.0f},
+ {2.0f, 1.0f},
+ {2.0f, 0.0f}};
+ TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
}
/* Issue 207, comment #1, http:# code.google.com/p/libgdx/issues/detail?id=207#c1 */
TEST(polyfill2d, Issue207_1)
{
- const float poly[][2] = {
- {72.42465f, 197.07095f}, {78.485535f, 189.92776f}, {86.12059f, 180.92929f}, {99.68253f, 164.94557f},
- {105.24325f, 165.79604f}, {107.21862f, 166.09814f}, {112.41958f, 162.78253f}, {113.73238f, 161.94562f},
- {123.29477f, 167.93805f}, {126.70667f, 170.07617f}, {73.22717f, 199.51062f}};
- TEST_POLYFILL_TEMPLATE_STATIC(poly, true);
+ const float poly[][2] = {{72.42465f, 197.07095f},
+ {78.485535f, 189.92776f},
+ {86.12059f, 180.92929f},
+ {99.68253f, 164.94557f},
+ {105.24325f, 165.79604f},
+ {107.21862f, 166.09814f},
+ {112.41958f, 162.78253f},
+ {113.73238f, 161.94562f},
+ {123.29477f, 167.93805f},
+ {126.70667f, 170.07617f},
+ {73.22717f, 199.51062f}};
+ TEST_POLYFILL_TEMPLATE_STATIC(poly, true);
}
/* Issue 207, comment #11, http:# code.google.com/p/libgdx/issues/detail?id=207#c11 */
/* Also on issue 1081, http:# code.google.com/p/libgdx/issues/detail?id=1081 */
TEST(polyfill2d, Issue207_11)
{
- const float poly[][2] = {
- {2400.0f, 480.0f}, {2400.0f, 176.0f}, {1920.0f, 480.0f}, {1920.0459f, 484.22314f},
- {1920.1797f, 487.91016f}, {1920.3955f, 491.0874f}, {1920.6875f, 493.78125f}, {1921.0498f, 496.01807f},
- {1921.4766f, 497.82422f}, {1921.9619f, 499.22607f}, {1922.5f, 500.25f}, {1923.085f, 500.92236f},
- {1923.7109f, 501.26953f}, {1924.3721f, 501.31787f}, {1925.0625f, 501.09375f}, {1925.7764f, 500.62354f},
- {1926.5078f, 499.9336f}, {1927.251f, 499.0503f}, {1928.0f, 498.0f}, {1928.749f, 496.80908f},
- {1929.4922f, 495.5039f}, {1930.2236f, 494.11084f}, {1930.9375f, 492.65625f}, {1931.6279f, 491.1665f},
- {1932.2891f, 489.66797f}, {1932.915f, 488.187f}, {1933.5f, 486.75f}, {1934.0381f, 485.3833f},
- {1934.5234f, 484.11328f}, {1934.9502f, 482.9663f}, {1935.3125f, 481.96875f}, {1935.6045f, 481.14697f},
- {1935.8203f, 480.52734f}, {1935.9541f, 480.13623f}, {1936.0f, 480.0f}};
- TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
+ const float poly[][2] = {
+ {2400.0f, 480.0f}, {2400.0f, 176.0f}, {1920.0f, 480.0f},
+ {1920.0459f, 484.22314f}, {1920.1797f, 487.91016f}, {1920.3955f, 491.0874f},
+ {1920.6875f, 493.78125f}, {1921.0498f, 496.01807f}, {1921.4766f, 497.82422f},
+ {1921.9619f, 499.22607f}, {1922.5f, 500.25f}, {1923.085f, 500.92236f},
+ {1923.7109f, 501.26953f}, {1924.3721f, 501.31787f}, {1925.0625f, 501.09375f},
+ {1925.7764f, 500.62354f}, {1926.5078f, 499.9336f}, {1927.251f, 499.0503f},
+ {1928.0f, 498.0f}, {1928.749f, 496.80908f}, {1929.4922f, 495.5039f},
+ {1930.2236f, 494.11084f}, {1930.9375f, 492.65625f}, {1931.6279f, 491.1665f},
+ {1932.2891f, 489.66797f}, {1932.915f, 488.187f}, {1933.5f, 486.75f},
+ {1934.0381f, 485.3833f}, {1934.5234f, 484.11328f}, {1934.9502f, 482.9663f},
+ {1935.3125f, 481.96875f}, {1935.6045f, 481.14697f}, {1935.8203f, 480.52734f},
+ {1935.9541f, 480.13623f}, {1936.0f, 480.0f}};
+ TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
}
/* Issue 1407, http:# code.google.com/p/libgdx/issues/detail?id=1407 */
TEST(polyfill2d, Issue1407)
{
- const float poly[][2] = {
- {3.914329f, 1.9008259f}, {4.414321f, 1.903619f}, {4.8973203f, 1.9063174f}, {5.4979978f, 1.9096732f}};
- TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
+ const float poly[][2] = {{3.914329f, 1.9008259f},
+ {4.414321f, 1.903619f},
+ {4.8973203f, 1.9063174f},
+ {5.4979978f, 1.9096732f}};
+ TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
}
/* Issue 1407, http:# code.google.com/p/libgdx/issues/detail?id=1407, */
/* with an additional point to show what is happening. */
TEST(polyfill2d, Issue1407_pt)
{
- const float poly[][2] = {
- {3.914329f, 1.9008259f}, {4.414321f, 1.903619f}, {4.8973203f, 1.9063174f}, {5.4979978f, 1.9096732f}, {4, 4}};
- TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
+ const float poly[][2] = {{3.914329f, 1.9008259f},
+ {4.414321f, 1.903619f},
+ {4.8973203f, 1.9063174f},
+ {5.4979978f, 1.9096732f},
+ {4, 4}};
+ TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
}
/* Simplified from Blender bug T40777 */
TEST(polyfill2d, IssueT40777_colinear)
{
- const float poly[][2] = {
- {0.7, 0.37}, {0.7, 0}, {0.76, 0}, {0.76, 0.4}, {0.83, 0.4}, {0.83, 0}, {0.88, 0}, {0.88, 0.4},
- {0.94, 0.4}, {0.94, 0}, {1, 0}, {1, 0.4}, {0.03, 0.62}, {0.03, 0.89}, {0.59, 0.89}, {0.03, 1},
- {0, 1}, {0, 0}, {0.03, 0}, {0.03, 0.37}};
- TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
+ const float poly[][2] = {{0.7, 0.37}, {0.7, 0}, {0.76, 0}, {0.76, 0.4}, {0.83, 0.4},
+ {0.83, 0}, {0.88, 0}, {0.88, 0.4}, {0.94, 0.4}, {0.94, 0},
+ {1, 0}, {1, 0.4}, {0.03, 0.62}, {0.03, 0.89}, {0.59, 0.89},
+ {0.03, 1}, {0, 1}, {0, 0}, {0.03, 0}, {0.03, 0.37}};
+ TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
}
/* Blender bug T41986 */
TEST(polyfill2d, IssueT41986_axis_align)
{
- const float poly[][2] = {
- {-0.25, -0.07}, {-0.25, 0.27}, {-1.19, 0.14}, {-0.06, 0.73}, {0.17, 1.25}, {-0.25, 1.07},
- {-0.38, 1.02}, {-0.25, 0.94}, {-0.40, 0.90}, {-0.41, 0.86}, {-0.34, 0.83}, {-0.25, 0.82},
- {-0.66, 0.73}, {-0.56, 1.09}, {-0.25, 1.10}, {0.00, 1.31}, {-0.03, 1.47}, {-0.25, 1.53},
- {0.12, 1.62}, {0.36, 1.07}, {0.12, 0.67}, {0.29, 0.57}, {0.44, 0.45}, {0.57, 0.29},
- {0.66, 0.12}, {0.68, 0.06}, {0.57, -0.36}, {-0.25, -0.37}, {0.49, -0.74}, {-0.59, -1.21},
- {-0.25, -0.15}, {-0.46, -0.52}, {-1.08, -0.83}, {-1.45, -0.33}, {-1.25, -0.04}};
+ const float poly[][2] = {
+ {-0.25, -0.07}, {-0.25, 0.27}, {-1.19, 0.14}, {-0.06, 0.73}, {0.17, 1.25},
+ {-0.25, 1.07}, {-0.38, 1.02}, {-0.25, 0.94}, {-0.40, 0.90}, {-0.41, 0.86},
+ {-0.34, 0.83}, {-0.25, 0.82}, {-0.66, 0.73}, {-0.56, 1.09}, {-0.25, 1.10},
+ {0.00, 1.31}, {-0.03, 1.47}, {-0.25, 1.53}, {0.12, 1.62}, {0.36, 1.07},
+ {0.12, 0.67}, {0.29, 0.57}, {0.44, 0.45}, {0.57, 0.29}, {0.66, 0.12},
+ {0.68, 0.06}, {0.57, -0.36}, {-0.25, -0.37}, {0.49, -0.74}, {-0.59, -1.21},
+ {-0.25, -0.15}, {-0.46, -0.52}, {-1.08, -0.83}, {-1.45, -0.33}, {-1.25, -0.04}};
- TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
+ TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
}
/* Blender bug T52834 */
TEST(polyfill2d, IssueT52834_axis_align_co_linear)
{
- const float poly[][2] = {
- {40, 0}, {36, 0}, {36, 5}, {35, 5}, {35, 0}, {30, 0}, {30, 5}, {29, 5}, {29, 0}, {24, 0}, {24, 3},
- {23, 4}, {23, 0}, {18, 0}, {18, 5}, {17, 5}, {17, 0}, {12, 0}, {12, 5}, {11, 5}, {11, 0}, {6, 0},
- {6, 5}, {5, 5}, {5, 0}, {0, 0}, {0, 5}, {-1, 5}, {-1, 0}, {-6, 0}, {-9, -3}, {-6, -3}, {-6, -2},
- {-1, -2}, {0, -2}, {5, -2}, {6, -2}, {11, -2}, {12, -2}, {17, -2}, {18, -2}, {23, -2}, {24, -2},
- {29, -2}, {30, -2}, {35, -2}, {36, -2}, {40, -2},
- };
+ const float poly[][2] = {
+ {40, 0}, {36, 0}, {36, 5}, {35, 5}, {35, 0}, {30, 0}, {30, 5}, {29, 5},
+ {29, 0}, {24, 0}, {24, 3}, {23, 4}, {23, 0}, {18, 0}, {18, 5}, {17, 5},
+ {17, 0}, {12, 0}, {12, 5}, {11, 5}, {11, 0}, {6, 0}, {6, 5}, {5, 5},
+ {5, 0}, {0, 0}, {0, 5}, {-1, 5}, {-1, 0}, {-6, 0}, {-9, -3}, {-6, -3},
+ {-6, -2}, {-1, -2}, {0, -2}, {5, -2}, {6, -2}, {11, -2}, {12, -2}, {17, -2},
+ {18, -2}, {23, -2}, {24, -2}, {29, -2}, {30, -2}, {35, -2}, {36, -2}, {40, -2},
+ };
- TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
+ TEST_POLYFILL_TEMPLATE_STATIC(poly, false);
}
diff --git a/tests/gtests/blenlib/BLI_ressource_strings.h b/tests/gtests/blenlib/BLI_ressource_strings.h
index da28a05d7ea..119aaeb0036 100644
--- a/tests/gtests/blenlib/BLI_ressource_strings.h
+++ b/tests/gtests/blenlib/BLI_ressource_strings.h
@@ -607,4 +607,4 @@ const char words10k[] =
/* clang-format on */
-#endif /* __BLENDER_TESTING_BLI_RESSOURCE_STRING_H__ */
+#endif /* __BLENDER_TESTING_BLI_RESSOURCE_STRING_H__ */
diff --git a/tests/gtests/blenlib/BLI_stack_test.cc b/tests/gtests/blenlib/BLI_stack_test.cc
index 18188937355..a3fd5efadf0 100644
--- a/tests/gtests/blenlib/BLI_stack_test.cc
+++ b/tests/gtests/blenlib/BLI_stack_test.cc
@@ -15,209 +15,204 @@ extern "C" {
#define STACK_CHUNK_SIZE 8
/* Ensure block size is set to #STACK_NEW_EX_ARGS */
-#define BLI_stack_new(esize, descr) \
- BLI_stack_new_ex(esize, descr, esize * STACK_CHUNK_SIZE)
-
+#define BLI_stack_new(esize, descr) BLI_stack_new_ex(esize, descr, esize *STACK_CHUNK_SIZE)
TEST(stack, Empty)
{
- BLI_Stack *stack;
+ BLI_Stack *stack;
- stack = BLI_stack_new(sizeof(int), __func__);
- EXPECT_TRUE(BLI_stack_is_empty(stack));
- EXPECT_EQ(BLI_stack_count(stack), 0);
- BLI_stack_free(stack);
+ stack = BLI_stack_new(sizeof(int), __func__);
+ EXPECT_TRUE(BLI_stack_is_empty(stack));
+ EXPECT_EQ(BLI_stack_count(stack), 0);
+ BLI_stack_free(stack);
}
TEST(stack, One)
{
- BLI_Stack *stack;
- unsigned int in = -1, out = 1;
-
- stack = BLI_stack_new(sizeof(in), __func__);
-
- BLI_stack_push(stack, (void *)&in);
- EXPECT_FALSE(BLI_stack_is_empty(stack));
- EXPECT_EQ(BLI_stack_count(stack), 1);
- BLI_stack_pop(stack, (void *)&out);
- EXPECT_EQ(out, in);
- EXPECT_TRUE(BLI_stack_is_empty(stack));
- EXPECT_EQ(BLI_stack_count(stack), 0);
- BLI_stack_free(stack);
+ BLI_Stack *stack;
+ unsigned int in = -1, out = 1;
+
+ stack = BLI_stack_new(sizeof(in), __func__);
+
+ BLI_stack_push(stack, (void *)&in);
+ EXPECT_FALSE(BLI_stack_is_empty(stack));
+ EXPECT_EQ(BLI_stack_count(stack), 1);
+ BLI_stack_pop(stack, (void *)&out);
+ EXPECT_EQ(out, in);
+ EXPECT_TRUE(BLI_stack_is_empty(stack));
+ EXPECT_EQ(BLI_stack_count(stack), 0);
+ BLI_stack_free(stack);
}
TEST(stack, Range)
{
- const int tot = SIZE;
- BLI_Stack *stack;
- int in, out;
-
- stack = BLI_stack_new(sizeof(in), __func__);
+ const int tot = SIZE;
+ BLI_Stack *stack;
+ int in, out;
- for (in = 0; in < tot; in++) {
- BLI_stack_push(stack, (void *)&in);
- }
+ stack = BLI_stack_new(sizeof(in), __func__);
- for (in = tot - 1; in >= 0; in--) {
- EXPECT_FALSE(BLI_stack_is_empty(stack));
- BLI_stack_pop(stack, (void *)&out);
- EXPECT_EQ(out, in);
+ for (in = 0; in < tot; in++) {
+ BLI_stack_push(stack, (void *)&in);
+ }
- }
- EXPECT_TRUE(BLI_stack_is_empty(stack));
+ for (in = tot - 1; in >= 0; in--) {
+ EXPECT_FALSE(BLI_stack_is_empty(stack));
+ BLI_stack_pop(stack, (void *)&out);
+ EXPECT_EQ(out, in);
+ }
+ EXPECT_TRUE(BLI_stack_is_empty(stack));
- BLI_stack_free(stack);
+ BLI_stack_free(stack);
}
TEST(stack, String)
{
- const int tot = SIZE;
- int i;
+ const int tot = SIZE;
+ int i;
- BLI_Stack *stack;
- char in[] = "hello world!";
- char out[sizeof(in)];
+ BLI_Stack *stack;
+ char in[] = "hello world!";
+ char out[sizeof(in)];
- stack = BLI_stack_new(sizeof(in), __func__);
+ stack = BLI_stack_new(sizeof(in), __func__);
- for (i = 0; i < tot; i++) {
- *((int *)in) = i;
- BLI_stack_push(stack, (void *)in);
- }
+ for (i = 0; i < tot; i++) {
+ *((int *)in) = i;
+ BLI_stack_push(stack, (void *)in);
+ }
- for (i = tot - 1; i >= 0; i--) {
- EXPECT_FALSE(BLI_stack_is_empty(stack));
- *((int *)in) = i;
- BLI_stack_pop(stack, (void *)&out);
- EXPECT_STREQ(in, out);
- }
- EXPECT_TRUE(BLI_stack_is_empty(stack));
+ for (i = tot - 1; i >= 0; i--) {
+ EXPECT_FALSE(BLI_stack_is_empty(stack));
+ *((int *)in) = i;
+ BLI_stack_pop(stack, (void *)&out);
+ EXPECT_STREQ(in, out);
+ }
+ EXPECT_TRUE(BLI_stack_is_empty(stack));
- BLI_stack_free(stack);
+ BLI_stack_free(stack);
}
TEST(stack, Peek)
{
- const int tot = SIZE;
- int i;
+ const int tot = SIZE;
+ int i;
- BLI_Stack *stack;
- const short in[] = {1, 10, 100, 1000};
+ BLI_Stack *stack;
+ const short in[] = {1, 10, 100, 1000};
- stack = BLI_stack_new(sizeof(*in), __func__);
+ stack = BLI_stack_new(sizeof(*in), __func__);
- for (i = 0; i < tot; i++) {
- BLI_stack_push(stack, &in[i % ARRAY_SIZE(in)]);
- }
+ for (i = 0; i < tot; i++) {
+ BLI_stack_push(stack, &in[i % ARRAY_SIZE(in)]);
+ }
- for (i = tot - 1; i >= 0; i--, BLI_stack_discard(stack)) {
- short *ret = (short *)BLI_stack_peek(stack);
- EXPECT_EQ(*ret, in[i % ARRAY_SIZE(in)]);
- }
+ for (i = tot - 1; i >= 0; i--, BLI_stack_discard(stack)) {
+ short *ret = (short *)BLI_stack_peek(stack);
+ EXPECT_EQ(*ret, in[i % ARRAY_SIZE(in)]);
+ }
- EXPECT_TRUE(BLI_stack_is_empty(stack));
+ EXPECT_TRUE(BLI_stack_is_empty(stack));
- BLI_stack_free(stack);
+ BLI_stack_free(stack);
}
/* Check that clearing the stack leaves in it a correct state. */
TEST(stack, Clear)
{
- const int tot_rerun = 4;
- int rerun;
+ const int tot_rerun = 4;
+ int rerun;
- /* based on range test */
- int tot = SIZE;
- BLI_Stack *stack;
- int in, out;
+ /* based on range test */
+ int tot = SIZE;
+ BLI_Stack *stack;
+ int in, out;
- /* use a small chunk size to ensure we test */
- stack = BLI_stack_new(sizeof(in), __func__);
+ /* use a small chunk size to ensure we test */
+ stack = BLI_stack_new(sizeof(in), __func__);
- for (rerun = 0; rerun < tot_rerun; rerun++) {
- for (in = 0; in < tot; in++) {
- BLI_stack_push(stack, (void *)&in);
- }
+ for (rerun = 0; rerun < tot_rerun; rerun++) {
+ for (in = 0; in < tot; in++) {
+ BLI_stack_push(stack, (void *)&in);
+ }
- BLI_stack_clear(stack);
- EXPECT_TRUE(BLI_stack_is_empty(stack));
+ BLI_stack_clear(stack);
+ EXPECT_TRUE(BLI_stack_is_empty(stack));
- /* and again, this time check its valid */
- for (in = 0; in < tot; in++) {
- BLI_stack_push(stack, (void *)&in);
- }
+ /* and again, this time check its valid */
+ for (in = 0; in < tot; in++) {
+ BLI_stack_push(stack, (void *)&in);
+ }
- for (in = tot - 1; in >= 0; in--) {
- EXPECT_FALSE(BLI_stack_is_empty(stack));
- BLI_stack_pop(stack, (void *)&out);
- EXPECT_EQ(out, in);
- }
+ for (in = tot - 1; in >= 0; in--) {
+ EXPECT_FALSE(BLI_stack_is_empty(stack));
+ BLI_stack_pop(stack, (void *)&out);
+ EXPECT_EQ(out, in);
+ }
- EXPECT_TRUE(BLI_stack_is_empty(stack));
+ EXPECT_TRUE(BLI_stack_is_empty(stack));
- /* without this, we wont test case when mixed free/used */
- tot /= 2;
- }
+ /* without this, we wont test case when mixed free/used */
+ tot /= 2;
+ }
- BLI_stack_free(stack);
+ BLI_stack_free(stack);
}
-
TEST(stack, Reuse)
{
- const int sizes[] = {3, 11, 81, 400, 999, 12, 1, 9721, 7, 99, 5, 0};
- int sizes_test[ARRAY_SIZE(sizes)];
- const int *s;
- int out, i;
- int sum, sum_test;
-
- BLI_Stack *stack;
-
- stack = BLI_stack_new(sizeof(i), __func__);
-
- /* add a bunch of numbers, ensure we get same sum out */
- sum = 0;
- for (s = sizes; *s; s++) {
- for (i = *s; i != 0; i--) {
- BLI_stack_push(stack, (void *)&i);
- sum += i;
- }
- }
- sum_test = 0;
- while (!BLI_stack_is_empty(stack)) {
- BLI_stack_pop(stack, (void *)&out);
- sum_test += out;
- }
- EXPECT_EQ(sum, sum_test);
-
- /* add and remove all except last */
- for (s = sizes; *s; s++) {
- for (i = *s; i >= 0; i--) {
- BLI_stack_push(stack, (void *)&i);
- }
- for (i = *s; i > 0; i--) {
- BLI_stack_pop(stack, (void *)&out);
- }
- }
-
- i = ARRAY_SIZE(sizes) - 1;
- while (!BLI_stack_is_empty(stack)) {
- i--;
- BLI_stack_pop(stack, (void *)&sizes_test[i]);
- EXPECT_EQ(sizes_test[i], sizes[i]);
- EXPECT_GT(i, -1);
- }
- EXPECT_EQ(0, i);
- EXPECT_EQ(memcmp(sizes, sizes_test, sizeof(sizes) - sizeof(int)), 0);
-
-
- /* finally test BLI_stack_pop_n */
- for (i = ARRAY_SIZE(sizes); i--; ) {
- BLI_stack_push(stack, (void *)&sizes[i]);
- }
- EXPECT_EQ(BLI_stack_count(stack), ARRAY_SIZE(sizes));
- BLI_stack_pop_n(stack, (void *)sizes_test, ARRAY_SIZE(sizes));
- EXPECT_EQ(memcmp(sizes, sizes_test, sizeof(sizes) - sizeof(int)), 0);
-
- BLI_stack_free(stack);
+ const int sizes[] = {3, 11, 81, 400, 999, 12, 1, 9721, 7, 99, 5, 0};
+ int sizes_test[ARRAY_SIZE(sizes)];
+ const int *s;
+ int out, i;
+ int sum, sum_test;
+
+ BLI_Stack *stack;
+
+ stack = BLI_stack_new(sizeof(i), __func__);
+
+ /* add a bunch of numbers, ensure we get same sum out */
+ sum = 0;
+ for (s = sizes; *s; s++) {
+ for (i = *s; i != 0; i--) {
+ BLI_stack_push(stack, (void *)&i);
+ sum += i;
+ }
+ }
+ sum_test = 0;
+ while (!BLI_stack_is_empty(stack)) {
+ BLI_stack_pop(stack, (void *)&out);
+ sum_test += out;
+ }
+ EXPECT_EQ(sum, sum_test);
+
+ /* add and remove all except last */
+ for (s = sizes; *s; s++) {
+ for (i = *s; i >= 0; i--) {
+ BLI_stack_push(stack, (void *)&i);
+ }
+ for (i = *s; i > 0; i--) {
+ BLI_stack_pop(stack, (void *)&out);
+ }
+ }
+
+ i = ARRAY_SIZE(sizes) - 1;
+ while (!BLI_stack_is_empty(stack)) {
+ i--;
+ BLI_stack_pop(stack, (void *)&sizes_test[i]);
+ EXPECT_EQ(sizes_test[i], sizes[i]);
+ EXPECT_GT(i, -1);
+ }
+ EXPECT_EQ(0, i);
+ EXPECT_EQ(memcmp(sizes, sizes_test, sizeof(sizes) - sizeof(int)), 0);
+
+ /* finally test BLI_stack_pop_n */
+ for (i = ARRAY_SIZE(sizes); i--;) {
+ BLI_stack_push(stack, (void *)&sizes[i]);
+ }
+ EXPECT_EQ(BLI_stack_count(stack), ARRAY_SIZE(sizes));
+ BLI_stack_pop_n(stack, (void *)sizes_test, ARRAY_SIZE(sizes));
+ EXPECT_EQ(memcmp(sizes, sizes_test, sizeof(sizes) - sizeof(int)), 0);
+
+ BLI_stack_free(stack);
}
diff --git a/tests/gtests/blenlib/BLI_string_test.cc b/tests/gtests/blenlib/BLI_string_test.cc
index d295b287715..8ce9a8c8f0a 100644
--- a/tests/gtests/blenlib/BLI_string_test.cc
+++ b/tests/gtests/blenlib/BLI_string_test.cc
@@ -16,8 +16,8 @@ extern "C" {
using std::initializer_list;
using std::pair;
-using std::vector;
using std::string;
+using std::vector;
/* -------------------------------------------------------------------- */
/* stubs */
@@ -29,553 +29,561 @@ int mk_wcswidth(const wchar_t *pwcs, size_t n);
int mk_wcwidth(wchar_t ucs)
{
- return 0;
+ return 0;
}
int mk_wcswidth(const wchar_t *pwcs, size_t n)
{
- return 0;
+ return 0;
}
-
}
-
/* -------------------------------------------------------------------- */
/* tests */
/* BLI_str_partition */
TEST(string, StrPartition)
{
- const char delim[] = {'-', '.', '_', '~', '\\', '\0'};
- const char *sep, *suf;
- size_t pre_ln;
-
- {
- const char *str = "mat.e-r_ial";
-
- /* "mat.e-r_ial" -> "mat", '.', "e-r_ial", 3 */
- pre_ln = BLI_str_partition(str, delim, &sep, &suf);
- EXPECT_EQ(pre_ln, 3);
- EXPECT_EQ(&str[3], sep);
- EXPECT_STREQ("e-r_ial", suf);
- }
-
- /* Corner cases. */
- {
- const char *str = ".mate-rial--";
-
- /* ".mate-rial--" -> "", '.', "mate-rial--", 0 */
- pre_ln = BLI_str_partition(str, delim, &sep, &suf);
- EXPECT_EQ(pre_ln, 0);
- EXPECT_EQ(&str[0], sep);
- EXPECT_STREQ("mate-rial--", suf);
- }
-
- {
- const char *str = ".__.--_";
-
- /* ".__.--_" -> "", '.', "__.--_", 0 */
- pre_ln = BLI_str_partition(str, delim, &sep, &suf);
- EXPECT_EQ(pre_ln, 0);
- EXPECT_EQ(&str[0], sep);
- EXPECT_STREQ("__.--_", suf);
- }
-
- {
- const char *str = "";
-
- /* "" -> "", NULL, NULL, 0 */
- pre_ln = BLI_str_partition(str, delim, &sep, &suf);
- EXPECT_EQ(pre_ln, 0);
- EXPECT_EQ(sep, (void*)NULL);
- EXPECT_EQ(suf, (void*)NULL);
- }
-
- {
- const char *str = "material";
-
- /* "material" -> "material", NULL, NULL, 8 */
- pre_ln = BLI_str_partition(str, delim, &sep, &suf);
- EXPECT_EQ(pre_ln, 8);
- EXPECT_EQ(sep, (void*)NULL);
- EXPECT_EQ(suf, (void*)NULL);
- }
+ const char delim[] = {'-', '.', '_', '~', '\\', '\0'};
+ const char *sep, *suf;
+ size_t pre_ln;
+
+ {
+ const char *str = "mat.e-r_ial";
+
+ /* "mat.e-r_ial" -> "mat", '.', "e-r_ial", 3 */
+ pre_ln = BLI_str_partition(str, delim, &sep, &suf);
+ EXPECT_EQ(pre_ln, 3);
+ EXPECT_EQ(&str[3], sep);
+ EXPECT_STREQ("e-r_ial", suf);
+ }
+
+ /* Corner cases. */
+ {
+ const char *str = ".mate-rial--";
+
+ /* ".mate-rial--" -> "", '.', "mate-rial--", 0 */
+ pre_ln = BLI_str_partition(str, delim, &sep, &suf);
+ EXPECT_EQ(pre_ln, 0);
+ EXPECT_EQ(&str[0], sep);
+ EXPECT_STREQ("mate-rial--", suf);
+ }
+
+ {
+ const char *str = ".__.--_";
+
+ /* ".__.--_" -> "", '.', "__.--_", 0 */
+ pre_ln = BLI_str_partition(str, delim, &sep, &suf);
+ EXPECT_EQ(pre_ln, 0);
+ EXPECT_EQ(&str[0], sep);
+ EXPECT_STREQ("__.--_", suf);
+ }
+
+ {
+ const char *str = "";
+
+ /* "" -> "", NULL, NULL, 0 */
+ pre_ln = BLI_str_partition(str, delim, &sep, &suf);
+ EXPECT_EQ(pre_ln, 0);
+ EXPECT_EQ(sep, (void *)NULL);
+ EXPECT_EQ(suf, (void *)NULL);
+ }
+
+ {
+ const char *str = "material";
+
+ /* "material" -> "material", NULL, NULL, 8 */
+ pre_ln = BLI_str_partition(str, delim, &sep, &suf);
+ EXPECT_EQ(pre_ln, 8);
+ EXPECT_EQ(sep, (void *)NULL);
+ EXPECT_EQ(suf, (void *)NULL);
+ }
}
/* BLI_str_rpartition */
TEST(string, StrRPartition)
{
- const char delim[] = {'-', '.', '_', '~', '\\', '\0'};
- const char *sep, *suf;
- size_t pre_ln;
-
- {
- const char *str = "mat.e-r_ial";
-
- /* "mat.e-r_ial" -> "mat.e-r", '_', "ial", 7 */
- pre_ln = BLI_str_rpartition(str, delim, &sep, &suf);
- EXPECT_EQ(pre_ln, 7);
- EXPECT_EQ(&str[7], sep);
- EXPECT_STREQ("ial", suf);
- }
-
- /* Corner cases. */
- {
- const char *str = ".mate-rial--";
-
- /* ".mate-rial--" -> ".mate-rial-", '-', "", 11 */
- pre_ln = BLI_str_rpartition(str, delim, &sep, &suf);
- EXPECT_EQ(pre_ln, 11);
- EXPECT_EQ(&str[11], sep);
- EXPECT_STREQ("", suf);
- }
-
- {
- const char *str = ".__.--_";
-
- /* ".__.--_" -> ".__.--", '_', "", 6 */
- pre_ln = BLI_str_rpartition(str, delim, &sep, &suf);
- EXPECT_EQ(pre_ln, 6);
- EXPECT_EQ(&str[6], sep);
- EXPECT_STREQ("", suf);
- }
-
- {
- const char *str = "";
-
- /* "" -> "", NULL, NULL, 0 */
- pre_ln = BLI_str_rpartition(str, delim, &sep, &suf);
- EXPECT_EQ(pre_ln, 0);
- EXPECT_EQ(sep, (void*)NULL);
- EXPECT_EQ(suf, (void*)NULL);
- }
-
- {
- const char *str = "material";
-
- /* "material" -> "material", NULL, NULL, 8 */
- pre_ln = BLI_str_rpartition(str, delim, &sep, &suf);
- EXPECT_EQ(pre_ln, 8);
- EXPECT_EQ(sep, (void*)NULL);
- EXPECT_EQ(suf, (void*)NULL);
- }
+ const char delim[] = {'-', '.', '_', '~', '\\', '\0'};
+ const char *sep, *suf;
+ size_t pre_ln;
+
+ {
+ const char *str = "mat.e-r_ial";
+
+ /* "mat.e-r_ial" -> "mat.e-r", '_', "ial", 7 */
+ pre_ln = BLI_str_rpartition(str, delim, &sep, &suf);
+ EXPECT_EQ(pre_ln, 7);
+ EXPECT_EQ(&str[7], sep);
+ EXPECT_STREQ("ial", suf);
+ }
+
+ /* Corner cases. */
+ {
+ const char *str = ".mate-rial--";
+
+ /* ".mate-rial--" -> ".mate-rial-", '-', "", 11 */
+ pre_ln = BLI_str_rpartition(str, delim, &sep, &suf);
+ EXPECT_EQ(pre_ln, 11);
+ EXPECT_EQ(&str[11], sep);
+ EXPECT_STREQ("", suf);
+ }
+
+ {
+ const char *str = ".__.--_";
+
+ /* ".__.--_" -> ".__.--", '_', "", 6 */
+ pre_ln = BLI_str_rpartition(str, delim, &sep, &suf);
+ EXPECT_EQ(pre_ln, 6);
+ EXPECT_EQ(&str[6], sep);
+ EXPECT_STREQ("", suf);
+ }
+
+ {
+ const char *str = "";
+
+ /* "" -> "", NULL, NULL, 0 */
+ pre_ln = BLI_str_rpartition(str, delim, &sep, &suf);
+ EXPECT_EQ(pre_ln, 0);
+ EXPECT_EQ(sep, (void *)NULL);
+ EXPECT_EQ(suf, (void *)NULL);
+ }
+
+ {
+ const char *str = "material";
+
+ /* "material" -> "material", NULL, NULL, 8 */
+ pre_ln = BLI_str_rpartition(str, delim, &sep, &suf);
+ EXPECT_EQ(pre_ln, 8);
+ EXPECT_EQ(sep, (void *)NULL);
+ EXPECT_EQ(suf, (void *)NULL);
+ }
}
/* BLI_str_partition_ex */
TEST(string, StrPartitionEx)
{
- const char delim[] = {'-', '.', '_', '~', '\\', '\0'};
- const char *sep, *suf;
- size_t pre_ln;
-
- /* Only considering 'from_right' cases here. */
-
- {
- const char *str = "mat.e-r_ia.l";
-
- /* "mat.e-r_ia.l" over "mat.e-r" -> "mat.e", '.', "r_ia.l", 3 */
- pre_ln = BLI_str_partition_ex(str, str + 6, delim, &sep, &suf, true);
- EXPECT_EQ(pre_ln, 5);
- EXPECT_EQ(&str[5], sep);
- EXPECT_STREQ("r_ia.l", suf);
- }
-
- /* Corner cases. */
- {
- const char *str = "mate.rial";
-
- /* "mate.rial" over "mate" -> "mate.rial", NULL, NULL, 4 */
- pre_ln = BLI_str_partition_ex(str, str + 4, delim, &sep, &suf, true);
- EXPECT_EQ(pre_ln, 4);
- EXPECT_EQ(sep, (void*)NULL);
- EXPECT_EQ(suf, (void*)NULL);
- }
+ const char delim[] = {'-', '.', '_', '~', '\\', '\0'};
+ const char *sep, *suf;
+ size_t pre_ln;
+
+ /* Only considering 'from_right' cases here. */
+
+ {
+ const char *str = "mat.e-r_ia.l";
+
+ /* "mat.e-r_ia.l" over "mat.e-r" -> "mat.e", '.', "r_ia.l", 3 */
+ pre_ln = BLI_str_partition_ex(str, str + 6, delim, &sep, &suf, true);
+ EXPECT_EQ(pre_ln, 5);
+ EXPECT_EQ(&str[5], sep);
+ EXPECT_STREQ("r_ia.l", suf);
+ }
+
+ /* Corner cases. */
+ {
+ const char *str = "mate.rial";
+
+ /* "mate.rial" over "mate" -> "mate.rial", NULL, NULL, 4 */
+ pre_ln = BLI_str_partition_ex(str, str + 4, delim, &sep, &suf, true);
+ EXPECT_EQ(pre_ln, 4);
+ EXPECT_EQ(sep, (void *)NULL);
+ EXPECT_EQ(suf, (void *)NULL);
+ }
}
/* BLI_str_partition_utf8 */
TEST(string, StrPartitionUtf8)
{
- const unsigned int delim[] = {'-', '.', '_', 0x00F1 /* n tilde */, 0x262F /* ying-yang */, '\0'};
- const char *sep, *suf;
- size_t pre_ln;
-
- {
- const char *str = "ma\xc3\xb1te-r\xe2\x98\xafial";
-
- /* "ma\xc3\xb1te-r\xe2\x98\xafial" -> "ma", '\xc3\xb1', "te-r\xe2\x98\xafial", 2 */
- pre_ln = BLI_str_partition_utf8(str, delim, &sep, &suf);
- EXPECT_EQ(pre_ln, 2);
- EXPECT_EQ(&str[2], sep);
- EXPECT_STREQ("te-r\xe2\x98\xafial", suf);
- }
-
- /* Corner cases. */
- {
- const char *str = "\xe2\x98\xafmate-rial-\xc3\xb1";
-
- /* "\xe2\x98\xafmate-rial-\xc3\xb1" -> "", '\xe2\x98\xaf', "mate-rial-\xc3\xb1", 0 */
- pre_ln = BLI_str_partition_utf8(str, delim, &sep, &suf);
- EXPECT_EQ(pre_ln, 0);
- EXPECT_EQ(&str[0], sep);
- EXPECT_STREQ("mate-rial-\xc3\xb1", suf);
- }
-
- {
- const char *str = "\xe2\x98\xaf.\xc3\xb1_.--\xc3\xb1";
-
- /* "\xe2\x98\xaf.\xc3\xb1_.--\xc3\xb1" -> "", '\xe2\x98\xaf', ".\xc3\xb1_.--\xc3\xb1", 0 */
- pre_ln = BLI_str_partition_utf8(str, delim, &sep, &suf);
- EXPECT_EQ(pre_ln, 0);
- EXPECT_EQ(&str[0], sep);
- EXPECT_STREQ(".\xc3\xb1_.--\xc3\xb1", suf);
- }
-
- {
- const char *str = "";
-
- /* "" -> "", NULL, NULL, 0 */
- pre_ln = BLI_str_partition_utf8(str, delim, &sep, &suf);
- EXPECT_EQ(pre_ln, 0);
- EXPECT_EQ(sep, (void*)NULL);
- EXPECT_EQ(suf, (void*)NULL);
- }
-
- {
- const char *str = "material";
-
- /* "material" -> "material", NULL, NULL, 8 */
- pre_ln = BLI_str_partition_utf8(str, delim, &sep, &suf);
- EXPECT_EQ(pre_ln, 8);
- EXPECT_EQ(sep, (void*)NULL);
- EXPECT_EQ(suf, (void*)NULL);
- }
+ const unsigned int delim[] = {'-', '.', '_', 0x00F1 /* n tilde */, 0x262F /* ying-yang */, '\0'};
+ const char *sep, *suf;
+ size_t pre_ln;
+
+ {
+ const char *str = "ma\xc3\xb1te-r\xe2\x98\xafial";
+
+ /* "ma\xc3\xb1te-r\xe2\x98\xafial" -> "ma", '\xc3\xb1', "te-r\xe2\x98\xafial", 2 */
+ pre_ln = BLI_str_partition_utf8(str, delim, &sep, &suf);
+ EXPECT_EQ(pre_ln, 2);
+ EXPECT_EQ(&str[2], sep);
+ EXPECT_STREQ("te-r\xe2\x98\xafial", suf);
+ }
+
+ /* Corner cases. */
+ {
+ const char *str = "\xe2\x98\xafmate-rial-\xc3\xb1";
+
+ /* "\xe2\x98\xafmate-rial-\xc3\xb1" -> "", '\xe2\x98\xaf', "mate-rial-\xc3\xb1", 0 */
+ pre_ln = BLI_str_partition_utf8(str, delim, &sep, &suf);
+ EXPECT_EQ(pre_ln, 0);
+ EXPECT_EQ(&str[0], sep);
+ EXPECT_STREQ("mate-rial-\xc3\xb1", suf);
+ }
+
+ {
+ const char *str = "\xe2\x98\xaf.\xc3\xb1_.--\xc3\xb1";
+
+ /* "\xe2\x98\xaf.\xc3\xb1_.--\xc3\xb1" -> "", '\xe2\x98\xaf', ".\xc3\xb1_.--\xc3\xb1", 0 */
+ pre_ln = BLI_str_partition_utf8(str, delim, &sep, &suf);
+ EXPECT_EQ(pre_ln, 0);
+ EXPECT_EQ(&str[0], sep);
+ EXPECT_STREQ(".\xc3\xb1_.--\xc3\xb1", suf);
+ }
+
+ {
+ const char *str = "";
+
+ /* "" -> "", NULL, NULL, 0 */
+ pre_ln = BLI_str_partition_utf8(str, delim, &sep, &suf);
+ EXPECT_EQ(pre_ln, 0);
+ EXPECT_EQ(sep, (void *)NULL);
+ EXPECT_EQ(suf, (void *)NULL);
+ }
+
+ {
+ const char *str = "material";
+
+ /* "material" -> "material", NULL, NULL, 8 */
+ pre_ln = BLI_str_partition_utf8(str, delim, &sep, &suf);
+ EXPECT_EQ(pre_ln, 8);
+ EXPECT_EQ(sep, (void *)NULL);
+ EXPECT_EQ(suf, (void *)NULL);
+ }
}
/* BLI_str_rpartition_utf8 */
TEST(string, StrRPartitionUtf8)
{
- const unsigned int delim[] = {'-', '.', '_', 0x00F1 /* n tilde */, 0x262F /* ying-yang */, '\0'};
- const char *sep, *suf;
- size_t pre_ln;
-
- {
- const char *str = "ma\xc3\xb1te-r\xe2\x98\xafial";
-
- /* "ma\xc3\xb1te-r\xe2\x98\xafial" -> "mat\xc3\xb1te-r", '\xe2\x98\xaf', "ial", 8 */
- pre_ln = BLI_str_rpartition_utf8(str, delim, &sep, &suf);
- EXPECT_EQ(pre_ln, 8);
- EXPECT_EQ(&str[8], sep);
- EXPECT_STREQ("ial", suf);
- }
-
- /* Corner cases. */
- {
- const char *str = "\xe2\x98\xafmate-rial-\xc3\xb1";
-
- /* "\xe2\x98\xafmate-rial-\xc3\xb1" -> "\xe2\x98\xafmate-rial-", '\xc3\xb1', "", 13 */
- pre_ln = BLI_str_rpartition_utf8(str, delim, &sep, &suf);
- EXPECT_EQ(pre_ln, 13);
- EXPECT_EQ(&str[13], sep);
- EXPECT_STREQ("", suf);
- }
-
- {
- const char *str = "\xe2\x98\xaf.\xc3\xb1_.--\xc3\xb1";
-
- /* "\xe2\x98\xaf.\xc3\xb1_.--\xc3\xb1" -> "\xe2\x98\xaf.\xc3\xb1_.--", '\xc3\xb1', "", 10 */
- pre_ln = BLI_str_rpartition_utf8(str, delim, &sep, &suf);
- EXPECT_EQ(pre_ln, 10);
- EXPECT_EQ(&str[10], sep);
- EXPECT_STREQ("", suf);
- }
-
- {
- const char *str = "";
-
- /* "" -> "", NULL, NULL, 0 */
- pre_ln = BLI_str_rpartition_utf8(str, delim, &sep, &suf);
- EXPECT_EQ(pre_ln, 0);
- EXPECT_EQ(sep, (void*)NULL);
- EXPECT_EQ(suf, (void*)NULL);
- }
-
- {
- const char *str = "material";
-
- /* "material" -> "material", NULL, NULL, 8 */
- pre_ln = BLI_str_rpartition_utf8(str, delim, &sep, &suf);
- EXPECT_EQ(pre_ln, 8);
- EXPECT_EQ(sep, (void*)NULL);
- EXPECT_EQ(suf, (void*)NULL);
- }
+ const unsigned int delim[] = {'-', '.', '_', 0x00F1 /* n tilde */, 0x262F /* ying-yang */, '\0'};
+ const char *sep, *suf;
+ size_t pre_ln;
+
+ {
+ const char *str = "ma\xc3\xb1te-r\xe2\x98\xafial";
+
+ /* "ma\xc3\xb1te-r\xe2\x98\xafial" -> "mat\xc3\xb1te-r", '\xe2\x98\xaf', "ial", 8 */
+ pre_ln = BLI_str_rpartition_utf8(str, delim, &sep, &suf);
+ EXPECT_EQ(pre_ln, 8);
+ EXPECT_EQ(&str[8], sep);
+ EXPECT_STREQ("ial", suf);
+ }
+
+ /* Corner cases. */
+ {
+ const char *str = "\xe2\x98\xafmate-rial-\xc3\xb1";
+
+ /* "\xe2\x98\xafmate-rial-\xc3\xb1" -> "\xe2\x98\xafmate-rial-", '\xc3\xb1', "", 13 */
+ pre_ln = BLI_str_rpartition_utf8(str, delim, &sep, &suf);
+ EXPECT_EQ(pre_ln, 13);
+ EXPECT_EQ(&str[13], sep);
+ EXPECT_STREQ("", suf);
+ }
+
+ {
+ const char *str = "\xe2\x98\xaf.\xc3\xb1_.--\xc3\xb1";
+
+ /* "\xe2\x98\xaf.\xc3\xb1_.--\xc3\xb1" -> "\xe2\x98\xaf.\xc3\xb1_.--", '\xc3\xb1', "", 10 */
+ pre_ln = BLI_str_rpartition_utf8(str, delim, &sep, &suf);
+ EXPECT_EQ(pre_ln, 10);
+ EXPECT_EQ(&str[10], sep);
+ EXPECT_STREQ("", suf);
+ }
+
+ {
+ const char *str = "";
+
+ /* "" -> "", NULL, NULL, 0 */
+ pre_ln = BLI_str_rpartition_utf8(str, delim, &sep, &suf);
+ EXPECT_EQ(pre_ln, 0);
+ EXPECT_EQ(sep, (void *)NULL);
+ EXPECT_EQ(suf, (void *)NULL);
+ }
+
+ {
+ const char *str = "material";
+
+ /* "material" -> "material", NULL, NULL, 8 */
+ pre_ln = BLI_str_rpartition_utf8(str, delim, &sep, &suf);
+ EXPECT_EQ(pre_ln, 8);
+ EXPECT_EQ(sep, (void *)NULL);
+ EXPECT_EQ(suf, (void *)NULL);
+ }
}
/* BLI_str_partition_ex_utf8 */
TEST(string, StrPartitionExUtf8)
{
- const unsigned int delim[] = {'-', '.', '_', 0x00F1 /* n tilde */, 0x262F /* ying-yang */, '\0'};
- const char *sep, *suf;
- size_t pre_ln;
-
- /* Only considering 'from_right' cases here. */
-
- {
- const char *str = "ma\xc3\xb1te-r\xe2\x98\xafial";
-
- /* "ma\xc3\xb1te-r\xe2\x98\xafial" over "ma\xc3\xb1te" -> "ma", '\xc3\xb1', "te-r\xe2\x98\xafial", 2 */
- pre_ln = BLI_str_partition_ex_utf8(str, str + 6, delim, &sep, &suf, true);
- EXPECT_EQ(pre_ln, 2);
- EXPECT_EQ(&str[2], sep);
- EXPECT_STREQ("te-r\xe2\x98\xafial", suf);
- }
-
- /* Corner cases. */
- {
- const char *str = "mate\xe2\x98\xafrial";
-
- /* "mate\xe2\x98\xafrial" over "mate" -> "mate\xe2\x98\xafrial", NULL, NULL, 4 */
- pre_ln = BLI_str_partition_ex_utf8(str, str + 4, delim, &sep, &suf, true);
- EXPECT_EQ(pre_ln, 4);
- EXPECT_EQ(sep, (void*)NULL);
- EXPECT_EQ(suf, (void*)NULL);
- }
+ const unsigned int delim[] = {'-', '.', '_', 0x00F1 /* n tilde */, 0x262F /* ying-yang */, '\0'};
+ const char *sep, *suf;
+ size_t pre_ln;
+
+ /* Only considering 'from_right' cases here. */
+
+ {
+ const char *str = "ma\xc3\xb1te-r\xe2\x98\xafial";
+
+ /* "ma\xc3\xb1te-r\xe2\x98\xafial" over "ma\xc3\xb1te" -> "ma", '\xc3\xb1', "te-r\xe2\x98\xafial", 2 */
+ pre_ln = BLI_str_partition_ex_utf8(str, str + 6, delim, &sep, &suf, true);
+ EXPECT_EQ(pre_ln, 2);
+ EXPECT_EQ(&str[2], sep);
+ EXPECT_STREQ("te-r\xe2\x98\xafial", suf);
+ }
+
+ /* Corner cases. */
+ {
+ const char *str = "mate\xe2\x98\xafrial";
+
+ /* "mate\xe2\x98\xafrial" over "mate" -> "mate\xe2\x98\xafrial", NULL, NULL, 4 */
+ pre_ln = BLI_str_partition_ex_utf8(str, str + 4, delim, &sep, &suf, true);
+ EXPECT_EQ(pre_ln, 4);
+ EXPECT_EQ(sep, (void *)NULL);
+ EXPECT_EQ(suf, (void *)NULL);
+ }
}
/* BLI_str_format_int_grouped */
TEST(string, StrFormatIntGrouped)
{
- char num_str[16];
- int num;
+ char num_str[16];
+ int num;
- BLI_str_format_int_grouped(num_str, num = 0);
- EXPECT_STREQ("0", num_str);
+ BLI_str_format_int_grouped(num_str, num = 0);
+ EXPECT_STREQ("0", num_str);
- BLI_str_format_int_grouped(num_str, num = 1);
- EXPECT_STREQ("1", num_str);
+ BLI_str_format_int_grouped(num_str, num = 1);
+ EXPECT_STREQ("1", num_str);
- BLI_str_format_int_grouped(num_str, num = -1);
- EXPECT_STREQ("-1", num_str);
+ BLI_str_format_int_grouped(num_str, num = -1);
+ EXPECT_STREQ("-1", num_str);
- BLI_str_format_int_grouped(num_str, num = -2147483648);
- EXPECT_STREQ("-2,147,483,648", num_str);
+ BLI_str_format_int_grouped(num_str, num = -2147483648);
+ EXPECT_STREQ("-2,147,483,648", num_str);
- BLI_str_format_int_grouped(num_str, num = 2147483647);
- EXPECT_STREQ("2,147,483,647", num_str);
+ BLI_str_format_int_grouped(num_str, num = 2147483647);
+ EXPECT_STREQ("2,147,483,647", num_str);
- BLI_str_format_int_grouped(num_str, num = 1000);
- EXPECT_STREQ("1,000", num_str);
+ BLI_str_format_int_grouped(num_str, num = 1000);
+ EXPECT_STREQ("1,000", num_str);
- BLI_str_format_int_grouped(num_str, num = -1000);
- EXPECT_STREQ("-1,000", num_str);
+ BLI_str_format_int_grouped(num_str, num = -1000);
+ EXPECT_STREQ("-1,000", num_str);
- BLI_str_format_int_grouped(num_str, num = 999);
- EXPECT_STREQ("999", num_str);
+ BLI_str_format_int_grouped(num_str, num = 999);
+ EXPECT_STREQ("999", num_str);
- BLI_str_format_int_grouped(num_str, num = -999);
- EXPECT_STREQ("-999", num_str);
+ BLI_str_format_int_grouped(num_str, num = -999);
+ EXPECT_STREQ("-999", num_str);
}
/* BLI_str_format_byte_unit */
TEST(string, StrFormatByteUnits)
{
- char size_str[15];
- long long int size;
-
- /* Base 10 */
- BLI_str_format_byte_unit(size_str, size = 0, true);
- EXPECT_STREQ("0 B", size_str);
- BLI_str_format_byte_unit(size_str, size = -0, true);
- EXPECT_STREQ("0 B", size_str);
-
- BLI_str_format_byte_unit(size_str, size = 1, true);
- EXPECT_STREQ("1 B", size_str);
- BLI_str_format_byte_unit(size_str, size = -1, true);
- EXPECT_STREQ("-1 B", size_str);
-
- BLI_str_format_byte_unit(size_str, size = 1000, true);
- EXPECT_STREQ("1 KB", size_str);
- BLI_str_format_byte_unit(size_str, size = -1000, true);
- EXPECT_STREQ("-1 KB", size_str);
-
- BLI_str_format_byte_unit(size_str, size = 1024, true);
- EXPECT_STREQ("1 KB", size_str);
- BLI_str_format_byte_unit(size_str, size = -1024, true);
- EXPECT_STREQ("-1 KB", size_str);
-
- BLI_str_format_byte_unit(size_str, size = 9223372036854775807, true); /* LLONG_MAX - largest possible value */
- EXPECT_STREQ("9223.372 PB", size_str);
- BLI_str_format_byte_unit(size_str, size = -9223372036854775807, true);
- EXPECT_STREQ("-9223.372 PB", size_str);
-
-
- /* Base 2 */
- BLI_str_format_byte_unit(size_str, size = 0, false);
- EXPECT_STREQ("0 B", size_str);
- BLI_str_format_byte_unit(size_str, size = -0, false);
- EXPECT_STREQ("0 B", size_str);
-
- BLI_str_format_byte_unit(size_str, size = 1, false);
- EXPECT_STREQ("1 B", size_str);
- BLI_str_format_byte_unit(size_str, size = -1, false);
- EXPECT_STREQ("-1 B", size_str);
-
- BLI_str_format_byte_unit(size_str, size = 1000, false);
- EXPECT_STREQ("1000 B", size_str);
- BLI_str_format_byte_unit(size_str, size = -1000, false);
- EXPECT_STREQ("-1000 B", size_str);
-
- BLI_str_format_byte_unit(size_str, size = 1024, false);
- EXPECT_STREQ("1 KiB", size_str);
- BLI_str_format_byte_unit(size_str, size = -1024, false);
- EXPECT_STREQ("-1 KiB", size_str);
-
- BLI_str_format_byte_unit(size_str, size = 9223372036854775807, false); /* LLONG_MAX - largest possible value */
- EXPECT_STREQ("8192.0 PiB", size_str);
- BLI_str_format_byte_unit(size_str, size = -9223372036854775807, false);
- EXPECT_STREQ("-8192.0 PiB", size_str);
-
- /* Test maximum string length. */
- BLI_str_format_byte_unit(size_str, size = -9223200000000000000, false);
- EXPECT_STREQ("-8191.8472 PiB", size_str);
+ char size_str[15];
+ long long int size;
+
+ /* Base 10 */
+ BLI_str_format_byte_unit(size_str, size = 0, true);
+ EXPECT_STREQ("0 B", size_str);
+ BLI_str_format_byte_unit(size_str, size = -0, true);
+ EXPECT_STREQ("0 B", size_str);
+
+ BLI_str_format_byte_unit(size_str, size = 1, true);
+ EXPECT_STREQ("1 B", size_str);
+ BLI_str_format_byte_unit(size_str, size = -1, true);
+ EXPECT_STREQ("-1 B", size_str);
+
+ BLI_str_format_byte_unit(size_str, size = 1000, true);
+ EXPECT_STREQ("1 KB", size_str);
+ BLI_str_format_byte_unit(size_str, size = -1000, true);
+ EXPECT_STREQ("-1 KB", size_str);
+
+ BLI_str_format_byte_unit(size_str, size = 1024, true);
+ EXPECT_STREQ("1 KB", size_str);
+ BLI_str_format_byte_unit(size_str, size = -1024, true);
+ EXPECT_STREQ("-1 KB", size_str);
+
+ BLI_str_format_byte_unit(
+ size_str, size = 9223372036854775807, true); /* LLONG_MAX - largest possible value */
+ EXPECT_STREQ("9223.372 PB", size_str);
+ BLI_str_format_byte_unit(size_str, size = -9223372036854775807, true);
+ EXPECT_STREQ("-9223.372 PB", size_str);
+
+ /* Base 2 */
+ BLI_str_format_byte_unit(size_str, size = 0, false);
+ EXPECT_STREQ("0 B", size_str);
+ BLI_str_format_byte_unit(size_str, size = -0, false);
+ EXPECT_STREQ("0 B", size_str);
+
+ BLI_str_format_byte_unit(size_str, size = 1, false);
+ EXPECT_STREQ("1 B", size_str);
+ BLI_str_format_byte_unit(size_str, size = -1, false);
+ EXPECT_STREQ("-1 B", size_str);
+
+ BLI_str_format_byte_unit(size_str, size = 1000, false);
+ EXPECT_STREQ("1000 B", size_str);
+ BLI_str_format_byte_unit(size_str, size = -1000, false);
+ EXPECT_STREQ("-1000 B", size_str);
+
+ BLI_str_format_byte_unit(size_str, size = 1024, false);
+ EXPECT_STREQ("1 KiB", size_str);
+ BLI_str_format_byte_unit(size_str, size = -1024, false);
+ EXPECT_STREQ("-1 KiB", size_str);
+
+ BLI_str_format_byte_unit(
+ size_str, size = 9223372036854775807, false); /* LLONG_MAX - largest possible value */
+ EXPECT_STREQ("8192.0 PiB", size_str);
+ BLI_str_format_byte_unit(size_str, size = -9223372036854775807, false);
+ EXPECT_STREQ("-8192.0 PiB", size_str);
+
+ /* Test maximum string length. */
+ BLI_str_format_byte_unit(size_str, size = -9223200000000000000, false);
+ EXPECT_STREQ("-8191.8472 PiB", size_str);
}
struct WordInfo {
- WordInfo() {}
- WordInfo(int start, int end) : start(start), end(end) {}
- bool operator==(const WordInfo& other) const {
- return start == other.start && end == other.end;
- }
- int start, end;
+ WordInfo()
+ {
+ }
+ WordInfo(int start, int end) : start(start), end(end)
+ {
+ }
+ bool operator==(const WordInfo &other) const
+ {
+ return start == other.start && end == other.end;
+ }
+ int start, end;
};
-std::ostream& operator<<(std::ostream& os, const WordInfo& word_info) {
- os << "start: " << word_info.start << ", end: " << word_info.end;
- return os;
+std::ostream &operator<<(std::ostream &os, const WordInfo &word_info)
+{
+ os << "start: " << word_info.start << ", end: " << word_info.end;
+ return os;
}
class StringFindSplitWords : public testing::Test {
-protected:
- StringFindSplitWords() {
- }
-
- /* If max_words is -1 it will be initialized from the number of expected
- * words +1. This way there is no need to pass an explicit number of words,
- * but is also making it possible to catch situation when too many words
- * are being returned. */
- void testStringFindSplitWords(
- const string& str, const size_t max_length,
- initializer_list<WordInfo> expected_words_info_init,
- int max_words = -1)
- {
- const vector<WordInfo> expected_words_info = expected_words_info_init;
- if (max_words != -1) {
- CHECK_LE(max_words, expected_words_info.size() - 1);
- }
- /* Since number of word info is used here, this makes it so we allow one
- * extra word to be collected from the input. This allows to catch possible
- * issues with word splitting not doing a correct thing. */
- const int effective_max_words = (max_words == -1) ? expected_words_info.size() : max_words;
- /* One extra element for the {-1, -1}. */
- vector<WordInfo> actual_word_info(effective_max_words + 1, WordInfo(-1, -1));
- const int actual_word_num = BLI_string_find_split_words(
- str.c_str(), max_length, ' ',
- reinterpret_cast<int(*)[2]>(actual_word_info.data()),
- effective_max_words);
- /* Schrink actual array to an actual number of words, so we can compare
- * vectors as-is. */
- EXPECT_LE(actual_word_num, actual_word_info.size() - 1);
- actual_word_info.resize(actual_word_num + 1);
- /* Perform actual comparison. */
- EXPECT_EQ_VECTOR(actual_word_info, expected_words_info);
- }
-
- void testStringFindSplitWords(
- const string& str,
- initializer_list<WordInfo> expected_words_info_init)
- {
- testStringFindSplitWords(str, str.length(), expected_words_info_init);
- }
+ protected:
+ StringFindSplitWords()
+ {
+ }
+
+ /* If max_words is -1 it will be initialized from the number of expected
+ * words +1. This way there is no need to pass an explicit number of words,
+ * but is also making it possible to catch situation when too many words
+ * are being returned. */
+ void testStringFindSplitWords(const string &str,
+ const size_t max_length,
+ initializer_list<WordInfo> expected_words_info_init,
+ int max_words = -1)
+ {
+ const vector<WordInfo> expected_words_info = expected_words_info_init;
+ if (max_words != -1) {
+ CHECK_LE(max_words, expected_words_info.size() - 1);
+ }
+ /* Since number of word info is used here, this makes it so we allow one
+ * extra word to be collected from the input. This allows to catch possible
+ * issues with word splitting not doing a correct thing. */
+ const int effective_max_words = (max_words == -1) ? expected_words_info.size() : max_words;
+ /* One extra element for the {-1, -1}. */
+ vector<WordInfo> actual_word_info(effective_max_words + 1, WordInfo(-1, -1));
+ const int actual_word_num = BLI_string_find_split_words(
+ str.c_str(),
+ max_length,
+ ' ',
+ reinterpret_cast<int(*)[2]>(actual_word_info.data()),
+ effective_max_words);
+ /* Schrink actual array to an actual number of words, so we can compare
+ * vectors as-is. */
+ EXPECT_LE(actual_word_num, actual_word_info.size() - 1);
+ actual_word_info.resize(actual_word_num + 1);
+ /* Perform actual comparison. */
+ EXPECT_EQ_VECTOR(actual_word_info, expected_words_info);
+ }
+
+ void testStringFindSplitWords(const string &str,
+ initializer_list<WordInfo> expected_words_info_init)
+ {
+ testStringFindSplitWords(str, str.length(), expected_words_info_init);
+ }
};
/* BLI_string_find_split_words */
TEST_F(StringFindSplitWords, Simple)
{
- testStringFindSplitWords("t", {{0, 1}, {-1, -1}});
- testStringFindSplitWords("test", {{0, 4}, {-1, -1}});
+ testStringFindSplitWords("t", {{0, 1}, {-1, -1}});
+ testStringFindSplitWords("test", {{0, 4}, {-1, -1}});
}
TEST_F(StringFindSplitWords, Triple)
{
- testStringFindSplitWords("f t w", {{0, 1}, {2, 1}, {4, 1}, {-1, -1}});
- testStringFindSplitWords("find three words", {{0, 4}, {5, 5}, {11, 5}, {-1, -1}});
+ testStringFindSplitWords("f t w", {{0, 1}, {2, 1}, {4, 1}, {-1, -1}});
+ testStringFindSplitWords("find three words", {{0, 4}, {5, 5}, {11, 5}, {-1, -1}});
}
TEST_F(StringFindSplitWords, Spacing)
{
- testStringFindSplitWords("# ## ### ####", {{0, 1}, {2, 2}, {5, 3}, {9, 4}, {-1, -1}});
- testStringFindSplitWords("# # # #", {{0, 1}, {3, 1}, {7, 1}, {12, 1}, {-1, -1}});
+ testStringFindSplitWords("# ## ### ####", {{0, 1}, {2, 2}, {5, 3}, {9, 4}, {-1, -1}});
+ testStringFindSplitWords("# # # #", {{0, 1}, {3, 1}, {7, 1}, {12, 1}, {-1, -1}});
}
TEST_F(StringFindSplitWords, Trailing_Left)
{
- testStringFindSplitWords(" t", {{3, 1}, {-1, -1}});
- testStringFindSplitWords(" test", {{3, 4}, {-1, -1}});
+ testStringFindSplitWords(" t", {{3, 1}, {-1, -1}});
+ testStringFindSplitWords(" test", {{3, 4}, {-1, -1}});
}
TEST_F(StringFindSplitWords, Trailing_Right)
{
- testStringFindSplitWords("t ", {{0, 1}, {-1, -1}});
- testStringFindSplitWords("test ", {{0, 4}, {-1, -1}});
+ testStringFindSplitWords("t ", {{0, 1}, {-1, -1}});
+ testStringFindSplitWords("test ", {{0, 4}, {-1, -1}});
}
TEST_F(StringFindSplitWords, Trailing_LeftRight)
{
- testStringFindSplitWords(" surrounding space test 123 ", {{3, 11}, {15, 5}, {21, 4}, {28, 3}, {-1, -1}});
+ testStringFindSplitWords(" surrounding space test 123 ",
+ {{3, 11}, {15, 5}, {21, 4}, {28, 3}, {-1, -1}});
}
TEST_F(StringFindSplitWords, Blank)
{
- testStringFindSplitWords("", {{-1, -1}});
+ testStringFindSplitWords("", {{-1, -1}});
}
TEST_F(StringFindSplitWords, Whitespace)
{
- testStringFindSplitWords(" ", {{-1, -1}});
- testStringFindSplitWords(" ", {{-1, -1}});
+ testStringFindSplitWords(" ", {{-1, -1}});
+ testStringFindSplitWords(" ", {{-1, -1}});
}
TEST_F(StringFindSplitWords, LimitWords)
{
- const string words = "too many chars";
- const int words_len = words.length();
- testStringFindSplitWords(words, words_len, {{0, 3}, {4, 4}, {9, 5}, {-1, -1}}, 3);
- testStringFindSplitWords(words, words_len, {{0, 3}, {4, 4}, {-1, -1}}, 2);
- testStringFindSplitWords(words, words_len, {{0, 3}, {-1, -1}}, 1);
- testStringFindSplitWords(words, words_len, {{-1, -1}}, 0);
+ const string words = "too many chars";
+ const int words_len = words.length();
+ testStringFindSplitWords(words, words_len, {{0, 3}, {4, 4}, {9, 5}, {-1, -1}}, 3);
+ testStringFindSplitWords(words, words_len, {{0, 3}, {4, 4}, {-1, -1}}, 2);
+ testStringFindSplitWords(words, words_len, {{0, 3}, {-1, -1}}, 1);
+ testStringFindSplitWords(words, words_len, {{-1, -1}}, 0);
}
TEST_F(StringFindSplitWords, LimitChars)
{
- const string words = "too many chars";
- const int words_len = words.length();
- testStringFindSplitWords(words, words_len, {{0, 3}, {4, 4}, {9, 5}, {-1, -1}});
- testStringFindSplitWords(words, words_len - 1, {{0, 3}, {4, 4}, {9, 4}, {-1, -1}});
- testStringFindSplitWords(words, words_len - 5, {{0, 3}, {4, 4}, {-1, -1}});
- testStringFindSplitWords(words, 1, {{0, 1}, {-1, -1}});
- testStringFindSplitWords(words, 0, {{-1, -1}});
+ const string words = "too many chars";
+ const int words_len = words.length();
+ testStringFindSplitWords(words, words_len, {{0, 3}, {4, 4}, {9, 5}, {-1, -1}});
+ testStringFindSplitWords(words, words_len - 1, {{0, 3}, {4, 4}, {9, 4}, {-1, -1}});
+ testStringFindSplitWords(words, words_len - 5, {{0, 3}, {4, 4}, {-1, -1}});
+ testStringFindSplitWords(words, 1, {{0, 1}, {-1, -1}});
+ testStringFindSplitWords(words, 0, {{-1, -1}});
}
/* BLI_strncasestr */
TEST(string, StringStrncasestr)
{
- const char *str_test0 = "search here";
- const char *res;
+ const char *str_test0 = "search here";
+ const char *res;
- res = BLI_strncasestr(str_test0, "", 0);
- EXPECT_EQ(res, str_test0);
+ res = BLI_strncasestr(str_test0, "", 0);
+ EXPECT_EQ(res, str_test0);
- res = BLI_strncasestr(str_test0, " ", 1);
- EXPECT_EQ(res, str_test0 + 6);
+ res = BLI_strncasestr(str_test0, " ", 1);
+ EXPECT_EQ(res, str_test0 + 6);
- res = BLI_strncasestr(str_test0, "her", 3);
- EXPECT_EQ(res, str_test0 + 7);
+ res = BLI_strncasestr(str_test0, "her", 3);
+ EXPECT_EQ(res, str_test0 + 7);
- res = BLI_strncasestr(str_test0, "ARCh", 4);
- EXPECT_EQ(res, str_test0 + 2);
+ res = BLI_strncasestr(str_test0, "ARCh", 4);
+ EXPECT_EQ(res, str_test0 + 2);
- res = BLI_strncasestr(str_test0, "earcq", 4);
- EXPECT_EQ(res, str_test0 + 1);
+ res = BLI_strncasestr(str_test0, "earcq", 4);
+ EXPECT_EQ(res, str_test0 + 1);
- res = BLI_strncasestr(str_test0, "not there", 9);
- EXPECT_EQ(res, (void*)NULL);
+ res = BLI_strncasestr(str_test0, "not there", 9);
+ EXPECT_EQ(res, (void *)NULL);
}
diff --git a/tests/gtests/blenlib/BLI_string_utf8_test.cc b/tests/gtests/blenlib/BLI_string_utf8_test.cc
index 0dbe36158c5..49d773c319e 100644
--- a/tests/gtests/blenlib/BLI_string_utf8_test.cc
+++ b/tests/gtests/blenlib/BLI_string_utf8_test.cc
@@ -22,14 +22,13 @@ int mk_wcswidth(const wchar_t *pwcs, size_t n);
int mk_wcwidth(wchar_t ucs)
{
- return 0;
+ return 0;
}
int mk_wcswidth(const wchar_t *pwcs, size_t n)
{
- return 0;
+ return 0;
}
-
}
/* -------------------------------------------------------------------- */
@@ -291,18 +290,18 @@ const char *utf8_invalid_tests[][3] = {
/* BLI_utf8_invalid_strip (and indirectly, BLI_utf8_invalid_byte). */
TEST(string, Utf8InvalidBytes)
{
- for (int i = 0; utf8_invalid_tests[i][0] != NULL; i++) {
- const char *tst = utf8_invalid_tests[i][0];
- const char *tst_stripped = utf8_invalid_tests[i][1];
- const int num_errors = (int)utf8_invalid_tests[i][2][0];
+ for (int i = 0; utf8_invalid_tests[i][0] != NULL; i++) {
+ const char *tst = utf8_invalid_tests[i][0];
+ const char *tst_stripped = utf8_invalid_tests[i][1];
+ const int num_errors = (int)utf8_invalid_tests[i][2][0];
- char buff[80];
- memcpy(buff, tst, sizeof(buff));
+ char buff[80];
+ memcpy(buff, tst, sizeof(buff));
- const int num_errors_found = BLI_utf8_invalid_strip(buff, sizeof(buff) - 1);
+ const int num_errors_found = BLI_utf8_invalid_strip(buff, sizeof(buff) - 1);
- printf("[%02d] -> [%02d] \"%s\" -> \"%s\"\n", num_errors, num_errors_found, tst, buff);
- EXPECT_EQ(num_errors_found, num_errors);
- EXPECT_STREQ(buff, tst_stripped);
- }
+ printf("[%02d] -> [%02d] \"%s\" -> \"%s\"\n", num_errors, num_errors_found, tst, buff);
+ EXPECT_EQ(num_errors_found, num_errors);
+ EXPECT_STREQ(buff, tst_stripped);
+ }
}
diff --git a/tests/gtests/blenlib/BLI_task_test.cc b/tests/gtests/blenlib/BLI_task_test.cc
index e6464164ecb..5979236b6ec 100644
--- a/tests/gtests/blenlib/BLI_task_test.cc
+++ b/tests/gtests/blenlib/BLI_task_test.cc
@@ -13,64 +13,66 @@ extern "C" {
#define NUM_ITEMS 10000
-static void task_mempool_iter_func(void *userdata, MempoolIterData *item) {
- int *data = (int *)item;
- int *count = (int *)userdata;
+static void task_mempool_iter_func(void *userdata, MempoolIterData *item)
+{
+ int *data = (int *)item;
+ int *count = (int *)userdata;
- EXPECT_TRUE(data != NULL);
+ EXPECT_TRUE(data != NULL);
- *data += 1;
- atomic_sub_and_fetch_uint32((uint32_t *)count, 1);
+ *data += 1;
+ atomic_sub_and_fetch_uint32((uint32_t *)count, 1);
}
TEST(task, MempoolIter)
{
- int *data[NUM_ITEMS];
- BLI_mempool *mempool = BLI_mempool_create(sizeof(*data[0]), NUM_ITEMS, 32, BLI_MEMPOOL_ALLOW_ITER);
-
- int i;
-
- /* 'Randomly' add and remove some items from mempool, to create a non-homogenous one. */
- int num_items = 0;
- for (i = 0; i < NUM_ITEMS; i++) {
- data[i] = (int *)BLI_mempool_alloc(mempool);
- *data[i] = i - 1;
- num_items++;
- }
-
- for (i = 0; i < NUM_ITEMS; i += 3) {
- BLI_mempool_free(mempool, data[i]);
- data[i] = NULL;
- num_items--;
- }
-
- for (i = 0; i < NUM_ITEMS; i += 7) {
- if (data[i] == NULL) {
- data[i] = (int *)BLI_mempool_alloc(mempool);
- *data[i] = i - 1;
- num_items++;
- }
- }
-
- for (i = 0; i < NUM_ITEMS - 5; i += 23) {
- for (int j = 0; j < 5; j++) {
- if (data[i + j] != NULL) {
- BLI_mempool_free(mempool, data[i + j]);
- data[i + j] = NULL;
- num_items--;
- }
- }
- }
-
- BLI_task_parallel_mempool(mempool, &num_items, task_mempool_iter_func, true);
-
- /* Those checks should ensure us all items of the mempool were processed once, and only once - as expected. */
- EXPECT_EQ(num_items, 0);
- for (i = 0; i < NUM_ITEMS; i++) {
- if (data[i] != NULL) {
- EXPECT_EQ(*data[i], i);
- }
- }
-
- BLI_mempool_destroy(mempool);
+ int *data[NUM_ITEMS];
+ BLI_mempool *mempool = BLI_mempool_create(
+ sizeof(*data[0]), NUM_ITEMS, 32, BLI_MEMPOOL_ALLOW_ITER);
+
+ int i;
+
+ /* 'Randomly' add and remove some items from mempool, to create a non-homogenous one. */
+ int num_items = 0;
+ for (i = 0; i < NUM_ITEMS; i++) {
+ data[i] = (int *)BLI_mempool_alloc(mempool);
+ *data[i] = i - 1;
+ num_items++;
+ }
+
+ for (i = 0; i < NUM_ITEMS; i += 3) {
+ BLI_mempool_free(mempool, data[i]);
+ data[i] = NULL;
+ num_items--;
+ }
+
+ for (i = 0; i < NUM_ITEMS; i += 7) {
+ if (data[i] == NULL) {
+ data[i] = (int *)BLI_mempool_alloc(mempool);
+ *data[i] = i - 1;
+ num_items++;
+ }
+ }
+
+ for (i = 0; i < NUM_ITEMS - 5; i += 23) {
+ for (int j = 0; j < 5; j++) {
+ if (data[i + j] != NULL) {
+ BLI_mempool_free(mempool, data[i + j]);
+ data[i + j] = NULL;
+ num_items--;
+ }
+ }
+ }
+
+ BLI_task_parallel_mempool(mempool, &num_items, task_mempool_iter_func, true);
+
+ /* Those checks should ensure us all items of the mempool were processed once, and only once - as expected. */
+ EXPECT_EQ(num_items, 0);
+ for (i = 0; i < NUM_ITEMS; i++) {
+ if (data[i] != NULL) {
+ EXPECT_EQ(*data[i], i);
+ }
+ }
+
+ BLI_mempool_destroy(mempool);
}
diff --git a/tests/gtests/blenlib/CMakeLists.txt b/tests/gtests/blenlib/CMakeLists.txt
index e837f703423..547ed99295c 100644
--- a/tests/gtests/blenlib/CMakeLists.txt
+++ b/tests/gtests/blenlib/CMakeLists.txt
@@ -19,12 +19,12 @@
# ***** END GPL LICENSE BLOCK *****
set(INC
- .
- ..
- ../../../source/blender/blenlib
- ../../../source/blender/makesdna
- ../../../intern/guardedalloc
- ../../../intern/atomic
+ .
+ ..
+ ../../../source/blender/blenlib
+ ../../../source/blender/makesdna
+ ../../../intern/guardedalloc
+ ../../../intern/atomic
)
include_directories(${INC})
@@ -33,9 +33,9 @@ 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(WIN32)
- set(BLI_path_util_extra_libs "bf_blenlib;bf_intern_utfconv;extern_wcwidth;${ZLIB_LIBRARIES}")
+ set(BLI_path_util_extra_libs "bf_blenlib;bf_intern_utfconv;extern_wcwidth;${ZLIB_LIBRARIES}")
else()
- set(BLI_path_util_extra_libs "bf_blenlib;extern_wcwidth;${ZLIB_LIBRARIES}")
+ set(BLI_path_util_extra_libs "bf_blenlib;extern_wcwidth;${ZLIB_LIBRARIES}")
endif()
BLENDER_TEST(BLI_array_store "bf_blenlib")
diff --git a/tests/gtests/blenlib/stubs/bf_intern_eigen_stubs.h b/tests/gtests/blenlib/stubs/bf_intern_eigen_stubs.h
index dad77a257d5..97c0916dd9b 100644
--- a/tests/gtests/blenlib/stubs/bf_intern_eigen_stubs.h
+++ b/tests/gtests/blenlib/stubs/bf_intern_eigen_stubs.h
@@ -2,17 +2,19 @@
extern "C" {
-bool EIG_self_adjoint_eigen_solve(const int size, const float *matrix, float *r_eigen_values, float *r_eigen_vectors)
+bool EIG_self_adjoint_eigen_solve(const int size,
+ const float *matrix,
+ float *r_eigen_values,
+ float *r_eigen_vectors)
{
- BLI_assert(0);
- UNUSED_VARS(size, matrix, r_eigen_values, r_eigen_vectors);
- return false;
+ BLI_assert(0);
+ UNUSED_VARS(size, matrix, r_eigen_values, r_eigen_vectors);
+ return false;
}
void EIG_svd_square_matrix(const int size, const float *matrix, float *r_U, float *r_S, float *r_V)
{
- BLI_assert(0);
- UNUSED_VARS(size, matrix, r_U, r_S, r_V);
+ BLI_assert(0);
+ UNUSED_VARS(size, matrix, r_U, r_S, r_V);
}
-
}
diff --git a/tests/gtests/bmesh/CMakeLists.txt b/tests/gtests/bmesh/CMakeLists.txt
index 10484751ca3..4093ace9ff4 100644
--- a/tests/gtests/bmesh/CMakeLists.txt
+++ b/tests/gtests/bmesh/CMakeLists.txt
@@ -19,17 +19,17 @@
# ***** END GPL LICENSE BLOCK *****
set(INC
- .
- ..
- ../../../source/blender/blenlib
- ../../../source/blender/makesdna
- ../../../source/blender/bmesh
- ../../../intern/guardedalloc
+ .
+ ..
+ ../../../source/blender/blenlib
+ ../../../source/blender/makesdna
+ ../../../source/blender/bmesh
+ ../../../intern/guardedalloc
)
set(LIB
- bf_blenloader # Should not be needed but gives linking error without it.
- bf_bmesh
+ bf_blenloader # Should not be needed but gives linking error without it.
+ bf_bmesh
)
include_directories(${INC})
@@ -37,9 +37,9 @@ include_directories(${INC})
setup_libdirs()
if(WITH_BUILDINFO)
- set(_buildinfo_src "$<TARGET_OBJECTS:buildinfoobj>")
+ set(_buildinfo_src "$<TARGET_OBJECTS:buildinfoobj>")
else()
- set(_buildinfo_src "")
+ set(_buildinfo_src "")
endif()
BLENDER_SRC_GTEST(bmesh_core "bmesh_core_test.cc;${_buildinfo_src}" "${LIB}")
unset(_buildinfo_src)
diff --git a/tests/gtests/bmesh/bmesh_core_test.cc b/tests/gtests/bmesh/bmesh_core_test.cc
index b2cb1a4e8a3..7531568af87 100644
--- a/tests/gtests/bmesh/bmesh_core_test.cc
+++ b/tests/gtests/bmesh/bmesh_core_test.cc
@@ -4,36 +4,37 @@
#include "bmesh.h"
#include "BLI_math.h"
-TEST(bmesh_core, BMVertCreate) {
- BMesh *bm;
- BMVert *bv1, *bv2, *bv3;
- const float co1[3] = {1.0f, 2.0f, 0.0f};
+TEST(bmesh_core, BMVertCreate)
+{
+ BMesh *bm;
+ BMVert *bv1, *bv2, *bv3;
+ const float co1[3] = {1.0f, 2.0f, 0.0f};
- BMeshCreateParams bm_params;
- bm_params.use_toolflags = true;
- bm = BM_mesh_create(&bm_mesh_allocsize_default, &bm_params);
- EXPECT_EQ(bm->totvert, 0);
- /* make a custom layer so we can see if it is copied properly */
- BM_data_layer_add(bm, &bm->vdata, CD_PROP_FLT);
- bv1 = BM_vert_create(bm, co1, NULL, BM_CREATE_NOP);
- ASSERT_TRUE(bv1 != NULL);
- EXPECT_EQ(bv1->co[0], 1.0f);
- EXPECT_EQ(bv1->co[1], 2.0f);
- EXPECT_EQ(bv1->co[2], 0.0f);
- EXPECT_TRUE(is_zero_v3(bv1->no));
- EXPECT_EQ(bv1->head.htype, (char)BM_VERT);
- EXPECT_EQ(bv1->head.hflag, 0);
- EXPECT_EQ(bv1->head.api_flag, 0);
- bv2 = BM_vert_create(bm, NULL, NULL, BM_CREATE_NOP);
- ASSERT_TRUE(bv2 != NULL);
- EXPECT_TRUE(is_zero_v3(bv2->co));
- /* create with example should copy custom data but not select flag */
- BM_vert_select_set(bm, bv2, true);
- BM_elem_float_data_set(&bm->vdata, bv2, CD_PROP_FLT, 1.5f);
- bv3 = BM_vert_create(bm, co1, bv2, BM_CREATE_NOP);
- ASSERT_TRUE(bv3 != NULL);
- EXPECT_FALSE(BM_elem_flag_test((BMElem *)bv3, BM_ELEM_SELECT));
- EXPECT_EQ(BM_elem_float_data_get(&bm->vdata, bv3, CD_PROP_FLT), 1.5f);
- EXPECT_EQ(BM_mesh_elem_count(bm, BM_VERT), 3);
- BM_mesh_free(bm);
+ BMeshCreateParams bm_params;
+ bm_params.use_toolflags = true;
+ bm = BM_mesh_create(&bm_mesh_allocsize_default, &bm_params);
+ EXPECT_EQ(bm->totvert, 0);
+ /* make a custom layer so we can see if it is copied properly */
+ BM_data_layer_add(bm, &bm->vdata, CD_PROP_FLT);
+ bv1 = BM_vert_create(bm, co1, NULL, BM_CREATE_NOP);
+ ASSERT_TRUE(bv1 != NULL);
+ EXPECT_EQ(bv1->co[0], 1.0f);
+ EXPECT_EQ(bv1->co[1], 2.0f);
+ EXPECT_EQ(bv1->co[2], 0.0f);
+ EXPECT_TRUE(is_zero_v3(bv1->no));
+ EXPECT_EQ(bv1->head.htype, (char)BM_VERT);
+ EXPECT_EQ(bv1->head.hflag, 0);
+ EXPECT_EQ(bv1->head.api_flag, 0);
+ bv2 = BM_vert_create(bm, NULL, NULL, BM_CREATE_NOP);
+ ASSERT_TRUE(bv2 != NULL);
+ EXPECT_TRUE(is_zero_v3(bv2->co));
+ /* create with example should copy custom data but not select flag */
+ BM_vert_select_set(bm, bv2, true);
+ BM_elem_float_data_set(&bm->vdata, bv2, CD_PROP_FLT, 1.5f);
+ bv3 = BM_vert_create(bm, co1, bv2, BM_CREATE_NOP);
+ ASSERT_TRUE(bv3 != NULL);
+ EXPECT_FALSE(BM_elem_flag_test((BMElem *)bv3, BM_ELEM_SELECT));
+ EXPECT_EQ(BM_elem_float_data_get(&bm->vdata, bv3, CD_PROP_FLT), 1.5f);
+ EXPECT_EQ(BM_mesh_elem_count(bm, BM_VERT), 3);
+ BM_mesh_free(bm);
}
diff --git a/tests/gtests/guardedalloc/CMakeLists.txt b/tests/gtests/guardedalloc/CMakeLists.txt
index 812285c3e33..6ca444f28b3 100644
--- a/tests/gtests/guardedalloc/CMakeLists.txt
+++ b/tests/gtests/guardedalloc/CMakeLists.txt
@@ -19,10 +19,10 @@
# ***** END GPL LICENSE BLOCK *****
set(INC
- .
- ..
- ../../../intern/guardedalloc
- ../../../source/blender/blenlib
+ .
+ ..
+ ../../../intern/guardedalloc
+ ../../../source/blender/blenlib
)
include_directories(${INC})
diff --git a/tests/gtests/guardedalloc/guardedalloc_alignment_test.cc b/tests/gtests/guardedalloc/guardedalloc_alignment_test.cc
index 01ff38f0528..efb29a6088d 100644
--- a/tests/gtests/guardedalloc/guardedalloc_alignment_test.cc
+++ b/tests/gtests/guardedalloc/guardedalloc_alignment_test.cc
@@ -14,35 +14,35 @@ namespace {
void DoBasicAlignmentChecks(const int alignment)
{
- int *foo, *bar;
+ int *foo, *bar;
- foo = (int *) MEM_mallocN_aligned(sizeof(int) * 10, alignment, "test");
- CHECK_ALIGNMENT(foo, alignment);
+ foo = (int *)MEM_mallocN_aligned(sizeof(int) * 10, alignment, "test");
+ CHECK_ALIGNMENT(foo, alignment);
- bar = (int *) MEM_dupallocN(foo);
- CHECK_ALIGNMENT(bar, alignment);
- MEM_freeN(bar);
+ bar = (int *)MEM_dupallocN(foo);
+ CHECK_ALIGNMENT(bar, alignment);
+ MEM_freeN(bar);
- foo = (int *) MEM_reallocN(foo, sizeof(int) * 5);
- CHECK_ALIGNMENT(foo, alignment);
+ foo = (int *)MEM_reallocN(foo, sizeof(int) * 5);
+ CHECK_ALIGNMENT(foo, alignment);
- foo = (int *) MEM_recallocN(foo, sizeof(int) * 5);
- CHECK_ALIGNMENT(foo, alignment);
+ foo = (int *)MEM_recallocN(foo, sizeof(int) * 5);
+ CHECK_ALIGNMENT(foo, alignment);
- MEM_freeN(foo);
+ MEM_freeN(foo);
}
} // namespace
TEST(guardedalloc, LockfreeAlignedAlloc16)
{
- DoBasicAlignmentChecks(16);
+ DoBasicAlignmentChecks(16);
}
TEST(guardedalloc, GuardedAlignedAlloc16)
{
- MEM_use_guarded_allocator();
- DoBasicAlignmentChecks(16);
+ MEM_use_guarded_allocator();
+ DoBasicAlignmentChecks(16);
}
// On Apple we currently support 16 bit alignment only.
@@ -51,7 +51,7 @@ TEST(guardedalloc, GuardedAlignedAlloc16)
#ifndef __APPLE__
TEST(guardedalloc, GuardedAlignedAlloc32)
{
- MEM_use_guarded_allocator();
- DoBasicAlignmentChecks(32);
+ MEM_use_guarded_allocator();
+ DoBasicAlignmentChecks(32);
}
#endif
diff --git a/tests/gtests/guardedalloc/guardedalloc_overflow_test.cc b/tests/gtests/guardedalloc/guardedalloc_overflow_test.cc
index 6f4df4fd047..bd47482d033 100644
--- a/tests/gtests/guardedalloc/guardedalloc_overflow_test.cc
+++ b/tests/gtests/guardedalloc/guardedalloc_overflow_test.cc
@@ -6,55 +6,55 @@
/* We expect to abort on integer overflow, to prevent possible exploits. */
#ifdef _WIN32
-#define ABORT_PREDICATE ::testing::ExitedWithCode(3)
+# define ABORT_PREDICATE ::testing::ExitedWithCode(3)
#else
-#define ABORT_PREDICATE ::testing::KilledBySignal(SIGABRT)
+# define ABORT_PREDICATE ::testing::KilledBySignal(SIGABRT)
#endif
namespace {
void MallocArray(size_t len, size_t size)
{
- void *mem = MEM_malloc_arrayN(len, size, "MallocArray");
- if (mem) {
- MEM_freeN(mem);
- }
+ void *mem = MEM_malloc_arrayN(len, size, "MallocArray");
+ if (mem) {
+ MEM_freeN(mem);
+ }
}
void CallocArray(size_t len, size_t size)
{
- void *mem = MEM_calloc_arrayN(len, size, "CallocArray");
- if (mem) {
- MEM_freeN(mem);
- }
+ void *mem = MEM_calloc_arrayN(len, size, "CallocArray");
+ if (mem) {
+ MEM_freeN(mem);
+ }
}
} // namespace
TEST(guardedalloc, LockfreeIntegerOverflow)
{
- MallocArray(1, SIZE_MAX);
- CallocArray(SIZE_MAX, 1);
- MallocArray(SIZE_MAX / 2, 2);
- CallocArray(SIZE_MAX / 1234567, 1234567);
-
- EXPECT_EXIT(MallocArray(SIZE_MAX, 2), ABORT_PREDICATE, "");
- EXPECT_EXIT(CallocArray(7, SIZE_MAX), ABORT_PREDICATE, "");
- EXPECT_EXIT(MallocArray(SIZE_MAX, 12345567), ABORT_PREDICATE, "");
- EXPECT_EXIT(CallocArray(SIZE_MAX, SIZE_MAX), ABORT_PREDICATE, "");
+ MallocArray(1, SIZE_MAX);
+ CallocArray(SIZE_MAX, 1);
+ MallocArray(SIZE_MAX / 2, 2);
+ CallocArray(SIZE_MAX / 1234567, 1234567);
+
+ EXPECT_EXIT(MallocArray(SIZE_MAX, 2), ABORT_PREDICATE, "");
+ EXPECT_EXIT(CallocArray(7, SIZE_MAX), ABORT_PREDICATE, "");
+ EXPECT_EXIT(MallocArray(SIZE_MAX, 12345567), ABORT_PREDICATE, "");
+ EXPECT_EXIT(CallocArray(SIZE_MAX, SIZE_MAX), ABORT_PREDICATE, "");
}
TEST(guardedalloc, GuardedIntegerOverflow)
{
- MEM_use_guarded_allocator();
+ MEM_use_guarded_allocator();
- MallocArray(1, SIZE_MAX);
- CallocArray(SIZE_MAX, 1);
- MallocArray(SIZE_MAX / 2, 2);
- CallocArray(SIZE_MAX / 1234567, 1234567);
+ MallocArray(1, SIZE_MAX);
+ CallocArray(SIZE_MAX, 1);
+ MallocArray(SIZE_MAX / 2, 2);
+ CallocArray(SIZE_MAX / 1234567, 1234567);
- EXPECT_EXIT(MallocArray(SIZE_MAX, 2), ABORT_PREDICATE, "");
- EXPECT_EXIT(CallocArray(7, SIZE_MAX), ABORT_PREDICATE, "");
- EXPECT_EXIT(MallocArray(SIZE_MAX, 12345567), ABORT_PREDICATE, "");
- EXPECT_EXIT(CallocArray(SIZE_MAX, SIZE_MAX), ABORT_PREDICATE, "");
+ EXPECT_EXIT(MallocArray(SIZE_MAX, 2), ABORT_PREDICATE, "");
+ EXPECT_EXIT(CallocArray(7, SIZE_MAX), ABORT_PREDICATE, "");
+ EXPECT_EXIT(MallocArray(SIZE_MAX, 12345567), ABORT_PREDICATE, "");
+ EXPECT_EXIT(CallocArray(SIZE_MAX, SIZE_MAX), ABORT_PREDICATE, "");
}
diff --git a/tests/gtests/testing/CMakeLists.txt b/tests/gtests/testing/CMakeLists.txt
index b868f4da8f4..e08ee486933 100644
--- a/tests/gtests/testing/CMakeLists.txt
+++ b/tests/gtests/testing/CMakeLists.txt
@@ -19,20 +19,20 @@
# ***** END GPL LICENSE BLOCK *****
set(INC
- .
- ..
- ${GLOG_INCLUDE_DIRS}
- ${GFLAGS_INCLUDE_DIRS}
- ../../../extern/gtest/include
+ .
+ ..
+ ${GLOG_INCLUDE_DIRS}
+ ${GFLAGS_INCLUDE_DIRS}
+ ../../../extern/gtest/include
)
set(INC_SYS
)
set(SRC
- testing_main.cc
+ testing_main.cc
- testing.h
+ testing.h
)
set(LIB
diff --git a/tests/gtests/testing/mock_log.h b/tests/gtests/testing/mock_log.h
index 2ec558fac87..e3414fa1533 100644
--- a/tests/gtests/testing/mock_log.h
+++ b/tests/gtests/testing/mock_log.h
@@ -74,10 +74,16 @@ class ScopedMockLog : public google::LogSink {
public:
// When a ScopedMockLog object is constructed, it starts to
// intercept logs.
- ScopedMockLog() { AddLogSink(this); }
+ ScopedMockLog()
+ {
+ AddLogSink(this);
+ }
// When the object is destructed, it stops intercepting logs.
- virtual ~ScopedMockLog() { RemoveLogSink(this); }
+ virtual ~ScopedMockLog()
+ {
+ RemoveLogSink(this);
+ }
// Implements the mock method:
//
@@ -92,9 +98,10 @@ class ScopedMockLog : public google::LogSink {
// for messages from different threads. In fact, if the same or multiple
// expectations are matched on two threads concurrently, their actions will
// be executed concurrently as well and may interleave.
- MOCK_METHOD3(Log, void(google::LogSeverity severity,
- const std::string& file_path,
- const std::string& message));
+ MOCK_METHOD3(Log,
+ void(google::LogSeverity severity,
+ const std::string &file_path,
+ const std::string &message));
private:
// Implements the send() virtual function in class LogSink.
@@ -119,12 +126,13 @@ class ScopedMockLog : public google::LogSink {
// send() and WaitTillSent(), and that for each message, LOG(), send(),
// WaitTillSent() and Log() are executed in the same thread.
virtual void send(google::LogSeverity severity,
- const char* full_filename,
- const char* /*base_filename*/,
+ const char *full_filename,
+ const char * /*base_filename*/,
int /*line*/,
- const tm* /*tm_time*/,
- const char* message,
- size_t message_len) {
+ const tm * /*tm_time*/,
+ const char *message,
+ size_t message_len)
+ {
// We are only interested in the log severity, full file name, and
// log message.
message_info_.severity = severity;
@@ -139,7 +147,8 @@ class ScopedMockLog : public google::LogSink {
//
// LOG(), send(), WaitTillSent() and Log() will occur in the same thread for
// a given log message.
- virtual void WaitTillSent() {
+ virtual void WaitTillSent()
+ {
// First, and very importantly, we save a copy of the message being
// processed before calling Log(), since Log() may indirectly call send()
// and WaitTillSent() in the same thread again.
diff --git a/tests/gtests/testing/testing.h b/tests/gtests/testing/testing.h
index 9efdbe22557..67138e4f874 100644
--- a/tests/gtests/testing/testing.h
+++ b/tests/gtests/testing/testing.h
@@ -12,115 +12,116 @@
EXPECT_NEAR(a[0], b[0], eps); \
EXPECT_NEAR(a[1], b[1], eps); \
EXPECT_NEAR(a[2], b[2], eps); \
- } (void) 0
+ } \
+ (void)0
#define EXPECT_V4_NEAR(a, b, eps) \
-{ \
- EXPECT_NEAR(a[0], b[0], eps); \
- EXPECT_NEAR(a[1], b[1], eps); \
- EXPECT_NEAR(a[2], b[2], eps); \
- EXPECT_NEAR(a[3], b[3], eps); \
- } (void) 0
+ { \
+ EXPECT_NEAR(a[0], b[0], eps); \
+ EXPECT_NEAR(a[1], b[1], eps); \
+ EXPECT_NEAR(a[2], b[2], eps); \
+ EXPECT_NEAR(a[3], b[3], eps); \
+ } \
+ (void)0
#define EXPECT_M3_NEAR(a, b, eps) \
-do { \
- EXPECT_V3_NEAR(a[0], b[0], eps); \
- EXPECT_V3_NEAR(a[1], b[1], eps); \
- EXPECT_V3_NEAR(a[2], b[2], eps); \
-} while(false);
+ do { \
+ EXPECT_V3_NEAR(a[0], b[0], eps); \
+ EXPECT_V3_NEAR(a[1], b[1], eps); \
+ EXPECT_V3_NEAR(a[2], b[2], eps); \
+ } while (false);
#define EXPECT_M4_NEAR(a, b, eps) \
-do { \
- EXPECT_V3_NEAR(a[0], b[0], eps); \
- EXPECT_V3_NEAR(a[1], b[1], eps); \
- EXPECT_V3_NEAR(a[2], b[2], eps); \
- EXPECT_V4_NEAR(a[3], b[3], eps); \
-} while(false);
+ do { \
+ EXPECT_V3_NEAR(a[0], b[0], eps); \
+ EXPECT_V3_NEAR(a[1], b[1], eps); \
+ EXPECT_V3_NEAR(a[2], b[2], eps); \
+ EXPECT_V4_NEAR(a[3], b[3], eps); \
+ } while (false);
#define EXPECT_MATRIX_NEAR(a, b, tolerance) \
-do { \
- bool dims_match = (a.rows() == b.rows()) && (a.cols() == b.cols()); \
- EXPECT_EQ(a.rows(), b.rows()) << "Matrix rows don't match."; \
- EXPECT_EQ(a.cols(), b.cols()) << "Matrix cols don't match."; \
- if (dims_match) { \
- for (int r = 0; r < a.rows(); ++r) { \
- for (int c = 0; c < a.cols(); ++c) { \
- EXPECT_NEAR(a(r, c), b(r, c), tolerance) \
- << "r=" << r << ", c=" << c << "."; \
+ do { \
+ bool dims_match = (a.rows() == b.rows()) && (a.cols() == b.cols()); \
+ EXPECT_EQ(a.rows(), b.rows()) << "Matrix rows don't match."; \
+ EXPECT_EQ(a.cols(), b.cols()) << "Matrix cols don't match."; \
+ if (dims_match) { \
+ for (int r = 0; r < a.rows(); ++r) { \
+ for (int c = 0; c < a.cols(); ++c) { \
+ EXPECT_NEAR(a(r, c), b(r, c), tolerance) << "r=" << r << ", c=" << c << "."; \
+ } \
} \
} \
- } \
-} while(false);
+ } while (false);
#define EXPECT_MATRIX_NEAR_ZERO(a, tolerance) \
-do { \
- for (int r = 0; r < a.rows(); ++r) { \
- for (int c = 0; c < a.cols(); ++c) { \
- EXPECT_NEAR(0.0, a(r, c), tolerance) \
- << "r=" << r << ", c=" << c << "."; \
+ do { \
+ for (int r = 0; r < a.rows(); ++r) { \
+ for (int c = 0; c < a.cols(); ++c) { \
+ EXPECT_NEAR(0.0, a(r, c), tolerance) << "r=" << r << ", c=" << c << "."; \
+ } \
} \
- } \
-} while(false);
+ } while (false);
#define EXPECT_MATRIX_EQ(a, b) \
-do { \
- bool dims_match = (a.rows() == b.rows()) && (a.cols() == b.cols()); \
- EXPECT_EQ(a.rows(), b.rows()) << "Matrix rows don't match."; \
- EXPECT_EQ(a.cols(), b.cols()) << "Matrix cols don't match."; \
- if (dims_match) { \
- for (int r = 0; r < a.rows(); ++r) { \
- for (int c = 0; c < a.cols(); ++c) { \
- EXPECT_EQ(a(r, c), b(r, c)) \
- << "r=" << r << ", c=" << c << "."; \
+ do { \
+ bool dims_match = (a.rows() == b.rows()) && (a.cols() == b.cols()); \
+ EXPECT_EQ(a.rows(), b.rows()) << "Matrix rows don't match."; \
+ EXPECT_EQ(a.cols(), b.cols()) << "Matrix cols don't match."; \
+ if (dims_match) { \
+ for (int r = 0; r < a.rows(); ++r) { \
+ for (int c = 0; c < a.cols(); ++c) { \
+ EXPECT_EQ(a(r, c), b(r, c)) << "r=" << r << ", c=" << c << "."; \
+ } \
} \
} \
- } \
-} while(false);
+ } while (false);
// Check that sin(angle(a, b)) < tolerance.
#define EXPECT_MATRIX_PROP(a, b, tolerance) \
-do { \
- bool dims_match = (a.rows() == b.rows()) && (a.cols() == b.cols()); \
- EXPECT_EQ(a.rows(), b.rows()) << "Matrix rows don't match."; \
- EXPECT_EQ(a.cols(), b.cols()) << "Matrix cols don't match."; \
- if (dims_match) { \
- double c = CosinusBetweenMatrices(a, b); \
- if (c * c < 1) { \
- double s = sqrt(1 - c * c); \
- EXPECT_NEAR(0, s, tolerance); \
+ do { \
+ bool dims_match = (a.rows() == b.rows()) && (a.cols() == b.cols()); \
+ EXPECT_EQ(a.rows(), b.rows()) << "Matrix rows don't match."; \
+ EXPECT_EQ(a.cols(), b.cols()) << "Matrix cols don't match."; \
+ if (dims_match) { \
+ double c = CosinusBetweenMatrices(a, b); \
+ if (c * c < 1) { \
+ double s = sqrt(1 - c * c); \
+ EXPECT_NEAR(0, s, tolerance); \
+ } \
} \
- } \
-} while(false);
+ } while (false);
#ifdef LIBMV_NUMERIC_NUMERIC_H
-template<class TMat>
-double CosinusBetweenMatrices(const TMat &a, const TMat &b) {
- return (a.array() * b.array()).sum() /
- libmv::FrobeniusNorm(a) / libmv::FrobeniusNorm(b);
+template<class TMat> double CosinusBetweenMatrices(const TMat &a, const TMat &b)
+{
+ return (a.array() * b.array()).sum() / libmv::FrobeniusNorm(a) / libmv::FrobeniusNorm(b);
}
#endif
-template <typename T>
-inline void EXPECT_EQ_VECTOR(const std::vector<T>& expected, const std::vector<T>& actual) {
+template<typename T>
+inline void EXPECT_EQ_VECTOR(const std::vector<T> &expected, const std::vector<T> &actual)
+{
EXPECT_EQ(expected.size(), actual.size());
if (expected.size() == actual.size()) {
- for(size_t i = 0; i < expected.size(); ++i) {
+ for (size_t i = 0; i < expected.size(); ++i) {
EXPECT_EQ(expected[i], actual[i]) << "Element mismatch at index " << i;
}
}
}
-template <typename T>
-inline void EXPECT_EQ_ARRAY(const T *expected, const T *actual, const size_t N) {
- for(size_t i = 0; i < N; ++i) {
+template<typename T>
+inline void EXPECT_EQ_ARRAY(const T *expected, const T *actual, const size_t N)
+{
+ for (size_t i = 0; i < N; ++i) {
EXPECT_EQ(expected[i], actual[i]) << "Element mismatch at index " << i;
}
}
-template <typename T>
-inline void EXPECT_EQ_ARRAY_ND(const T *expected, const T *actual, const size_t N, const size_t D) {
- for(size_t i = 0; i < N; ++i) {
- for(size_t j = 0; j < D; ++j) {
+template<typename T>
+inline void EXPECT_EQ_ARRAY_ND(const T *expected, const T *actual, const size_t N, const size_t D)
+{
+ for (size_t i = 0; i < N; ++i) {
+ for (size_t j = 0; j < D; ++j) {
EXPECT_EQ(expected[i][j], actual[i][j])
<< "Element mismatch at index " << i << ", component index " << j;
}
diff --git a/tests/gtests/testing/testing_main.cc b/tests/gtests/testing/testing_main.cc
index fc607c948c3..6b3a8e5515d 100644
--- a/tests/gtests/testing/testing_main.cc
+++ b/tests/gtests/testing/testing_main.cc
@@ -19,7 +19,8 @@
#include "testing/testing.h"
-int main(int argc, char **argv) {
+int main(int argc, char **argv)
+{
testing::InitGoogleTest(&argc, argv);
BLENDER_GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]);