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

Side by Side Diff: base/containers/scoped_ptr_map_unittest.cc

Issue 1480773002: base: Make ScopedPtrMap use DISALLOW_COPY_AND_ASSIGN. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move-only-1: dontchangetype Created 5 years 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
« no previous file with comments | « base/containers/scoped_ptr_map.h ('k') | sync/engine/commit.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 ScopedPtrMap<int, scoped_ptr<ScopedDestroyer>> scoped_map_assign; 225 ScopedPtrMap<int, scoped_ptr<ScopedDestroyer>> scoped_map_assign;
226 scoped_map_assign = std::move(scoped_map); 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>
236 ScopedPtrMap<Key, ScopedPtr> PassThru(ScopedPtrMap<Key, ScopedPtr> scoper) {
237 return scoper;
238 }
239
240 TEST(ScopedPtrMapTest, Passed) {
241 bool destroyed = false;
242 ScopedPtrMap<int, scoped_ptr<ScopedDestroyer>> scoped_map;
243 ScopedDestroyer* elem = new ScopedDestroyer(&destroyed);
244 scoped_map.insert(0, make_scoped_ptr(elem));
245 EXPECT_EQ(elem, scoped_map.find(0)->second);
246 EXPECT_FALSE(destroyed);
247
248 base::Callback<ScopedPtrMap<int, scoped_ptr<ScopedDestroyer>>(void)>
249 callback = base::Bind(&PassThru<int, scoped_ptr<ScopedDestroyer>>,
250 base::Passed(&scoped_map));
251 EXPECT_TRUE(scoped_map.empty());
252 EXPECT_FALSE(destroyed);
253
254 ScopedPtrMap<int, scoped_ptr<ScopedDestroyer>> result = callback.Run();
255 EXPECT_TRUE(scoped_map.empty());
256 EXPECT_EQ(elem, result.find(0)->second);
257 EXPECT_FALSE(destroyed);
258
259 result.clear();
260 EXPECT_TRUE(destroyed);
261 };
262
263 // Test that using a value type from a namespace containing an ignore_result 235 // Test that using a value type from a namespace containing an ignore_result
264 // function compiles correctly. 236 // function compiles correctly.
265 TEST(ScopedPtrMapTest, IgnoreResultCompile) { 237 TEST(ScopedPtrMapTest, IgnoreResultCompile) {
266 ScopedPtrMap<int, scoped_ptr<namespace_with_ignore_result::Value>> scoped_map; 238 ScopedPtrMap<int, scoped_ptr<namespace_with_ignore_result::Value>> scoped_map;
267 scoped_map.insert(1, 239 scoped_map.insert(1,
268 make_scoped_ptr(new namespace_with_ignore_result::Value)); 240 make_scoped_ptr(new namespace_with_ignore_result::Value));
269 } 241 }
270 242
271 } // namespace 243 } // namespace
272 } // namespace base 244 } // namespace base
OLDNEW
« no previous file with comments | « base/containers/scoped_ptr_map.h ('k') | sync/engine/commit.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698