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/callback.h" | 5 #include "base/callback.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
11 #include "base/callback_internal.h" | 11 #include "base/callback_internal.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 | 16 |
17 void NopInvokeFunc() {} | 17 void NopInvokeFunc() {} |
18 | 18 |
19 // White-box testpoints to inject into a Callback<> object for checking | 19 // White-box testpoints to inject into a Callback<> object for checking |
20 // comparators and emptiness APIs. Use a BindState that is specialized | 20 // comparators and emptiness APIs. Use a BindState that is specialized |
21 // based on a type we declared in the anonymous namespace above to remove any | 21 // based on a type we declared in the anonymous namespace above to remove any |
22 // chance of colliding with another instantiation and breaking the | 22 // chance of colliding with another instantiation and breaking the |
23 // one-definition-rule. | 23 // one-definition-rule. |
24 struct FakeBindState1 : internal::BindStateBase { | 24 struct FakeBindState1 : internal::BindStateBase { |
25 FakeBindState1() : BindStateBase(&NopInvokeFunc, &Destroy, &IsCancelled) {} | 25 FakeBindState1() : BindStateBase(&NopInvokeFunc, &Destroy, &IsCancelled) {} |
26 private: | 26 private: |
27 ~FakeBindState1() {} | 27 ~FakeBindState1() {} |
28 static void Destroy(internal::BindStateBase* self) { | 28 static void Destroy(const internal::BindStateBase* self) { |
29 delete static_cast<FakeBindState1*>(self); | 29 delete static_cast<const FakeBindState1*>(self); |
30 } | 30 } |
31 static bool IsCancelled(const internal::BindStateBase*) { | 31 static bool IsCancelled(const internal::BindStateBase*) { |
32 return false; | 32 return false; |
33 } | 33 } |
34 }; | 34 }; |
35 | 35 |
36 struct FakeBindState2 : internal::BindStateBase { | 36 struct FakeBindState2 : internal::BindStateBase { |
37 FakeBindState2() : BindStateBase(&NopInvokeFunc, &Destroy, &IsCancelled) {} | 37 FakeBindState2() : BindStateBase(&NopInvokeFunc, &Destroy, &IsCancelled) {} |
38 private: | 38 private: |
39 ~FakeBindState2() {} | 39 ~FakeBindState2() {} |
40 static void Destroy(internal::BindStateBase* self) { | 40 static void Destroy(const internal::BindStateBase* self) { |
41 delete static_cast<FakeBindState2*>(self); | 41 delete static_cast<const FakeBindState2*>(self); |
42 } | 42 } |
43 static bool IsCancelled(const internal::BindStateBase*) { | 43 static bool IsCancelled(const internal::BindStateBase*) { |
44 return false; | 44 return false; |
45 } | 45 } |
46 }; | 46 }; |
47 | 47 |
48 namespace { | 48 namespace { |
49 | 49 |
50 class CallbackTest : public ::testing::Test { | 50 class CallbackTest : public ::testing::Test { |
51 public: | 51 public: |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 163 |
164 TEST_F(CallbackTest, CallbackHasLastRefOnContainingObject) { | 164 TEST_F(CallbackTest, CallbackHasLastRefOnContainingObject) { |
165 bool deleted = false; | 165 bool deleted = false; |
166 CallbackOwner* owner = new CallbackOwner(&deleted); | 166 CallbackOwner* owner = new CallbackOwner(&deleted); |
167 owner->Reset(); | 167 owner->Reset(); |
168 ASSERT_TRUE(deleted); | 168 ASSERT_TRUE(deleted); |
169 } | 169 } |
170 | 170 |
171 } // namespace | 171 } // namespace |
172 } // namespace base | 172 } // namespace base |
OLD | NEW |