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

Unified Diff: Source/core/platform/animation/TimingFunctionTestHelperTest.cpp

Issue 60323005: Adding operator== to TimingFunctionTestHelper. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase + Fixing "control reaches end of non-void function". Created 7 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/core/platform/animation/TimingFunctionTestHelper.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/platform/animation/TimingFunctionTestHelperTest.cpp
diff --git a/Source/core/platform/animation/TimingFunctionTestHelperTest.cpp b/Source/core/platform/animation/TimingFunctionTestHelperTest.cpp
index dc29985923077f55eab24cdd6345990b8ba80e2c..643c62640a8f480691c2cb33e093496130340071 100644
--- a/Source/core/platform/animation/TimingFunctionTestHelperTest.cpp
+++ b/Source/core/platform/animation/TimingFunctionTestHelperTest.cpp
@@ -37,11 +37,37 @@
#include <sstream>
#include <string>
+// FIXME: Remove once https://codereview.chromium.org/50603011/ lands.
+#define EXPECT_REFV_EQ(a, b) EXPECT_EQ(*(a.get()), *(b.get()))
+#define EXPECT_REFV_NE(a, b) EXPECT_NE(*(a.get()), *(b.get()))
-using namespace WebCore;
+// Couple of macros to quickly assert a bunch of timing functions are not
+// equal.
+#define NE_STRINGIZE(x) NE_STRINGIZE2(x)
+#define NE_STRINGIZE2(x) #x
+#define NE_HELPER(v) \
+ Vector<std::pair<std::string, RefPtr<TimingFunction> > > v;
+#define NE_HELPER_APPEND(v, x) \
+ v.append(std::make_pair(std::string("Line " NE_STRINGIZE(__LINE__) ":" # x), x))
+#define NE_HELPER_LOOP(v) \
+ for (size_t i = 0; i != v.size(); ++i) { \
+ for (size_t j = 0; j != v.size(); ++j) { \
+ if (i == j) \
+ continue; \
+ EXPECT_REFV_NE(v[i].second, v[j].second) \
+ << v[i].first \
+ << " (" << ::testing::PrintToString(*v[i].second.get()) << ")" \
+ << " == " \
+ << v[j].first \
+ << " (" << ::testing::PrintToString(*v[j].second.get()) << ")" \
+ << "\n"; \
+ } \
+ }
namespace {
+using namespace WebCore;
+
class TimingFunctionTestHelperTest : public ::testing::Test {
protected:
@@ -141,4 +167,175 @@ TEST_F(TimingFunctionTestHelperTest, ChainedPrintTo)
"\\)"));
}
+TEST_F(TimingFunctionTestHelperTest, BaseOperatorEq)
+{
+ RefPtr<TimingFunction> linearTiming = LinearTimingFunction::create();
+ RefPtr<TimingFunction> cubicTiming1 = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseIn);
+ RefPtr<TimingFunction> cubicTiming2 = CubicBezierTimingFunction::create(0.17, 0.67, 1, -1.73);
+ RefPtr<TimingFunction> stepsTiming1 = StepsTimingFunction::preset(StepsTimingFunction::End);
+ RefPtr<TimingFunction> stepsTiming2 = StepsTimingFunction::create(5, true);
+
+ RefPtr<ChainedTimingFunction> chainedTiming1 = ChainedTimingFunction::create();
+ chainedTiming1->appendSegment(1.0, linearTiming.get());
+
+ RefPtr<ChainedTimingFunction> chainedTiming2 = ChainedTimingFunction::create();
+ chainedTiming2->appendSegment(0.5, cubicTiming1.get());
+ chainedTiming2->appendSegment(1.0, cubicTiming2.get());
+
+ NE_HELPER(v);
+ NE_HELPER_APPEND(v, linearTiming);
+ NE_HELPER_APPEND(v, cubicTiming1);
+ NE_HELPER_APPEND(v, cubicTiming2);
+ NE_HELPER_APPEND(v, stepsTiming1);
+ NE_HELPER_APPEND(v, stepsTiming2);
+ NE_HELPER_APPEND(v, chainedTiming1);
+ NE_HELPER_APPEND(v, chainedTiming2);
+ NE_HELPER_LOOP(v);
+}
+
+TEST_F(TimingFunctionTestHelperTest, LinearOperatorEq)
+{
+ RefPtr<TimingFunction> linearTiming1 = LinearTimingFunction::create();
+ RefPtr<TimingFunction> linearTiming2 = LinearTimingFunction::create();
+ EXPECT_REFV_EQ(linearTiming1, linearTiming1);
+ EXPECT_REFV_EQ(linearTiming1, linearTiming2);
+}
+
+TEST_F(TimingFunctionTestHelperTest, CubicOperatorEq)
+{
+ RefPtr<TimingFunction> cubicEaseInTiming1 = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseIn);
+ RefPtr<TimingFunction> cubicEaseInTiming2 = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseIn);
+ EXPECT_REFV_EQ(cubicEaseInTiming1, cubicEaseInTiming1);
+ EXPECT_REFV_EQ(cubicEaseInTiming1, cubicEaseInTiming2);
+
+ RefPtr<TimingFunction> cubicEaseOutTiming1 = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseOut);
+ RefPtr<TimingFunction> cubicEaseOutTiming2 = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseOut);
+ EXPECT_REFV_EQ(cubicEaseOutTiming1, cubicEaseOutTiming2);
+
+ RefPtr<TimingFunction> cubicEaseInOutTiming1 = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseInOut);
+ RefPtr<TimingFunction> cubicEaseInOutTiming2 = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseInOut);
+ EXPECT_REFV_EQ(cubicEaseInOutTiming1, cubicEaseInOutTiming2);
+
+ RefPtr<TimingFunction> cubicCustomTiming1 = CubicBezierTimingFunction::create(0.17, 0.67, 1, -1.73);
+ RefPtr<TimingFunction> cubicCustomTiming2 = CubicBezierTimingFunction::create(0.17, 0.67, 1, -1.73);
+ EXPECT_REFV_EQ(cubicCustomTiming1, cubicCustomTiming2);
+
+ NE_HELPER(v);
+ NE_HELPER_APPEND(v, cubicEaseInTiming1);
+ NE_HELPER_APPEND(v, cubicEaseOutTiming1);
+ NE_HELPER_APPEND(v, cubicEaseInOutTiming1);
+ NE_HELPER_APPEND(v, cubicCustomTiming1);
+ NE_HELPER_LOOP(v);
+}
+
+TEST_F(TimingFunctionTestHelperTest, CubicOperatorEqReflectivity)
+{
+ RefPtr<TimingFunction> cubicA = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseIn);
+ RefPtr<TimingFunction> cubicB = CubicBezierTimingFunction::create(0.42, 0.0, 1.0, 1.0);
+ EXPECT_REFV_NE(cubicA, cubicB);
+ EXPECT_REFV_NE(cubicB, cubicA);
+}
+
+TEST_F(TimingFunctionTestHelperTest, StepsOperatorEq)
+{
+ RefPtr<TimingFunction> stepsTimingStart1 = StepsTimingFunction::preset(StepsTimingFunction::Start);
+ RefPtr<TimingFunction> stepsTimingStart2 = StepsTimingFunction::preset(StepsTimingFunction::Start);
+ EXPECT_REFV_EQ(stepsTimingStart1, stepsTimingStart1);
+ EXPECT_REFV_EQ(stepsTimingStart1, stepsTimingStart2);
+
+ RefPtr<TimingFunction> stepsTimingEnd1 = StepsTimingFunction::preset(StepsTimingFunction::End);
+ RefPtr<TimingFunction> stepsTimingEnd2 = StepsTimingFunction::preset(StepsTimingFunction::End);
+ EXPECT_REFV_EQ(stepsTimingEnd1, stepsTimingEnd2);
+
+ RefPtr<TimingFunction> stepsTimingCustom1 = StepsTimingFunction::create(5, true);
+ RefPtr<TimingFunction> stepsTimingCustom2 = StepsTimingFunction::create(5, false);
+ RefPtr<TimingFunction> stepsTimingCustom3 = StepsTimingFunction::create(7, true);
+ RefPtr<TimingFunction> stepsTimingCustom4 = StepsTimingFunction::create(7, false);
+
+ EXPECT_REFV_EQ(stepsTimingCustom1, StepsTimingFunction::create(5, true));
+ EXPECT_REFV_EQ(stepsTimingCustom2, StepsTimingFunction::create(5, false));
+ EXPECT_REFV_EQ(stepsTimingCustom3, StepsTimingFunction::create(7, true));
+ EXPECT_REFV_EQ(stepsTimingCustom4, StepsTimingFunction::create(7, false));
+
+ NE_HELPER(v);
+ NE_HELPER_APPEND(v, stepsTimingStart1);
+ NE_HELPER_APPEND(v, stepsTimingEnd1);
+ NE_HELPER_APPEND(v, stepsTimingCustom1);
+ NE_HELPER_APPEND(v, stepsTimingCustom2);
+ NE_HELPER_APPEND(v, stepsTimingCustom3);
+ NE_HELPER_APPEND(v, stepsTimingCustom4);
+ NE_HELPER_LOOP(v);
+}
+
+TEST_F(TimingFunctionTestHelperTest, StepsOperatorEqReflectivity)
+{
+ RefPtr<TimingFunction> stepsA = StepsTimingFunction::preset(StepsTimingFunction::Start);
+ RefPtr<TimingFunction> stepsB = StepsTimingFunction::create(1, true);
+ EXPECT_REFV_NE(stepsA, stepsB);
+ EXPECT_REFV_NE(stepsB, stepsA);
+}
+
+TEST_F(TimingFunctionTestHelperTest, ChainedEq)
+{
+ // Single item in chain
+ RefPtr<TimingFunction> cubicTiming1 = CubicBezierTimingFunction::create(0.25, 0.1, 0.25, 1.0);
+ RefPtr<TimingFunction> cubicTiming2 = CubicBezierTimingFunction::create(0.25, 0.1, 0.25, 1.0);
+ RefPtr<TimingFunction> cubicTiming3 = CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseOut);
+
+ RefPtr<ChainedTimingFunction> chainedSingleCubic1 = ChainedTimingFunction::create();
+ chainedSingleCubic1->appendSegment(1.0, cubicTiming1.get());
+ EXPECT_REFV_EQ(chainedSingleCubic1, chainedSingleCubic1);
+
+ RefPtr<ChainedTimingFunction> chainedSingleCubic2 = ChainedTimingFunction::create();
+ chainedSingleCubic2->appendSegment(1.0, cubicTiming1.get()); // Same inner timing function
+ EXPECT_REFV_EQ(chainedSingleCubic1, chainedSingleCubic2);
+
+ RefPtr<ChainedTimingFunction> chainedSingleCubic3 = ChainedTimingFunction::create();
+ chainedSingleCubic3->appendSegment(1.0, cubicTiming2.get()); // == inner timing function
+ EXPECT_REFV_EQ(chainedSingleCubic1, chainedSingleCubic3);
+
+ RefPtr<ChainedTimingFunction> chainedSingleCubic4 = ChainedTimingFunction::create();
+ chainedSingleCubic4->appendSegment(0.5, cubicTiming1.get()); // Different offset
+ EXPECT_REFV_NE(chainedSingleCubic1, chainedSingleCubic4);
+ EXPECT_REFV_NE(chainedSingleCubic3, chainedSingleCubic4);
+
+ RefPtr<ChainedTimingFunction> chainedSingleCubic5 = ChainedTimingFunction::create();
+ chainedSingleCubic5->appendSegment(1.0, cubicTiming3.get()); // != inner timing function (same type)
+ EXPECT_REFV_NE(chainedSingleCubic1, chainedSingleCubic5);
+ EXPECT_REFV_NE(chainedSingleCubic2, chainedSingleCubic5);
+ EXPECT_REFV_NE(chainedSingleCubic3, chainedSingleCubic5);
+ EXPECT_REFV_NE(chainedSingleCubic4, chainedSingleCubic5);
+
+ RefPtr<TimingFunction> linearTiming1 = LinearTimingFunction::create();
+ RefPtr<ChainedTimingFunction> chainedSingleLinear1 = ChainedTimingFunction::create();
+ chainedSingleLinear1->appendSegment(1.0, linearTiming1.get()); // != inner timing function (different type)
+ EXPECT_REFV_NE(chainedSingleLinear1, chainedSingleCubic1);
+ EXPECT_REFV_NE(chainedSingleLinear1, chainedSingleCubic2);
+ EXPECT_REFV_NE(chainedSingleLinear1, chainedSingleCubic3);
+ EXPECT_REFV_NE(chainedSingleLinear1, chainedSingleCubic4);
+
+ // Multiple items in chain
+ RefPtr<ChainedTimingFunction> chainedMixed1 = ChainedTimingFunction::create();
+ chainedMixed1->appendSegment(0.25, chainedSingleLinear1.get());
+ chainedMixed1->appendSegment(1.0, cubicTiming1.get());
+
+ RefPtr<ChainedTimingFunction> chainedMixed2 = ChainedTimingFunction::create();
+ chainedMixed2->appendSegment(0.25, chainedSingleLinear1.get());
+ chainedMixed2->appendSegment(1.0, cubicTiming1.get());
+
+ RefPtr<ChainedTimingFunction> chainedMixed3 = ChainedTimingFunction::create();
+ chainedMixed3->appendSegment(0.25, chainedSingleLinear1.get());
+ chainedMixed3->appendSegment(1.0, cubicTiming2.get());
+
+ EXPECT_REFV_EQ(chainedMixed1, chainedMixed2);
+ EXPECT_REFV_EQ(chainedMixed1, chainedMixed3);
+ EXPECT_REFV_NE(chainedMixed1, chainedSingleCubic1);
+ EXPECT_REFV_NE(chainedMixed1, chainedSingleLinear1);
+
+ RefPtr<ChainedTimingFunction> chainedMixed4 = ChainedTimingFunction::create();
+ chainedMixed4->appendSegment(0.20, chainedSingleLinear1.get()); // Different offset
+ chainedMixed4->appendSegment(1.0, cubicTiming1.get());
+ EXPECT_REFV_NE(chainedMixed1, chainedMixed4);
+}
+
} // namespace
« no previous file with comments | « Source/core/platform/animation/TimingFunctionTestHelper.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698