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

Side by Side Diff: Source/core/animation/LengthStyleInterpolationTest.cpp

Issue 1193053002: Made LengthStyleInterpolationTest display better output when failing (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 6 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "core/animation/LengthStyleInterpolation.h" 6 #include "core/animation/LengthStyleInterpolation.h"
7 7
8 #include "core/css/CSSPrimitiveValue.h" 8 #include "core/css/CSSPrimitiveValue.h"
9 #include "core/css/StylePropertySet.h" 9 #include "core/css/StylePropertySet.h"
10 10
(...skipping 11 matching lines...) Expand all
22 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToLength(Interpolab leValue* value, InterpolationRange range) 22 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToLength(Interpolab leValue* value, InterpolationRange range)
23 { 23 {
24 return LengthStyleInterpolation::fromInterpolableValue(*value, range); 24 return LengthStyleInterpolation::fromInterpolableValue(*value, range);
25 } 25 }
26 26
27 static PassRefPtrWillBeRawPtr<CSSValue> roundTrip(PassRefPtrWillBeRawPtr<CSS Value> value) 27 static PassRefPtrWillBeRawPtr<CSSValue> roundTrip(PassRefPtrWillBeRawPtr<CSS Value> value)
28 { 28 {
29 return interpolableValueToLength(lengthToInterpolableValue(*value).get() , RangeAll); 29 return interpolableValueToLength(lengthToInterpolableValue(*value).get() , RangeAll);
30 } 30 }
31 31
32 static void testPrimitiveValue(RefPtrWillBeRawPtr<CSSValue> value, double do ubleValue, CSSPrimitiveValue::UnitType unitType)
33 {
34 EXPECT_TRUE(value->isPrimitiveValue());
35 EXPECT_EQ(doubleValue, toCSSPrimitiveValue(value.get())->getDoubleValue( ));
36 EXPECT_EQ(unitType, toCSSPrimitiveValue(value.get())->primitiveType());
37 }
38
39 static PassOwnPtrWillBeRawPtr<InterpolableList> createInterpolableLength(dou ble a, double b, double c, double d, double e, double f, double g, double h, dou ble i, double j) 32 static PassOwnPtrWillBeRawPtr<InterpolableList> createInterpolableLength(dou ble a, double b, double c, double d, double e, double f, double g, double h, dou ble i, double j)
40 { 33 {
41 OwnPtrWillBeRawPtr<InterpolableList> list = InterpolableList::create(10) ; 34 OwnPtrWillBeRawPtr<InterpolableList> list = InterpolableList::create(10) ;
42 list->set(0, InterpolableNumber::create(a)); 35 list->set(0, InterpolableNumber::create(a));
43 list->set(1, InterpolableNumber::create(b)); 36 list->set(1, InterpolableNumber::create(b));
44 list->set(2, InterpolableNumber::create(c)); 37 list->set(2, InterpolableNumber::create(c));
45 list->set(3, InterpolableNumber::create(d)); 38 list->set(3, InterpolableNumber::create(d));
46 list->set(4, InterpolableNumber::create(e)); 39 list->set(4, InterpolableNumber::create(e));
47 list->set(5, InterpolableNumber::create(f)); 40 list->set(5, InterpolableNumber::create(f));
48 list->set(6, InterpolableNumber::create(g)); 41 list->set(6, InterpolableNumber::create(g));
(...skipping 13 matching lines...) Expand all
62 55
63 CSSLengthArray& setLengthArray(CSSLengthArray& lengthArray, String text) 56 CSSLengthArray& setLengthArray(CSSLengthArray& lengthArray, String text)
64 { 57 {
65 CSSPrimitiveValue::CSSLengthTypeArray lengthTypeArray; 58 CSSPrimitiveValue::CSSLengthTypeArray lengthTypeArray;
66 initLengthArray(lengthArray); 59 initLengthArray(lengthArray);
67 RefPtrWillBeRawPtr<MutableStylePropertySet> propertySet = MutableStylePr opertySet::create(); 60 RefPtrWillBeRawPtr<MutableStylePropertySet> propertySet = MutableStylePr opertySet::create();
68 propertySet->setProperty(CSSPropertyLeft, text); 61 propertySet->setProperty(CSSPropertyLeft, text);
69 toCSSPrimitiveValue(propertySet->getPropertyCSSValue(CSSPropertyLeft).ge t())->accumulateLengthArray(lengthArray); 62 toCSSPrimitiveValue(propertySet->getPropertyCSSValue(CSSPropertyLeft).ge t())->accumulateLengthArray(lengthArray);
70 return lengthArray; 63 return lengthArray;
71 } 64 }
65 };
72 66
73 bool lengthArraysEqual(CSSLengthArray& a, CSSLengthArray& b) 67 #define TEST_PRIMITIVE_VALUE(ACTUAL_VALUE, EXPECTED_DOUBLE_VALUE, EXPECTED_UNIT_ TYPE) \
esprehn 2015/06/20 01:07:31 Why can't this be a regular function?
esprehn 2015/06/20 01:18:41 I think we normally name these with regular variab
sashab 2015/06/20 01:20:08 If these fail inside a regular function, the line
74 { 68 EXPECT_TRUE((ACTUAL_VALUE)->isPrimitiveValue()); \
75 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) { 69 EXPECT_EQ((EXPECTED_DOUBLE_VALUE), toCSSPrimitiveValue((ACTUAL_VALUE).get()) ->getDoubleValue()); \
76 if (a.at(i) != b.at(i)) 70 EXPECT_EQ((EXPECTED_UNIT_TYPE), toCSSPrimitiveValue((ACTUAL_VALUE).get())->p rimitiveType());
77 return false; 71
78 } 72 #define EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(EXPECTED, ACTUAL) \
esprehn 2015/06/20 01:07:31 just make a function?
sashab 2015/06/20 01:20:08 Same as above. As far as I know gtest never gives
79 return true; 73 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) \
80 } 74 EXPECT_EQ((EXPECTED).at(i), (ACTUAL).at(i))
81 };
82 75
83 TEST_F(AnimationLengthStyleInterpolationTest, ZeroLength) 76 TEST_F(AnimationLengthStyleInterpolationTest, ZeroLength)
84 { 77 {
85 RefPtrWillBeRawPtr<CSSValue> value1 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); 78 RefPtrWillBeRawPtr<CSSValue> value1 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX));
86 testPrimitiveValue(value1, 0, CSSPrimitiveValue::CSS_PX); 79 TEST_PRIMITIVE_VALUE(value1, 0, CSSPrimitiveValue::CSS_PX);
87 80
88 RefPtrWillBeRawPtr<CSSValue> value2 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PERCENTAGE)); 81 RefPtrWillBeRawPtr<CSSValue> value2 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PERCENTAGE));
89 testPrimitiveValue(value2, 0, CSSPrimitiveValue::CSS_PERCENTAGE); 82 TEST_PRIMITIVE_VALUE(value2, 0, CSSPrimitiveValue::CSS_PERCENTAGE);
90 83
91 RefPtrWillBeRawPtr<CSSValue> value3 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_EMS)); 84 RefPtrWillBeRawPtr<CSSValue> value3 = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_EMS));
92 testPrimitiveValue(value3, 0, CSSPrimitiveValue::CSS_EMS); 85 TEST_PRIMITIVE_VALUE(value3, 0, CSSPrimitiveValue::CSS_EMS);
93
94 } 86 }
95 87
96 TEST_F(AnimationLengthStyleInterpolationTest, SingleUnit) 88 TEST_F(AnimationLengthStyleInterpolationTest, SingleUnit)
97 { 89 {
98 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_PX)); 90 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_PX));
99 testPrimitiveValue(value, 10, CSSPrimitiveValue::CSS_PX); 91 TEST_PRIMITIVE_VALUE(value, 10, CSSPrimitiveValue::CSS_PX);
100 92
101 value = roundTrip(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCE NTAGE)); 93 value = roundTrip(CSSPrimitiveValue::create(30, CSSPrimitiveValue::CSS_PERCE NTAGE));
102 testPrimitiveValue(value, 30, CSSPrimitiveValue::CSS_PERCENTAGE); 94 TEST_PRIMITIVE_VALUE(value, 30, CSSPrimitiveValue::CSS_PERCENTAGE);
103 95
104 value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_EMS)) ; 96 value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiveValue::CSS_EMS)) ;
105 testPrimitiveValue(value, 10, CSSPrimitiveValue::CSS_EMS); 97 TEST_PRIMITIVE_VALUE(value, 10, CSSPrimitiveValue::CSS_EMS);
106 } 98 }
107 99
108 TEST_F(AnimationLengthStyleInterpolationTest, SingleClampedUnit) 100 TEST_F(AnimationLengthStyleInterpolationTest, SingleClampedUnit)
109 { 101 {
110 RefPtrWillBeRawPtr<CSSValue> value1 = CSSPrimitiveValue::create(-10, CSSPrim itiveValue::CSS_PX); 102 RefPtrWillBeRawPtr<CSSValue> value1 = CSSPrimitiveValue::create(-10, CSSPrim itiveValue::CSS_PX);
111 value1 = interpolableValueToLength(lengthToInterpolableValue(*value1).get(), RangeNonNegative); 103 value1 = interpolableValueToLength(lengthToInterpolableValue(*value1).get(), RangeNonNegative);
112 testPrimitiveValue(value1, 0, CSSPrimitiveValue::CSS_PX); 104 TEST_PRIMITIVE_VALUE(value1, 0, CSSPrimitiveValue::CSS_PX);
113 105
114 RefPtrWillBeRawPtr<CSSValue> value2 = CSSPrimitiveValue::create(-10, CSSPrim itiveValue::CSS_EMS); 106 RefPtrWillBeRawPtr<CSSValue> value2 = CSSPrimitiveValue::create(-10, CSSPrim itiveValue::CSS_EMS);
115 value2 = interpolableValueToLength(lengthToInterpolableValue(*value2).get(), RangeNonNegative); 107 value2 = interpolableValueToLength(lengthToInterpolableValue(*value2).get(), RangeNonNegative);
116 testPrimitiveValue(value2, 0, CSSPrimitiveValue::CSS_EMS); 108 TEST_PRIMITIVE_VALUE(value2, 0, CSSPrimitiveValue::CSS_EMS);
117 } 109 }
118 110
119 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnits) 111 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnits)
120 { 112 {
121 CSSLengthArray expectation, actual; 113 CSSLengthArray expectation, actual;
122 initLengthArray(expectation); 114 initLengthArray(expectation);
123 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); 115 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2);
124 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10)); 116 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10));
125 result->set(1, createInterpolableLength(0, 1, 0, 1, 0, 1, 0, 1, 0, 1)); 117 result->set(1, createInterpolableLength(0, 1, 0, 1, 0, 1, 0, 1, 0, 1));
126 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get()) ->accumulateLengthArray(expectation); 118 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get()) ->accumulateLengthArray(expectation);
127 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(10% + 10ex + 10ch + 10vh + 10vmax)"))); 119 setLengthArray(actual, "calc(10% + 10ex + 10ch + 10vh + 10vmax)");
120 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual);
128 } 121 }
129 122
130 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithSingleValues) 123 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithSingleValues)
131 { 124 {
132 CSSLengthArray expectation, actual; 125 CSSLengthArray expectation, actual;
133 initLengthArray(expectation); 126 initLengthArray(expectation);
134 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); 127 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2);
135 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10)); 128 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10));
136 result->set(1, createInterpolableLength(0, 1, 0, 1, 0, 1, 0, 1, 0, 1)); 129 result->set(1, createInterpolableLength(0, 1, 0, 1, 0, 1, 0, 1, 0, 1));
137 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get()) ->accumulateLengthArray(expectation); 130 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get()) ->accumulateLengthArray(expectation);
138 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(10% + 10ex + 10ch + 10vh + 10vmax)"))); 131 setLengthArray(actual, "calc(10% + 10ex + 10ch + 10vh + 10vmax)");
139 132 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual);
140 } 133 }
141 134
142 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithMultipleValues) 135 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithMultipleValues)
143 { 136 {
144 CSSLengthArray expectation, actual; 137 CSSLengthArray expectation, actual;
145 initLengthArray(expectation); 138 initLengthArray(expectation);
146 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); 139 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2);
147 result->set(0, createInterpolableLength(0, 20, 0, 30, 0, 8, 0, 10, 0, 7)); 140 result->set(0, createInterpolableLength(0, 20, 0, 30, 0, 8, 0, 10, 0, 7));
148 result->set(1, createInterpolableLength(0, 1, 0, 1, 0, 1, 0, 1, 0, 1)); 141 result->set(1, createInterpolableLength(0, 1, 0, 1, 0, 1, 0, 1, 0, 1));
149 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get()) ->accumulateLengthArray(expectation); 142 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get()) ->accumulateLengthArray(expectation);
150 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(20% + 30ex + 8ch + 10vh + 7vmax)"))); 143 setLengthArray(actual, "calc(20% + 30ex + 8ch + 10vh + 7vmax)");
151 144 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual);
152 } 145 }
153 146
154 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithZeroValue) 147 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithZeroValue)
155 { 148 {
156 CSSLengthArray expectation, actual; 149 CSSLengthArray expectation, actual;
157 initLengthArray(expectation); 150 initLengthArray(expectation);
158 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); 151 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2);
159 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10)); 152 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10));
160 result->set(1, createInterpolableLength(1, 1, 0, 1, 0, 1, 0, 1, 0, 1)); 153 result->set(1, createInterpolableLength(1, 1, 0, 1, 0, 1, 0, 1, 0, 1));
161 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get()) ->accumulateLengthArray(expectation); 154 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get()) ->accumulateLengthArray(expectation);
162 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(0px + 10% + 10ex + 10ch + 10vh + 10vmax)"))); 155 setLengthArray(actual, "calc(0px + 10% + 10ex + 10ch + 10vh + 10vmax)");
156 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual);
163 } 157 }
164 158
165 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithZeroValues) 159 TEST_F(AnimationLengthStyleInterpolationTest, MultipleUnitsWithZeroValues)
166 { 160 {
167 CSSLengthArray expectation, actual; 161 CSSLengthArray expectation, actual;
168 initLengthArray(expectation); 162 initLengthArray(expectation);
169 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2); 163 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(2);
170 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10)); 164 result->set(0, createInterpolableLength(0, 10, 0, 10, 0, 10, 0, 10, 0, 10));
171 result->set(1, createInterpolableLength(1, 1, 1, 1, 0, 1, 0, 1, 1, 1)); 165 result->set(1, createInterpolableLength(1, 1, 1, 1, 0, 1, 0, 1, 1, 1));
172 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get()) ->accumulateLengthArray(expectation); 166 toCSSPrimitiveValue(interpolableValueToLength(result.get(), RangeAll).get()) ->accumulateLengthArray(expectation);
173 EXPECT_TRUE(lengthArraysEqual(expectation, setLengthArray(actual, "calc(0px + 10% + 0em + 10ex + 10ch + 10vh + 0vmin + 10vmax)"))); 167 setLengthArray(actual, "calc(0px + 10% + 0em + 10ex + 10ch + 10vh + 0vmin + 10vmax)");
168 EXPECT_CSS_LENGTH_ARRAY_ELEMENTS_EQUAL(expectation, actual);
174 } 169 }
175 170
176 } 171 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698