BLI: move some tests into blenlib/tests

Reviewers: sybren

Differential Revision: https://developer.blender.org/D8315
This commit is contained in:
Jacques Lucke 2020-07-23 15:23:55 +02:00
parent 4ae24c0b57
commit c8b24af1b2
17 changed files with 84 additions and 71 deletions

View File

@ -340,3 +340,28 @@ set_source_files_properties(
)
blender_add_lib(bf_blenlib "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
if(WITH_GTESTS)
set(TEST_SRC
tests/BLI_array_test.cc
tests/BLI_disjoint_set_test.cc
tests/BLI_edgehash_test.cc
tests/BLI_index_mask_test.cc
tests/BLI_index_range_test.cc
tests/BLI_linear_allocator_test.cc
tests/BLI_map_test.cc
tests/BLI_math_base_safe_test.cc
tests/BLI_memory_utils_test.cc
tests/BLI_set_test.cc
tests/BLI_span_test.cc
tests/BLI_stack_cxx_test.cc
tests/BLI_string_ref_test.cc
tests/BLI_vector_set_test.cc
tests/BLI_vector_test.cc
)
set(TEST_LIB
bf_blenlib
)
include(GTestTesting)
blender_add_test_lib(bf_bli_tests "${TEST_SRC}" "${INC};${TEST_INC}" "${INC_SYS}" "${LIB};${TEST_LIB}")
endif()

View File

@ -4,7 +4,7 @@
#include "BLI_strict_flags.h"
#include "testing/testing.h"
namespace blender {
namespace blender::tests {
TEST(array, DefaultConstructor)
{
@ -72,7 +72,7 @@ TEST(array, MoveConstructor)
Array<int> array = {5, 6, 7, 8};
Array<int> new_array(std::move(array));
EXPECT_EQ(array.size(), 0);
EXPECT_EQ(array.size(), 0); /* NOLINT: bugprone-use-after-move */
EXPECT_EQ(new_array.size(), 4);
EXPECT_EQ(new_array[0], 5);
EXPECT_EQ(new_array[1], 6);
@ -101,7 +101,7 @@ TEST(array, MoveAssignment)
EXPECT_EQ(new_array.size(), 1);
new_array = std::move(array);
EXPECT_EQ(new_array.size(), 3);
EXPECT_EQ(array.size(), 0);
EXPECT_EQ(array.size(), 0); /* NOLINT: bugprone-use-after-move */
EXPECT_EQ(new_array[0], 1);
EXPECT_EQ(new_array[1], 2);
EXPECT_EQ(new_array[2], 3);
@ -141,7 +141,7 @@ TEST(array, NoInitializationSizeConstructor)
using MyArray = Array<ConstructibleType>;
TypedBuffer<MyArray> buffer;
memset(buffer, 100, sizeof(MyArray));
memset((void *)&buffer, 100, sizeof(MyArray));
/* Doing this to avoid some compiler optimization. */
for (int64_t i : IndexRange(sizeof(MyArray))) {
@ -173,4 +173,4 @@ TEST(array, Fill)
EXPECT_EQ(array[4], 3);
}
} // namespace blender
} // namespace blender::tests

View File

@ -5,7 +5,7 @@
#include "testing/testing.h"
namespace blender {
namespace blender::tests {
TEST(disjoint_set, Test)
{
@ -33,4 +33,4 @@ TEST(disjoint_set, Test)
EXPECT_FALSE(disjoint_set.in_same_set(0, 4));
}
} // namespace blender
} // namespace blender::tests

View File

@ -5,10 +5,8 @@
#include <random>
#include <vector>
extern "C" {
#include "BLI_edgehash.h"
#include "BLI_utildefines.h"
}
#define VALUE_1 POINTER_FROM_INT(1)
#define VALUE_2 POINTER_FROM_INT(2)
@ -334,10 +332,12 @@ TEST(edgehash, StressTest)
/* 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)
if (i < remove_until) {
ASSERT_FALSE(haskey);
else
}
else {
ASSERT_TRUE(haskey);
}
}
/* reinsert all edges */

View File

@ -3,7 +3,7 @@
#include "BLI_index_mask.hh"
#include "testing/testing.h"
namespace blender {
namespace blender::tests {
TEST(index_mask, DefaultConstructor)
{
@ -40,4 +40,4 @@ TEST(index_mask, RangeConstructor)
EXPECT_EQ(indices[2], 5);
}
} // namespace blender
} // namespace blender::tests

View File

@ -5,7 +5,7 @@
#include "BLI_vector.hh"
#include "testing/testing.h"
namespace blender {
namespace blender::tests {
TEST(index_range, DefaultConstructor)
{
@ -140,4 +140,4 @@ TEST(index_range, AsSpan)
EXPECT_EQ(span[3], 7);
}
} // namespace blender
} // namespace blender::tests

View File

@ -4,7 +4,7 @@
#include "BLI_strict_flags.h"
#include "testing/testing.h"
namespace blender {
namespace blender::tests {
static bool is_aligned(void *ptr, uint alignment)
{
@ -115,4 +115,4 @@ TEST(linear_allocator, ConstructArrayCopy)
EXPECT_EQ(span2[2], 3);
}
} // namespace blender
} // namespace blender::tests

View File

@ -8,7 +8,7 @@
#include "BLI_vector.hh"
#include "testing/testing.h"
namespace blender {
namespace blender::tests {
TEST(map, DefaultConstructor)
{
@ -335,7 +335,7 @@ TEST(map, MoveConstructorSmall)
EXPECT_EQ(map2.size(), 2);
EXPECT_EQ(map2.lookup(1), 2.0f);
EXPECT_EQ(map2.lookup(4), 1.0f);
EXPECT_EQ(map1.size(), 0);
EXPECT_EQ(map1.size(), 0); /* NOLINT: bugprone-use-after-move */
EXPECT_EQ(map1.lookup_ptr(4), nullptr);
}
@ -349,7 +349,7 @@ TEST(map, MoveConstructorLarge)
EXPECT_EQ(map2.size(), 100);
EXPECT_EQ(map2.lookup(1), 1);
EXPECT_EQ(map2.lookup(4), 4);
EXPECT_EQ(map1.size(), 0);
EXPECT_EQ(map1.size(), 0); /* NOLINT: bugprone-use-after-move */
EXPECT_EQ(map1.lookup_ptr(4), nullptr);
}
@ -363,7 +363,7 @@ TEST(map, MoveAssignment)
EXPECT_EQ(map2.size(), 2);
EXPECT_EQ(map2.lookup(1), 2.0f);
EXPECT_EQ(map2.lookup(4), 1.0f);
EXPECT_EQ(map1.size(), 0);
EXPECT_EQ(map1.size(), 0); /* NOLINT: bugprone-use-after-move */
EXPECT_EQ(map1.lookup_ptr(4), nullptr);
}
@ -587,4 +587,4 @@ TEST(map, Benchmark)
#endif /* Benchmark */
} // namespace blender
} // namespace blender::tests

View File

@ -5,7 +5,7 @@
#include "BLI_strict_flags.h"
#include "testing/testing.h"
namespace blender {
namespace blender::tests {
struct MyValue {
static inline int alive = 0;
@ -19,7 +19,7 @@ struct MyValue {
alive++;
}
MyValue(const MyValue &other)
MyValue(const MyValue &UNUSED(other))
{
if (alive == 15) {
throw std::exception();
@ -156,4 +156,4 @@ static_assert(is_convertible_pointer_v<int **, int **const>);
static_assert(is_convertible_pointer_v<int **, int *const *>);
static_assert(is_convertible_pointer_v<int **, int const *const *>);
} // namespace blender
} // namespace blender::tests

View File

@ -12,6 +12,7 @@
#include "testing/testing.h"
namespace blender {
namespace tests {
TEST(set, DefaultConstructor)
{
@ -81,7 +82,7 @@ TEST(set, MoveConstructor)
Set<int> set = {1, 2, 3};
EXPECT_EQ(set.size(), 3);
Set<int> set2(std::move(set));
EXPECT_EQ(set.size(), 0);
EXPECT_EQ(set.size(), 0); /* NOLINT: bugprone-use-after-move */
EXPECT_EQ(set2.size(), 3);
}
@ -106,7 +107,7 @@ TEST(set, MoveAssignment)
EXPECT_EQ(set.size(), 3);
Set<int> set2;
set2 = std::move(set);
EXPECT_EQ(set.size(), 0);
EXPECT_EQ(set.size(), 0); /* NOLINT: bugprone-use-after-move */
EXPECT_EQ(set2.size(), 3);
}
@ -279,31 +280,32 @@ struct Type2 {
uint32_t value;
};
bool operator==(const Type1 &a, const Type1 &b)
static bool operator==(const Type1 &a, const Type1 &b)
{
return a.value == b.value;
}
bool operator==(const Type1 &a, const Type2 &b)
{
return a.value == b.value;
}
bool operator==(const Type2 &a, const Type1 &b)
static bool operator==(const Type2 &a, const Type1 &b)
{
return a.value == b.value;
}
template<> struct DefaultHash<Type1> {
uint32_t operator()(const Type1 &value) const
} // namespace tests
/* This has to be defined in ::blender namespace. */
template<> struct DefaultHash<tests::Type1> {
uint32_t operator()(const tests::Type1 &value) const
{
return value.value;
}
uint32_t operator()(const Type2 &value) const
uint32_t operator()(const tests::Type2 &value) const
{
return value.value;
}
};
namespace tests {
TEST(set, ContainsAs)
{
Set<Type1> set;
@ -559,4 +561,5 @@ TEST(set, Benchmark)
#endif /* Benchmark */
} // namespace tests
} // namespace blender

View File

@ -5,7 +5,7 @@
#include "BLI_vector.hh"
#include "testing/testing.h"
namespace blender {
namespace blender::tests {
TEST(span, FromSmallVector)
{
@ -295,4 +295,4 @@ TEST(span, VoidPointerSpan)
func1({&a, &b, &c});
}
} // namespace blender
} // namespace blender::tests

View File

@ -5,7 +5,7 @@
#include "BLI_vector.hh"
#include "testing/testing.h"
namespace blender {
namespace blender::tests {
TEST(stack, DefaultConstructor)
{
@ -45,7 +45,7 @@ TEST(stack, MoveConstructor)
{
Stack<int> stack1 = {1, 2, 3, 4, 5, 6, 7};
Stack<int> stack2 = std::move(stack1);
EXPECT_EQ(stack1.size(), 0);
EXPECT_EQ(stack1.size(), 0); /* NOLINT: bugprone-use-after-move */
EXPECT_EQ(stack2.size(), 7);
for (int i = 7; i >= 1; i--) {
EXPECT_EQ(stack2.pop(), i);
@ -75,7 +75,7 @@ TEST(stack, MoveAssignment)
Stack<int> stack1 = {1, 2, 3, 4, 5, 6, 7};
Stack<int> stack2 = {5, 3, 7, 2, 2};
stack2 = std::move(stack1);
EXPECT_EQ(stack1.size(), 0);
EXPECT_EQ(stack1.size(), 0); /* NOLINT: bugprone-use-after-move */
EXPECT_EQ(stack2.size(), 7);
for (int i = 7; i >= 1; i--) {
EXPECT_EQ(stack2.pop(), i);
@ -185,4 +185,4 @@ TEST(stack, OveralignedValues)
}
}
} // namespace blender
} // namespace blender::tests

View File

@ -5,7 +5,7 @@
#include "BLI_vector.hh"
#include "testing/testing.h"
namespace blender {
namespace blender::tests {
TEST(string_ref_null, DefaultConstructor)
{
@ -274,4 +274,4 @@ TEST(string_ref, Copy)
EXPECT_EQ(ref, dst);
}
} // namespace blender
} // namespace blender::tests

View File

@ -4,7 +4,7 @@
#include "BLI_vector_set.hh"
#include "testing/testing.h"
namespace blender {
namespace blender::tests {
TEST(vector_set, DefaultConstructor)
{
@ -57,7 +57,7 @@ TEST(vector_set, Move)
{
VectorSet<int> set1 = {1, 2, 3};
VectorSet<int> set2 = std::move(set1);
EXPECT_EQ(set1.size(), 0);
EXPECT_EQ(set1.size(), 0); /* NOLINT: bugprone-use-after-move */
EXPECT_EQ(set2.size(), 3);
}
@ -66,7 +66,7 @@ TEST(vector_set, MoveAssignment)
VectorSet<int> set1 = {1, 2, 3};
VectorSet<int> set2 = {};
set2 = std::move(set1);
EXPECT_EQ(set1.size(), 0);
EXPECT_EQ(set1.size(), 0); /* NOLINT: bugprone-use-after-move */
EXPECT_EQ(set2.size(), 3);
}
@ -161,4 +161,4 @@ TEST(vector_set, Remove)
EXPECT_FALSE(set.contains(5));
}
} // namespace blender
} // namespace blender::tests

View File

@ -5,7 +5,7 @@
#include "testing/testing.h"
#include <forward_list>
namespace blender {
namespace blender::tests {
TEST(vector, DefaultConstructor)
{
@ -167,7 +167,7 @@ TEST(vector, MoveConstructor)
Vector<int> vec1 = {1, 2, 3, 4};
Vector<int> vec2(std::move(vec1));
EXPECT_EQ(vec1.size(), 0);
EXPECT_EQ(vec1.size(), 0); /* NOLINT: bugprone-use-after-move */
EXPECT_EQ(vec2.size(), 4);
EXPECT_EQ(vec2[0], 1);
EXPECT_EQ(vec2[1], 2);
@ -180,7 +180,7 @@ TEST(vector, MoveConstructor2)
Vector<int, 2> vec1 = {1, 2, 3, 4};
Vector<int, 3> vec2(std::move(vec1));
EXPECT_EQ(vec1.size(), 0);
EXPECT_EQ(vec1.size(), 0); /* NOLINT: bugprone-use-after-move */
EXPECT_EQ(vec2.size(), 4);
EXPECT_EQ(vec2[0], 1);
EXPECT_EQ(vec2[1], 2);
@ -193,7 +193,7 @@ TEST(vector, MoveConstructor3)
Vector<int, 20> vec1 = {1, 2, 3, 4};
Vector<int, 1> vec2(std::move(vec1));
EXPECT_EQ(vec1.size(), 0);
EXPECT_EQ(vec1.size(), 0); /* NOLINT: bugprone-use-after-move */
EXPECT_EQ(vec2.size(), 4);
EXPECT_EQ(vec2[2], 3);
}
@ -203,7 +203,7 @@ TEST(vector, MoveConstructor4)
Vector<int, 5> vec1 = {1, 2, 3, 4};
Vector<int, 6> vec2(std::move(vec1));
EXPECT_EQ(vec1.size(), 0);
EXPECT_EQ(vec1.size(), 0); /* NOLINT: bugprone-use-after-move */
EXPECT_EQ(vec2.size(), 4);
EXPECT_EQ(vec2[3], 4);
}
@ -473,11 +473,11 @@ class TypeConstructMock {
{
}
TypeConstructMock(const TypeConstructMock &other) : copy_constructed(true)
TypeConstructMock(const TypeConstructMock &UNUSED(other)) : copy_constructed(true)
{
}
TypeConstructMock(TypeConstructMock &&other) noexcept : move_constructed(true)
TypeConstructMock(TypeConstructMock &&UNUSED(other)) noexcept : move_constructed(true)
{
}
@ -636,4 +636,4 @@ TEST(vector, Fill)
EXPECT_EQ(vec[4], 3);
}
} // namespace blender
} // namespace blender::tests

View File

@ -39,46 +39,31 @@ else()
set(BLI_path_util_extra_libs "bf_blenlib;extern_wcwidth;${ZLIB_LIBRARIES}")
endif()
BLENDER_TEST(BLI_array "bf_blenlib")
BLENDER_TEST(BLI_array_store "bf_blenlib")
BLENDER_TEST(BLI_array_utils "bf_blenlib")
BLENDER_TEST(BLI_delaunay_2d "bf_blenlib")
BLENDER_TEST(BLI_disjoint_set "bf_blenlib")
BLENDER_TEST(BLI_edgehash "bf_blenlib")
BLENDER_TEST(BLI_expr_pylike_eval "bf_blenlib")
BLENDER_TEST(BLI_ghash "bf_blenlib")
BLENDER_TEST(BLI_hash_mm2a "bf_blenlib")
BLENDER_TEST(BLI_heap "bf_blenlib")
BLENDER_TEST(BLI_heap_simple "bf_blenlib")
BLENDER_TEST(BLI_index_mask "bf_blenlib")
BLENDER_TEST(BLI_index_range "bf_blenlib")
BLENDER_TEST(BLI_kdopbvh "bf_blenlib;bf_intern_numaapi")
BLENDER_TEST(BLI_linear_allocator "bf_blenlib")
BLENDER_TEST(BLI_linklist_lockfree "bf_blenlib;bf_intern_numaapi")
BLENDER_TEST(BLI_listbase "bf_blenlib")
BLENDER_TEST(BLI_map "bf_blenlib")
BLENDER_TEST(BLI_math_base "bf_blenlib")
BLENDER_TEST(BLI_math_base_safe "bf_blenlib")
BLENDER_TEST(BLI_math_bits "bf_blenlib")
BLENDER_TEST(BLI_math_color "bf_blenlib")
BLENDER_TEST(BLI_math_geom "bf_blenlib")
BLENDER_TEST(BLI_math_matrix "bf_blenlib")
BLENDER_TEST(BLI_math_vector "bf_blenlib")
BLENDER_TEST(BLI_memiter "bf_blenlib")
BLENDER_TEST(BLI_memory_utils "bf_blenlib")
BLENDER_TEST(BLI_path_util "${BLI_path_util_extra_libs}")
BLENDER_TEST(BLI_polyfill_2d "bf_blenlib")
BLENDER_TEST(BLI_set "bf_blenlib")
BLENDER_TEST(BLI_span "bf_blenlib")
BLENDER_TEST(BLI_stack "bf_blenlib")
BLENDER_TEST(BLI_stack_cxx "bf_blenlib")
BLENDER_TEST(BLI_string "bf_blenlib")
BLENDER_TEST(BLI_string_ref "bf_blenlib")
BLENDER_TEST(BLI_string_utf8 "bf_blenlib")
BLENDER_TEST(BLI_task "bf_blenlib;bf_intern_numaapi")
BLENDER_TEST(BLI_task_graph "bf_blenlib;bf_intern_numaapi")
BLENDER_TEST(BLI_vector "bf_blenlib")
BLENDER_TEST(BLI_vector_set "bf_blenlib")
BLENDER_TEST_PERFORMANCE(BLI_ghash_performance "bf_blenlib")
BLENDER_TEST_PERFORMANCE(BLI_task_performance "bf_blenlib")