Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3009)

Unified Diff: base/bind_unittest.cc

Issue 8915024: Retry 114494 - Remove BindStateHolder and have Bind() return a Callback<> object directly." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/bind.h.pump ('k') | base/callback.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/bind_unittest.cc
diff --git a/base/bind_unittest.cc b/base/bind_unittest.cc
index 654a2775a2f23efc2f266d8db8286e20fed15b0a..372523ba99cde6b9c06279b6f91fb40f9a3cdf61 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.
« no previous file with comments | « base/bind.h.pump ('k') | base/callback.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698