Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Unified Diff: tests/FunctionTest.cpp

Issue 1050113003: Constructor and call argument forwarding for SkFunction. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: run them Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkFunction.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/FunctionTest.cpp
diff --git a/tests/FunctionTest.cpp b/tests/FunctionTest.cpp
index 6fffcbd43ae92d5699aa7d3194a68135b1b2078c..21b60110ee076db7d607295f475a872283619d25 100644
--- a/tests/FunctionTest.cpp
+++ b/tests/FunctionTest.cpp
@@ -31,3 +31,23 @@ DEF_TEST(Function, r) {
int a = 1, b = 1, c = 1, d = 1, e = 1;
test_add_five(r, SkFunction<int(int)>([&](int x) { return x + a + b + c + d + e; }));
}
+
+DEF_TEST(Function_forwarding, r) {
+ class MoveOnlyAdd5 : SkNoncopyable {
+ public:
+ MoveOnlyAdd5() {}
+ MoveOnlyAdd5(MoveOnlyAdd5&&) {}
+ MoveOnlyAdd5& operator=(MoveOnlyAdd5&&) { return *this; }
+
+ int operator()(int x) { return x + 5; }
+ };
+
+ // Makes sure we forward the functor when constructing SkFunction.
+ test_add_five(r, SkFunction<int(int)>(MoveOnlyAdd5()));
+
+ // Makes sure we forward arguments when calling SkFunction.
+ SkFunction<int(int, MoveOnlyAdd5&&, int)> b([](int x, MoveOnlyAdd5&& f, int y) {
+ return x * f(y);
+ });
+ REPORTER_ASSERT(r, b(2, MoveOnlyAdd5(), 4) == 18);
+}
« no previous file with comments | « src/core/SkFunction.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698