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

Unified Diff: third_party/WebKit/Source/wtf/FunctionalTest.cpp

Issue 1611343002: wtf reformat test Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pydent Created 4 years, 11 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 | « third_party/WebKit/Source/wtf/Functional.h ('k') | third_party/WebKit/Source/wtf/GetPtr.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/FunctionalTest.cpp
diff --git a/third_party/WebKit/Source/wtf/FunctionalTest.cpp b/third_party/WebKit/Source/wtf/FunctionalTest.cpp
index 80fbf93210e270418872b96641c02c6b3c7e515f..747d7b1f9ced46e8ff68f2fef7bf1a291cb5b1e6 100644
--- a/third_party/WebKit/Source/wtf/FunctionalTest.cpp
+++ b/third_party/WebKit/Source/wtf/FunctionalTest.cpp
@@ -32,265 +32,242 @@
namespace WTF {
class UnwrappedClass {
-public:
- explicit UnwrappedClass(int value)
- : m_value(value)
- {
- }
+ public:
+ explicit UnwrappedClass(int value) : m_value(value) {}
- int value() const { return m_value; }
+ int value() const { return m_value; }
-private:
- int m_value;
+ private:
+ int m_value;
};
class WrappedClass {
-public:
- explicit WrappedClass(int value)
- : m_value(value)
- {
- }
+ public:
+ explicit WrappedClass(int value) : m_value(value) {}
- UnwrappedClass unwrap() const { return UnwrappedClass(m_value); }
+ UnwrappedClass unwrap() const { return UnwrappedClass(m_value); }
-private:
- int m_value;
+ private:
+ int m_value;
};
// This class must be wrapped in bind() and unwrapped in closure execution.
class ClassToBeWrapped {
- WTF_MAKE_NONCOPYABLE(ClassToBeWrapped);
-public:
- explicit ClassToBeWrapped(int value)
- : m_value(value)
- {
- }
+ WTF_MAKE_NONCOPYABLE(ClassToBeWrapped);
- WrappedClass wrap() const { return WrappedClass(m_value); }
+ public:
+ explicit ClassToBeWrapped(int value) : m_value(value) {}
-private:
- int m_value;
+ WrappedClass wrap() const { return WrappedClass(m_value); }
+
+ private:
+ int m_value;
};
-template<> struct ParamStorageTraits<ClassToBeWrapped> {
- using StorageType = WrappedClass;
- static StorageType wrap(const ClassToBeWrapped& value) { return value.wrap(); }
- static UnwrappedClass unwrap(const StorageType& value) { return value.unwrap(); }
+template <>
+struct ParamStorageTraits<ClassToBeWrapped> {
+ using StorageType = WrappedClass;
+ static StorageType wrap(const ClassToBeWrapped& value) {
+ return value.wrap();
+ }
+ static UnwrappedClass unwrap(const StorageType& value) {
+ return value.unwrap();
+ }
};
namespace {
-int returnFortyTwo()
-{
- return 42;
+int returnFortyTwo() {
+ return 42;
}
-TEST(FunctionalTest, Basic)
-{
- OwnPtr<Function<int()>> returnFortyTwoFunction = bind(returnFortyTwo);
- EXPECT_EQ(42, (*returnFortyTwoFunction)());
+TEST(FunctionalTest, Basic) {
+ OwnPtr<Function<int()>> returnFortyTwoFunction = bind(returnFortyTwo);
+ EXPECT_EQ(42, (*returnFortyTwoFunction)());
}
-int multiplyByTwo(int n)
-{
- return n * 2;
+int multiplyByTwo(int n) {
+ return n * 2;
}
-double multiplyByOneAndAHalf(double d)
-{
- return d * 1.5;
+double multiplyByOneAndAHalf(double d) {
+ return d * 1.5;
}
-TEST(FunctionalTest, UnaryBind)
-{
- OwnPtr<Function<int()>> multiplyFourByTwoFunction = bind(multiplyByTwo, 4);
- EXPECT_EQ(8, (*multiplyFourByTwoFunction)());
+TEST(FunctionalTest, UnaryBind) {
+ OwnPtr<Function<int()>> multiplyFourByTwoFunction = bind(multiplyByTwo, 4);
+ EXPECT_EQ(8, (*multiplyFourByTwoFunction)());
- OwnPtr<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)
-{
- OwnPtr<Function<int(int)>> multiplyByTwoFunction = bind<int>(multiplyByTwo);
- EXPECT_EQ(8, (*multiplyByTwoFunction)(4));
+TEST(FunctionalTest, UnaryPartBind) {
+ OwnPtr<Function<int(int)>> multiplyByTwoFunction = bind<int>(multiplyByTwo);
+ EXPECT_EQ(8, (*multiplyByTwoFunction)(4));
- OwnPtr<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));
}
-int multiply(int x, int y)
-{
- return x * y;
+int multiply(int x, int y) {
+ return x * y;
}
-int subtract(int x, int y)
-{
- return x - y;
+int subtract(int x, int y) {
+ return x - y;
}
-TEST(FunctionalTest, BinaryBind)
-{
- OwnPtr<Function<int()>> multiplyFourByTwoFunction = bind(multiply, 4, 2);
- EXPECT_EQ(8, (*multiplyFourByTwoFunction)());
+TEST(FunctionalTest, BinaryBind) {
+ OwnPtr<Function<int()>> multiplyFourByTwoFunction = bind(multiply, 4, 2);
+ EXPECT_EQ(8, (*multiplyFourByTwoFunction)());
- OwnPtr<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)
-{
- 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));
-
- 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));
+TEST(FunctionalTest, BinaryPartBind) {
+ 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));
+
+ 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));
}
-void sixArgFunc(int a, double b, char c, int* d, double* e, char* f)
-{
- *d = a;
- *e = b;
- *f = c;
+void sixArgFunc(int a, double b, char c, int* d, double* e, char* f) {
+ *d = a;
+ *e = b;
+ *f = c;
}
-void assertArgs(int actualInt, double actualDouble, char actualChar, int expectedInt, double expectedDouble, char expectedChar)
-{
- EXPECT_EQ(expectedInt, actualInt);
- EXPECT_EQ(expectedDouble, actualDouble);
- EXPECT_EQ(expectedChar, actualChar);
+void assertArgs(int actualInt,
+ double actualDouble,
+ char actualChar,
+ int expectedInt,
+ double expectedDouble,
+ char expectedChar) {
+ EXPECT_EQ(expectedInt, actualInt);
+ EXPECT_EQ(expectedDouble, actualDouble);
+ EXPECT_EQ(expectedChar, actualChar);
}
-TEST(FunctionalTest, MultiPartBind)
-{
- int a = 0;
- double b = 0.5;
- char c = 'a';
-
- 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);
- assertArgs(a, b, c, 1, 1.5, 'b');
-
- OwnPtr<Function<void(double, char, int*, double*, char*)>> oneBound =
- bind<double, char, int*, double*, char*>(sixArgFunc, 2);
- (*oneBound)(2.5, 'c', &a, &b, &c);
- assertArgs(a, b, c, 2, 2.5, 'c');
-
- OwnPtr<Function<void(char, int*, double*, char*)>> twoBound =
- bind<char, int*, double*, char*>(sixArgFunc, 3, 3.5);
- (*twoBound)('d', &a, &b, &c);
- assertArgs(a, b, c, 3, 3.5, 'd');
-
- OwnPtr<Function<void(int*, double*, char*)>> threeBound =
- bind<int*, double*, char*>(sixArgFunc, 4, 4.5, 'e');
- (*threeBound)(&a, &b, &c);
- assertArgs(a, b, c, 4, 4.5, 'e');
-
- OwnPtr<Function<void(double*, char*)>> fourBound =
- bind<double*, char*>(sixArgFunc, 5, 5.5, 'f', &a);
- (*fourBound)(&b, &c);
- assertArgs(a, b, c, 5, 5.5, 'f');
-
- OwnPtr<Function<void(char*)>> fiveBound =
- bind<char*>(sixArgFunc, 6, 6.5, 'g', &a, &b);
- (*fiveBound)(&c);
- assertArgs(a, b, c, 6, 6.5, 'g');
-
- OwnPtr<Function<void()>> sixBound =
- bind(sixArgFunc, 7, 7.5, 'h', &a, &b, &c);
- (*sixBound)();
- assertArgs(a, b, c, 7, 7.5, 'h');
+TEST(FunctionalTest, MultiPartBind) {
+ int a = 0;
+ double b = 0.5;
+ char c = 'a';
+
+ 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);
+ assertArgs(a, b, c, 1, 1.5, 'b');
+
+ OwnPtr<Function<void(double, char, int*, double*, char*)>> oneBound =
+ bind<double, char, int*, double*, char*>(sixArgFunc, 2);
+ (*oneBound)(2.5, 'c', &a, &b, &c);
+ assertArgs(a, b, c, 2, 2.5, 'c');
+
+ OwnPtr<Function<void(char, int*, double*, char*)>> twoBound =
+ bind<char, int*, double*, char*>(sixArgFunc, 3, 3.5);
+ (*twoBound)('d', &a, &b, &c);
+ assertArgs(a, b, c, 3, 3.5, 'd');
+
+ OwnPtr<Function<void(int*, double*, char*)>> threeBound =
+ bind<int*, double*, char*>(sixArgFunc, 4, 4.5, 'e');
+ (*threeBound)(&a, &b, &c);
+ assertArgs(a, b, c, 4, 4.5, 'e');
+
+ OwnPtr<Function<void(double*, char*)>> fourBound =
+ bind<double*, char*>(sixArgFunc, 5, 5.5, 'f', &a);
+ (*fourBound)(&b, &c);
+ assertArgs(a, b, c, 5, 5.5, 'f');
+
+ OwnPtr<Function<void(char*)>> fiveBound =
+ bind<char*>(sixArgFunc, 6, 6.5, 'g', &a, &b);
+ (*fiveBound)(&c);
+ assertArgs(a, b, c, 6, 6.5, 'g');
+
+ OwnPtr<Function<void()>> sixBound = bind(sixArgFunc, 7, 7.5, 'h', &a, &b, &c);
+ (*sixBound)();
+ assertArgs(a, b, c, 7, 7.5, 'h');
}
class A {
-public:
- explicit A(int i)
- : m_i(i)
- {
- }
+ public:
+ explicit A(int i) : m_i(i) {}
- int f() { return m_i; }
- int addF(int j) { return m_i + j; }
+ int f() { return m_i; }
+ int addF(int j) { return m_i + j; }
-private:
- int m_i;
+ private:
+ int m_i;
};
-TEST(FunctionalTest, MemberFunctionBind)
-{
- A a(10);
- OwnPtr<Function<int()>> function1 = bind(&A::f, &a);
- EXPECT_EQ(10, (*function1)());
+TEST(FunctionalTest, MemberFunctionBind) {
+ A a(10);
+ OwnPtr<Function<int()>> function1 = bind(&A::f, &a);
+ EXPECT_EQ(10, (*function1)());
- OwnPtr<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);
- OwnPtr<Function<int(class A*)>> function1 = bind<class A*>(&A::f);
- EXPECT_EQ(10, (*function1)(&a));
-
- OwnPtr<Function<int(class A*, int)>> unboundFunction2 =
- bind<class A*, int>(&A::addF);
- EXPECT_EQ(25, (*unboundFunction2)(&a, 15));
- OwnPtr<Function<int(int)>> objectBoundFunction2 =
- bind<int>(&A::addF, &a);
- EXPECT_EQ(25, (*objectBoundFunction2)(15));
+TEST(FunctionalTest, MemberFunctionPartBind) {
+ A a(10);
+ OwnPtr<Function<int(class A*)>> function1 = bind<class A*>(&A::f);
+ EXPECT_EQ(10, (*function1)(&a));
+
+ OwnPtr<Function<int(class A*, int)>> unboundFunction2 =
+ bind<class A*, int>(&A::addF);
+ EXPECT_EQ(25, (*unboundFunction2)(&a, 15));
+ OwnPtr<Function<int(int)>> objectBoundFunction2 = bind<int>(&A::addF, &a);
+ EXPECT_EQ(25, (*objectBoundFunction2)(15));
}
class Number : public RefCounted<Number> {
-public:
- static PassRefPtr<Number> create(int value)
- {
- return adoptRef(new Number(value));
- }
-
- ~Number()
- {
- m_value = 0;
- }
-
- int value() const { return m_value; }
-
-private:
- explicit Number(int value)
- : m_value(value)
- {
- }
-
- int m_value;
-};
+ public:
+ static PassRefPtr<Number> create(int value) {
+ return adoptRef(new Number(value));
+ }
-int multiplyNumberByTwo(Number* number)
-{
- return number->value() * 2;
-}
+ ~Number() { m_value = 0; }
-TEST(FunctionalTest, RefCountedStorage)
-{
- RefPtr<Number> five = Number::create(5);
- OwnPtr<Function<int()>> multiplyFiveByTwoFunction = bind(multiplyNumberByTwo, five);
- EXPECT_EQ(10, (*multiplyFiveByTwoFunction)());
+ int value() const { return m_value; }
- OwnPtr<Function<int()>> multiplyFourByTwoFunction = bind(multiplyNumberByTwo, Number::create(4));
- EXPECT_EQ(8, (*multiplyFourByTwoFunction)());
+ private:
+ explicit Number(int value) : m_value(value) {}
+
+ int m_value;
+};
+
+int multiplyNumberByTwo(Number* number) {
+ return number->value() * 2;
+}
- RefPtr<Number> six = Number::create(6);
- OwnPtr<Function<int()>> multiplySixByTwoFunction = bind(multiplyNumberByTwo, six.release());
- EXPECT_FALSE(six);
- EXPECT_EQ(12, (*multiplySixByTwoFunction)());
+TEST(FunctionalTest, RefCountedStorage) {
+ RefPtr<Number> five = Number::create(5);
+ OwnPtr<Function<int()>> multiplyFiveByTwoFunction =
+ bind(multiplyNumberByTwo, five);
+ EXPECT_EQ(10, (*multiplyFiveByTwoFunction)());
+
+ OwnPtr<Function<int()>> multiplyFourByTwoFunction =
+ bind(multiplyNumberByTwo, Number::create(4));
+ EXPECT_EQ(8, (*multiplyFourByTwoFunction)());
+
+ RefPtr<Number> six = Number::create(6);
+ OwnPtr<Function<int()>> multiplySixByTwoFunction =
+ bind(multiplyNumberByTwo, six.release());
+ EXPECT_FALSE(six);
+ EXPECT_EQ(12, (*multiplySixByTwoFunction)());
}
-int processUnwrappedClass(const UnwrappedClass& u, int v)
-{
- return u.value() * v;
+int processUnwrappedClass(const UnwrappedClass& u, int v) {
+ return u.value() * v;
}
// Tests that:
@@ -299,18 +276,18 @@ int processUnwrappedClass(const UnwrappedClass& u, int v)
// with no additional copies.
// This test would fail in compile if something is wrong,
// rather than in runtime.
-TEST(FunctionalTest, WrapUnwrap)
-{
- OwnPtr<Function<int()>> function = bind(processUnwrappedClass, ClassToBeWrapped(3), 7);
- EXPECT_EQ(21, (*function)());
+TEST(FunctionalTest, WrapUnwrap) {
+ OwnPtr<Function<int()>> function =
+ bind(processUnwrappedClass, ClassToBeWrapped(3), 7);
+ EXPECT_EQ(21, (*function)());
}
-TEST(FunctionalTest, WrapUnwrapInPartialBind)
-{
- OwnPtr<Function<int(int)>> partiallyBoundFunction = bind<int>(processUnwrappedClass, ClassToBeWrapped(3));
- EXPECT_EQ(21, (*partiallyBoundFunction)(7));
+TEST(FunctionalTest, WrapUnwrapInPartialBind) {
+ OwnPtr<Function<int(int)>> partiallyBoundFunction =
+ bind<int>(processUnwrappedClass, ClassToBeWrapped(3));
+ EXPECT_EQ(21, (*partiallyBoundFunction)(7));
}
-} // anonymous namespace
+} // anonymous namespace
-} // namespace WTF
+} // namespace WTF
« no previous file with comments | « third_party/WebKit/Source/wtf/Functional.h ('k') | third_party/WebKit/Source/wtf/GetPtr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698