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
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2020-06-05 14:09:31 +0300
committerJulian Eisel <julian@blender.org>2020-06-05 14:09:31 +0300
commit920a58d9b6d667894cf166cbbd25e4c2fbd238ea (patch)
tree7ca5a9da640753b5e070c439ac3bdd14dfad92cf /tests/gtests/blenlib/BLI_string_map_test.cc
parentc94b6209861ca7cc3985b53474feed7d94c0221a (diff)
parenta1d55bdd530390e58c51abe9707b8d3b0ae3e861 (diff)
Merge branch 'master' into wm-drag-drop-rewritewm-drag-drop-rewrite
Diffstat (limited to 'tests/gtests/blenlib/BLI_string_map_test.cc')
-rw-r--r--tests/gtests/blenlib/BLI_string_map_test.cc45
1 files changed, 43 insertions, 2 deletions
diff --git a/tests/gtests/blenlib/BLI_string_map_test.cc b/tests/gtests/blenlib/BLI_string_map_test.cc
index 4cb67d5fbac..6acad0ce581 100644
--- a/tests/gtests/blenlib/BLI_string_map_test.cc
+++ b/tests/gtests/blenlib/BLI_string_map_test.cc
@@ -1,5 +1,5 @@
-#include "BLI_string_map.h"
-#include "BLI_vector.h"
+#include "BLI_string_map.hh"
+#include "BLI_vector.hh"
#include "testing/testing.h"
using namespace BLI;
@@ -232,3 +232,44 @@ 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);
+}
+
+TEST(string_map, LookupOrAdd)
+{
+ StringMap<int> map;
+ auto return_5 = []() { return 5; };
+ auto return_8 = []() { return 8; };
+
+ int &a = map.lookup_or_add("A", return_5);
+ EXPECT_EQ(a, 5);
+ EXPECT_EQ(map.lookup_or_add("A", return_8), 5);
+ EXPECT_EQ(map.lookup_or_add("B", return_8), 8);
+}
+
+TEST(string_map, LookupOrAddDefault)
+{
+ StringMap<std::string> map;
+
+ std::string &a = map.lookup_or_add_default("A");
+ EXPECT_EQ(a.size(), 0);
+ a += "Test";
+ EXPECT_EQ(a.size(), 4);
+ std::string &b = map.lookup_or_add_default("A");
+ EXPECT_EQ(b, "Test");
+}