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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/public/cpp/bindings/wtf_map.h" 5 #include "mojo/public/cpp/bindings/wtf_map.h"
6 6
7 #include "mojo/public/cpp/bindings/lib/wtf_serialization.h" 7 #include "mojo/public/cpp/bindings/lib/wtf_serialization.h"
8 #include "mojo/public/cpp/bindings/tests/container_test_util.h" 8 #include "mojo/public/cpp/bindings/tests/container_test_util.h"
9 #include "mojo/public/cpp/bindings/tests/map_common_test.h" 9 #include "mojo/public/cpp/bindings/tests/map_common_test.h"
10 #include "mojo/public/cpp/bindings/wtf_array.h" 10 #include "mojo/public/cpp/bindings/wtf_array.h"
11 #include "mojo/public/interfaces/bindings/tests/rect.mojom-blink.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/WebKit/Source/wtf/text/WTFString.h" 13 #include "third_party/WebKit/Source/wtf/text/WTFString.h"
13 14
14 namespace mojo { 15 namespace mojo {
15 namespace test { 16 namespace test {
16 17
17 namespace { 18 namespace {
18 19
19 using WTFMapTest = testing::Test; 20 using WTFMapTest = testing::Test;
20 21
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 ASSERT_NE(mojo_map.end(), mojo_map.find(123)); 56 ASSERT_NE(mojo_map.end(), mojo_map.find(123));
56 57
57 WTF::HashMap<int32_t, MoveOnlyType> map2(mojo_map.PassStorage()); 58 WTF::HashMap<int32_t, MoveOnlyType> map2(mojo_map.PassStorage());
58 ASSERT_EQ(1u, map2.size()); 59 ASSERT_EQ(1u, map2.size());
59 ASSERT_NE(map2.end(), map2.find(123)); 60 ASSERT_NE(map2.end(), map2.find(123));
60 61
61 ASSERT_EQ(0u, mojo_map.size()); 62 ASSERT_EQ(0u, mojo_map.size());
62 ASSERT_TRUE(mojo_map.is_null()); 63 ASSERT_TRUE(mojo_map.is_null());
63 } 64 }
64 65
66 static blink::RectPtr MakeRect(int32_t x,
67 int32_t y,
68 int32_t width,
69 int32_t height) {
70 blink::RectPtr rect_ptr = blink::Rect::New();
71 rect_ptr->x = x;
72 rect_ptr->y = y;
73 rect_ptr->width = width;
74 rect_ptr->height = height;
75 return rect_ptr;
76 }
77
78 TEST_F(WTFMapTest, StructKey) {
79 WTF::HashMap<blink::RectPtr, int32_t> map;
80 map.add(MakeRect(1, 2, 3, 4), 123);
81
82 blink::RectPtr key = MakeRect(1, 2, 3, 4);
83 ASSERT_NE(map.end(), map.find(key));
84 ASSERT_EQ(123, map.find(key)->value);
85
86 map.remove(key);
87 ASSERT_EQ(0u, map.size());
88 }
89
65 } // namespace 90 } // namespace
66 } // namespace test 91 } // namespace test
67 } // namespace mojo 92 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698