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

Side by Side Diff: mojo/public/cpp/bindings/tests/wtf_map_unittest.cc

Issue 2608503002: Remove mojo::WTFMap. (Closed)
Patch Set: Created 3 years, 12 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "mojo/public/cpp/bindings/wtf_map.h"
6
7 #include "mojo/public/cpp/bindings/lib/wtf_serialization.h"
8 #include "mojo/public/cpp/bindings/tests/container_test_util.h"
9 #include "mojo/public/cpp/bindings/tests/map_common_test.h"
10 #include "mojo/public/cpp/bindings/tests/rect_blink.h"
11 #include "mojo/public/cpp/bindings/wtf_array.h"
12 #include "mojo/public/interfaces/bindings/tests/rect.mojom-blink.h"
13 #include "mojo/public/interfaces/bindings/tests/test_structs.mojom-blink.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/WebKit/Source/wtf/text/WTFString.h"
16
17 namespace mojo {
18 namespace test {
19
20 namespace {
21
22 using WTFMapTest = testing::Test;
23
24 MAP_COMMON_TEST(WTFMap, NullAndEmpty)
25 MAP_COMMON_TEST(WTFMap, InsertWorks)
26 MAP_COMMON_TEST(WTFMap, TestIndexOperator)
27 MAP_COMMON_TEST(WTFMap, TestIndexOperatorAsRValue)
28 MAP_COMMON_TEST(WTFMap, TestIndexOperatorMoveOnly)
29 MAP_COMMON_TEST(WTFMap, MapArrayClone)
30 MAP_COMMON_TEST(WTFMap, ArrayOfMap)
31
32 TEST_F(WTFMapTest, MoveFromAndToWTFHashMap_Copyable) {
33 WTF::HashMap<int32_t, CopyableType> map1;
34 map1.add(123, CopyableType());
35 map1.find(123)->value.ResetCopied();
36 ASSERT_FALSE(map1.find(123)->value.copied());
37
38 WTFMap<int32_t, CopyableType> mojo_map(std::move(map1));
39 ASSERT_EQ(1u, mojo_map.size());
40 ASSERT_NE(mojo_map.end(), mojo_map.find(123));
41 ASSERT_FALSE(mojo_map[123].copied());
42
43 WTF::HashMap<int32_t, CopyableType> map2(mojo_map.PassStorage());
44 ASSERT_EQ(1u, map2.size());
45 ASSERT_NE(map2.end(), map2.find(123));
46 ASSERT_FALSE(map2.find(123)->value.copied());
47
48 ASSERT_EQ(0u, mojo_map.size());
49 ASSERT_TRUE(mojo_map.is_null());
50 }
51
52 TEST_F(WTFMapTest, MoveFromAndToWTFHashMap_MoveOnly) {
53 WTF::HashMap<int32_t, MoveOnlyType> map1;
54 map1.add(123, MoveOnlyType());
55
56 WTFMap<int32_t, MoveOnlyType> mojo_map(std::move(map1));
57 ASSERT_EQ(1u, mojo_map.size());
58 ASSERT_NE(mojo_map.end(), mojo_map.find(123));
59
60 WTF::HashMap<int32_t, MoveOnlyType> map2(mojo_map.PassStorage());
61 ASSERT_EQ(1u, map2.size());
62 ASSERT_NE(map2.end(), map2.find(123));
63
64 ASSERT_EQ(0u, mojo_map.size());
65 ASSERT_TRUE(mojo_map.is_null());
66 }
67
68 static blink::RectPtr MakeRect(int32_t x,
69 int32_t y,
70 int32_t width,
71 int32_t height) {
72 blink::RectPtr rect_ptr = blink::Rect::New();
73 rect_ptr->x = x;
74 rect_ptr->y = y;
75 rect_ptr->width = width;
76 rect_ptr->height = height;
77 return rect_ptr;
78 }
79
80 TEST_F(WTFMapTest, StructKey) {
81 WTF::HashMap<blink::RectPtr, int32_t> map;
82 map.add(MakeRect(1, 2, 3, 4), 123);
83
84 blink::RectPtr key = MakeRect(1, 2, 3, 4);
85 ASSERT_NE(map.end(), map.find(key));
86 ASSERT_EQ(123, map.find(key)->value);
87
88 map.remove(key);
89 ASSERT_EQ(0u, map.size());
90 }
91
92 static blink::ContainsHashablePtr MakeContainsHashablePtr(RectBlink rect) {
93 blink::ContainsHashablePtr ptr = blink::ContainsHashable::New();
94 ptr->rect = rect;
95 return ptr;
96 }
97
98 TEST_F(WTFMapTest, TypemappedStructKey) {
99 WTF::HashMap<blink::ContainsHashablePtr, int32_t> map;
100 map.add(MakeContainsHashablePtr(RectBlink(1, 2, 3, 4)), 123);
101
102 blink::ContainsHashablePtr key =
103 MakeContainsHashablePtr(RectBlink(1, 2, 3, 4));
104 ASSERT_NE(map.end(), map.find(key));
105 ASSERT_EQ(123, map.find(key)->value);
106
107 map.remove(key);
108 ASSERT_EQ(0u, map.size());
109 }
110
111 } // namespace
112 } // namespace test
113 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/BUILD.gn ('k') | mojo/public/cpp/bindings/tests/wtf_types_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698