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
diff options
context:
space:
mode:
authorJacques Lucke <mail@jlucke.com>2020-02-10 15:54:57 +0300
committerJacques Lucke <mail@jlucke.com>2020-02-10 16:09:01 +0300
commit68cc982dcb7c1063a96f7ec9b7ccb95da4919d6b (patch)
tree9d2076363b54cb6b6da96064453ac3499a5f65c8 /tests/gtests/blenlib/BLI_array_ref_test.cc
parent76208a5670bc9d70f99f22a3c49463959461b5c1 (diff)
BLI: improve various C++ data structures
The changes come from the `functions` branch, where I'm using these structures a lot. This also includes a new `BLI::Optional<T>` type, which is similar to `std::Optional<T>` which can be used when Blender starts using C++17.
Diffstat (limited to 'tests/gtests/blenlib/BLI_array_ref_test.cc')
-rw-r--r--tests/gtests/blenlib/BLI_array_ref_test.cc56
1 files changed, 55 insertions, 1 deletions
diff --git a/tests/gtests/blenlib/BLI_array_ref_test.cc b/tests/gtests/blenlib/BLI_array_ref_test.cc
index 4507d9e6e84..538fadc1cf9 100644
--- a/tests/gtests/blenlib/BLI_array_ref_test.cc
+++ b/tests/gtests/blenlib/BLI_array_ref_test.cc
@@ -2,7 +2,8 @@
#include "BLI_array_ref.h"
#include "BLI_vector.h"
-using BLI::IndexRange;
+using namespace BLI;
+
using IntVector = BLI::Vector<int>;
using IntArrayRef = BLI::ArrayRef<int>;
using MutableIntArrayRef = BLI::MutableArrayRef<int>;
@@ -17,6 +18,15 @@ TEST(array_ref, FromSmallVector)
EXPECT_EQ(a_ref[2], 3);
}
+TEST(array_ref, AddConstToPointer)
+{
+ int a = 0;
+ std::vector<int *> vec = {&a};
+ ArrayRef<int *> ref = vec;
+ ArrayRef<const int *> const_ref = ref;
+ EXPECT_EQ(const_ref.size(), 1);
+}
+
TEST(array_ref, IsReferencing)
{
int array[] = {3, 5, 8};
@@ -264,3 +274,47 @@ TEST(array_ref, ContainsPtr)
EXPECT_FALSE(a_ref.contains_ptr(&a[0] - 1));
EXPECT_FALSE(a_ref.contains_ptr(&other));
}
+
+TEST(array_ref, FirstIndex)
+{
+ std::array<int, 5> a = {4, 5, 4, 2, 5};
+ IntArrayRef a_ref(a);
+
+ EXPECT_EQ(a_ref.first_index(4), 0);
+ EXPECT_EQ(a_ref.first_index(5), 1);
+ EXPECT_EQ(a_ref.first_index(2), 3);
+}
+
+TEST(array_ref, CastSameSize)
+{
+ int value = 0;
+ std::array<int *, 4> a = {&value, nullptr, nullptr, nullptr};
+ ArrayRef<int *> a_ref = a;
+ ArrayRef<float *> new_a_ref = a_ref.cast<float *>();
+
+ EXPECT_EQ(a_ref.size(), 4);
+ EXPECT_EQ(new_a_ref.size(), 4);
+
+ EXPECT_EQ(a_ref[0], &value);
+ EXPECT_EQ(new_a_ref[0], (float *)&value);
+}
+
+TEST(array_ref, CastSmallerSize)
+{
+ std::array<uint32_t, 4> a = {3, 4, 5, 6};
+ ArrayRef<uint32_t> a_ref = a;
+ ArrayRef<uint16_t> new_a_ref = a_ref.cast<uint16_t>();
+
+ EXPECT_EQ(a_ref.size(), 4);
+ EXPECT_EQ(new_a_ref.size(), 8);
+}
+
+TEST(array_ref, CastLargerSize)
+{
+ std::array<uint16_t, 4> a = {4, 5, 6, 7};
+ ArrayRef<uint16_t> a_ref = a;
+ ArrayRef<uint32_t> new_a_ref = a_ref.cast<uint32_t>();
+
+ EXPECT_EQ(a_ref.size(), 4);
+ EXPECT_EQ(new_a_ref.size(), 2);
+}