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:
authorJacques Lucke <jacques@blender.org>2020-06-09 12:58:47 +0300
committerJacques Lucke <jacques@blender.org>2020-06-09 12:58:47 +0300
commitf7c0f1b8b83ac475755b633abf59cf9f447b2d49 (patch)
tree97302f741ce4e40f6e4de9f0cfd54c7320ee7fd5 /tests
parent7d2b4ae9c6ecce394130cd08694914bf93497a11 (diff)
BLI: rename ArrayRef to Span
This also renames `MutableArrayRef` to `MutableSpan`. The name "Span" works better, because `std::span` will provide similar functionality in C++20. Furthermore, a shorter, more concise name for a common data structure is nice.
Diffstat (limited to 'tests')
-rw-r--r--tests/gtests/blenlib/BLI_array_ref_test.cc288
-rw-r--r--tests/gtests/blenlib/BLI_array_test.cc6
-rw-r--r--tests/gtests/blenlib/BLI_index_mask_test.cc2
-rw-r--r--tests/gtests/blenlib/BLI_index_range_test.cc14
-rw-r--r--tests/gtests/blenlib/BLI_linear_allocator_test.cc20
-rw-r--r--tests/gtests/blenlib/BLI_span_test.cc284
-rw-r--r--tests/gtests/blenlib/BLI_stack_cxx_test.cc2
-rw-r--r--tests/gtests/blenlib/BLI_vector_test.cc12
-rw-r--r--tests/gtests/blenlib/CMakeLists.txt2
9 files changed, 313 insertions, 317 deletions
diff --git a/tests/gtests/blenlib/BLI_array_ref_test.cc b/tests/gtests/blenlib/BLI_array_ref_test.cc
deleted file mode 100644
index 431e2d517f8..00000000000
--- a/tests/gtests/blenlib/BLI_array_ref_test.cc
+++ /dev/null
@@ -1,288 +0,0 @@
-#include "BLI_array_ref.hh"
-#include "BLI_strict_flags.h"
-#include "BLI_vector.hh"
-#include "testing/testing.h"
-
-using namespace blender;
-
-using IntVector = blender::Vector<int>;
-using IntArrayRef = blender::ArrayRef<int>;
-using MutableIntArrayRef = blender::MutableArrayRef<int>;
-
-TEST(array_ref, FromSmallVector)
-{
- IntVector a = {1, 2, 3};
- IntArrayRef a_ref = a;
- EXPECT_EQ(a_ref.size(), 3);
- EXPECT_EQ(a_ref[0], 1);
- EXPECT_EQ(a_ref[1], 2);
- 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};
- MutableIntArrayRef ref(array, ARRAY_SIZE(array));
- EXPECT_EQ(ref.size(), 3);
- EXPECT_EQ(ref[1], 5);
- array[1] = 10;
- EXPECT_EQ(ref[1], 10);
-}
-
-TEST(array_ref, DropBack)
-{
- IntVector a = {4, 5, 6, 7};
- auto slice = IntArrayRef(a).drop_back(2);
- EXPECT_EQ(slice.size(), 2);
- EXPECT_EQ(slice[0], 4);
- EXPECT_EQ(slice[1], 5);
-}
-
-TEST(array_ref, DropBackAll)
-{
- IntVector a = {4, 5, 6, 7};
- auto slice = IntArrayRef(a).drop_back(a.size());
- EXPECT_EQ(slice.size(), 0);
-}
-
-TEST(array_ref, DropFront)
-{
- IntVector a = {4, 5, 6, 7};
- auto slice = IntArrayRef(a).drop_front(1);
- EXPECT_EQ(slice.size(), 3);
- EXPECT_EQ(slice[0], 5);
- EXPECT_EQ(slice[1], 6);
- EXPECT_EQ(slice[2], 7);
-}
-
-TEST(array_ref, DropFrontAll)
-{
- IntVector a = {4, 5, 6, 7};
- auto slice = IntArrayRef(a).drop_front(a.size());
- EXPECT_EQ(slice.size(), 0);
-}
-
-TEST(array_ref, TakeFront)
-{
- IntVector a = {4, 5, 6, 7};
- auto slice = IntArrayRef(a).take_front(2);
- EXPECT_EQ(slice.size(), 2);
- EXPECT_EQ(slice[0], 4);
- EXPECT_EQ(slice[1], 5);
-}
-
-TEST(array_ref, TakeBack)
-{
- IntVector a = {5, 6, 7, 8};
- auto slice = IntArrayRef(a).take_back(2);
- EXPECT_EQ(slice.size(), 2);
- EXPECT_EQ(slice[0], 7);
- EXPECT_EQ(slice[1], 8);
-}
-
-TEST(array_ref, Slice)
-{
- IntVector a = {4, 5, 6, 7};
- auto slice = IntArrayRef(a).slice(1, 2);
- EXPECT_EQ(slice.size(), 2);
- EXPECT_EQ(slice[0], 5);
- EXPECT_EQ(slice[1], 6);
-}
-
-TEST(array_ref, SliceEmpty)
-{
- IntVector a = {4, 5, 6, 7};
- auto slice = IntArrayRef(a).slice(2, 0);
- EXPECT_EQ(slice.size(), 0);
-}
-
-TEST(array_ref, SliceRange)
-{
- IntVector a = {1, 2, 3, 4, 5};
- auto slice = IntArrayRef(a).slice(IndexRange(2, 2));
- EXPECT_EQ(slice.size(), 2);
- EXPECT_EQ(slice[0], 3);
- EXPECT_EQ(slice[1], 4);
-}
-
-TEST(array_ref, Contains)
-{
- IntVector a = {4, 5, 6, 7};
- IntArrayRef a_ref = a;
- EXPECT_TRUE(a_ref.contains(4));
- EXPECT_TRUE(a_ref.contains(5));
- EXPECT_TRUE(a_ref.contains(6));
- EXPECT_TRUE(a_ref.contains(7));
- EXPECT_FALSE(a_ref.contains(3));
- EXPECT_FALSE(a_ref.contains(8));
-}
-
-TEST(array_ref, Count)
-{
- IntVector a = {2, 3, 4, 3, 3, 2, 2, 2, 2};
- IntArrayRef a_ref = a;
- EXPECT_EQ(a_ref.count(1), 0);
- EXPECT_EQ(a_ref.count(2), 5);
- EXPECT_EQ(a_ref.count(3), 3);
- EXPECT_EQ(a_ref.count(4), 1);
- EXPECT_EQ(a_ref.count(5), 0);
-}
-
-static void test_ref_from_initializer_list(IntArrayRef ref)
-{
- EXPECT_EQ(ref.size(), 4);
- EXPECT_EQ(ref[0], 3);
- EXPECT_EQ(ref[1], 6);
- EXPECT_EQ(ref[2], 8);
- EXPECT_EQ(ref[3], 9);
-}
-
-TEST(array_ref, FromInitializerList)
-{
- test_ref_from_initializer_list({3, 6, 8, 9});
-}
-
-TEST(array_ref, FromVector)
-{
- std::vector<int> a = {1, 2, 3, 4};
- IntArrayRef a_ref(a);
- EXPECT_EQ(a_ref.size(), 4);
- EXPECT_EQ(a_ref[0], 1);
- EXPECT_EQ(a_ref[1], 2);
- EXPECT_EQ(a_ref[2], 3);
- EXPECT_EQ(a_ref[3], 4);
-}
-
-TEST(array_ref, FromArray)
-{
- std::array<int, 2> a = {5, 6};
- IntArrayRef a_ref(a);
- EXPECT_EQ(a_ref.size(), 2);
- EXPECT_EQ(a_ref[0], 5);
- EXPECT_EQ(a_ref[1], 6);
-}
-
-TEST(array_ref, Fill)
-{
- std::array<int, 5> a = {4, 5, 6, 7, 8};
- MutableIntArrayRef a_ref(a);
- a_ref.fill(1);
- EXPECT_EQ(a[0], 1);
- EXPECT_EQ(a[1], 1);
- EXPECT_EQ(a[2], 1);
- EXPECT_EQ(a[3], 1);
- EXPECT_EQ(a[4], 1);
-}
-
-TEST(array_ref, FillIndices)
-{
- std::array<int, 5> a = {0, 0, 0, 0, 0};
- MutableIntArrayRef a_ref(a);
- a_ref.fill_indices({0, 2, 3}, 1);
- EXPECT_EQ(a[0], 1);
- EXPECT_EQ(a[1], 0);
- EXPECT_EQ(a[2], 1);
- EXPECT_EQ(a[3], 1);
- EXPECT_EQ(a[4], 0);
-}
-
-TEST(array_ref, SizeInBytes)
-{
- std::array<int, 10> a;
- IntArrayRef a_ref(a);
- EXPECT_EQ(a_ref.size_in_bytes(), sizeof(a));
- EXPECT_EQ(a_ref.size_in_bytes(), 40);
-}
-
-TEST(array_ref, FirstLast)
-{
- std::array<int, 4> a = {6, 7, 8, 9};
- IntArrayRef a_ref(a);
- EXPECT_EQ(a_ref.first(), 6);
- EXPECT_EQ(a_ref.last(), 9);
-}
-
-TEST(array_ref, FirstLast_OneElement)
-{
- int a = 3;
- IntArrayRef a_ref(&a, 1);
- EXPECT_EQ(a_ref.first(), 3);
- EXPECT_EQ(a_ref.last(), 3);
-}
-
-TEST(array_ref, Get)
-{
- std::array<int, 3> a = {5, 6, 7};
- IntArrayRef a_ref(a);
- EXPECT_EQ(a_ref.get(0, 42), 5);
- EXPECT_EQ(a_ref.get(1, 42), 6);
- EXPECT_EQ(a_ref.get(2, 42), 7);
- EXPECT_EQ(a_ref.get(3, 42), 42);
- EXPECT_EQ(a_ref.get(4, 42), 42);
-}
-
-TEST(array_ref, ContainsPtr)
-{
- std::array<int, 3> a = {5, 6, 7};
- int other = 10;
- IntArrayRef a_ref(a);
- EXPECT_TRUE(a_ref.contains_ptr(&a[0] + 0));
- EXPECT_TRUE(a_ref.contains_ptr(&a[0] + 1));
- EXPECT_TRUE(a_ref.contains_ptr(&a[0] + 2));
- EXPECT_FALSE(a_ref.contains_ptr(&a[0] + 3));
- 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);
-}
diff --git a/tests/gtests/blenlib/BLI_array_test.cc b/tests/gtests/blenlib/BLI_array_test.cc
index 398acfef866..fc3c15fe813 100644
--- a/tests/gtests/blenlib/BLI_array_test.cc
+++ b/tests/gtests/blenlib/BLI_array_test.cc
@@ -39,11 +39,11 @@ TEST(array, InitializerListConstructor)
EXPECT_EQ(array[3], 7);
}
-TEST(array, ArrayRefConstructor)
+TEST(array, SpanConstructor)
{
int stackarray[4] = {6, 7, 8, 9};
- ArrayRef<int> array_ref(stackarray, ARRAY_SIZE(stackarray));
- Array<int> array(array_ref);
+ Span<int> span(stackarray, ARRAY_SIZE(stackarray));
+ Array<int> array(span);
EXPECT_EQ(array.size(), 4);
EXPECT_EQ(array[0], 6);
EXPECT_EQ(array[1], 7);
diff --git a/tests/gtests/blenlib/BLI_index_mask_test.cc b/tests/gtests/blenlib/BLI_index_mask_test.cc
index 87e936a76ea..63b528c91b1 100644
--- a/tests/gtests/blenlib/BLI_index_mask_test.cc
+++ b/tests/gtests/blenlib/BLI_index_mask_test.cc
@@ -32,7 +32,7 @@ TEST(index_mask, RangeConstructor)
EXPECT_TRUE(mask.is_range());
EXPECT_EQ(mask.as_range().first(), 3);
EXPECT_EQ(mask.as_range().last(), 7);
- ArrayRef<uint> indices = mask.indices();
+ Span<uint> indices = mask.indices();
EXPECT_EQ(indices[0], 3);
EXPECT_EQ(indices[1], 4);
EXPECT_EQ(indices[2], 5);
diff --git a/tests/gtests/blenlib/BLI_index_range_test.cc b/tests/gtests/blenlib/BLI_index_range_test.cc
index 578b37c5a27..da51b7a66c0 100644
--- a/tests/gtests/blenlib/BLI_index_range_test.cc
+++ b/tests/gtests/blenlib/BLI_index_range_test.cc
@@ -127,13 +127,13 @@ TEST(index_range, SliceRange)
EXPECT_EQ(slice.last(), 12);
}
-TEST(index_range, AsArrayRef)
+TEST(index_range, AsSpan)
{
IndexRange range = IndexRange(4, 6);
- ArrayRef<uint> ref = range.as_array_ref();
- EXPECT_EQ(ref.size(), 6);
- EXPECT_EQ(ref[0], 4);
- EXPECT_EQ(ref[1], 5);
- EXPECT_EQ(ref[2], 6);
- EXPECT_EQ(ref[3], 7);
+ Span<uint> span = range.as_span();
+ EXPECT_EQ(span.size(), 6);
+ EXPECT_EQ(span[0], 4);
+ EXPECT_EQ(span[1], 5);
+ EXPECT_EQ(span[2], 6);
+ EXPECT_EQ(span[3], 7);
}
diff --git a/tests/gtests/blenlib/BLI_linear_allocator_test.cc b/tests/gtests/blenlib/BLI_linear_allocator_test.cc
index 33ca8c5e2b3..0d926ca7931 100644
--- a/tests/gtests/blenlib/BLI_linear_allocator_test.cc
+++ b/tests/gtests/blenlib/BLI_linear_allocator_test.cc
@@ -67,8 +67,8 @@ TEST(linear_allocator, AllocateArray)
{
LinearAllocator<> allocator;
- MutableArrayRef<int> array = allocator.allocate_array<int>(5);
- EXPECT_EQ(array.size(), 5);
+ MutableSpan<int> span = allocator.allocate_array<int>(5);
+ EXPECT_EQ(span.size(), 5);
}
TEST(linear_allocator, Construct)
@@ -87,7 +87,7 @@ TEST(linear_allocator, ConstructElementsAndPointerArray)
LinearAllocator<> allocator;
std::array<int, 7> values = {1, 2, 3, 4, 5, 6, 7};
- ArrayRef<Vector<int> *> vectors = allocator.construct_elements_and_pointer_array<Vector<int>>(
+ Span<Vector<int> *> vectors = allocator.construct_elements_and_pointer_array<Vector<int>>(
5, values);
EXPECT_EQ(vectors.size(), 5);
@@ -104,11 +104,11 @@ TEST(linear_allocator, ConstructArrayCopy)
LinearAllocator<> allocator;
Vector<int> values = {1, 2, 3};
- MutableArrayRef<int> array1 = allocator.construct_array_copy(values.as_ref());
- MutableArrayRef<int> array2 = allocator.construct_array_copy(values.as_ref());
- EXPECT_NE(array1.data(), array2.data());
- EXPECT_EQ(array1.size(), 3);
- EXPECT_EQ(array2.size(), 3);
- EXPECT_EQ(array1[1], 2);
- EXPECT_EQ(array2[2], 3);
+ MutableSpan<int> span1 = allocator.construct_array_copy(values.as_span());
+ MutableSpan<int> span2 = allocator.construct_array_copy(values.as_span());
+ EXPECT_NE(span1.data(), span2.data());
+ EXPECT_EQ(span1.size(), 3);
+ EXPECT_EQ(span2.size(), 3);
+ EXPECT_EQ(span1[1], 2);
+ EXPECT_EQ(span2[2], 3);
}
diff --git a/tests/gtests/blenlib/BLI_span_test.cc b/tests/gtests/blenlib/BLI_span_test.cc
new file mode 100644
index 00000000000..32a6b978328
--- /dev/null
+++ b/tests/gtests/blenlib/BLI_span_test.cc
@@ -0,0 +1,284 @@
+#include "BLI_span.hh"
+#include "BLI_strict_flags.h"
+#include "BLI_vector.hh"
+#include "testing/testing.h"
+
+using namespace blender;
+
+TEST(array_ref, FromSmallVector)
+{
+ Vector<int> a = {1, 2, 3};
+ Span<int> a_span = a;
+ EXPECT_EQ(a_span.size(), 3);
+ EXPECT_EQ(a_span[0], 1);
+ EXPECT_EQ(a_span[1], 2);
+ EXPECT_EQ(a_span[2], 3);
+}
+
+TEST(array_ref, AddConstToPointer)
+{
+ int a = 0;
+ std::vector<int *> vec = {&a};
+ Span<int *> span = vec;
+ Span<const int *> const_span = span;
+ EXPECT_EQ(const_span.size(), 1);
+}
+
+TEST(array_ref, IsReferencing)
+{
+ int array[] = {3, 5, 8};
+ MutableSpan<int> span(array, ARRAY_SIZE(array));
+ EXPECT_EQ(span.size(), 3);
+ EXPECT_EQ(span[1], 5);
+ array[1] = 10;
+ EXPECT_EQ(span[1], 10);
+}
+
+TEST(array_ref, DropBack)
+{
+ Vector<int> a = {4, 5, 6, 7};
+ auto slice = Span<int>(a).drop_back(2);
+ EXPECT_EQ(slice.size(), 2);
+ EXPECT_EQ(slice[0], 4);
+ EXPECT_EQ(slice[1], 5);
+}
+
+TEST(array_ref, DropBackAll)
+{
+ Vector<int> a = {4, 5, 6, 7};
+ auto slice = Span<int>(a).drop_back(a.size());
+ EXPECT_EQ(slice.size(), 0);
+}
+
+TEST(array_ref, DropFront)
+{
+ Vector<int> a = {4, 5, 6, 7};
+ auto slice = Span<int>(a).drop_front(1);
+ EXPECT_EQ(slice.size(), 3);
+ EXPECT_EQ(slice[0], 5);
+ EXPECT_EQ(slice[1], 6);
+ EXPECT_EQ(slice[2], 7);
+}
+
+TEST(array_ref, DropFrontAll)
+{
+ Vector<int> a = {4, 5, 6, 7};
+ auto slice = Span<int>(a).drop_front(a.size());
+ EXPECT_EQ(slice.size(), 0);
+}
+
+TEST(array_ref, TakeFront)
+{
+ Vector<int> a = {4, 5, 6, 7};
+ auto slice = Span<int>(a).take_front(2);
+ EXPECT_EQ(slice.size(), 2);
+ EXPECT_EQ(slice[0], 4);
+ EXPECT_EQ(slice[1], 5);
+}
+
+TEST(array_ref, TakeBack)
+{
+ Vector<int> a = {5, 6, 7, 8};
+ auto slice = Span<int>(a).take_back(2);
+ EXPECT_EQ(slice.size(), 2);
+ EXPECT_EQ(slice[0], 7);
+ EXPECT_EQ(slice[1], 8);
+}
+
+TEST(array_ref, Slice)
+{
+ Vector<int> a = {4, 5, 6, 7};
+ auto slice = Span<int>(a).slice(1, 2);
+ EXPECT_EQ(slice.size(), 2);
+ EXPECT_EQ(slice[0], 5);
+ EXPECT_EQ(slice[1], 6);
+}
+
+TEST(array_ref, SliceEmpty)
+{
+ Vector<int> a = {4, 5, 6, 7};
+ auto slice = Span<int>(a).slice(2, 0);
+ EXPECT_EQ(slice.size(), 0);
+}
+
+TEST(array_ref, SliceRange)
+{
+ Vector<int> a = {1, 2, 3, 4, 5};
+ auto slice = Span<int>(a).slice(IndexRange(2, 2));
+ EXPECT_EQ(slice.size(), 2);
+ EXPECT_EQ(slice[0], 3);
+ EXPECT_EQ(slice[1], 4);
+}
+
+TEST(array_ref, Contains)
+{
+ Vector<int> a = {4, 5, 6, 7};
+ Span<int> a_span = a;
+ EXPECT_TRUE(a_span.contains(4));
+ EXPECT_TRUE(a_span.contains(5));
+ EXPECT_TRUE(a_span.contains(6));
+ EXPECT_TRUE(a_span.contains(7));
+ EXPECT_FALSE(a_span.contains(3));
+ EXPECT_FALSE(a_span.contains(8));
+}
+
+TEST(array_ref, Count)
+{
+ Vector<int> a = {2, 3, 4, 3, 3, 2, 2, 2, 2};
+ Span<int> a_span = a;
+ EXPECT_EQ(a_span.count(1), 0);
+ EXPECT_EQ(a_span.count(2), 5);
+ EXPECT_EQ(a_span.count(3), 3);
+ EXPECT_EQ(a_span.count(4), 1);
+ EXPECT_EQ(a_span.count(5), 0);
+}
+
+static void test_ref_from_initializer_list(Span<int> span)
+{
+ EXPECT_EQ(span.size(), 4);
+ EXPECT_EQ(span[0], 3);
+ EXPECT_EQ(span[1], 6);
+ EXPECT_EQ(span[2], 8);
+ EXPECT_EQ(span[3], 9);
+}
+
+TEST(array_ref, FromInitializerList)
+{
+ test_ref_from_initializer_list({3, 6, 8, 9});
+}
+
+TEST(array_ref, FromVector)
+{
+ std::vector<int> a = {1, 2, 3, 4};
+ Span<int> a_span(a);
+ EXPECT_EQ(a_span.size(), 4);
+ EXPECT_EQ(a_span[0], 1);
+ EXPECT_EQ(a_span[1], 2);
+ EXPECT_EQ(a_span[2], 3);
+ EXPECT_EQ(a_span[3], 4);
+}
+
+TEST(array_ref, FromArray)
+{
+ std::array<int, 2> a = {5, 6};
+ Span<int> a_span(a);
+ EXPECT_EQ(a_span.size(), 2);
+ EXPECT_EQ(a_span[0], 5);
+ EXPECT_EQ(a_span[1], 6);
+}
+
+TEST(array_ref, Fill)
+{
+ std::array<int, 5> a = {4, 5, 6, 7, 8};
+ MutableSpan<int> a_span(a);
+ a_span.fill(1);
+ EXPECT_EQ(a[0], 1);
+ EXPECT_EQ(a[1], 1);
+ EXPECT_EQ(a[2], 1);
+ EXPECT_EQ(a[3], 1);
+ EXPECT_EQ(a[4], 1);
+}
+
+TEST(array_ref, FillIndices)
+{
+ std::array<int, 5> a = {0, 0, 0, 0, 0};
+ MutableSpan<int> a_span(a);
+ a_span.fill_indices({0, 2, 3}, 1);
+ EXPECT_EQ(a[0], 1);
+ EXPECT_EQ(a[1], 0);
+ EXPECT_EQ(a[2], 1);
+ EXPECT_EQ(a[3], 1);
+ EXPECT_EQ(a[4], 0);
+}
+
+TEST(array_ref, SizeInBytes)
+{
+ std::array<int, 10> a;
+ Span<int> a_span(a);
+ EXPECT_EQ(a_span.size_in_bytes(), sizeof(a));
+ EXPECT_EQ(a_span.size_in_bytes(), 40);
+}
+
+TEST(array_ref, FirstLast)
+{
+ std::array<int, 4> a = {6, 7, 8, 9};
+ Span<int> a_span(a);
+ EXPECT_EQ(a_span.first(), 6);
+ EXPECT_EQ(a_span.last(), 9);
+}
+
+TEST(array_ref, FirstLast_OneElement)
+{
+ int a = 3;
+ Span<int> a_span(&a, 1);
+ EXPECT_EQ(a_span.first(), 3);
+ EXPECT_EQ(a_span.last(), 3);
+}
+
+TEST(array_ref, Get)
+{
+ std::array<int, 3> a = {5, 6, 7};
+ Span<int> a_span(a);
+ EXPECT_EQ(a_span.get(0, 42), 5);
+ EXPECT_EQ(a_span.get(1, 42), 6);
+ EXPECT_EQ(a_span.get(2, 42), 7);
+ EXPECT_EQ(a_span.get(3, 42), 42);
+ EXPECT_EQ(a_span.get(4, 42), 42);
+}
+
+TEST(array_ref, ContainsPtr)
+{
+ std::array<int, 3> a = {5, 6, 7};
+ int other = 10;
+ Span<int> a_span(a);
+ EXPECT_TRUE(a_span.contains_ptr(&a[0] + 0));
+ EXPECT_TRUE(a_span.contains_ptr(&a[0] + 1));
+ EXPECT_TRUE(a_span.contains_ptr(&a[0] + 2));
+ EXPECT_FALSE(a_span.contains_ptr(&a[0] + 3));
+ EXPECT_FALSE(a_span.contains_ptr(&a[0] - 1));
+ EXPECT_FALSE(a_span.contains_ptr(&other));
+}
+
+TEST(array_ref, FirstIndex)
+{
+ std::array<int, 5> a = {4, 5, 4, 2, 5};
+ Span<int> a_span(a);
+
+ EXPECT_EQ(a_span.first_index(4), 0);
+ EXPECT_EQ(a_span.first_index(5), 1);
+ EXPECT_EQ(a_span.first_index(2), 3);
+}
+
+TEST(array_ref, CastSameSize)
+{
+ int value = 0;
+ std::array<int *, 4> a = {&value, nullptr, nullptr, nullptr};
+ Span<int *> a_span = a;
+ Span<float *> new_a_span = a_span.cast<float *>();
+
+ EXPECT_EQ(a_span.size(), 4);
+ EXPECT_EQ(new_a_span.size(), 4);
+
+ EXPECT_EQ(a_span[0], &value);
+ EXPECT_EQ(new_a_span[0], (float *)&value);
+}
+
+TEST(array_ref, CastSmallerSize)
+{
+ std::array<uint32_t, 4> a = {3, 4, 5, 6};
+ Span<uint32_t> a_span = a;
+ Span<uint16_t> new_a_span = a_span.cast<uint16_t>();
+
+ EXPECT_EQ(a_span.size(), 4);
+ EXPECT_EQ(new_a_span.size(), 8);
+}
+
+TEST(array_ref, CastLargerSize)
+{
+ std::array<uint16_t, 4> a = {4, 5, 6, 7};
+ Span<uint16_t> a_span = a;
+ Span<uint32_t> new_a_span = a_span.cast<uint32_t>();
+
+ EXPECT_EQ(a_span.size(), 4);
+ EXPECT_EQ(new_a_span.size(), 2);
+}
diff --git a/tests/gtests/blenlib/BLI_stack_cxx_test.cc b/tests/gtests/blenlib/BLI_stack_cxx_test.cc
index 87d545a00ff..2fb4c11ca83 100644
--- a/tests/gtests/blenlib/BLI_stack_cxx_test.cc
+++ b/tests/gtests/blenlib/BLI_stack_cxx_test.cc
@@ -12,7 +12,7 @@ TEST(stack, DefaultConstructor)
EXPECT_TRUE(stack.is_empty());
}
-TEST(stack, ArrayRefConstructor)
+TEST(stack, SpanConstructor)
{
std::array<int, 3> array = {4, 7, 2};
Stack<int> stack(array);
diff --git a/tests/gtests/blenlib/BLI_vector_test.cc b/tests/gtests/blenlib/BLI_vector_test.cc
index 2641c6ffb9a..4a04d002580 100644
--- a/tests/gtests/blenlib/BLI_vector_test.cc
+++ b/tests/gtests/blenlib/BLI_vector_test.cc
@@ -408,17 +408,17 @@ TEST(vector, Remove)
{
Vector<int> vec = {1, 2, 3, 4, 5, 6};
vec.remove(3);
- EXPECT_TRUE(std::equal(vec.begin(), vec.end(), ArrayRef<int>({1, 2, 3, 5, 6}).begin()));
+ EXPECT_TRUE(std::equal(vec.begin(), vec.end(), Span<int>({1, 2, 3, 5, 6}).begin()));
vec.remove(0);
- EXPECT_TRUE(std::equal(vec.begin(), vec.end(), ArrayRef<int>({2, 3, 5, 6}).begin()));
+ EXPECT_TRUE(std::equal(vec.begin(), vec.end(), Span<int>({2, 3, 5, 6}).begin()));
vec.remove(3);
- EXPECT_TRUE(std::equal(vec.begin(), vec.end(), ArrayRef<int>({2, 3, 5}).begin()));
+ EXPECT_TRUE(std::equal(vec.begin(), vec.end(), Span<int>({2, 3, 5}).begin()));
vec.remove(1);
- EXPECT_TRUE(std::equal(vec.begin(), vec.end(), ArrayRef<int>({2, 5}).begin()));
+ EXPECT_TRUE(std::equal(vec.begin(), vec.end(), Span<int>({2, 5}).begin()));
vec.remove(1);
- EXPECT_TRUE(std::equal(vec.begin(), vec.end(), ArrayRef<int>({2}).begin()));
+ EXPECT_TRUE(std::equal(vec.begin(), vec.end(), Span<int>({2}).begin()));
vec.remove(0);
- EXPECT_TRUE(std::equal(vec.begin(), vec.end(), ArrayRef<int>({}).begin()));
+ EXPECT_TRUE(std::equal(vec.begin(), vec.end(), Span<int>({}).begin()));
}
TEST(vector, ExtendSmallVector)
diff --git a/tests/gtests/blenlib/CMakeLists.txt b/tests/gtests/blenlib/CMakeLists.txt
index b76050531da..8ddb2702b83 100644
--- a/tests/gtests/blenlib/CMakeLists.txt
+++ b/tests/gtests/blenlib/CMakeLists.txt
@@ -40,7 +40,6 @@ else()
endif()
BLENDER_TEST(BLI_array "bf_blenlib")
-BLENDER_TEST(BLI_array_ref "bf_blenlib")
BLENDER_TEST(BLI_array_store "bf_blenlib")
BLENDER_TEST(BLI_array_utils "bf_blenlib")
BLENDER_TEST(BLI_delaunay_2d "bf_blenlib")
@@ -67,6 +66,7 @@ BLENDER_TEST(BLI_optional "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")