OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
7 #include "ui/gfx/rect.h" | 7 #include "ui/gfx/rect.h" |
8 #include "ui/gfx/rect_conversions.h" | 8 #include "ui/gfx/rect_conversions.h" |
9 #include "ui/gfx/skia_util.h" | 9 #include "ui/gfx/skia_util.h" |
10 | 10 |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 gfx::Rect(10, 10, 0, 10).SplitVertically(&left_half, &right_half); | 300 gfx::Rect(10, 10, 0, 10).SplitVertically(&left_half, &right_half); |
301 EXPECT_TRUE(left_half.Equals(gfx::Rect(10, 10, 0, 10))); | 301 EXPECT_TRUE(left_half.Equals(gfx::Rect(10, 10, 0, 10))); |
302 EXPECT_TRUE(right_half.Equals(gfx::Rect(10, 10, 0, 10))); | 302 EXPECT_TRUE(right_half.Equals(gfx::Rect(10, 10, 0, 10))); |
303 | 303 |
304 // Splitting a rectangle of odd width. | 304 // Splitting a rectangle of odd width. |
305 gfx::Rect(10, 10, 5, 10).SplitVertically(&left_half, &right_half); | 305 gfx::Rect(10, 10, 5, 10).SplitVertically(&left_half, &right_half); |
306 EXPECT_TRUE(left_half.Equals(gfx::Rect(10, 10, 2, 10))); | 306 EXPECT_TRUE(left_half.Equals(gfx::Rect(10, 10, 2, 10))); |
307 EXPECT_TRUE(right_half.Equals(gfx::Rect(12, 10, 3, 10))); | 307 EXPECT_TRUE(right_half.Equals(gfx::Rect(12, 10, 3, 10))); |
308 } | 308 } |
309 | 309 |
310 TEST(RectTest, CenterPoint) { | |
311 gfx::Point center; | |
312 | |
313 // When origin is (0, 0). | |
314 center = gfx::Rect(0, 0, 20, 20).CenterPoint(); | |
315 EXPECT_TRUE(center == gfx::Point(10, 10)); | |
sky
2012/10/09 15:55:50
Use EXPECT_EQ("10,10", center) for these. Doing so
| |
316 | |
317 // When origin is even. | |
318 center = gfx::Rect(10, 10, 20, 20).CenterPoint(); | |
319 EXPECT_TRUE(center == gfx::Point(20, 20)); | |
320 | |
321 // When origin is odd. | |
322 center = gfx::Rect(11, 11, 20, 20).CenterPoint(); | |
323 EXPECT_TRUE(center == gfx::Point(21, 21)); | |
324 | |
325 // When 0 width or height. | |
326 center = gfx::Rect(10, 10, 0, 20).CenterPoint(); | |
327 EXPECT_TRUE(center == gfx::Point(10, 20)); | |
328 center = gfx::Rect(10, 10, 20, 0).CenterPoint(); | |
329 EXPECT_TRUE(center == gfx::Point(20, 10)); | |
330 | |
331 // When an odd size. | |
332 center = gfx::Rect(10, 10, 21, 21).CenterPoint(); | |
333 EXPECT_TRUE(center == gfx::Point(20, 20)); | |
334 | |
335 // When an odd size and position. | |
336 center = gfx::Rect(11, 11, 21, 21).CenterPoint(); | |
337 EXPECT_TRUE(center == gfx::Point(21, 21)); | |
338 } | |
339 | |
340 TEST(RectTest, CenterPointF) { | |
341 gfx::PointF center; | |
342 | |
343 // When origin is (0, 0). | |
344 center = gfx::RectF(0, 0, 20, 20).CenterPoint(); | |
345 EXPECT_TRUE(center == gfx::PointF(10, 10)); | |
346 | |
347 // When origin is even. | |
348 center = gfx::RectF(10, 10, 20, 20).CenterPoint(); | |
349 EXPECT_TRUE(center == gfx::PointF(20, 20)); | |
350 | |
351 // When origin is odd. | |
352 center = gfx::RectF(11, 11, 20, 20).CenterPoint(); | |
353 EXPECT_TRUE(center == gfx::PointF(21, 21)); | |
354 | |
355 // When 0 width or height. | |
356 center = gfx::RectF(10, 10, 0, 20).CenterPoint(); | |
357 EXPECT_TRUE(center == gfx::PointF(10, 20)); | |
358 center = gfx::RectF(10, 10, 20, 0).CenterPoint(); | |
359 EXPECT_TRUE(center == gfx::PointF(20, 10)); | |
360 | |
361 // When an odd size. | |
362 center = gfx::RectF(10, 10, 21, 21).CenterPoint(); | |
363 EXPECT_TRUE(center == gfx::PointF(20.5f, 20.5f)); | |
364 | |
365 // When an odd size and position. | |
366 center = gfx::RectF(11, 11, 21, 21).CenterPoint(); | |
367 EXPECT_TRUE(center == gfx::PointF(21.5f, 21.5f)); | |
368 } | |
369 | |
310 TEST(RectTest, SharesEdgeWith) { | 370 TEST(RectTest, SharesEdgeWith) { |
311 gfx::Rect r(2, 3, 4, 5); | 371 gfx::Rect r(2, 3, 4, 5); |
312 | 372 |
313 // Must be non-overlapping | 373 // Must be non-overlapping |
314 EXPECT_FALSE(r.SharesEdgeWith(r)); | 374 EXPECT_FALSE(r.SharesEdgeWith(r)); |
315 | 375 |
316 gfx::Rect just_above(2, 1, 4, 2); | 376 gfx::Rect just_above(2, 1, 4, 2); |
317 gfx::Rect just_below(2, 8, 4, 2); | 377 gfx::Rect just_below(2, 8, 4, 2); |
318 gfx::Rect just_left(0, 3, 2, 5); | 378 gfx::Rect just_left(0, 3, 2, 5); |
319 gfx::Rect just_right(6, 3, 2, 5); | 379 gfx::Rect just_right(6, 3, 2, 5); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
502 #if defined(OS_WIN) | 562 #if defined(OS_WIN) |
503 TEST(RectTest, ConstructAndAssign) { | 563 TEST(RectTest, ConstructAndAssign) { |
504 const RECT rect_1 = { 0, 0, 10, 10 }; | 564 const RECT rect_1 = { 0, 0, 10, 10 }; |
505 const RECT rect_2 = { 0, 0, -10, -10 }; | 565 const RECT rect_2 = { 0, 0, -10, -10 }; |
506 gfx::Rect test1(rect_1); | 566 gfx::Rect test1(rect_1); |
507 gfx::Rect test2(rect_2); | 567 gfx::Rect test2(rect_2); |
508 } | 568 } |
509 #endif | 569 #endif |
510 | 570 |
511 } // namespace ui | 571 } // namespace ui |
OLD | NEW |