| OLD | NEW |
| 1 // Copyright (c) 2013 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 #include "ui/gfx/geometry/rect.h" | 6 #include "ui/gfx/geometry/rect.h" |
| 7 #include "ui/gfx/skia_util.h" | 7 #include "ui/gfx/skia_util.h" |
| 8 | 8 |
| 9 namespace gfx { | 9 namespace gfx { |
| 10 | 10 |
| 11 TEST(RectTest, SkiaRectConversions) { | 11 TEST(RectTest, SkiaRectConversions) { |
| 12 Rect isrc(10, 20, 30, 40); | 12 Rect isrc(10, 20, 30, 40); |
| 13 RectF fsrc(10.5f, 20.5f, 30.5f, 40.5f); | 13 RectF fsrc(10.5f, 20.5f, 30.5f, 40.5f); |
| 14 | 14 |
| 15 SkIRect skirect = RectToSkIRect(isrc); | 15 SkIRect skirect = RectToSkIRect(isrc); |
| 16 EXPECT_EQ(isrc.ToString(), SkIRectToRect(skirect).ToString()); | 16 EXPECT_EQ(isrc.ToString(), SkIRectToRect(skirect).ToString()); |
| 17 | 17 |
| 18 SkRect skrect = RectToSkRect(isrc); | 18 SkRect skrect = RectToSkRect(isrc); |
| 19 EXPECT_EQ(gfx::RectF(isrc).ToString(), SkRectToRectF(skrect).ToString()); | 19 EXPECT_EQ(gfx::RectF(isrc).ToString(), SkRectToRectF(skrect).ToString()); |
| 20 | 20 |
| 21 skrect = RectFToSkRect(fsrc); | 21 skrect = RectFToSkRect(fsrc); |
| 22 EXPECT_EQ(fsrc.ToString(), SkRectToRectF(skrect).ToString()); | 22 EXPECT_EQ(fsrc.ToString(), SkRectToRectF(skrect).ToString()); |
| 23 } | 23 } |
| 24 | 24 |
| 25 TEST(RectTest, SkIRectToRectClamping) { |
| 26 // This clamping only makes sense if SkIRect and gfx::Rect have the same size. |
| 27 // Otherwise, either other overflows can occur that we don't handle, or no |
| 28 // overflows can ocur. |
| 29 if (sizeof(int) != sizeof(int32_t)) |
| 30 return; |
| 31 using Limits = std::numeric_limits<int>; |
| 32 |
| 33 // right-left and bottom-top would overflow. |
| 34 // These should be mapped to max width/height, which is as close as gfx::Rect |
| 35 // can represent. |
| 36 EXPECT_EQ( |
| 37 gfx::Rect(Limits::min(), Limits::min(), Limits::max(), Limits::max()), |
| 38 SkIRectToRect(SkIRect::MakeLTRB(Limits::min(), Limits::min(), |
| 39 Limits::max(), Limits::max()))); |
| 40 |
| 41 // right-left and bottom-top would underflow. |
| 42 // These should be mapped to zero, like all negative values. |
| 43 EXPECT_EQ(gfx::Rect(Limits::max(), Limits::max(), 0, 0), |
| 44 SkIRectToRect(SkIRect::MakeLTRB(Limits::max(), Limits::max(), |
| 45 Limits::min(), Limits::min()))); |
| 46 } |
| 47 |
| 25 } // namespace gfx | 48 } // namespace gfx |
| OLD | NEW |