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/callback.h" | 6 #include "base/callback.h" |
6 #include "base/callback_internal.h" | 7 #include "base/callback_internal.h" |
7 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
9 | 10 |
10 namespace base { | 11 namespace base { |
11 | 12 |
12 namespace { | 13 namespace { |
13 | 14 |
14 class HelperObject { | |
15 public: | |
16 HelperObject() : next_number_(0) { } | |
17 int GetNextNumber() { return ++next_number_; } | |
18 void GetNextNumberArg(int* number) { *number = GetNextNumber(); } | |
19 | |
20 private: | |
21 int next_number_; | |
22 }; | |
23 | |
24 struct FakeInvoker { | 15 struct FakeInvoker { |
25 typedef void(RunType)(internal::BindStateBase*); | 16 typedef void(RunType)(internal::BindStateBase*); |
26 static void Run(internal::BindStateBase*) { | 17 static void Run(internal::BindStateBase*) { |
27 } | 18 } |
28 }; | 19 }; |
20 | |
29 } // namespace | 21 } // namespace |
30 | 22 |
31 namespace internal { | 23 namespace internal { |
32 template <typename Runnable, typename RunType, typename BoundArgsType> | 24 template <typename Runnable, typename RunType, typename BoundArgsType> |
33 struct BindState; | 25 struct BindState; |
34 | 26 |
35 // White-box testpoints to inject into a Callback<> object for checking | 27 // White-box testpoints to inject into a Callback<> object for checking |
36 // comparators and emptiness APIs. Use a BindState that is specialized | 28 // comparators and emptiness APIs. Use a BindState that is specialized |
37 // based on a type we declared in the anonymous namespace above to remove any | 29 // based on a type we declared in the anonymous namespace above to remove any |
38 // chance of colliding with another instantiation and breaking the | 30 // chance of colliding with another instantiation and breaking the |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 // Resetting should bring us back to empty. | 115 // Resetting should bring us back to empty. |
124 ASSERT_FALSE(callback_a_.is_null()); | 116 ASSERT_FALSE(callback_a_.is_null()); |
125 ASSERT_FALSE(callback_a_.Equals(null_callback_)); | 117 ASSERT_FALSE(callback_a_.Equals(null_callback_)); |
126 | 118 |
127 callback_a_.Reset(); | 119 callback_a_.Reset(); |
128 | 120 |
129 EXPECT_TRUE(callback_a_.is_null()); | 121 EXPECT_TRUE(callback_a_.is_null()); |
130 EXPECT_TRUE(callback_a_.Equals(null_callback_)); | 122 EXPECT_TRUE(callback_a_.Equals(null_callback_)); |
131 } | 123 } |
132 | 124 |
125 struct TestForReentrancy { | |
126 TestForReentrancy() { | |
akalin
2012/03/19 21:53:20
constructor list syntax?
| |
127 cb_already_run = false; | |
128 cb = base::Bind(&TestForReentrancy::CheckCBIsNull, base::Unretained(this)); | |
129 } | |
130 void CheckCBIsNull() { | |
131 CHECK(cb.is_null()); | |
akalin
2012/03/19 21:53:20
ASSERT_TRUE
| |
132 cb_already_run = true; | |
133 } | |
134 bool cb_already_run; | |
135 Closure cb; | |
136 }; | |
137 | |
138 TEST_F(CallbackTest, ResetAndRun) { | |
139 TestForReentrancy tfr; | |
140 ASSERT_FALSE(tfr.cb.is_null()); | |
141 ASSERT_FALSE(tfr.cb_already_run); | |
142 tfr.cb.ResetAndRun(); | |
143 ASSERT_TRUE(tfr.cb.is_null()); | |
144 ASSERT_TRUE(tfr.cb_already_run); | |
145 } | |
146 | |
133 } // namespace | 147 } // namespace |
134 } // namespace base | 148 } // namespace base |
OLD | NEW |