| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 EXPECT_EQ(10, (*function1)(&a)); | 287 EXPECT_EQ(10, (*function1)(&a)); |
| 288 | 288 |
| 289 std::unique_ptr<Function<int(class A*, int)>> unboundFunction2 = | 289 std::unique_ptr<Function<int(class A*, int)>> unboundFunction2 = |
| 290 bind<class A*, int>(&A::addF); | 290 bind<class A*, int>(&A::addF); |
| 291 EXPECT_EQ(25, (*unboundFunction2)(&a, 15)); | 291 EXPECT_EQ(25, (*unboundFunction2)(&a, 15)); |
| 292 std::unique_ptr<Function<int(int)>> objectBoundFunction2 = | 292 std::unique_ptr<Function<int(int)>> objectBoundFunction2 = |
| 293 bind<int>(&A::addF, &a); | 293 bind<int>(&A::addF, &a); |
| 294 EXPECT_EQ(25, (*objectBoundFunction2)(15)); | 294 EXPECT_EQ(25, (*objectBoundFunction2)(15)); |
| 295 } | 295 } |
| 296 | 296 |
| 297 TEST(FunctionalTest, MemberFunctionBindByUniquePtr) |
| 298 { |
| 299 std::unique_ptr<Function<int()>> function1 = WTF::bind(&A::f, wrapUnique(new
A(10))); |
| 300 EXPECT_EQ(10, (*function1)()); |
| 301 } |
| 302 |
| 303 TEST(FunctionalTest, MemberFunctionBindByPassedUniquePtr) |
| 304 { |
| 305 std::unique_ptr<Function<int()>> function1 = WTF::bind(&A::f, passed(wrapUni
que(new A(10)))); |
| 306 EXPECT_EQ(10, (*function1)()); |
| 307 } |
| 308 |
| 297 class Number : public RefCounted<Number> { | 309 class Number : public RefCounted<Number> { |
| 298 public: | 310 public: |
| 299 static PassRefPtr<Number> create(int value) | 311 static PassRefPtr<Number> create(int value) |
| 300 { | 312 { |
| 301 return adoptRef(new Number(value)); | 313 return adoptRef(new Number(value)); |
| 302 } | 314 } |
| 303 | 315 |
| 304 ~Number() | 316 ~Number() |
| 305 { | 317 { |
| 306 m_value = 0; | 318 m_value = 0; |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 EXPECT_EQ(0, (*bound1)(CountCopy())); | 524 EXPECT_EQ(0, (*bound1)(CountCopy())); |
| 513 | 525 |
| 514 std::unique_ptr<Function<int(CountCopy)>> bound2 = bind<CountCopy>(takeCount
CopyAsValue); | 526 std::unique_ptr<Function<int(CountCopy)>> bound2 = bind<CountCopy>(takeCount
CopyAsValue); |
| 515 EXPECT_EQ(2, (*bound2)(lvalue)); // At PartBoundFunctionImpl::operator() and
at the destination function. | 527 EXPECT_EQ(2, (*bound2)(lvalue)); // At PartBoundFunctionImpl::operator() and
at the destination function. |
| 516 EXPECT_LE((*bound2)(CountCopy()), 2); // Compiler is allowed to optimize one
copy away if the argument is rvalue. | 528 EXPECT_LE((*bound2)(CountCopy()), 2); // Compiler is allowed to optimize one
copy away if the argument is rvalue. |
| 517 } | 529 } |
| 518 | 530 |
| 519 } // anonymous namespace | 531 } // anonymous namespace |
| 520 | 532 |
| 521 } // namespace WTF | 533 } // namespace WTF |
| OLD | NEW |