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

Side by Side Diff: base/memory/weak_ptr_unittest.cc

Issue 2094873003: Make base::WeakPtr moveable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: std::move WeakPtrBase Created 4 years, 6 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
« no previous file with comments | « base/memory/weak_ptr.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/memory/weak_ptr.h" 5 #include "base/memory/weak_ptr.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 } 196 }
197 197
198 TEST(WeakPtrFactoryTest, Comparison) { 198 TEST(WeakPtrFactoryTest, Comparison) {
199 int data; 199 int data;
200 WeakPtrFactory<int> factory(&data); 200 WeakPtrFactory<int> factory(&data);
201 WeakPtr<int> ptr = factory.GetWeakPtr(); 201 WeakPtr<int> ptr = factory.GetWeakPtr();
202 WeakPtr<int> ptr2 = ptr; 202 WeakPtr<int> ptr2 = ptr;
203 EXPECT_EQ(ptr.get(), ptr2.get()); 203 EXPECT_EQ(ptr.get(), ptr2.get());
204 } 204 }
205 205
206 TEST(WeakPtrFactoryTest, Move) {
207 int data;
208 WeakPtrFactory<int> factory(&data);
209 WeakPtr<int> ptr = factory.GetWeakPtr();
210 WeakPtr<int> ptr2 = factory.GetWeakPtr();
211 WeakPtr<int> ptr3 = std::move(ptr2);
212 EXPECT_NE(ptr.get(), ptr2.get());
213 EXPECT_EQ(ptr.get(), ptr3.get());
214 }
215
206 TEST(WeakPtrFactoryTest, OutOfScope) { 216 TEST(WeakPtrFactoryTest, OutOfScope) {
207 WeakPtr<int> ptr; 217 WeakPtr<int> ptr;
208 EXPECT_EQ(nullptr, ptr.get()); 218 EXPECT_EQ(nullptr, ptr.get());
209 { 219 {
210 int data; 220 int data;
211 WeakPtrFactory<int> factory(&data); 221 WeakPtrFactory<int> factory(&data);
212 ptr = factory.GetWeakPtr(); 222 ptr = factory.GetWeakPtr();
213 } 223 }
214 EXPECT_EQ(nullptr, ptr.get()); 224 EXPECT_EQ(nullptr, ptr.get());
215 } 225 }
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 background.Start(); 672 background.Start();
663 background.DeleteTarget(target.release()); 673 background.DeleteTarget(target.release());
664 674
665 // Main thread attempts to dereference the target, violating thread binding. 675 // Main thread attempts to dereference the target, violating thread binding.
666 ASSERT_DEATH(arrow.target.get(), ""); 676 ASSERT_DEATH(arrow.target.get(), "");
667 } 677 }
668 678
669 #endif 679 #endif
670 680
671 } // namespace base 681 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/weak_ptr.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698