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 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 Callback<void(int,int,int,int,int)> c5 = Bind(&OutputSum, &output); | 277 Callback<void(int,int,int,int,int)> c5 = Bind(&OutputSum, &output); |
278 c = Bind(c5, 10, 9, 8, 7, 6); | 278 c = Bind(c5, 10, 9, 8, 7, 6); |
279 c.Run(); | 279 c.Run(); |
280 EXPECT_EQ(40, output); | 280 EXPECT_EQ(40, output); |
281 } | 281 } |
282 | 282 |
283 // Function type support. | 283 // Function type support. |
284 // - Normal function. | 284 // - Normal function. |
285 // - Normal function bound with non-refcounted first argument. | 285 // - Normal function bound with non-refcounted first argument. |
286 // - Method bound to non-const object. | 286 // - Method bound to non-const object. |
| 287 // - Method bound to scoped_refptr. |
287 // - Const method bound to non-const object. | 288 // - Const method bound to non-const object. |
288 // - Const method bound to const object. | 289 // - Const method bound to const object. |
289 // - Derived classes can be used with pointers to non-virtual base functions. | 290 // - Derived classes can be used with pointers to non-virtual base functions. |
290 // - Derived classes can be used with pointers to virtual base functions (and | 291 // - Derived classes can be used with pointers to virtual base functions (and |
291 // preserve virtual dispatch). | 292 // preserve virtual dispatch). |
292 TEST_F(BindTest, FunctionTypeSupport) { | 293 TEST_F(BindTest, FunctionTypeSupport) { |
293 EXPECT_CALL(static_func_mock_, VoidMethod0()); | 294 EXPECT_CALL(static_func_mock_, VoidMethod0()); |
294 EXPECT_CALL(has_ref_, AddRef()).Times(3); | 295 EXPECT_CALL(has_ref_, AddRef()).Times(5); |
295 EXPECT_CALL(has_ref_, Release()).Times(3); | 296 EXPECT_CALL(has_ref_, Release()).Times(5); |
296 EXPECT_CALL(has_ref_, VoidMethod0()); | 297 EXPECT_CALL(has_ref_, VoidMethod0()).Times(2); |
297 EXPECT_CALL(has_ref_, VoidConstMethod0()).Times(2); | 298 EXPECT_CALL(has_ref_, VoidConstMethod0()).Times(2); |
298 | 299 |
299 Closure normal_cb = Bind(&VoidFunc0); | 300 Closure normal_cb = Bind(&VoidFunc0); |
300 Callback<NoRef*(void)> normal_non_refcounted_cb = | 301 Callback<NoRef*(void)> normal_non_refcounted_cb = |
301 Bind(&PolymorphicIdentity<NoRef*>, &no_ref_); | 302 Bind(&PolymorphicIdentity<NoRef*>, &no_ref_); |
302 normal_cb.Run(); | 303 normal_cb.Run(); |
303 EXPECT_EQ(&no_ref_, normal_non_refcounted_cb.Run()); | 304 EXPECT_EQ(&no_ref_, normal_non_refcounted_cb.Run()); |
304 | 305 |
305 Closure method_cb = Bind(&HasRef::VoidMethod0, &has_ref_); | 306 Closure method_cb = Bind(&HasRef::VoidMethod0, &has_ref_); |
| 307 Closure method_refptr_cb = Bind(&HasRef::VoidMethod0, |
| 308 make_scoped_refptr(&has_ref_)); |
306 Closure const_method_nonconst_obj_cb = Bind(&HasRef::VoidConstMethod0, | 309 Closure const_method_nonconst_obj_cb = Bind(&HasRef::VoidConstMethod0, |
307 &has_ref_); | 310 &has_ref_); |
308 Closure const_method_const_obj_cb = Bind(&HasRef::VoidConstMethod0, | 311 Closure const_method_const_obj_cb = Bind(&HasRef::VoidConstMethod0, |
309 const_has_ref_ptr_); | 312 const_has_ref_ptr_); |
310 method_cb.Run(); | 313 method_cb.Run(); |
| 314 method_refptr_cb.Run(); |
311 const_method_nonconst_obj_cb.Run(); | 315 const_method_nonconst_obj_cb.Run(); |
312 const_method_const_obj_cb.Run(); | 316 const_method_const_obj_cb.Run(); |
313 | 317 |
314 Child child; | 318 Child child; |
315 child.value = 0; | 319 child.value = 0; |
316 Closure virtual_set_cb = Bind(&Parent::VirtualSet, &child); | 320 Closure virtual_set_cb = Bind(&Parent::VirtualSet, &child); |
317 virtual_set_cb.Run(); | 321 virtual_set_cb.Run(); |
318 EXPECT_EQ(kChildValue, child.value); | 322 EXPECT_EQ(kChildValue, child.value); |
319 | 323 |
320 child.value = 0; | 324 child.value = 0; |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 Callback<int(void)> fastcall_cb = Bind(&FastCallFunc, 1); | 651 Callback<int(void)> fastcall_cb = Bind(&FastCallFunc, 1); |
648 EXPECT_EQ(1, fastcall_cb.Run()); | 652 EXPECT_EQ(1, fastcall_cb.Run()); |
649 | 653 |
650 Callback<int(void)> stdcall_cb = Bind(&StdCallFunc, 2); | 654 Callback<int(void)> stdcall_cb = Bind(&StdCallFunc, 2); |
651 EXPECT_EQ(2, stdcall_cb.Run()); | 655 EXPECT_EQ(2, stdcall_cb.Run()); |
652 } | 656 } |
653 #endif | 657 #endif |
654 | 658 |
655 } // namespace | 659 } // namespace |
656 } // namespace base | 660 } // namespace base |
OLD | NEW |