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 <functional> |
8 #include <map> | 8 #include <map> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 scoped_map1.insert(0, make_scoped_ptr(new int(0))); | 160 scoped_map1.insert(0, make_scoped_ptr(new int(0))); |
161 scoped_map1.insert(1, make_scoped_ptr(new int(0))); | 161 scoped_map1.insert(1, make_scoped_ptr(new int(0))); |
162 | 162 |
163 auto it = scoped_map1.begin(); | 163 auto it = scoped_map1.begin(); |
164 EXPECT_EQ(1, it->first); | 164 EXPECT_EQ(1, it->first); |
165 ++it; | 165 ++it; |
166 EXPECT_EQ(0, it->first); | 166 EXPECT_EQ(0, it->first); |
167 | 167 |
168 // Test the move constructor. | 168 // Test the move constructor. |
169 ScopedPtrMap<int, scoped_ptr<int>, std::greater<int>> scoped_map2( | 169 ScopedPtrMap<int, scoped_ptr<int>, std::greater<int>> scoped_map2( |
170 scoped_map1.Pass()); | 170 std::move(scoped_map1)); |
171 EXPECT_EQ(2u, scoped_map2.size()); | 171 EXPECT_EQ(2u, scoped_map2.size()); |
172 EXPECT_TRUE(scoped_map1.empty()); | 172 EXPECT_TRUE(scoped_map1.empty()); |
173 | 173 |
174 // Test move assignment. | 174 // Test move assignment. |
175 scoped_map1 = scoped_map2.Pass(); | 175 scoped_map1 = std::move(scoped_map2); |
176 EXPECT_EQ(2u, scoped_map1.size()); | 176 EXPECT_EQ(2u, scoped_map1.size()); |
177 EXPECT_TRUE(scoped_map2.empty()); | 177 EXPECT_TRUE(scoped_map2.empty()); |
178 | 178 |
179 // Test swap. | 179 // Test swap. |
180 scoped_map2.swap(scoped_map1); | 180 scoped_map2.swap(scoped_map1); |
181 EXPECT_EQ(2u, scoped_map2.size()); | 181 EXPECT_EQ(2u, scoped_map2.size()); |
182 EXPECT_TRUE(scoped_map1.empty()); | 182 EXPECT_TRUE(scoped_map1.empty()); |
183 } | 183 } |
184 | 184 |
185 TEST(ScopedPtrMapTest, Scope) { | 185 TEST(ScopedPtrMapTest, Scope) { |
(...skipping 10 matching lines...) Expand all Loading... |
196 bool destroyed = false; | 196 bool destroyed = false; |
197 { | 197 { |
198 ScopedPtrMap<int, scoped_ptr<ScopedDestroyer>> scoped_map; | 198 ScopedPtrMap<int, scoped_ptr<ScopedDestroyer>> scoped_map; |
199 ScopedDestroyer* elem = new ScopedDestroyer(&destroyed); | 199 ScopedDestroyer* elem = new ScopedDestroyer(&destroyed); |
200 scoped_map.insert(0, make_scoped_ptr(elem)); | 200 scoped_map.insert(0, make_scoped_ptr(elem)); |
201 EXPECT_EQ(elem, scoped_map.find(0)->second); | 201 EXPECT_EQ(elem, scoped_map.find(0)->second); |
202 EXPECT_FALSE(destroyed); | 202 EXPECT_FALSE(destroyed); |
203 EXPECT_FALSE(scoped_map.empty()); | 203 EXPECT_FALSE(scoped_map.empty()); |
204 | 204 |
205 ScopedPtrMap<int, scoped_ptr<ScopedDestroyer>> scoped_map_copy( | 205 ScopedPtrMap<int, scoped_ptr<ScopedDestroyer>> scoped_map_copy( |
206 scoped_map.Pass()); | 206 std::move(scoped_map)); |
207 EXPECT_TRUE(scoped_map.empty()); | 207 EXPECT_TRUE(scoped_map.empty()); |
208 EXPECT_FALSE(scoped_map_copy.empty()); | 208 EXPECT_FALSE(scoped_map_copy.empty()); |
209 EXPECT_EQ(elem, scoped_map_copy.find(0)->second); | 209 EXPECT_EQ(elem, scoped_map_copy.find(0)->second); |
210 EXPECT_FALSE(destroyed); | 210 EXPECT_FALSE(destroyed); |
211 } | 211 } |
212 EXPECT_TRUE(destroyed); | 212 EXPECT_TRUE(destroyed); |
213 } | 213 } |
214 | 214 |
215 TEST(ScopedPtrMapTest, MoveAssign) { | 215 TEST(ScopedPtrMapTest, MoveAssign) { |
216 bool destroyed = false; | 216 bool destroyed = false; |
217 { | 217 { |
218 ScopedPtrMap<int, scoped_ptr<ScopedDestroyer>> scoped_map; | 218 ScopedPtrMap<int, scoped_ptr<ScopedDestroyer>> scoped_map; |
219 ScopedDestroyer* elem = new ScopedDestroyer(&destroyed); | 219 ScopedDestroyer* elem = new ScopedDestroyer(&destroyed); |
220 scoped_map.insert(0, make_scoped_ptr(elem)); | 220 scoped_map.insert(0, make_scoped_ptr(elem)); |
221 EXPECT_EQ(elem, scoped_map.find(0)->second); | 221 EXPECT_EQ(elem, scoped_map.find(0)->second); |
222 EXPECT_FALSE(destroyed); | 222 EXPECT_FALSE(destroyed); |
223 EXPECT_FALSE(scoped_map.empty()); | 223 EXPECT_FALSE(scoped_map.empty()); |
224 | 224 |
225 ScopedPtrMap<int, scoped_ptr<ScopedDestroyer>> scoped_map_assign; | 225 ScopedPtrMap<int, scoped_ptr<ScopedDestroyer>> scoped_map_assign; |
226 scoped_map_assign = scoped_map.Pass(); | 226 scoped_map_assign = std::move(scoped_map); |
227 EXPECT_TRUE(scoped_map.empty()); | 227 EXPECT_TRUE(scoped_map.empty()); |
228 EXPECT_FALSE(scoped_map_assign.empty()); | 228 EXPECT_FALSE(scoped_map_assign.empty()); |
229 EXPECT_EQ(elem, scoped_map_assign.find(0)->second); | 229 EXPECT_EQ(elem, scoped_map_assign.find(0)->second); |
230 EXPECT_FALSE(destroyed); | 230 EXPECT_FALSE(destroyed); |
231 } | 231 } |
232 EXPECT_TRUE(destroyed); | 232 EXPECT_TRUE(destroyed); |
233 } | 233 } |
234 | 234 |
235 template <typename Key, typename ScopedPtr> | 235 template <typename Key, typename ScopedPtr> |
236 ScopedPtrMap<Key, ScopedPtr> PassThru(ScopedPtrMap<Key, ScopedPtr> scoper) { | 236 ScopedPtrMap<Key, ScopedPtr> PassThru(ScopedPtrMap<Key, ScopedPtr> scoper) { |
(...skipping 26 matching lines...) Expand all Loading... |
263 // Test that using a value type from a namespace containing an ignore_result | 263 // Test that using a value type from a namespace containing an ignore_result |
264 // function compiles correctly. | 264 // function compiles correctly. |
265 TEST(ScopedPtrMapTest, IgnoreResultCompile) { | 265 TEST(ScopedPtrMapTest, IgnoreResultCompile) { |
266 ScopedPtrMap<int, scoped_ptr<namespace_with_ignore_result::Value>> scoped_map; | 266 ScopedPtrMap<int, scoped_ptr<namespace_with_ignore_result::Value>> scoped_map; |
267 scoped_map.insert(1, | 267 scoped_map.insert(1, |
268 make_scoped_ptr(new namespace_with_ignore_result::Value)); | 268 make_scoped_ptr(new namespace_with_ignore_result::Value)); |
269 } | 269 } |
270 | 270 |
271 } // namespace | 271 } // namespace |
272 } // namespace base | 272 } // namespace base |
OLD | NEW |