diff options
author | Jacques Lucke <jacques@blender.org> | 2020-07-08 23:27:25 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-07-08 23:27:25 +0300 |
commit | 403384998a6bb5f428e15ced5503206b45032b25 (patch) | |
tree | 23e09b183faa196603aafb1572ed0f13b3964333 /tests/gtests/blenlib | |
parent | 4b85ed819dc0746f6fc46eab1019aab4c4fcf9c9 (diff) |
BLI: improve constructors and conversions to span
This allows us to avoid many calls to `as_span()` methods. I will
remove those in the next commit. Furthermore, constructors
of Vector and Array can convert from one type to another now.
I tested these changes on Linux with gcc and on Windows.
Diffstat (limited to 'tests/gtests/blenlib')
-rw-r--r-- | tests/gtests/blenlib/BLI_memory_utils_test.cc | 37 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_vector_test.cc | 12 |
2 files changed, 49 insertions, 0 deletions
diff --git a/tests/gtests/blenlib/BLI_memory_utils_test.cc b/tests/gtests/blenlib/BLI_memory_utils_test.cc index eb896c0cca6..b99db5c5eca 100644 --- a/tests/gtests/blenlib/BLI_memory_utils_test.cc +++ b/tests/gtests/blenlib/BLI_memory_utils_test.cc @@ -1,5 +1,6 @@ /* Apache License, Version 2.0 */ +#include "BLI_float3.hh" #include "BLI_memory_utils.hh" #include "BLI_strict_flags.h" #include "testing/testing.h" @@ -119,4 +120,40 @@ TEST(memory_utils, UninitializedFillN_StrongExceptionSafety) EXPECT_EQ(MyValue::alive, 0); } +class TestBaseClass { + virtual void mymethod(){}; +}; + +class TestChildClass : public TestBaseClass { + void mymethod() override + { + } +}; + +static_assert(is_convertible_pointer_v<int *, int *>); +static_assert(is_convertible_pointer_v<int *, const int *>); +static_assert(is_convertible_pointer_v<int *, int *const>); +static_assert(is_convertible_pointer_v<int *, const int *const>); +static_assert(!is_convertible_pointer_v<const int *, int *>); +static_assert(!is_convertible_pointer_v<int, int *>); +static_assert(!is_convertible_pointer_v<int *, int>); +static_assert(is_convertible_pointer_v<TestBaseClass *, const TestBaseClass *>); +static_assert(!is_convertible_pointer_v<const TestBaseClass *, TestBaseClass *>); +static_assert(is_convertible_pointer_v<TestChildClass *, TestBaseClass *>); +static_assert(!is_convertible_pointer_v<TestBaseClass *, TestChildClass *>); +static_assert(is_convertible_pointer_v<const TestChildClass *, const TestBaseClass *>); +static_assert(!is_convertible_pointer_v<TestBaseClass, const TestChildClass *>); +static_assert(!is_convertible_pointer_v<float3, float *>); +static_assert(!is_convertible_pointer_v<float *, float3>); +static_assert(!is_convertible_pointer_v<int **, int *>); +static_assert(!is_convertible_pointer_v<int *, int **>); +static_assert(is_convertible_pointer_v<int **, int **>); +static_assert(is_convertible_pointer_v<const int **, const int **>); +static_assert(!is_convertible_pointer_v<const int **, int **>); +static_assert(!is_convertible_pointer_v<int *const *, int **>); +static_assert(!is_convertible_pointer_v<int *const *const, int **>); +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 diff --git a/tests/gtests/blenlib/BLI_vector_test.cc b/tests/gtests/blenlib/BLI_vector_test.cc index 1f6bd1ded5b..92fb12fb4e5 100644 --- a/tests/gtests/blenlib/BLI_vector_test.cc +++ b/tests/gtests/blenlib/BLI_vector_test.cc @@ -59,6 +59,18 @@ TEST(vector, InitializerListConstructor) EXPECT_EQ(vec[3], 6); } +TEST(vector, ConvertingConstructor) +{ + std::array<float, 5> values = {5.4f, 7.3f, -8.1f, 5.0f, 0.0f}; + Vector<int> vec = values; + EXPECT_EQ(vec.size(), 5u); + EXPECT_EQ(vec[0], 5); + EXPECT_EQ(vec[1], 7); + EXPECT_EQ(vec[2], -8); + EXPECT_EQ(vec[3], 5); + EXPECT_EQ(vec[4], 0); +} + struct TestListValue { TestListValue *next, *prev; int value; |