diff options
author | Jacques Lucke <jacques@blender.org> | 2020-04-24 23:33:48 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-04-24 23:33:48 +0300 |
commit | 62f6255b476a9fbd2c85b8fc7466734da912fa34 (patch) | |
tree | 53513a3c6f04783b87536953af2511f9b260077e /tests/gtests | |
parent | fd10ac9acaa0788ef5e73677a97e5cff27978d0c (diff) |
BLI: Implement StringMap.add and StringMap.add_or_modify
Diffstat (limited to 'tests/gtests')
-rw-r--r-- | tests/gtests/blenlib/BLI_string_map_test.cc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/gtests/blenlib/BLI_string_map_test.cc b/tests/gtests/blenlib/BLI_string_map_test.cc index 5e671da86c7..41cda920a89 100644 --- a/tests/gtests/blenlib/BLI_string_map_test.cc +++ b/tests/gtests/blenlib/BLI_string_map_test.cc @@ -232,3 +232,20 @@ TEST(string_map, UniquePtrValues) std::unique_ptr<int> *b = map.lookup_ptr("A"); EXPECT_EQ(a.get(), b->get()); } + +TEST(string_map, AddOrModify) +{ + StringMap<int> map; + auto create_func = [](int *value) { + *value = 10; + return true; + }; + auto modify_func = [](int *value) { + *value += 5; + return false; + }; + EXPECT_TRUE(map.add_or_modify("Hello", create_func, modify_func)); + EXPECT_EQ(map.lookup("Hello"), 10); + EXPECT_FALSE(map.add_or_modify("Hello", create_func, modify_func)); + EXPECT_EQ(map.lookup("Hello"), 15); +} |