| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 | 6 |
| 7 #if defined(BASE_CALLBACK_H_) | |
| 8 // We explicitly do not want to include callback.h so people are not tempted | |
| 9 // to use bind.h in a headerfile for getting the Callback types. | |
| 10 #error "base/bind.h should avoid pulling in callback.h by default." | |
| 11 #endif | |
| 12 | |
| 13 #include "base/callback.h" | 7 #include "base/callback.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 10 |
| 17 using ::testing::Mock; | 11 using ::testing::Mock; |
| 18 using ::testing::Return; | 12 using ::testing::Return; |
| 19 using ::testing::StrictMock; | 13 using ::testing::StrictMock; |
| 20 | 14 |
| 21 namespace base { | 15 namespace base { |
| 22 namespace { | 16 namespace { |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 Callback<int(void)> const_method_nonconst_obj_cb = | 304 Callback<int(void)> const_method_nonconst_obj_cb = |
| 311 Bind(&HasRef::IntConstMethod0, &has_ref_); | 305 Bind(&HasRef::IntConstMethod0, &has_ref_); |
| 312 Callback<int(void)> const_method_const_obj_cb = | 306 Callback<int(void)> const_method_const_obj_cb = |
| 313 Bind(&HasRef::IntConstMethod0, const_has_ref_ptr_); | 307 Bind(&HasRef::IntConstMethod0, const_has_ref_ptr_); |
| 314 EXPECT_EQ(1337, normal_cb.Run()); | 308 EXPECT_EQ(1337, normal_cb.Run()); |
| 315 EXPECT_EQ(31337, method_cb.Run()); | 309 EXPECT_EQ(31337, method_cb.Run()); |
| 316 EXPECT_EQ(41337, const_method_nonconst_obj_cb.Run()); | 310 EXPECT_EQ(41337, const_method_nonconst_obj_cb.Run()); |
| 317 EXPECT_EQ(51337, const_method_const_obj_cb.Run()); | 311 EXPECT_EQ(51337, const_method_const_obj_cb.Run()); |
| 318 } | 312 } |
| 319 | 313 |
| 314 // IgnoreReturn adapter test. |
| 315 // - Function with return value, and no params can be converted to Closure. |
| 316 TEST_F(BindTest, IgnoreReturn) { |
| 317 EXPECT_CALL(static_func_mock_, IntMethod0()).WillOnce(Return(1337)); |
| 318 Callback<int(void)> normal_cb = Bind(&IntFunc0); |
| 319 Closure c = IgnoreReturn(normal_cb); |
| 320 c.Run(); |
| 321 } |
| 322 |
| 320 // Argument binding tests. | 323 // Argument binding tests. |
| 321 // - Argument binding to primitive. | 324 // - Argument binding to primitive. |
| 322 // - Argument binding to primitive pointer. | 325 // - Argument binding to primitive pointer. |
| 323 // - Argument binding to a literal integer. | 326 // - Argument binding to a literal integer. |
| 324 // - Argument binding to a literal string. | 327 // - Argument binding to a literal string. |
| 325 // - Argument binding with template function. | 328 // - Argument binding with template function. |
| 326 // - Argument binding to an object. | 329 // - Argument binding to an object. |
| 327 // - Argument gets type converted. | 330 // - Argument gets type converted. |
| 328 // - Pointer argument gets converted. | 331 // - Pointer argument gets converted. |
| 329 // - Const Reference forces conversion. | 332 // - Const Reference forces conversion. |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 Callback<int(void)> fastcall_cb = Bind(&FastCallFunc, 1); | 604 Callback<int(void)> fastcall_cb = Bind(&FastCallFunc, 1); |
| 602 EXPECT_EQ(1, fastcall_cb.Run()); | 605 EXPECT_EQ(1, fastcall_cb.Run()); |
| 603 | 606 |
| 604 Callback<int(void)> stdcall_cb = Bind(&StdCallFunc, 2); | 607 Callback<int(void)> stdcall_cb = Bind(&StdCallFunc, 2); |
| 605 EXPECT_EQ(2, stdcall_cb.Run()); | 608 EXPECT_EQ(2, stdcall_cb.Run()); |
| 606 } | 609 } |
| 607 #endif | 610 #endif |
| 608 | 611 |
| 609 } // namespace | 612 } // namespace |
| 610 } // namespace base | 613 } // namespace base |
| OLD | NEW |