diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-20 00:10:04 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-20 00:10:04 +0000 |
commit | e24f876c537646cab5a9e8492658f570ccd7da4a (patch) | |
tree | 85aa283d18c10b47f1e3acbafce3283661407477 /base/bind_unittest.cc | |
parent | b538d7ea0b2484074dea680d60f7f68750d1d1e3 (diff) | |
download | chromium_src-e24f876c537646cab5a9e8492658f570ccd7da4a.zip chromium_src-e24f876c537646cab5a9e8492658f570ccd7da4a.tar.gz chromium_src-e24f876c537646cab5a9e8492658f570ccd7da4a.tar.bz2 |
Retry 114494 - Remove BindStateHolder and have Bind() return a Callback<> object directly."
This removes some complexity and also fixes a bug where if you call Bind() with the result of Bind(), the resulting Callback would only be valid during the first call. Ouch.
Also makes the static type checking a bit more strict when assigning into a Callback<>.
BUG=none
TEST=new unittests
Review URL: http://codereview.chromium.org/8915024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115045 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/bind_unittest.cc')
-rw-r--r-- | base/bind_unittest.cc | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/base/bind_unittest.cc b/base/bind_unittest.cc index 654a277..372523b 100644 --- a/base/bind_unittest.cc +++ b/base/bind_unittest.cc @@ -199,10 +199,18 @@ void RefArgSet(int &n) { n = 2; } +void PtrArgSet(int *n) { + *n = 2; +} + int FunctionWithWeakFirstParam(WeakPtr<NoRef> o, int n) { return n; } +void TakesACallback(const Closure& callback) { + callback.Run(); +} + class BindTest : public ::testing::Test { public: BindTest() { @@ -284,6 +292,25 @@ TEST_F(BindTest, CurryingTest) { EXPECT_EQ(63, c0.Run()); } +// Test that currying the rvalue result of another Bind() works correctly. +// - rvalue should be usable as argument to Bind(). +// - multiple runs of resulting Callback remain valid. +TEST_F(BindTest, CurryingRvalueResultOfBind) { + int n = 0; + Closure cb = base::Bind(&TakesACallback, base::Bind(&PtrArgSet, &n)); + + // If we implement Bind() such that the return value has auto_ptr-like + // semantics, the second call here will fail because ownership of + // the internal BindState<> would have been transfered to a *temporary* + // constructon of a Callback object on the first call. + cb.Run(); + EXPECT_EQ(2, n); + + n = 0; + cb.Run(); + EXPECT_EQ(2, n); +} + // Function type support. // - Normal function. // - Normal function bound with non-refcounted first argument. |