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

Unified Diff: base/bind_unittest.cc

Issue 8073012: Callback API Change: Allow Bind() to take a Callback<> and bind all its free parameters. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 months 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_internal.h.pump ('k') | no next file » | 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 dde2226f64cb82c4bf41d54bab6fa8e852b796d2..0c24710736caba9d91a7bc73e6de0cff7f865020 100644
--- a/base/bind_unittest.cc
+++ b/base/bind_unittest.cc
@@ -153,6 +153,10 @@ int Sum(int a, int b, int c, int d, int e, int f) {
return a + b + c + d + e + f;
}
+void OutputSum(int* output, int a, int b, int c, int d, int e) {
+ *output = a + b + c + d + e;
+}
+
const char* CStringIdentity(const char* s) {
return s;
}
@@ -243,6 +247,37 @@ TEST_F(BindTest, ArityTest) {
EXPECT_EQ(69, c6.Run(13, 12, 11, 10, 9, 14));
}
+// Bind should be able to take existing Callbacks and convert to a Closure.
+TEST_F(BindTest, CallbackBindMore) {
+ int output = 0;
+ Closure c;
+
+ Callback<void(int)> c1 = Bind(&OutputSum, &output, 16, 8, 4, 2);
+ c = Bind(c1, 10);
+ c.Run();
+ EXPECT_EQ(40, output);
+
+ Callback<void(int,int)> c2 = Bind(&OutputSum, &output, 16, 8, 4);
+ c = Bind(c2, 10, 9);
+ c.Run();
+ EXPECT_EQ(47, output);
+
+ Callback<void(int,int,int)> c3 = Bind(&OutputSum, &output, 16, 8);
+ c = Bind(c3, 10, 9, 8);
+ c.Run();
+ EXPECT_EQ(51, output);
+
+ Callback<void(int,int,int,int)> c4 = Bind(&OutputSum, &output, 16);
+ c = Bind(c4, 10, 9, 8, 7);
+ c.Run();
+ EXPECT_EQ(50, output);
+
+ Callback<void(int,int,int,int,int)> c5 = Bind(&OutputSum, &output);
+ c = Bind(c5, 10, 9, 8, 7, 6);
+ c.Run();
+ EXPECT_EQ(40, output);
+}
+
// Function type support.
// - Normal function.
// - Normal function bound with non-refcounted first argument.
« no previous file with comments | « base/bind_internal.h.pump ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698