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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/gfx/geometry/point.h" | 9 #include "ui/gfx/geometry/point.h" |
10 #include "ui/gfx/geometry/point_conversions.h" | 10 #include "ui/gfx/geometry/point_conversions.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 a.SetToMin(PointF(8.5f, 10.5f)); | 153 a.SetToMin(PointF(8.5f, 10.5f)); |
154 EXPECT_EQ(PointF(8.5f, 10.5f).ToString(), a.ToString()); | 154 EXPECT_EQ(PointF(8.5f, 10.5f).ToString(), a.ToString()); |
155 a.SetToMin(PointF(11.5f, 9.5f)); | 155 a.SetToMin(PointF(11.5f, 9.5f)); |
156 EXPECT_EQ(PointF(8.5f, 9.5f).ToString(), a.ToString()); | 156 EXPECT_EQ(PointF(8.5f, 9.5f).ToString(), a.ToString()); |
157 a.SetToMin(PointF(7.5f, 11.5f)); | 157 a.SetToMin(PointF(7.5f, 11.5f)); |
158 EXPECT_EQ(PointF(7.5f, 9.5f).ToString(), a.ToString()); | 158 EXPECT_EQ(PointF(7.5f, 9.5f).ToString(), a.ToString()); |
159 a.SetToMin(PointF(3.5f, 5.5f)); | 159 a.SetToMin(PointF(3.5f, 5.5f)); |
160 EXPECT_EQ(PointF(3.5f, 5.5f).ToString(), a.ToString()); | 160 EXPECT_EQ(PointF(3.5f, 5.5f).ToString(), a.ToString()); |
161 } | 161 } |
162 | 162 |
| 163 TEST(PointTest, Offset) { |
| 164 Point test(3, 4); |
| 165 test.Offset(5, -8); |
| 166 EXPECT_EQ(test, Point(8, -4)); |
| 167 } |
| 168 |
| 169 TEST(PointTest, VectorMath) { |
| 170 Point test = Point(3, 4); |
| 171 test += Vector2d(5, -8); |
| 172 EXPECT_EQ(test, Point(8, -4)); |
| 173 |
| 174 Point test2 = Point(3, 4); |
| 175 test2 -= Vector2d(5, -8); |
| 176 EXPECT_EQ(test2, Point(-2, 12)); |
| 177 } |
| 178 |
| 179 TEST(PointTest, IntegerOverflow) { |
| 180 int int_max = std::numeric_limits<int>::max(); |
| 181 int int_min = std::numeric_limits<int>::min(); |
| 182 |
| 183 Point max_point(int_max, int_max); |
| 184 Point min_point(int_min, int_min); |
| 185 Point test; |
| 186 |
| 187 test = Point(); |
| 188 test.Offset(int_max, int_max); |
| 189 EXPECT_EQ(test, max_point); |
| 190 |
| 191 test = Point(); |
| 192 test.Offset(int_min, int_min); |
| 193 EXPECT_EQ(test, min_point); |
| 194 |
| 195 test = Point(10, 20); |
| 196 test.Offset(int_max, int_max); |
| 197 EXPECT_EQ(test, max_point); |
| 198 |
| 199 test = Point(-10, -20); |
| 200 test.Offset(int_min, int_min); |
| 201 EXPECT_EQ(test, min_point); |
| 202 |
| 203 test = Point(); |
| 204 test += Vector2d(int_max, int_max); |
| 205 EXPECT_EQ(test, max_point); |
| 206 |
| 207 test = Point(); |
| 208 test += Vector2d(int_min, int_min); |
| 209 EXPECT_EQ(test, min_point); |
| 210 |
| 211 test = Point(10, 20); |
| 212 test += Vector2d(int_max, int_max); |
| 213 EXPECT_EQ(test, max_point); |
| 214 |
| 215 test = Point(-10, -20); |
| 216 test += Vector2d(int_min, int_min); |
| 217 EXPECT_EQ(test, min_point); |
| 218 |
| 219 test = Point(); |
| 220 test -= Vector2d(int_max, int_max); |
| 221 EXPECT_EQ(test, Point(-int_max, -int_max)); |
| 222 |
| 223 test = Point(); |
| 224 test -= Vector2d(int_min, int_min); |
| 225 EXPECT_EQ(test, max_point); |
| 226 |
| 227 test = Point(10, 20); |
| 228 test -= Vector2d(int_min, int_min); |
| 229 EXPECT_EQ(test, max_point); |
| 230 |
| 231 test = Point(-10, -20); |
| 232 test -= Vector2d(int_max, int_max); |
| 233 EXPECT_EQ(test, min_point); |
| 234 } |
| 235 |
163 } // namespace gfx | 236 } // namespace gfx |
OLD | NEW |