Chromium Code Reviews| Index: base/callback_unittest.cc |
| diff --git a/base/callback_unittest.cc b/base/callback_unittest.cc |
| index 1c3db04c10eb5038066e2651a7700695a411a703..3bc338b2c9b0a93056abbc7d9398612e166a59f4 100644 |
| --- a/base/callback_unittest.cc |
| +++ b/base/callback_unittest.cc |
| @@ -2,6 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include "base/bind.h" |
| #include "base/callback.h" |
| #include "base/callback_internal.h" |
| #include "base/memory/scoped_ptr.h" |
| @@ -11,21 +12,12 @@ namespace base { |
| namespace { |
| -class HelperObject { |
| - public: |
| - HelperObject() : next_number_(0) { } |
| - int GetNextNumber() { return ++next_number_; } |
| - void GetNextNumberArg(int* number) { *number = GetNextNumber(); } |
| - |
| - private: |
| - int next_number_; |
| -}; |
| - |
| struct FakeInvoker { |
| typedef void(RunType)(internal::BindStateBase*); |
| static void Run(internal::BindStateBase*) { |
| } |
| }; |
| + |
| } // namespace |
| namespace internal { |
| @@ -130,5 +122,27 @@ TEST_F(CallbackTest, Reset) { |
| EXPECT_TRUE(callback_a_.Equals(null_callback_)); |
| } |
| +struct TestForReentrancy { |
| + TestForReentrancy() { |
|
akalin
2012/03/19 21:53:20
constructor list syntax?
|
| + cb_already_run = false; |
| + cb = base::Bind(&TestForReentrancy::CheckCBIsNull, base::Unretained(this)); |
| + } |
| + void CheckCBIsNull() { |
| + CHECK(cb.is_null()); |
|
akalin
2012/03/19 21:53:20
ASSERT_TRUE
|
| + cb_already_run = true; |
| + } |
| + bool cb_already_run; |
| + Closure cb; |
| +}; |
| + |
| +TEST_F(CallbackTest, ResetAndRun) { |
| + TestForReentrancy tfr; |
| + ASSERT_FALSE(tfr.cb.is_null()); |
| + ASSERT_FALSE(tfr.cb_already_run); |
| + tfr.cb.ResetAndRun(); |
| + ASSERT_TRUE(tfr.cb.is_null()); |
| + ASSERT_TRUE(tfr.cb_already_run); |
| +} |
| + |
| } // namespace |
| } // namespace base |