| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 delete object; | 130 delete object; |
| 131 completion->Signal(); | 131 completion->Signal(); |
| 132 } | 132 } |
| 133 | 133 |
| 134 static void DoDeleteArrow(Arrow* object, WaitableEvent* completion) { | 134 static void DoDeleteArrow(Arrow* object, WaitableEvent* completion) { |
| 135 delete object; | 135 delete object; |
| 136 completion->Signal(); | 136 completion->Signal(); |
| 137 } | 137 } |
| 138 }; | 138 }; |
| 139 | 139 |
| 140 } // namespace | |
| 141 | |
| 142 TEST(WeakPtrFactoryTest, Basic) { | 140 TEST(WeakPtrFactoryTest, Basic) { |
| 143 int data; | 141 int data; |
| 144 WeakPtrFactory<int> factory(&data); | 142 WeakPtrFactory<int> factory(&data); |
| 145 WeakPtr<int> ptr = factory.GetWeakPtr(); | 143 WeakPtr<int> ptr = factory.GetWeakPtr(); |
| 146 EXPECT_EQ(&data, ptr.get()); | 144 EXPECT_EQ(&data, ptr.get()); |
| 147 } | 145 } |
| 148 | 146 |
| 149 TEST(WeakPtrFactoryTest, Comparison) { | 147 TEST(WeakPtrFactoryTest, Comparison) { |
| 150 int data; | 148 int data; |
| 151 WeakPtrFactory<int> factory(&data); | 149 WeakPtrFactory<int> factory(&data); |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 arrow.target = target->AsWeakPtr(); | 465 arrow.target = target->AsWeakPtr(); |
| 468 | 466 |
| 469 // Background thread tries to delete target, which violates thread ownership. | 467 // Background thread tries to delete target, which violates thread ownership. |
| 470 BackgroundThread background; | 468 BackgroundThread background; |
| 471 background.Start(); | 469 background.Start(); |
| 472 ASSERT_DEATH(background.DeleteTarget(target.release()), ""); | 470 ASSERT_DEATH(background.DeleteTarget(target.release()), ""); |
| 473 } | 471 } |
| 474 | 472 |
| 475 #endif | 473 #endif |
| 476 | 474 |
| 475 } // namespace |
| 476 |
| 477 } // namespace base | 477 } // namespace base |
| OLD | NEW |