OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/containers/scoped_ptr_map.h" | 5 #include "base/containers/scoped_ptr_map.h" |
6 | 6 |
| 7 #include <functional> |
7 #include <map> | 8 #include <map> |
8 #include <utility> | 9 #include <utility> |
9 | 10 |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/callback.h" | 12 #include "base/callback.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 TEST(ScopedPtrMapTest, Clear) { | 137 TEST(ScopedPtrMapTest, Clear) { |
137 bool destroyed = false; | 138 bool destroyed = false; |
138 ScopedPtrMap<int, scoped_ptr<ScopedDestroyer>> scoped_map; | 139 ScopedPtrMap<int, scoped_ptr<ScopedDestroyer>> scoped_map; |
139 scoped_map.insert(0, make_scoped_ptr(new ScopedDestroyer(&destroyed))); | 140 scoped_map.insert(0, make_scoped_ptr(new ScopedDestroyer(&destroyed))); |
140 EXPECT_FALSE(destroyed); | 141 EXPECT_FALSE(destroyed); |
141 scoped_map.clear(); | 142 scoped_map.clear(); |
142 EXPECT_TRUE(destroyed); | 143 EXPECT_TRUE(destroyed); |
143 EXPECT_TRUE(scoped_map.empty()); | 144 EXPECT_TRUE(scoped_map.empty()); |
144 } | 145 } |
145 | 146 |
| 147 TEST(ScopedPtrMapTest, Compare) { |
| 148 // Construct a ScopedPtrMap with a custom comparison function. |
| 149 bool destroyed = false; |
| 150 ScopedPtrMap<int, scoped_ptr<ScopedDestroyer>, std::greater<int>> scoped_map; |
| 151 scoped_map.insert(0, make_scoped_ptr(new ScopedDestroyer(&destroyed))); |
| 152 scoped_map.insert(1, make_scoped_ptr(new ScopedDestroyer(&destroyed))); |
| 153 |
| 154 auto it = scoped_map.begin(); |
| 155 EXPECT_EQ(1, it->first); |
| 156 ++it; |
| 157 EXPECT_EQ(0, it->first); |
| 158 } |
| 159 |
146 TEST(ScopedPtrMapTest, Scope) { | 160 TEST(ScopedPtrMapTest, Scope) { |
147 bool destroyed = false; | 161 bool destroyed = false; |
148 { | 162 { |
149 ScopedPtrMap<int, scoped_ptr<ScopedDestroyer>> scoped_map; | 163 ScopedPtrMap<int, scoped_ptr<ScopedDestroyer>> scoped_map; |
150 scoped_map.insert(0, make_scoped_ptr(new ScopedDestroyer(&destroyed))); | 164 scoped_map.insert(0, make_scoped_ptr(new ScopedDestroyer(&destroyed))); |
151 EXPECT_FALSE(destroyed); | 165 EXPECT_FALSE(destroyed); |
152 } | 166 } |
153 EXPECT_TRUE(destroyed); | 167 EXPECT_TRUE(destroyed); |
154 } | 168 } |
155 | 169 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 ScopedPtrMap<int, scoped_ptr<ScopedDestroyer>> result = callback.Run(); | 229 ScopedPtrMap<int, scoped_ptr<ScopedDestroyer>> result = callback.Run(); |
216 EXPECT_TRUE(scoped_map.empty()); | 230 EXPECT_TRUE(scoped_map.empty()); |
217 EXPECT_EQ(elem, result.find(0)->second); | 231 EXPECT_EQ(elem, result.find(0)->second); |
218 EXPECT_FALSE(destroyed); | 232 EXPECT_FALSE(destroyed); |
219 | 233 |
220 result.clear(); | 234 result.clear(); |
221 EXPECT_TRUE(destroyed); | 235 EXPECT_TRUE(destroyed); |
222 }; | 236 }; |
223 | 237 |
224 } // namespace | 238 } // namespace |
OLD | NEW |