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 // This checks that we set IsEmpty appropriately. |
| 157 TEST(SizeTest, TrivialDimensionTests) { |
| 158 const float clearly_trivial = SizeF::kTrivial / 2.f; |
| 159 const float massize_dimension = 4e13f; |
| 160 |
| 161 // First, using the constructor. |
| 162 EXPECT_TRUE(SizeF(clearly_trivial, 1.f).IsEmpty()); |
| 163 EXPECT_TRUE(SizeF(.01f, clearly_trivial).IsEmpty()); |
| 164 EXPECT_TRUE(SizeF(0.f, 0.f).IsEmpty()); |
| 165 EXPECT_FALSE(SizeF(.01f, .01f).IsEmpty()); |
| 166 |
| 167 // Then use the setter. |
| 168 SizeF test(2.f, 1.f); |
| 169 EXPECT_FALSE(test.IsEmpty()); |
| 170 |
| 171 test.SetSize(clearly_trivial, 1.f); |
| 172 EXPECT_TRUE(test.IsEmpty()); |
| 173 |
| 174 test.SetSize(.01f, clearly_trivial); |
| 175 EXPECT_TRUE(test.IsEmpty()); |
| 176 |
| 177 test.SetSize(0.f, 0.f); |
| 178 EXPECT_TRUE(test.IsEmpty()); |
| 179 |
| 180 test.SetSize(.01f, .01f); |
| 181 EXPECT_FALSE(test.IsEmpty()); |
| 182 |
| 183 // Now just one dimension at a time. |
| 184 test.set_width(clearly_trivial); |
| 185 EXPECT_TRUE(test.IsEmpty()); |
| 186 |
| 187 test.set_width(massize_dimension); |
| 188 test.set_height(clearly_trivial); |
| 189 EXPECT_TRUE(test.IsEmpty()); |
| 190 |
| 191 test.set_width(clearly_trivial); |
| 192 test.set_height(massize_dimension); |
| 193 EXPECT_TRUE(test.IsEmpty()); |
| 194 |
| 195 test.set_width(2.f); |
| 196 EXPECT_FALSE(test.IsEmpty()); |
| 197 } |
| 198 |
| 199 // These are the ramifications of the decision to keep the recorded size |
| 200 // at zero for trivial sizes. |
| 201 TEST(SizeTest, ClampsToZero) { |
| 202 const float clearly_trivial = SizeF::kTrivial / 2.f; |
| 203 const float nearly_trivial = SizeF::kTrivial * 1.5f; |
| 204 |
| 205 SizeF test(clearly_trivial, 1.f); |
| 206 |
| 207 EXPECT_FLOAT_EQ(0.f, test.width()); |
| 208 EXPECT_FLOAT_EQ(1.f, test.height()); |
| 209 |
| 210 test.SetSize(.01f, clearly_trivial); |
| 211 |
| 212 EXPECT_FLOAT_EQ(.01f, test.width()); |
| 213 EXPECT_FLOAT_EQ(0.f, test.height()); |
| 214 |
| 215 test.SetSize(nearly_trivial, nearly_trivial); |
| 216 |
| 217 EXPECT_FLOAT_EQ(nearly_trivial, test.width()); |
| 218 EXPECT_FLOAT_EQ(nearly_trivial, test.height()); |
| 219 |
| 220 test.Scale(0.5f); |
| 221 |
| 222 EXPECT_FLOAT_EQ(0.f, test.width()); |
| 223 EXPECT_FLOAT_EQ(0.f, test.height()); |
| 224 |
| 225 test.SetSize(0.f, 0.f); |
| 226 test.Enlarge(clearly_trivial, clearly_trivial); |
| 227 test.Enlarge(clearly_trivial, clearly_trivial); |
| 228 test.Enlarge(clearly_trivial, clearly_trivial); |
| 229 |
| 230 EXPECT_EQ(SizeF(0.f, 0.f), test); |
| 231 } |
| 232 |
| 233 // These make sure the constructor and setter have the same effect on the |
| 234 // boundary case. This claims to know the boundary, but not which way it goes. |
| 235 TEST(SizeTest, ConsistentClamping) { |
| 236 SizeF resized; |
| 237 |
| 238 resized.SetSize(SizeF::kTrivial, 0.f); |
| 239 EXPECT_EQ(SizeF(SizeF::kTrivial, 0.f), resized); |
| 240 |
| 241 resized.SetSize(0.f, SizeF::kTrivial); |
| 242 EXPECT_EQ(SizeF(0.f, SizeF::kTrivial), resized); |
| 243 } |
| 244 |
| 245 // Let's make sure we don't unexpectedly grow the struct by adding constants. |
| 246 // Also, if some platform packs floats inefficiently, it would be worth noting. |
| 247 TEST(SizeTest, StaysSmall) { |
| 248 EXPECT_EQ(2 * sizeof(float), sizeof(SizeF)); |
| 249 } |
| 250 |
156 } // namespace gfx | 251 } // namespace gfx |
OLD | NEW |