Chromium Code Reviews| Index: base/bind_unittest.cc |
| diff --git a/base/bind_unittest.cc b/base/bind_unittest.cc |
| index 654a2775a2f23efc2f266d8db8286e20fed15b0a..1eed9f7ee6a5416d7ad40d3ff10cb559949a353a 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 curring the rvalue result of Bind() works correclty. |
|
akalin
2011/12/02 18:54:45
curring -> currying
Although don't you mean 'bind
awong
2011/12/06 00:21:12
Not sure there's a distinction...
akalin
2011/12/06 17:57:57
currying = changing a function '(A, B) -> C' to 'A
|
| +// - 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 implemt Bind() such that the return value has auto_ptr-like |
|
akalin
2011/12/02 18:54:45
implemt -> implement
awong
2011/12/06 00:21:12
Done.
|
| + // semantics, the second call here will fail because ownership of |
| + // the internal BindState<> would have been trasnfered to a *temporary* |
|
akalin
2011/12/02 18:54:45
trasnfered -> transferred
awong
2011/12/06 00:21:12
Done.
|
| + // 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. |