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-10 20:02:28 +0300
committerJacques Lucke <jacques@blender.org>2020-06-10 20:02:34 +0300
commit474b2889339e24e602a7498c30ed07e2c47e6982 (patch)
tree89086e555908acf84b37bdb71e79e1203b350004 /tests
parent20658e6a29bd33264d99fcee9cea1886d1c9d0c9 (diff)
BLI: add Map.pop_default method
There is a nice use case for this in depsgraph code. Also I added some previously missing calls to std::move.
Diffstat (limited to 'tests')
-rw-r--r--tests/gtests/blenlib/BLI_map_test.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/gtests/blenlib/BLI_map_test.cc b/tests/gtests/blenlib/BLI_map_test.cc
index aa064e2f427..b14ba40ed7c 100644
--- a/tests/gtests/blenlib/BLI_map_test.cc
+++ b/tests/gtests/blenlib/BLI_map_test.cc
@@ -99,6 +99,25 @@ TEST(map, PopTry)
EXPECT_EQ(map.size(), 0);
}
+TEST(map, PopDefault)
+{
+ Map<int, int> map;
+ map.add(1, 4);
+ map.add(2, 7);
+ map.add(3, 8);
+ EXPECT_EQ(map.size(), 3);
+ EXPECT_EQ(map.pop_default(4, 10), 10);
+ EXPECT_EQ(map.size(), 3);
+ EXPECT_EQ(map.pop_default(1, 10), 4);
+ EXPECT_EQ(map.size(), 2);
+ EXPECT_EQ(map.pop_default(2, 20), 7);
+ EXPECT_EQ(map.size(), 1);
+ EXPECT_EQ(map.pop_default(2, 20), 20);
+ EXPECT_EQ(map.size(), 1);
+ EXPECT_EQ(map.pop_default(3, 0), 8);
+ EXPECT_EQ(map.size(), 0);
+}
+
TEST(map, PopItemMany)
{
Map<int, int> map;
@@ -373,6 +392,7 @@ TEST(map, UniquePtrValue)
map.add(6, std::unique_ptr<int>(new int()));
map.add_overwrite(7, std::unique_ptr<int>(new int()));
map.lookup_or_add(8, std::unique_ptr<int>(new int()));
+ map.pop_default(9, std::unique_ptr<int>(new int()));
EXPECT_EQ(map.lookup(1).get(), value1_ptr);
EXPECT_EQ(map.lookup_ptr(100), nullptr);