diff options
Diffstat (limited to 'tests/gtests')
-rw-r--r-- | tests/gtests/blenlib/BLI_map_test.cc | 24 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_set_test.cc | 16 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_set_vector_test.cc | 13 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_stack_cxx_test.cc | 13 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_string_map_test.cc | 9 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_vector_test.cc | 14 |
6 files changed, 85 insertions, 4 deletions
diff --git a/tests/gtests/blenlib/BLI_map_test.cc b/tests/gtests/blenlib/BLI_map_test.cc index 8d5b178aea6..3acb76e09f0 100644 --- a/tests/gtests/blenlib/BLI_map_test.cc +++ b/tests/gtests/blenlib/BLI_map_test.cc @@ -2,7 +2,8 @@ #include "BLI_map.h" #include "BLI_set.h" -using IntFloatMap = BLI::Map<int, float>; +using BLI::Map; +using IntFloatMap = Map<int, float>; TEST(map, DefaultConstructor) { @@ -258,3 +259,24 @@ TEST(map, Clear) EXPECT_FALSE(map.contains(1)); EXPECT_FALSE(map.contains(2)); } + +TEST(map, UniquePtrValue) +{ + auto value1 = std::unique_ptr<int>(new int()); + auto value2 = std::unique_ptr<int>(new int()); + auto value3 = std::unique_ptr<int>(new int()); + + int *value1_ptr = value1.get(); + + Map<int, std::unique_ptr<int>> map; + map.add_new(1, std::move(value1)); + map.add(2, std::move(value2)); + map.add_override(3, std::move(value3)); + map.lookup_or_add(4, []() { return std::unique_ptr<int>(new int()); }); + map.add_new(5, std::unique_ptr<int>(new int())); + map.add(6, std::unique_ptr<int>(new int())); + map.add_override(7, std::unique_ptr<int>(new int())); + + EXPECT_EQ(map.lookup(1).get(), value1_ptr); + EXPECT_EQ(map.lookup_ptr(100), nullptr); +} diff --git a/tests/gtests/blenlib/BLI_set_test.cc b/tests/gtests/blenlib/BLI_set_test.cc index f331639b345..5baf069557e 100644 --- a/tests/gtests/blenlib/BLI_set_test.cc +++ b/tests/gtests/blenlib/BLI_set_test.cc @@ -1,7 +1,10 @@ #include "testing/testing.h" #include "BLI_set.h" +#include "BLI_vector.h" -using IntSet = BLI::Set<int>; +using BLI::Set; +using BLI::Vector; +using IntSet = Set<int>; TEST(set, Defaultconstructor) { @@ -187,3 +190,14 @@ TEST(set, OftenAddRemove) EXPECT_EQ(set.size(), 0); } } + +TEST(set, UniquePtrValues) +{ + Set<std::unique_ptr<int>> set; + set.add_new(std::unique_ptr<int>(new int())); + auto value1 = std::unique_ptr<int>(new int()); + set.add_new(std::move(value1)); + set.add(std::unique_ptr<int>(new int())); + + EXPECT_EQ(set.size(), 3); +} diff --git a/tests/gtests/blenlib/BLI_set_vector_test.cc b/tests/gtests/blenlib/BLI_set_vector_test.cc index be6f9a80d7c..b135e31914c 100644 --- a/tests/gtests/blenlib/BLI_set_vector_test.cc +++ b/tests/gtests/blenlib/BLI_set_vector_test.cc @@ -1,7 +1,8 @@ #include "testing/testing.h" #include "BLI_set_vector.h" -using IntSetVector = BLI::SetVector<int>; +using BLI::SetVector; +using IntSetVector = SetVector<int>; TEST(set_vector, DefaultConstructor) { @@ -100,3 +101,13 @@ TEST(set_vector, Remove) set.remove(7); EXPECT_EQ(set.size(), 0); } + +TEST(set_vector, UniquePtrValue) +{ + SetVector<std::unique_ptr<int>> set; + set.add_new(std::unique_ptr<int>(new int())); + set.add(std::unique_ptr<int>(new int())); + set.index_try(std::unique_ptr<int>(new int())); + std::unique_ptr<int> value = set.pop(); + UNUSED_VARS(value); +} diff --git a/tests/gtests/blenlib/BLI_stack_cxx_test.cc b/tests/gtests/blenlib/BLI_stack_cxx_test.cc index 02c5407fda3..436f1f307b9 100644 --- a/tests/gtests/blenlib/BLI_stack_cxx_test.cc +++ b/tests/gtests/blenlib/BLI_stack_cxx_test.cc @@ -1,7 +1,8 @@ #include "testing/testing.h" #include "BLI_stack_cxx.h" -using IntStack = BLI::Stack<int>; +using BLI::Stack; +using IntStack = Stack<int>; TEST(stack, DefaultConstructor) { @@ -50,3 +51,13 @@ TEST(stack, Peek) stack.pop(); EXPECT_EQ(stack.peek(), 3); } + +TEST(stack, UniquePtrValues) +{ + Stack<std::unique_ptr<int>> stack; + stack.push(std::unique_ptr<int>(new int())); + stack.push(std::unique_ptr<int>(new int())); + std::unique_ptr<int> a = stack.pop(); + std::unique_ptr<int> &b = stack.peek(); + UNUSED_VARS(a, b); +} diff --git a/tests/gtests/blenlib/BLI_string_map_test.cc b/tests/gtests/blenlib/BLI_string_map_test.cc index e5e32352161..cc02a54e0c8 100644 --- a/tests/gtests/blenlib/BLI_string_map_test.cc +++ b/tests/gtests/blenlib/BLI_string_map_test.cc @@ -199,3 +199,12 @@ TEST(string_map, WithVectors) EXPECT_EQ(map.lookup("A").size(), 3); EXPECT_EQ(map.lookup("B").size(), 7); } + +TEST(string_map, UniquePtrValues) +{ + StringMap<std::unique_ptr<int>> map; + map.add_new("A", std::unique_ptr<int>(new int())); + std::unique_ptr<int> &a = map.lookup("A"); + std::unique_ptr<int> *b = map.lookup_ptr("A"); + EXPECT_EQ(a.get(), b->get()); +} diff --git a/tests/gtests/blenlib/BLI_vector_test.cc b/tests/gtests/blenlib/BLI_vector_test.cc index 60f78025269..9486c9c0ef2 100644 --- a/tests/gtests/blenlib/BLI_vector_test.cc +++ b/tests/gtests/blenlib/BLI_vector_test.cc @@ -398,3 +398,17 @@ TEST(vector, AppendNTimes) EXPECT_EQ(a[3], 2); EXPECT_EQ(a[4], 2); } + +TEST(vector, UniquePtrValue) +{ + Vector<std::unique_ptr<int>> vec; + vec.append(std::unique_ptr<int>(new int())); + vec.append(std::unique_ptr<int>(new int())); + vec.append(std::unique_ptr<int>(new int())); + + std::unique_ptr<int> &a = vec.last(); + std::unique_ptr<int> b = vec.pop_last(); + vec.remove_and_reorder(0); + + UNUSED_VARS(a, b); +} |