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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 Rect just_below_no_edge(2, 8, 3, 2); // too narrow | 387 Rect just_below_no_edge(2, 8, 3, 2); // too narrow |
388 Rect just_left_no_edge(0, 3, 2, 6); // too tall | 388 Rect just_left_no_edge(0, 3, 2, 6); // too tall |
389 Rect just_right_no_edge(6, 3, 2, 4); // too short | 389 Rect just_right_no_edge(6, 3, 2, 4); // too short |
390 | 390 |
391 EXPECT_FALSE(r.SharesEdgeWith(just_above_no_edge)); | 391 EXPECT_FALSE(r.SharesEdgeWith(just_above_no_edge)); |
392 EXPECT_FALSE(r.SharesEdgeWith(just_below_no_edge)); | 392 EXPECT_FALSE(r.SharesEdgeWith(just_below_no_edge)); |
393 EXPECT_FALSE(r.SharesEdgeWith(just_left_no_edge)); | 393 EXPECT_FALSE(r.SharesEdgeWith(just_left_no_edge)); |
394 EXPECT_FALSE(r.SharesEdgeWith(just_right_no_edge)); | 394 EXPECT_FALSE(r.SharesEdgeWith(just_right_no_edge)); |
395 } | 395 } |
396 | 396 |
397 TEST(RectTest, SkRectToRect) { | 397 TEST(RectTest, SkiaRectConversions) { |
398 Rect src(10, 20, 30, 40); | 398 Rect isrc(10, 20, 30, 40); |
399 SkRect skrect = RectToSkRect(src); | 399 RectF fsrc(10.5f, 20.5f, 30.5f, 40.5f); |
400 EXPECT_EQ(src, SkRectToRect(skrect)); | 400 |
| 401 SkIRect skirect = RectToSkIRect(isrc); |
| 402 EXPECT_EQ(isrc.ToString(), SkIRectToRect(skirect).ToString()); |
| 403 |
| 404 SkRect skrect = RectToSkRect(isrc); |
| 405 EXPECT_EQ(gfx::RectF(isrc).ToString(), SkRectToRectF(skrect).ToString()); |
| 406 |
| 407 skrect = RectFToSkRect(fsrc); |
| 408 EXPECT_EQ(fsrc.ToString(), SkRectToRectF(skrect).ToString()); |
401 } | 409 } |
402 | 410 |
403 // Similar to EXPECT_FLOAT_EQ, but lets NaN equal NaN | 411 // Similar to EXPECT_FLOAT_EQ, but lets NaN equal NaN |
404 #define EXPECT_FLOAT_AND_NAN_EQ(a, b) \ | 412 #define EXPECT_FLOAT_AND_NAN_EQ(a, b) \ |
405 { if (a == a || b == b) { EXPECT_FLOAT_EQ(a, b); } } | 413 { if (a == a || b == b) { EXPECT_FLOAT_EQ(a, b); } } |
406 | 414 |
407 TEST(RectTest, ScaleRect) { | 415 TEST(RectTest, ScaleRect) { |
408 static const struct Test { | 416 static const struct Test { |
409 int x1; // source | 417 int x1; // source |
410 int y1; | 418 int y1; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); | 549 Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); |
542 | 550 |
543 Rect enclosed = ToEnclosingRect(r1); | 551 Rect enclosed = ToEnclosingRect(r1); |
544 EXPECT_FLOAT_AND_NAN_EQ(r2.x(), enclosed.x()); | 552 EXPECT_FLOAT_AND_NAN_EQ(r2.x(), enclosed.x()); |
545 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), enclosed.y()); | 553 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), enclosed.y()); |
546 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), enclosed.width()); | 554 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), enclosed.width()); |
547 EXPECT_FLOAT_AND_NAN_EQ(r2.height(), enclosed.height()); | 555 EXPECT_FLOAT_AND_NAN_EQ(r2.height(), enclosed.height()); |
548 } | 556 } |
549 } | 557 } |
550 | 558 |
| 559 TEST(RectTest, ToNearestRect) { |
| 560 Rect rect; |
| 561 EXPECT_EQ(rect.ToString(), ToNearestRect(RectF(rect)).ToString()); |
| 562 |
| 563 rect = Rect(-1, -1, 3, 3); |
| 564 EXPECT_EQ(rect.ToString(), ToNearestRect(RectF(rect)).ToString()); |
| 565 |
| 566 RectF rectf(-1.00001f, -0.999999f, 3.0000001f, 2.999999f); |
| 567 EXPECT_EQ(rect.ToString(), ToNearestRect(rectf).ToString()); |
| 568 } |
| 569 |
551 TEST(RectTest, ToFlooredRect) { | 570 TEST(RectTest, ToFlooredRect) { |
552 static const struct Test { | 571 static const struct Test { |
553 float x1; // source | 572 float x1; // source |
554 float y1; | 573 float y1; |
555 float w1; | 574 float w1; |
556 float h1; | 575 float h1; |
557 int x2; // target | 576 int x2; // target |
558 int y2; | 577 int y2; |
559 int w2; | 578 int w2; |
560 int h2; | 579 int h2; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 (Vector2dF(1.1f, -1.1f) + f).ToString()); | 734 (Vector2dF(1.1f, -1.1f) + f).ToString()); |
716 f += Vector2dF(1.1f, -1.1f); | 735 f += Vector2dF(1.1f, -1.1f); |
717 EXPECT_EQ(RectF(2.2f, 1.1f, 3.3f, 4.4f).ToString(), f.ToString()); | 736 EXPECT_EQ(RectF(2.2f, 1.1f, 3.3f, 4.4f).ToString(), f.ToString()); |
718 EXPECT_EQ(RectF(1.1f, 2.2f, 3.3f, 4.4f).ToString(), | 737 EXPECT_EQ(RectF(1.1f, 2.2f, 3.3f, 4.4f).ToString(), |
719 (f - Vector2dF(1.1f, -1.1f)).ToString()); | 738 (f - Vector2dF(1.1f, -1.1f)).ToString()); |
720 f -= Vector2dF(1.1f, -1.1f); | 739 f -= Vector2dF(1.1f, -1.1f); |
721 EXPECT_EQ(RectF(1.1f, 2.2f, 3.3f, 4.4f).ToString(), f.ToString()); | 740 EXPECT_EQ(RectF(1.1f, 2.2f, 3.3f, 4.4f).ToString(), f.ToString()); |
722 } | 741 } |
723 | 742 |
724 } // namespace gfx | 743 } // namespace gfx |
OLD | NEW |