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/skia_util.h" | 8 #include "ui/gfx/skia_util.h" |
9 | 9 |
10 namespace ui { | 10 namespace ui { |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 EXPECT_FALSE(r.SharesEdgeWith(just_left_no_edge)); | 337 EXPECT_FALSE(r.SharesEdgeWith(just_left_no_edge)); |
338 EXPECT_FALSE(r.SharesEdgeWith(just_right_no_edge)); | 338 EXPECT_FALSE(r.SharesEdgeWith(just_right_no_edge)); |
339 } | 339 } |
340 | 340 |
341 TEST(RectTest, SkRectToRect) { | 341 TEST(RectTest, SkRectToRect) { |
342 gfx::Rect src(10, 20, 30, 40); | 342 gfx::Rect src(10, 20, 30, 40); |
343 SkRect skrect = gfx::RectToSkRect(src); | 343 SkRect skrect = gfx::RectToSkRect(src); |
344 EXPECT_EQ(src, gfx::SkRectToRect(skrect)); | 344 EXPECT_EQ(src, gfx::SkRectToRect(skrect)); |
345 } | 345 } |
346 | 346 |
| 347 TEST(RectTest, ScaleRect) { |
| 348 static const struct { |
| 349 int x1; // rect 1 |
| 350 int y1; |
| 351 int w1; |
| 352 int h1; |
| 353 int x2; // rect 2 |
| 354 int y2; |
| 355 int w2; |
| 356 int h2; |
| 357 float scale; |
| 358 } tests[] = { |
| 359 { 0, 0, 0, 0, 0, 0, 0, 0, 1.0 }, |
| 360 { 0, 0, 0, 0, 0, 0, 0, 0, 2.0 }, |
| 361 { 0, 0, 4, 4, 0, 0, 2, 2, 0.5 }, |
| 362 { 1, 1, 4, 4, 0, 0, 3, 3, 0.5 }, |
| 363 { 53, 75, 100, 100, 53, 75, 100, 100, 1.0 }, |
| 364 { 53, 75, 100, 100, 106, 150, 200, 200, 2.0 }, |
| 365 { 53, 75, 100, 100, 26, 37, 51, 51, 0.5 }, |
| 366 { 53, 74, 100, 100, 26, 37, 51, 50, 0.5 }, |
| 367 { -1, -1, 100, 100, -1, -1, 51, 51, 0.5 }, |
| 368 { -2, -2, 100, 100, -1, -1, 50, 50, 0.5 }, |
| 369 { -101, -100, 50, 50, -51, -50, 26, 25, 0.5 } |
| 370 }; |
| 371 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 372 gfx::Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); |
| 373 gfx::Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); |
| 374 gfx::Rect orig(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); |
| 375 r1.ScaleBounds(tests[i].scale); |
| 376 EXPECT_TRUE(r1.Equals(r2)); |
| 377 r1.ScaleBounds(1.0 / tests[i].scale); |
| 378 EXPECT_TRUE(r1.x() <= orig.x()); |
| 379 EXPECT_TRUE(r1.y() <= orig.y()); |
| 380 EXPECT_TRUE(r1.x() + r1.width() >= orig.x() + orig.width()); |
| 381 EXPECT_TRUE(r1.y() + r1.height() >= orig.y() + orig.height()); |
| 382 } |
| 383 |
| 384 } |
| 385 |
347 #if defined(OS_WIN) | 386 #if defined(OS_WIN) |
348 TEST(RectTest, ConstructAndAssign) { | 387 TEST(RectTest, ConstructAndAssign) { |
349 const RECT rect_1 = { 0, 0, 10, 10 }; | 388 const RECT rect_1 = { 0, 0, 10, 10 }; |
350 const RECT rect_2 = { 0, 0, -10, -10 }; | 389 const RECT rect_2 = { 0, 0, -10, -10 }; |
351 gfx::Rect test1(rect_1); | 390 gfx::Rect test1(rect_1); |
352 gfx::Rect test2(rect_2); | 391 gfx::Rect test2(rect_2); |
353 } | 392 } |
354 #endif | 393 #endif |
355 | 394 |
356 } // namespace ui | 395 } // namespace ui |
OLD | NEW |