OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkFunction.h" | 8 #include "SkFunction.h" |
9 #include "Test.h" | 9 #include "Test.h" |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 // all into an SkFunction equally well. | 24 // all into an SkFunction equally well. |
25 test_add_five(r, SkFunction<int(int)>(&add_five)); | 25 test_add_five(r, SkFunction<int(int)>(&add_five)); |
26 test_add_five(r, SkFunction<int(int)>(AddFive())); | 26 test_add_five(r, SkFunction<int(int)>(AddFive())); |
27 test_add_five(r, SkFunction<int(int)>([](int x) { return x + 5; })); | 27 test_add_five(r, SkFunction<int(int)>([](int x) { return x + 5; })); |
28 | 28 |
29 // AddFive and the lambda above are both small enough to test small-object o
ptimization. | 29 // AddFive and the lambda above are both small enough to test small-object o
ptimization. |
30 // Now test a lambda that's much too large for the small-object optimization
. | 30 // Now test a lambda that's much too large for the small-object optimization
. |
31 int a = 1, b = 1, c = 1, d = 1, e = 1; | 31 int a = 1, b = 1, c = 1, d = 1, e = 1; |
32 test_add_five(r, SkFunction<int(int)>([&](int x) { return x + a + b + c + d
+ e; })); | 32 test_add_five(r, SkFunction<int(int)>([&](int x) { return x + a + b + c + d
+ e; })); |
33 } | 33 } |
| 34 |
| 35 DEF_TEST(Function_forwarding, r) { |
| 36 class MoveOnlyAdd5 : SkNoncopyable { |
| 37 public: |
| 38 MoveOnlyAdd5() {} |
| 39 MoveOnlyAdd5(MoveOnlyAdd5&&) {} |
| 40 MoveOnlyAdd5& operator=(MoveOnlyAdd5&&) { return *this; } |
| 41 |
| 42 int operator()(int x) { return x + 5; } |
| 43 }; |
| 44 |
| 45 // Makes sure we forward the functor when constructing SkFunction. |
| 46 test_add_five(r, SkFunction<int(int)>(MoveOnlyAdd5())); |
| 47 |
| 48 // Makes sure we forward arguments when calling SkFunction. |
| 49 SkFunction<int(int, MoveOnlyAdd5&&, int)> b([](int x, MoveOnlyAdd5&& f, int
y) { |
| 50 return x * f(y); |
| 51 }); |
| 52 REPORTER_ASSERT(r, b(2, MoveOnlyAdd5(), 4) == 18); |
| 53 } |
OLD | NEW |