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-11 11:48:52 +0300
committerJacques Lucke <jacques@blender.org>2020-06-11 11:48:52 +0300
commitf028760b83c340b802adea7bab019ca14d95bad4 (patch)
tree1bed6e156bbb4d3c37939a4fbc842d5b014dccbc /tests
parent3f648f5b423347fa31e60cf52701a10862a157f1 (diff)
BLI: make Map::Item and Map::MutableItem more accessible
This makes it easier to write range-for loops over all items in the map without using auto.
Diffstat (limited to 'tests')
-rw-r--r--tests/gtests/blenlib/BLI_map_test.cc23
1 files changed, 22 insertions, 1 deletions
diff --git a/tests/gtests/blenlib/BLI_map_test.cc b/tests/gtests/blenlib/BLI_map_test.cc
index b14ba40ed7c..623055d5032 100644
--- a/tests/gtests/blenlib/BLI_map_test.cc
+++ b/tests/gtests/blenlib/BLI_map_test.cc
@@ -185,7 +185,8 @@ TEST(map, ItemIterator)
blender::Set<float> values;
uint iterations = 0;
- for (auto item : map.items()) {
+ const Map<int, float> &const_map = map;
+ for (auto item : const_map.items()) {
keys.add(item.key);
values.add(item.value);
iterations++;
@@ -228,6 +229,26 @@ TEST(map, MutableItemIterator)
EXPECT_EQ(map.lookup(2), 3.0f);
}
+TEST(map, MutableItemToItemConversion)
+{
+ Map<int, int> map;
+ map.add(3, 6);
+ map.add(2, 1);
+
+ Vector<int> keys, values;
+ for (Map<int, int>::Item item : map.items()) {
+ keys.append(item.key);
+ values.append(item.value);
+ }
+
+ EXPECT_EQ(keys.size(), 2);
+ EXPECT_EQ(values.size(), 2);
+ EXPECT_TRUE(keys.contains(3));
+ EXPECT_TRUE(keys.contains(2));
+ EXPECT_TRUE(values.contains(6));
+ EXPECT_TRUE(values.contains(1));
+}
+
static float return_42()
{
return 42.0f;