Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Unified Diff: ui/gfx/geometry/rect_unittest.cc

Issue 2744423002: Handle large rects better. (Closed)
Patch Set: Followup fixes Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/gfx/geometry/rect_unittest.cc
diff --git a/ui/gfx/geometry/rect_unittest.cc b/ui/gfx/geometry/rect_unittest.cc
index 29d6f2c8ce53f1c2752b29c18d757b532f414ac0..c4a8b346ee9792b68abae481b987ebf6d10dae36 100644
--- a/ui/gfx/geometry/rect_unittest.cc
+++ b/ui/gfx/geometry/rect_unittest.cc
@@ -425,6 +425,14 @@ TEST(RectTest, SharesEdgeWith) {
#define EXPECT_FLOAT_AND_NAN_EQ(a, b) \
{ if (a == a || b == b) { EXPECT_FLOAT_EQ(a, b); } }
+static const int dont_care = -451329;
+#define MAYBE_EXPECT_INT_EQ(a, b) \
+ { \
+ if (a != dont_care) { \
+ EXPECT_EQ(a, b); \
+ } \
+ }
+
TEST(RectTest, ScaleRect) {
static const struct Test {
int x1; // source
@@ -482,38 +490,28 @@ TEST(RectTest, ToEnclosedRect) {
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},
- {max_float, max_float, 2.0f, 2.0f, max_int, max_int, 0, 0},
- {0.0f, 0.0f, max_float, max_float, 0, 0, max_int, max_int},
- {20000.5f, 20000.5f, 0.5f, 0.5f, 20001, 20001, 0, 0},
- {static_cast<float>(min_int),
- static_cast<float>(min_int),
- max_int * 2.f,
- max_int * 2.f,
- min_int,
- min_int,
- max_int,
- max_int},
- {static_cast<float>(max_int),
- static_cast<float>(max_int),
- static_cast<float>(max_int),
- static_cast<float>(max_int),
- max_int,
- max_int,
- 0,
- 0}};
+ } 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},
+ {max_float, max_float, 2.0f, 2.0f, max_int, max_int, 0, 0},
+ {0.0f, 0.0f, max_float, max_float, 0, 0, max_int, max_int},
+ {20000.5f, 20000.5f, 0.5f, 0.5f, 20001, 20001, 0, 0},
+ {static_cast<float>(min_int), static_cast<float>(min_int), max_int * 2.f,
Peter Mayo 2017/03/17 00:30:48 ICK - git cl upload insisted this should be reform
+ max_int * 2.f, dont_care, dont_care, max_int, max_int},
+ {static_cast<float>(max_int), static_cast<float>(max_int),
+ static_cast<float>(max_int), static_cast<float>(max_int), max_int,
+ max_int, 0, 0}};
for (size_t i = 0; i < arraysize(tests); ++i) {
RectF r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1);
Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2);
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());
+ MAYBE_EXPECT_INT_EQ(r2.x(), enclosed.x());
+ MAYBE_EXPECT_INT_EQ(r2.y(), enclosed.y());
+ MAYBE_EXPECT_INT_EQ(r2.width(), enclosed.width());
+ MAYBE_EXPECT_INT_EQ(r2.height(), enclosed.height());
}
}
@@ -533,13 +531,14 @@ TEST(RectTest, ToEnclosingRect) {
} tests[] = {
{0.0f, 0.0f, 0.0f, 0.0f, 0, 0, 0, 0},
{5.5f, 5.5f, 0.0f, 0.0f, 5, 5, 0, 0},
+ {3.5f, 2.5f, 0.01f, 0.01f, 3, 2, 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},
{max_float, max_float, 2.0f, 2.0f, max_int, max_int, 0, 0},
{0.0f, 0.0f, max_float, max_float, 0, 0, max_int, max_int},
{20000.5f, 20000.5f, 0.5f, 0.5f, 20000, 20000, 1, 1},
{static_cast<float>(min_int), static_cast<float>(min_int), max_int * 2.f,
- max_int * 2.f, min_int, min_int, max_int, max_int},
+ max_int * 2.f, dont_care, dont_care, max_int, max_int},
{static_cast<float>(max_int), static_cast<float>(max_int),
static_cast<float>(max_int), static_cast<float>(max_int), max_int,
max_int, 0, 0},
@@ -550,10 +549,10 @@ TEST(RectTest, ToEnclosingRect) {
Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2);
Rect enclosed = ToEnclosingRect(r1);
- EXPECT_EQ(r2.x(), enclosed.x());
- EXPECT_EQ(r2.y(), enclosed.y());
- EXPECT_EQ(r2.width(), enclosed.width());
- EXPECT_EQ(r2.height(), enclosed.height());
+ MAYBE_EXPECT_INT_EQ(r2.x(), enclosed.x());
+ MAYBE_EXPECT_INT_EQ(r2.y(), enclosed.y());
+ MAYBE_EXPECT_INT_EQ(r2.width(), enclosed.width());
+ MAYBE_EXPECT_INT_EQ(r2.height(), enclosed.height());
}
}
@@ -1046,13 +1045,14 @@ TEST(RectTest, IntegerOverflow) {
}
// Unioning a left=minint rect with a right=maxint rect.
- // Width is always clamped before adjusting position, so this
- // should taking the min left/top and then finding the max width.
+ // We can't represent both ends of the spectrum in the same rect.
+ // Make sure we keep the most useful area.
{
+ int part_limit = min_limit / 3;
Rect left_minint(min_limit, min_limit, 1, 1);
Rect right_maxint(limit - 1, limit - 1, limit, limit);
- Rect expected(min_limit, min_limit, limit, limit);
- EXPECT_EQ(UnionRects(left_minint, right_maxint), expected);
+ Rect expected(part_limit, part_limit, 2 * part_limit, 2 * part_limit);
+ EXPECT_TRUE(UnionRects(left_minint, right_maxint).Contains(expected));
}
}

Powered by Google App Engine
This is Rietveld 408576698