| Index: ui/gfx/rect_unittest.cc
|
| diff --git a/ui/gfx/rect_unittest.cc b/ui/gfx/rect_unittest.cc
|
| index 4eefdd69f5622da8e6a058cfafd21e77eb37efd4..abc94c1bdd8f68edf50df33bc97871bba7847af5 100644
|
| --- a/ui/gfx/rect_unittest.cc
|
| +++ b/ui/gfx/rect_unittest.cc
|
| @@ -5,8 +5,11 @@
|
| #include "base/basictypes.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "ui/gfx/rect.h"
|
| +#include "ui/gfx/rect_conversions.h"
|
| #include "ui/gfx/skia_util.h"
|
|
|
| +#include <limits>
|
| +
|
| namespace ui {
|
|
|
| TEST(RectTest, Contains) {
|
| @@ -344,6 +347,158 @@ TEST(RectTest, SkRectToRect) {
|
| EXPECT_EQ(src, gfx::SkRectToRect(skrect));
|
| }
|
|
|
| +// Similar to EXPECT_FLOAT_EQ, but lets NaN equal NaN
|
| +#define EXPECT_FLOAT_AND_NAN_EQ(a, b) \
|
| + { if (a == a || b == b) { EXPECT_FLOAT_EQ(a, b); } }
|
| +
|
| +
|
| +TEST(RectTest, ScaleRect) {
|
| + static const struct Test {
|
| + int x1; // source
|
| + int y1;
|
| + int w1;
|
| + int h1;
|
| + float scale;
|
| + float x2; // target
|
| + float y2;
|
| + float w2;
|
| + float h2;
|
| + } tests[] = {
|
| + { 3, 3, 3, 3,
|
| + 1.5f,
|
| + 4.5f, 4.5f, 4.5f, 4.5f },
|
| + { 3, 3, 3, 3,
|
| + 0.0f,
|
| + 0.0f, 0.0f, 0.0f, 0.0f },
|
| + { 3, 3, 3, 3,
|
| + std::numeric_limits<float>::quiet_NaN(),
|
| + std::numeric_limits<float>::quiet_NaN(),
|
| + std::numeric_limits<float>::quiet_NaN(),
|
| + std::numeric_limits<float>::quiet_NaN(),
|
| + std::numeric_limits<float>::quiet_NaN() },
|
| + { 3, 3, 3, 3,
|
| + std::numeric_limits<float>::max(),
|
| + std::numeric_limits<float>::max(),
|
| + std::numeric_limits<float>::max(),
|
| + std::numeric_limits<float>::max(),
|
| + std::numeric_limits<float>::max() },
|
| + { 3, 3, 3, 3,
|
| + -1.0f,
|
| + -3.0f, -3.0f, 0.0f, 0.0f }
|
| + };
|
| +
|
| + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
|
| + gfx::Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1);
|
| + gfx::RectF r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2);
|
| +
|
| + gfx::RectF scaled = r1.Scale(tests[i].scale);
|
| + EXPECT_FLOAT_AND_NAN_EQ(r2.x(), scaled.x());
|
| + EXPECT_FLOAT_AND_NAN_EQ(r2.y(), scaled.y());
|
| + EXPECT_FLOAT_AND_NAN_EQ(r2.width(), scaled.width());
|
| + EXPECT_FLOAT_AND_NAN_EQ(r2.height(), scaled.height());
|
| + }
|
| +}
|
| +
|
| +TEST(RectTest, ToEnclosedRect) {
|
| + static const struct Test {
|
| + float x1; // source
|
| + float y1;
|
| + float w1;
|
| + float h1;
|
| + int x2; // target
|
| + int y2;
|
| + int w2;
|
| + int h2;
|
| + } tests [] = {
|
| + { 0.0f, 0.0f, 0.0f, 0.0f,
|
| + 0, 0, 0, 0 },
|
| + { -1.5f, -1.5f, 3.0f, 3.0f,
|
| + -1, -1, 2, 2 },
|
| + { -1.5f, -1.5f, 3.5f, 3.5f,
|
| + -1, -1, 3, 3 },
|
| + { std::numeric_limits<float>::max(),
|
| + std::numeric_limits<float>::max(),
|
| + 2.0f, 2.0f,
|
| + std::numeric_limits<int>::max(),
|
| + std::numeric_limits<int>::max(),
|
| + 0, 0 },
|
| + { 0.0f, 0.0f,
|
| + std::numeric_limits<float>::max(),
|
| + std::numeric_limits<float>::max(),
|
| + 0, 0,
|
| + std::numeric_limits<int>::max(),
|
| + std::numeric_limits<int>::max() },
|
| + { 20000.5f, 20000.5f, 0.5f, 0.5f,
|
| + 20001, 20001, 0, 0 },
|
| + { std::numeric_limits<float>::quiet_NaN(),
|
| + std::numeric_limits<float>::quiet_NaN(),
|
| + std::numeric_limits<float>::quiet_NaN(),
|
| + std::numeric_limits<float>::quiet_NaN(),
|
| + 0, 0, 0, 0 }
|
| + };
|
| +
|
| + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
|
| + gfx::RectF r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1);
|
| + gfx::Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2);
|
| +
|
| + gfx::Rect enclosed = ToEnclosedRect(r1);
|
| + EXPECT_FLOAT_AND_NAN_EQ(r2.x(), enclosed.x());
|
| + EXPECT_FLOAT_AND_NAN_EQ(r2.y(), enclosed.y());
|
| + EXPECT_FLOAT_AND_NAN_EQ(r2.width(), enclosed.width());
|
| + EXPECT_FLOAT_AND_NAN_EQ(r2.height(), enclosed.height());
|
| + }
|
| +}
|
| +
|
| +TEST(RectTest, ToEnclosingRect) {
|
| + static const struct Test {
|
| + float x1; // source
|
| + float y1;
|
| + float w1;
|
| + float h1;
|
| + int x2; // target
|
| + int y2;
|
| + int w2;
|
| + int h2;
|
| + } tests [] = {
|
| + { 0.0f, 0.0f, 0.0f, 0.0f,
|
| + 0, 0, 0, 0 },
|
| + { -1.5f, -1.5f, 3.0f, 3.0f,
|
| + -2, -2, 4, 4 },
|
| + { -1.5f, -1.5f, 3.5f, 3.5f,
|
| + -2, -2, 4, 4 },
|
| + { std::numeric_limits<float>::max(),
|
| + std::numeric_limits<float>::max(),
|
| + 2.0f, 2.0f,
|
| + std::numeric_limits<int>::max(),
|
| + std::numeric_limits<int>::max(),
|
| + 0, 0 },
|
| + { 0.0f, 0.0f,
|
| + std::numeric_limits<float>::max(),
|
| + std::numeric_limits<float>::max(),
|
| + 0, 0,
|
| + std::numeric_limits<int>::max(),
|
| + std::numeric_limits<int>::max() },
|
| + { 20000.5f, 20000.5f, 0.5f, 0.5f,
|
| + 20000, 20000, 1, 1 },
|
| + { std::numeric_limits<float>::quiet_NaN(),
|
| + std::numeric_limits<float>::quiet_NaN(),
|
| + std::numeric_limits<float>::quiet_NaN(),
|
| + std::numeric_limits<float>::quiet_NaN(),
|
| + 0, 0, 0, 0 }
|
| + };
|
| +
|
| + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
|
| + gfx::RectF r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1);
|
| + gfx::Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2);
|
| +
|
| + gfx::Rect enclosed = ToEnclosingRect(r1);
|
| + EXPECT_FLOAT_AND_NAN_EQ(r2.x(), enclosed.x());
|
| + EXPECT_FLOAT_AND_NAN_EQ(r2.y(), enclosed.y());
|
| + EXPECT_FLOAT_AND_NAN_EQ(r2.width(), enclosed.width());
|
| + EXPECT_FLOAT_AND_NAN_EQ(r2.height(), enclosed.height());
|
| + }
|
| +}
|
| +
|
| #if defined(OS_WIN)
|
| TEST(RectTest, ConstructAndAssign) {
|
| const RECT rect_1 = { 0, 0, 10, 10 };
|
|
|