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

Unified Diff: tests/FunctionTest.cpp

Issue 1441753002: Replace SkFunction with std::function (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 1 month 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 | « tests/CPlusPlusEleven.cpp ('k') | tools/BUILD.public.expected » ('j') | 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
deleted file mode 100644
index cf6b78905f5007a194a931e925a604b4a16c81c8..0000000000000000000000000000000000000000
--- a/tests/FunctionTest.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright 2015 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkFunction.h"
-#include "Test.h"
-
-static void test_add_five(skiatest::Reporter* r, SkFunction<int(int)>& f) {
- REPORTER_ASSERT(r, f(3) == 8);
- REPORTER_ASSERT(r, f(4) == 9);
-}
-
-static void test_add_five(skiatest::Reporter* r, SkFunction<int(int)>&& f) { test_add_five(r, f); }
-
-static int add_five(int x) { return x + 5; }
-
-struct AddFive {
- int operator()(int x) const { return x + 5; };
-};
-
-class MoveOnlyThree : SkNoncopyable {
-public:
- MoveOnlyThree() {}
- MoveOnlyThree(MoveOnlyThree&&) {}
- MoveOnlyThree& operator=(MoveOnlyThree&&) { return *this; }
-
- int val() { return 3; }
-};
-
-DEF_TEST(Function, r) {
- // We should be able to turn a function pointer, an explicit functor, or a
- // lambda into an SkFunction all equally well.
- test_add_five(r, &add_five);
- test_add_five(r, AddFive());
- test_add_five(r, [](int x) { return x + 5; });
-
- // AddFive and the lambda above are both small enough to test small-object optimization.
- // Now test a lambda that's much too large for the small-object optimization.
- int a = 1, b = 1, c = 1, d = 1, e = 1;
- test_add_five(r, [&](int x) { return x + a + b + c + d + e; });
-
- // Makes sure we forward arguments when calling SkFunction.
- SkFunction<int(int, MoveOnlyThree&&, int)> f([](int x, MoveOnlyThree&& three, int y) {
- return x * three.val() + y;
- });
- REPORTER_ASSERT(r, f(2, MoveOnlyThree(), 4) == 10);
-
- // SkFunctions can go in containers.
- SkTArray<SkFunction<int(int)>> add_fivers;
- add_fivers.push_back(&add_five);
- add_fivers.push_back(AddFive());
- add_fivers.push_back([](int x) { return x + 5; });
- add_fivers.push_back([&](int x) { return x + a + b + c + d + e; });
- for (auto& f : add_fivers) {
- test_add_five(r, f);
- }
-
- // SkFunctions are assignable.
- SkFunction<int(int)> empty;
- empty = [](int x) { return x + 5; };
- test_add_five(r, empty);
-
- // This all is silly acrobatics, but it should at least work correctly.
- SkFunction<int(int)> emptyA, emptyB(emptyA);
- emptyA = emptyB;
- emptyA = emptyA;
-}
« no previous file with comments | « tests/CPlusPlusEleven.cpp ('k') | tools/BUILD.public.expected » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698