OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 #include "ui/gfx/geometry/size.h" | 6 #include "ui/gfx/geometry/size.h" |
7 #include "ui/gfx/geometry/size_conversions.h" | 7 #include "ui/gfx/geometry/size_conversions.h" |
8 #include "ui/gfx/geometry/size_f.h" | 8 #include "ui/gfx/geometry/size_f.h" |
9 | 9 |
10 namespace gfx { | 10 namespace gfx { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 | 146 |
147 test = Size(10, 20); | 147 test = Size(10, 20); |
148 test.Enlarge(int_max, int_max); | 148 test.Enlarge(int_max, int_max); |
149 EXPECT_EQ(test, max_size); | 149 EXPECT_EQ(test, max_size); |
150 | 150 |
151 test = Size(-10, -20); | 151 test = Size(-10, -20); |
152 test.Enlarge(int_min, int_min); | 152 test.Enlarge(int_min, int_min); |
153 EXPECT_EQ(test, min_size); | 153 EXPECT_EQ(test, min_size); |
154 } | 154 } |
155 | 155 |
156 float SizeFPrivateMatch() { | |
157 return SizeF::kTrivial; | |
158 }; | |
159 | |
160 static float myTrivial = SizeFPrivateMatch() / 2.f; | |
danakj
2017/03/28 18:00:20
these names are all (old) blink style not chromium
Peter Mayo
2017/03/28 20:11:21
Done.
| |
161 static float boundaryTrivial = SizeFPrivateMatch(); | |
162 static float nearlyTrivial = SizeFPrivateMatch() * 1.5f; | |
163 | |
164 // This checks that we set IsEmpty appropriately. | |
165 TEST(SizeTest, TrivialDimensionTests) { | |
166 // First, using the constructor. | |
167 EXPECT_TRUE(SizeF(myTrivial, 1.f).IsEmpty()); | |
168 EXPECT_TRUE(SizeF(.01f, myTrivial).IsEmpty()); | |
169 EXPECT_TRUE(SizeF(0.f, 0.f).IsEmpty()); | |
170 EXPECT_FALSE(SizeF(.01f, .01f).IsEmpty()); | |
171 | |
172 // Then use the setter. | |
173 SizeF test(2.f, 1.f); | |
174 EXPECT_FALSE(test.IsEmpty()); | |
175 | |
176 test.SetSize(myTrivial, 1.f); | |
177 EXPECT_TRUE(test.IsEmpty()); | |
178 | |
179 test.SetSize(.01f, myTrivial); | |
180 EXPECT_TRUE(test.IsEmpty()); | |
181 | |
182 test.SetSize(0.f, 0.f); | |
183 EXPECT_TRUE(test.IsEmpty()); | |
184 | |
185 test.SetSize(.01f, .01f); | |
186 EXPECT_FALSE(test.IsEmpty()); | |
187 | |
188 // Now just one dimension at a time. | |
189 test.set_width(myTrivial); | |
190 EXPECT_TRUE(test.IsEmpty()); | |
191 | |
192 test.set_width(4e13f); | |
193 test.set_height(myTrivial); | |
194 EXPECT_TRUE(test.IsEmpty()); | |
195 | |
196 test.set_width(myTrivial); | |
197 test.set_height(4e13f); | |
198 EXPECT_TRUE(test.IsEmpty()); | |
199 | |
200 test.set_width(2.f); | |
201 EXPECT_FALSE(test.IsEmpty()); | |
202 } | |
203 | |
204 // These are the ramifications of the decision to keep the recorded size | |
205 // at zero for trivial sizes. | |
206 TEST(SizeTest, ClampsToZero) { | |
207 SizeF test(myTrivial, 1.f); | |
208 | |
209 EXPECT_FLOAT_EQ(0.f, test.width()); | |
210 EXPECT_FLOAT_EQ(1.f, test.height()); | |
211 | |
212 test.SetSize(.01f, myTrivial); | |
213 | |
214 EXPECT_FLOAT_EQ(.01f, test.width()); | |
215 EXPECT_FLOAT_EQ(0.f, test.height()); | |
216 | |
217 test.SetSize(nearlyTrivial, nearlyTrivial); | |
Peter Mayo
2017/03/28 20:11:21
Added an expectation here that validates nearly_tr
| |
218 test.Scale(0.5f); | |
219 | |
220 EXPECT_FLOAT_EQ(0.f, test.width()); | |
221 EXPECT_FLOAT_EQ(0.f, test.height()); | |
222 | |
223 test.SetSize(0.f, 0.f); | |
224 test.Enlarge(myTrivial, myTrivial); | |
225 test.Enlarge(myTrivial, myTrivial); | |
226 test.Enlarge(myTrivial, myTrivial); | |
227 | |
228 EXPECT_EQ(SizeF(0.f, 0.f), test); | |
229 } | |
230 | |
231 // These make sure the constructor and setter have the same effect on the | |
232 // boundary case. This claims to know the boundary, but not which way it goes. | |
233 TEST(SizeTest, ConsistentClamping) { | |
234 SizeF resized; | |
235 | |
236 resized.SetSize(boundaryTrivial, 0.f); | |
237 EXPECT_EQ(SizeF(boundaryTrivial, 0.f), resized); | |
238 | |
239 resized.SetSize(0.f, boundaryTrivial); | |
240 EXPECT_EQ(SizeF(0.f, boundaryTrivial), resized); | |
241 } | |
242 | |
243 // Let's make sure we don't unexpectedly grow the struct by adding constants. | |
244 // Also, if some platform packs floats inefficiently, it would be worth noting. | |
245 TEST(SizeTest, StaysSmall) { | |
246 EXPECT_EQ(2 * sizeof(float), sizeof(SizeF)); | |
247 } | |
248 | |
156 } // namespace gfx | 249 } // namespace gfx |
OLD | NEW |