| 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 <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 if (null_ptr) { | 301 if (null_ptr) { |
| 302 ADD_FAILURE() << "Null pointer should result in false."; | 302 ADD_FAILURE() << "Null pointer should result in false."; |
| 303 } | 303 } |
| 304 | 304 |
| 305 if (!null_ptr) { // check for operator!(). | 305 if (!null_ptr) { // check for operator!(). |
| 306 } else { | 306 } else { |
| 307 ADD_FAILURE() << "Null pointer should result in !x being true."; | 307 ADD_FAILURE() << "Null pointer should result in !x being true."; |
| 308 } | 308 } |
| 309 } | 309 } |
| 310 | 310 |
| 311 TEST(WeakPtrFactoryTest, ComparisonToNull) { |
| 312 int data; |
| 313 WeakPtrFactory<int> factory(&data); |
| 314 |
| 315 WeakPtr<int> ptr_to_an_instance = factory.GetWeakPtr(); |
| 316 EXPECT_NE(nullptr, ptr_to_an_instance); |
| 317 EXPECT_NE(ptr_to_an_instance, nullptr); |
| 318 |
| 319 WeakPtr<int> null_ptr; |
| 320 EXPECT_EQ(null_ptr, nullptr); |
| 321 EXPECT_EQ(nullptr, null_ptr); |
| 322 } |
| 323 |
| 311 TEST(WeakPtrTest, InvalidateWeakPtrs) { | 324 TEST(WeakPtrTest, InvalidateWeakPtrs) { |
| 312 int data; | 325 int data; |
| 313 WeakPtrFactory<int> factory(&data); | 326 WeakPtrFactory<int> factory(&data); |
| 314 WeakPtr<int> ptr = factory.GetWeakPtr(); | 327 WeakPtr<int> ptr = factory.GetWeakPtr(); |
| 315 EXPECT_EQ(&data, ptr.get()); | 328 EXPECT_EQ(&data, ptr.get()); |
| 316 EXPECT_TRUE(factory.HasWeakPtrs()); | 329 EXPECT_TRUE(factory.HasWeakPtrs()); |
| 317 factory.InvalidateWeakPtrs(); | 330 factory.InvalidateWeakPtrs(); |
| 318 EXPECT_EQ(nullptr, ptr.get()); | 331 EXPECT_EQ(nullptr, ptr.get()); |
| 319 EXPECT_FALSE(factory.HasWeakPtrs()); | 332 EXPECT_FALSE(factory.HasWeakPtrs()); |
| 320 | 333 |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 background.Start(); | 662 background.Start(); |
| 650 background.DeleteTarget(target.release()); | 663 background.DeleteTarget(target.release()); |
| 651 | 664 |
| 652 // Main thread attempts to dereference the target, violating thread binding. | 665 // Main thread attempts to dereference the target, violating thread binding. |
| 653 ASSERT_DEATH(arrow.target.get(), ""); | 666 ASSERT_DEATH(arrow.target.get(), ""); |
| 654 } | 667 } |
| 655 | 668 |
| 656 #endif | 669 #endif |
| 657 | 670 |
| 658 } // namespace base | 671 } // namespace base |
| OLD | NEW |