OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <limits> |
| 6 |
5 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
7 #include "ui/gfx/rect.h" | 9 #include "ui/gfx/geometry/rect.h" |
8 #include "ui/gfx/rect_conversions.h" | 10 #include "ui/gfx/geometry/rect_conversions.h" |
9 #include "ui/gfx/skia_util.h" | |
10 | 11 |
11 #include <limits> | 12 #if defined(OS_WIN) |
| 13 #include <windows.h> |
| 14 #endif |
12 | 15 |
13 namespace gfx { | 16 namespace gfx { |
14 | 17 |
15 TEST(RectTest, Contains) { | 18 TEST(RectTest, Contains) { |
16 static const struct ContainsCase { | 19 static const struct ContainsCase { |
17 int rect_x; | 20 int rect_x; |
18 int rect_y; | 21 int rect_y; |
19 int rect_width; | 22 int rect_width; |
20 int rect_height; | 23 int rect_height; |
21 int point_x; | 24 int point_x; |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 Rect just_below_no_edge(2, 8, 3, 2); // too narrow | 410 Rect just_below_no_edge(2, 8, 3, 2); // too narrow |
408 Rect just_left_no_edge(0, 3, 2, 6); // too tall | 411 Rect just_left_no_edge(0, 3, 2, 6); // too tall |
409 Rect just_right_no_edge(6, 3, 2, 4); // too short | 412 Rect just_right_no_edge(6, 3, 2, 4); // too short |
410 | 413 |
411 EXPECT_FALSE(r.SharesEdgeWith(just_above_no_edge)); | 414 EXPECT_FALSE(r.SharesEdgeWith(just_above_no_edge)); |
412 EXPECT_FALSE(r.SharesEdgeWith(just_below_no_edge)); | 415 EXPECT_FALSE(r.SharesEdgeWith(just_below_no_edge)); |
413 EXPECT_FALSE(r.SharesEdgeWith(just_left_no_edge)); | 416 EXPECT_FALSE(r.SharesEdgeWith(just_left_no_edge)); |
414 EXPECT_FALSE(r.SharesEdgeWith(just_right_no_edge)); | 417 EXPECT_FALSE(r.SharesEdgeWith(just_right_no_edge)); |
415 } | 418 } |
416 | 419 |
417 TEST(RectTest, SkiaRectConversions) { | |
418 Rect isrc(10, 20, 30, 40); | |
419 RectF fsrc(10.5f, 20.5f, 30.5f, 40.5f); | |
420 | |
421 SkIRect skirect = RectToSkIRect(isrc); | |
422 EXPECT_EQ(isrc.ToString(), SkIRectToRect(skirect).ToString()); | |
423 | |
424 SkRect skrect = RectToSkRect(isrc); | |
425 EXPECT_EQ(gfx::RectF(isrc).ToString(), SkRectToRectF(skrect).ToString()); | |
426 | |
427 skrect = RectFToSkRect(fsrc); | |
428 EXPECT_EQ(fsrc.ToString(), SkRectToRectF(skrect).ToString()); | |
429 } | |
430 | |
431 // Similar to EXPECT_FLOAT_EQ, but lets NaN equal NaN | 420 // Similar to EXPECT_FLOAT_EQ, but lets NaN equal NaN |
432 #define EXPECT_FLOAT_AND_NAN_EQ(a, b) \ | 421 #define EXPECT_FLOAT_AND_NAN_EQ(a, b) \ |
433 { if (a == a || b == b) { EXPECT_FLOAT_EQ(a, b); } } | 422 { if (a == a || b == b) { EXPECT_FLOAT_EQ(a, b); } } |
434 | 423 |
435 TEST(RectTest, ScaleRect) { | 424 TEST(RectTest, ScaleRect) { |
436 static const struct Test { | 425 static const struct Test { |
437 int x1; // source | 426 int x1; // source |
438 int y1; | 427 int y1; |
439 int w1; | 428 int w1; |
440 int h1; | 429 int h1; |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
927 0.0f, f.ManhattanInternalDistance(gfx::RectF(-1.0f, 0.0f, 1.1f, 1.0f))); | 916 0.0f, f.ManhattanInternalDistance(gfx::RectF(-1.0f, 0.0f, 1.1f, 1.0f))); |
928 EXPECT_FLOAT_EQ( | 917 EXPECT_FLOAT_EQ( |
929 0.1f + kEpsilon, | 918 0.1f + kEpsilon, |
930 f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.4f, 1.0f))); | 919 f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.4f, 1.0f))); |
931 EXPECT_FLOAT_EQ( | 920 EXPECT_FLOAT_EQ( |
932 kEpsilon, | 921 kEpsilon, |
933 f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.5f, 1.0f))); | 922 f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.5f, 1.0f))); |
934 } | 923 } |
935 | 924 |
936 } // namespace gfx | 925 } // namespace gfx |
OLD | NEW |