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

Unified Diff: Source/wtf/FunctionalTest.cpp

Issue 705003002: Change the return type of WTF::bind() to |OwnPtr<Function>| (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Reflect comments from yhirano Created 6 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 | « Source/wtf/Functional.h ('k') | Source/wtf/MainThread.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/FunctionalTest.cpp
diff --git a/Source/wtf/FunctionalTest.cpp b/Source/wtf/FunctionalTest.cpp
index 2c13f0dc686ab75a7adb576d4665cba50d618aba..e48c0c7b3bca40e5f450268c24333741e46b1a33 100644
--- a/Source/wtf/FunctionalTest.cpp
+++ b/Source/wtf/FunctionalTest.cpp
@@ -25,8 +25,9 @@
#include "config.h"
-#include "wtf/RefCounted.h"
#include "wtf/Functional.h"
+#include "wtf/OwnPtr.h"
+#include "wtf/RefCounted.h"
#include <gtest/gtest.h>
namespace {
@@ -41,9 +42,9 @@ TEST(FunctionalTest, Basic)
Function<int()> emptyFunction;
EXPECT_TRUE(emptyFunction.isNull());
- Function<int()> returnFortyTwoFunction = bind(returnFortyTwo);
- EXPECT_FALSE(returnFortyTwoFunction.isNull());
- EXPECT_EQ(42, returnFortyTwoFunction());
+ OwnPtr<Function<int()>> returnFortyTwoFunction = bind(returnFortyTwo);
+ EXPECT_FALSE(returnFortyTwoFunction->isNull());
+ EXPECT_EQ(42, (*returnFortyTwoFunction)());
}
static int multiplyByTwo(int n)
@@ -58,20 +59,20 @@ static double multiplyByOneAndAHalf(double d)
TEST(FunctionalTest, UnaryBind)
{
- Function<int()> multiplyFourByTwoFunction = bind(multiplyByTwo, 4);
- EXPECT_EQ(8, multiplyFourByTwoFunction());
+ OwnPtr<Function<int()>> multiplyFourByTwoFunction = bind(multiplyByTwo, 4);
+ EXPECT_EQ(8, (*multiplyFourByTwoFunction)());
- Function<double()> multiplyByOneAndAHalfFunction = bind(multiplyByOneAndAHalf, 3);
- EXPECT_EQ(4.5, multiplyByOneAndAHalfFunction());
+ OwnPtr<Function<double()>> multiplyByOneAndAHalfFunction = bind(multiplyByOneAndAHalf, 3);
+ EXPECT_EQ(4.5, (*multiplyByOneAndAHalfFunction)());
}
TEST(FunctionalTest, UnaryPartBind)
{
- Function<int(int)> multiplyByTwoFunction = bind<int>(multiplyByTwo);
- EXPECT_EQ(8, multiplyByTwoFunction(4));
+ OwnPtr<Function<int(int)>> multiplyByTwoFunction = bind<int>(multiplyByTwo);
+ EXPECT_EQ(8, (*multiplyByTwoFunction)(4));
- Function<double(double)> multiplyByOneAndAHalfFunction = bind<double>(multiplyByOneAndAHalf);
- EXPECT_EQ(4.5, multiplyByOneAndAHalfFunction(3));
+ OwnPtr<Function<double(double)>> multiplyByOneAndAHalfFunction = bind<double>(multiplyByOneAndAHalf);
+ EXPECT_EQ(4.5, (*multiplyByOneAndAHalfFunction)(3));
}
static int multiply(int x, int y)
@@ -86,24 +87,24 @@ static int subtract(int x, int y)
TEST(FunctionalTest, BinaryBind)
{
- Function<int()> multiplyFourByTwoFunction = bind(multiply, 4, 2);
- EXPECT_EQ(8, multiplyFourByTwoFunction());
+ OwnPtr<Function<int()>> multiplyFourByTwoFunction = bind(multiply, 4, 2);
+ EXPECT_EQ(8, (*multiplyFourByTwoFunction)());
- Function<int()> subtractTwoFromFourFunction = bind(subtract, 4, 2);
- EXPECT_EQ(2, subtractTwoFromFourFunction());
+ OwnPtr<Function<int()>> subtractTwoFromFourFunction = bind(subtract, 4, 2);
+ EXPECT_EQ(2, (*subtractTwoFromFourFunction)());
}
TEST(FunctionalTest, BinaryPartBind)
{
- Function<int(int)> multiplyFourFunction = bind<int>(multiply, 4);
- EXPECT_EQ(8, multiplyFourFunction(2));
- Function<int(int, int)> multiplyFunction = bind<int, int>(multiply);
- EXPECT_EQ(8, multiplyFunction(4, 2));
+ OwnPtr<Function<int(int)>> multiplyFourFunction = bind<int>(multiply, 4);
+ EXPECT_EQ(8, (*multiplyFourFunction)(2));
+ OwnPtr<Function<int(int, int)>> multiplyFunction = bind<int, int>(multiply);
+ EXPECT_EQ(8, (*multiplyFunction)(4, 2));
- Function<int(int)> subtractFromFourFunction = bind<int>(subtract, 4);
- EXPECT_EQ(2, subtractFromFourFunction(2));
- Function<int(int, int)> subtractFunction = bind<int, int>(subtract);
- EXPECT_EQ(2, subtractFunction(4, 2));
+ OwnPtr<Function<int(int)>> subtractFromFourFunction = bind<int>(subtract, 4);
+ EXPECT_EQ(2, (*subtractFromFourFunction)(2));
+ OwnPtr<Function<int(int, int)>> subtractFunction = bind<int, int>(subtract);
+ EXPECT_EQ(2, (*subtractFunction)(4, 2));
}
static void sixArgFunc(int a, double b, char c, int* d, double* e, char* f)
@@ -126,39 +127,39 @@ TEST(FunctionalTest, MultiPartBind)
double b = 0.5;
char c = 'a';
- Function<void(int, double, char, int*, double*, char*)> unbound =
+ OwnPtr<Function<void(int, double, char, int*, double*, char*)>> unbound =
bind<int, double, char, int*, double*, char*>(sixArgFunc);
- unbound(1, 1.5, 'b', &a, &b, &c);
+ (*unbound)(1, 1.5, 'b', &a, &b, &c);
assertArgs(a, b, c, 1, 1.5, 'b');
- Function<void(double, char, int*, double*, char*)> oneBound =
+ OwnPtr<Function<void(double, char, int*, double*, char*)>> oneBound =
bind<double, char, int*, double*, char*>(sixArgFunc, 2);
- oneBound(2.5, 'c', &a, &b, &c);
+ (*oneBound)(2.5, 'c', &a, &b, &c);
assertArgs(a, b, c, 2, 2.5, 'c');
- Function<void(char, int*, double*, char*)> twoBound =
+ OwnPtr<Function<void(char, int*, double*, char*)>> twoBound =
bind<char, int*, double*, char*>(sixArgFunc, 3, 3.5);
- twoBound('d', &a, &b, &c);
+ (*twoBound)('d', &a, &b, &c);
assertArgs(a, b, c, 3, 3.5, 'd');
- Function<void(int*, double*, char*)> threeBound =
+ OwnPtr<Function<void(int*, double*, char*)>> threeBound =
bind<int*, double*, char*>(sixArgFunc, 4, 4.5, 'e');
- threeBound(&a, &b, &c);
+ (*threeBound)(&a, &b, &c);
assertArgs(a, b, c, 4, 4.5, 'e');
- Function<void(double*, char*)> fourBound =
+ OwnPtr<Function<void(double*, char*)>> fourBound =
bind<double*, char*>(sixArgFunc, 5, 5.5, 'f', &a);
- fourBound(&b, &c);
+ (*fourBound)(&b, &c);
assertArgs(a, b, c, 5, 5.5, 'f');
- Function<void(char*)> fiveBound =
+ OwnPtr<Function<void(char*)>> fiveBound =
bind<char*>(sixArgFunc, 6, 6.5, 'g', &a, &b);
- fiveBound(&c);
+ (*fiveBound)(&c);
assertArgs(a, b, c, 6, 6.5, 'g');
- Function<void()> sixBound =
+ OwnPtr<Function<void()>> sixBound =
bind(sixArgFunc, 7, 7.5, 'h', &a, &b, &c);
- sixBound();
+ (*sixBound)();
assertArgs(a, b, c, 7, 7.5, 'h');
}
@@ -179,25 +180,25 @@ private:
TEST(FunctionalTest, MemberFunctionBind)
{
A a(10);
- Function<int()> function1 = bind(&A::f, &a);
- EXPECT_EQ(10, function1());
+ OwnPtr<Function<int()>> function1 = bind(&A::f, &a);
+ EXPECT_EQ(10, (*function1)());
- Function<int()> function2 = bind(&A::addF, &a, 15);
- EXPECT_EQ(25, function2());
+ OwnPtr<Function<int()>> function2 = bind(&A::addF, &a, 15);
+ EXPECT_EQ(25, (*function2)());
}
TEST(FunctionalTest, MemberFunctionPartBind)
{
A a(10);
- Function<int(class A*)> function1 = bind<class A*>(&A::f);
- EXPECT_EQ(10, function1(&a));
+ OwnPtr<Function<int(class A*)>> function1 = bind<class A*>(&A::f);
+ EXPECT_EQ(10, (*function1)(&a));
- Function<int(class A*, int)> unboundFunction2 =
+ OwnPtr<Function<int(class A*, int)>> unboundFunction2 =
bind<class A*, int>(&A::addF);
- EXPECT_EQ(25, unboundFunction2(&a, 15));
- Function<int(int)> objectBoundFunction2 =
+ EXPECT_EQ(25, (*unboundFunction2)(&a, 15));
+ OwnPtr<Function<int(int)>> objectBoundFunction2 =
bind<int>(&A::addF, &a);
- EXPECT_EQ(25, objectBoundFunction2(15));
+ EXPECT_EQ(25, (*objectBoundFunction2)(15));
}
class Number : public RefCounted<Number> {
@@ -231,16 +232,16 @@ static int multiplyNumberByTwo(Number* number)
TEST(FunctionalTest, RefCountedStorage)
{
RefPtr<Number> five = Number::create(5);
- Function<int()> multiplyFiveByTwoFunction = bind(multiplyNumberByTwo, five);
- EXPECT_EQ(10, multiplyFiveByTwoFunction());
+ OwnPtr<Function<int()>> multiplyFiveByTwoFunction = bind(multiplyNumberByTwo, five);
+ EXPECT_EQ(10, (*multiplyFiveByTwoFunction)());
- Function<int()> multiplyFourByTwoFunction = bind(multiplyNumberByTwo, Number::create(4));
- EXPECT_EQ(8, multiplyFourByTwoFunction());
+ OwnPtr<Function<int()>> multiplyFourByTwoFunction = bind(multiplyNumberByTwo, Number::create(4));
+ EXPECT_EQ(8, (*multiplyFourByTwoFunction)());
RefPtr<Number> six = Number::create(6);
- Function<int()> multiplySixByTwoFunction = bind(multiplyNumberByTwo, six.release());
+ OwnPtr<Function<int()>> multiplySixByTwoFunction = bind(multiplyNumberByTwo, six.release());
EXPECT_FALSE(six);
- EXPECT_EQ(12, multiplySixByTwoFunction());
+ EXPECT_EQ(12, (*multiplySixByTwoFunction)());
}
} // namespace
« no previous file with comments | « Source/wtf/Functional.h ('k') | Source/wtf/MainThread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698