| OLD | NEW |
| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 WeakPtrFactory<int> factory(&data); | 182 WeakPtrFactory<int> factory(&data); |
| 183 WeakPtr<int> ptr = factory.GetWeakPtr(); | 183 WeakPtr<int> ptr = factory.GetWeakPtr(); |
| 184 EXPECT_EQ(&data, ptr.get()); | 184 EXPECT_EQ(&data, ptr.get()); |
| 185 } | 185 } |
| 186 | 186 |
| 187 TEST(WeakPtrFactoryTest, Comparison) { | 187 TEST(WeakPtrFactoryTest, Comparison) { |
| 188 int data; | 188 int data; |
| 189 WeakPtrFactory<int> factory(&data); | 189 WeakPtrFactory<int> factory(&data); |
| 190 WeakPtr<int> ptr = factory.GetWeakPtr(); | 190 WeakPtr<int> ptr = factory.GetWeakPtr(); |
| 191 WeakPtr<int> ptr2 = ptr; | 191 WeakPtr<int> ptr2 = ptr; |
| 192 EXPECT_EQ(ptr, ptr2); | 192 EXPECT_EQ(ptr.get(), ptr2.get()); |
| 193 } | 193 } |
| 194 | 194 |
| 195 TEST(WeakPtrFactoryTest, OutOfScope) { | 195 TEST(WeakPtrFactoryTest, OutOfScope) { |
| 196 WeakPtr<int> ptr; | 196 WeakPtr<int> ptr; |
| 197 EXPECT_EQ(NULL, ptr.get()); | 197 EXPECT_EQ(NULL, ptr.get()); |
| 198 { | 198 { |
| 199 int data; | 199 int data; |
| 200 WeakPtrFactory<int> factory(&data); | 200 WeakPtrFactory<int> factory(&data); |
| 201 ptr = factory.GetWeakPtr(); | 201 ptr = factory.GetWeakPtr(); |
| 202 } | 202 } |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 background.Start(); | 579 background.Start(); |
| 580 background.DeleteTarget(target.release()); | 580 background.DeleteTarget(target.release()); |
| 581 | 581 |
| 582 // Main thread attempts to dereference the target, violating thread binding. | 582 // Main thread attempts to dereference the target, violating thread binding. |
| 583 ASSERT_DEATH(arrow.target.get(), ""); | 583 ASSERT_DEATH(arrow.target.get(), ""); |
| 584 } | 584 } |
| 585 | 585 |
| 586 #endif | 586 #endif |
| 587 | 587 |
| 588 } // namespace base | 588 } // namespace base |
| OLD | NEW |