| 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/bind.h" | 5 #include "base/bind.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 : copies_(copies), assigns_(assigns) { | 99 : copies_(copies), assigns_(assigns) { |
| 100 } | 100 } |
| 101 | 101 |
| 102 CopyCounter(const CopyCounter& other) | 102 CopyCounter(const CopyCounter& other) |
| 103 : copies_(other.copies_), | 103 : copies_(other.copies_), |
| 104 assigns_(other.assigns_) { | 104 assigns_(other.assigns_) { |
| 105 (*copies_)++; | 105 (*copies_)++; |
| 106 } | 106 } |
| 107 | 107 |
| 108 // Probing for copies from coercion. | 108 // Probing for copies from coercion. |
| 109 CopyCounter(const DerivedCopyCounter& other) | 109 explicit CopyCounter(const DerivedCopyCounter& other) |
| 110 : copies_(other.copies_), | 110 : copies_(other.copies_), |
| 111 assigns_(other.assigns_) { | 111 assigns_(other.assigns_) { |
| 112 (*copies_)++; | 112 (*copies_)++; |
| 113 } | 113 } |
| 114 | 114 |
| 115 const CopyCounter& operator=(const CopyCounter& rhs) { | 115 const CopyCounter& operator=(const CopyCounter& rhs) { |
| 116 copies_ = rhs.copies_; | 116 copies_ = rhs.copies_; |
| 117 assigns_ = rhs.assigns_; | 117 assigns_ = rhs.assigns_; |
| 118 | 118 |
| 119 if (assigns_) { | 119 if (assigns_) { |
| (...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 Bind(&VoidPolymorphic1<CopyCounter>); | 759 Bind(&VoidPolymorphic1<CopyCounter>); |
| 760 forward_cb.Run(counter); | 760 forward_cb.Run(counter); |
| 761 EXPECT_GE(1, copies); | 761 EXPECT_GE(1, copies); |
| 762 EXPECT_EQ(0, assigns); | 762 EXPECT_EQ(0, assigns); |
| 763 | 763 |
| 764 copies = 0; | 764 copies = 0; |
| 765 assigns = 0; | 765 assigns = 0; |
| 766 DerivedCopyCounter dervied(&copies, &assigns); | 766 DerivedCopyCounter dervied(&copies, &assigns); |
| 767 Callback<void(CopyCounter)> coerce_cb = | 767 Callback<void(CopyCounter)> coerce_cb = |
| 768 Bind(&VoidPolymorphic1<CopyCounter>); | 768 Bind(&VoidPolymorphic1<CopyCounter>); |
| 769 coerce_cb.Run(dervied); | 769 coerce_cb.Run(CopyCounter(dervied)); |
| 770 EXPECT_GE(2, copies); | 770 EXPECT_GE(2, copies); |
| 771 EXPECT_EQ(0, assigns); | 771 EXPECT_EQ(0, assigns); |
| 772 } | 772 } |
| 773 | 773 |
| 774 // Callback construction and assignment tests. | 774 // Callback construction and assignment tests. |
| 775 // - Construction from an InvokerStorageHolder should not cause ref/deref. | 775 // - Construction from an InvokerStorageHolder should not cause ref/deref. |
| 776 // - Assignment from other callback should only cause one ref | 776 // - Assignment from other callback should only cause one ref |
| 777 // | 777 // |
| 778 // TODO(ajwong): Is there actually a way to test this? | 778 // TODO(ajwong): Is there actually a way to test this? |
| 779 | 779 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 805 base::Callback<void(int)> null_cb; | 805 base::Callback<void(int)> null_cb; |
| 806 ASSERT_TRUE(null_cb.is_null()); | 806 ASSERT_TRUE(null_cb.is_null()); |
| 807 EXPECT_DEATH(base::Bind(null_cb, 42), ""); | 807 EXPECT_DEATH(base::Bind(null_cb, 42), ""); |
| 808 } | 808 } |
| 809 | 809 |
| 810 #endif // (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && | 810 #endif // (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && |
| 811 // GTEST_HAS_DEATH_TEST | 811 // GTEST_HAS_DEATH_TEST |
| 812 | 812 |
| 813 } // namespace | 813 } // namespace |
| 814 } // namespace base | 814 } // namespace base |
| OLD | NEW |