Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(620)

Unified Diff: mojo/public/cpp/bindings/tests/wtf_map_unittest.cc

Issue 2339413004: Allow Mojo structs as map keys (Closed)
Patch Set: Address all review comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/cpp/bindings/tests/wtf_map_unittest.cc
diff --git a/mojo/public/cpp/bindings/tests/wtf_map_unittest.cc b/mojo/public/cpp/bindings/tests/wtf_map_unittest.cc
index a70c134ac254f51a80aca51082ee2fe2b49450a5..d5888249cf6d1ca60e422e3fe4407bbf2f5bc8bb 100644
--- a/mojo/public/cpp/bindings/tests/wtf_map_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/wtf_map_unittest.cc
@@ -8,6 +8,7 @@
#include "mojo/public/cpp/bindings/tests/container_test_util.h"
#include "mojo/public/cpp/bindings/tests/map_common_test.h"
#include "mojo/public/cpp/bindings/wtf_array.h"
+#include "mojo/public/interfaces/bindings/tests/rect.mojom-blink.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/Source/wtf/text/WTFString.h"
@@ -62,6 +63,30 @@ TEST_F(WTFMapTest, MoveFromAndToWTFHashMap_MoveOnly) {
ASSERT_TRUE(mojo_map.is_null());
}
+static blink::RectPtr MakeRect(int32_t x,
+ int32_t y,
+ int32_t width,
+ int32_t height) {
+ blink::RectPtr rect_ptr = blink::Rect::New();
+ rect_ptr->x = x;
+ rect_ptr->y = y;
+ rect_ptr->width = width;
+ rect_ptr->height = height;
+ return rect_ptr;
+}
+
+TEST_F(WTFMapTest, StructKey) {
+ WTF::HashMap<blink::RectPtr, int32_t> map;
+ map.add(MakeRect(1, 2, 3, 4), 123);
+
+ blink::RectPtr key = MakeRect(1, 2, 3, 4);
+ ASSERT_NE(map.end(), map.find(key));
+ ASSERT_EQ(123, map.find(key)->value);
+
+ map.remove(key);
+ ASSERT_EQ(0u, map.size());
+}
+
} // namespace
} // namespace test
} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698