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

Unified Diff: base/bind_unittest.cc

Issue 694453002: Added utility base::BindLambda to allow passing lambdas as base::Callback<> Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tried to work around msvc failure Created 6 years, 2 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_lambda.h ('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 a30b7756704658a599a84e3df88e80166e731ce7..2f3891bfd95b954ec35bacea4b2812d2aed18e6f 100644
--- a/base/bind_unittest.cc
+++ b/base/bind_unittest.cc
@@ -4,6 +4,7 @@
#include "base/bind.h"
+#include "base/bind_lambda.h"
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
@@ -786,6 +787,27 @@ TEST_F(BindTest, ArgumentCopies) {
EXPECT_EQ(0, assigns);
}
+TEST_F(BindTest, Lambdas) {
+ static const int kValueToSet = 55;
+ int value_set_from_lambda = 0;
+
+ Callback<void(int)> callback =
+ BindLambda([&](int new_val) { value_set_from_lambda = new_val; });
+ callback.Run(kValueToSet);
+ EXPECT_EQ(kValueToSet, value_set_from_lambda);
+}
+
+TEST_F(BindTest, LambdasNestedInBind) {
+ static const int kValueToSet = 55;
+ int value_set_from_lambda = 0;
+
+ Callback<void()> callback =
+ Bind(BindLambda([&](int new_val) { value_set_from_lambda = new_val; }),
+ kValueToSet);
+ callback.Run();
+ EXPECT_EQ(kValueToSet, value_set_from_lambda);
+}
+
// Callback construction and assignment tests.
// - Construction from an InvokerStorageHolder should not cause ref/deref.
// - Assignment from other callback should only cause one ref
« no previous file with comments | « base/bind_lambda.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698