| Index: base/bind_unittest.cc
|
| diff --git a/base/bind_unittest.cc b/base/bind_unittest.cc
|
| index 5a7ce38627a44d3d5e225e95fc7b9191ce8e259b..e2158d3781cae556e532725e3bcb34f4e65c5dac 100644
|
| --- a/base/bind_unittest.cc
|
| +++ b/base/bind_unittest.cc
|
| @@ -1038,6 +1038,36 @@ TEST_F(BindTest, ArgumentCopiesAndMoves) {
|
| EXPECT_EQ(0, move_assigns);
|
| }
|
|
|
| +TEST_F(BindTest, CapturelessLambda) {
|
| + EXPECT_FALSE(internal::IsCapturelessLambda<void>::value);
|
| + EXPECT_FALSE(internal::IsCapturelessLambda<int>::value);
|
| + EXPECT_FALSE(internal::IsCapturelessLambda<void(*)()>::value);
|
| + EXPECT_FALSE(internal::IsCapturelessLambda<void(NoRef::*)()>::value);
|
| +
|
| + auto f = []() {};
|
| + EXPECT_TRUE(internal::IsCapturelessLambda<decltype(f)>::value);
|
| +
|
| + int i = 0;
|
| + auto g = [i]() {};
|
| + EXPECT_FALSE(internal::IsCapturelessLambda<decltype(g)>::value);
|
| +
|
| + auto h = [](int, double) { return 'k'; };
|
| + EXPECT_TRUE((std::is_same<
|
| + char(int, double),
|
| + internal::ExtractLambdaRunType<decltype(h)>>::value));
|
| +
|
| + EXPECT_EQ(42, Bind([] { return 42; }).Run());
|
| + EXPECT_EQ(42, Bind([](int i) { return i * 7; }, 6).Run());
|
| +
|
| + int x = 1;
|
| + base::Callback<void(int)> cb =
|
| + Bind([](int* x, int i) { *x *= i; }, Unretained(&x));
|
| + cb.Run(6);
|
| + EXPECT_EQ(6, x);
|
| + cb.Run(7);
|
| + EXPECT_EQ(42, x);
|
| +}
|
| +
|
| // Callback construction and assignment tests.
|
| // - Construction from an InvokerStorageHolder should not cause ref/deref.
|
| // - Assignment from other callback should only cause one ref
|
|
|