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

Side by Side Diff: ui/gfx/rect_unittest.cc

Issue 11235017: Revert to old rect conversion behavior (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 2 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 unified diff | Download patch | Annotate | Revision Log
« ui/gfx/rect_conversions.h ('K') | « ui/gfx/rect_conversions.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 gfx::Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); 551 gfx::Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2);
552 552
553 gfx::Rect enclosed = ToEnclosingRect(r1); 553 gfx::Rect enclosed = ToEnclosingRect(r1);
554 EXPECT_FLOAT_AND_NAN_EQ(r2.x(), enclosed.x()); 554 EXPECT_FLOAT_AND_NAN_EQ(r2.x(), enclosed.x());
555 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), enclosed.y()); 555 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), enclosed.y());
556 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), enclosed.width()); 556 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), enclosed.width());
557 EXPECT_FLOAT_AND_NAN_EQ(r2.height(), enclosed.height()); 557 EXPECT_FLOAT_AND_NAN_EQ(r2.height(), enclosed.height());
558 } 558 }
559 } 559 }
560 560
561 TEST(RectTest, ToFlooredRect) {
562 static const struct Test {
563 float x1; // source
564 float y1;
565 float w1;
566 float h1;
567 int x2; // target
568 int y2;
569 int w2;
570 int h2;
571 } tests [] = {
572 { 0.0f, 0.0f, 0.0f, 0.0f,
573 0, 0, 0, 0 },
574 { -1.5f, -1.5f, 3.0f, 3.0f,
575 -2, -2, 3, 3 },
576 { -1.5f, -1.5f, 3.5f, 3.5f,
577 -2, -2, 3, 3 },
578 { 20000.5f, 20000.5f, 0.5f, 0.5f,
579 20000, 20000, 0, 0 },
580 };
581
582 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
583 gfx::RectF r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1);
584 gfx::Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2);
585
586 gfx::Rect floored = ToFlooredRectDeprecated(r1);
587 EXPECT_FLOAT_EQ(r2.x(), floored.x());
588 EXPECT_FLOAT_EQ(r2.y(), floored.y());
589 EXPECT_FLOAT_EQ(r2.width(), floored.width());
590 EXPECT_FLOAT_EQ(r2.height(), floored.height());
591 }
592 }
593
561 #if defined(OS_WIN) 594 #if defined(OS_WIN)
562 TEST(RectTest, ConstructAndAssign) { 595 TEST(RectTest, ConstructAndAssign) {
563 const RECT rect_1 = { 0, 0, 10, 10 }; 596 const RECT rect_1 = { 0, 0, 10, 10 };
564 const RECT rect_2 = { 0, 0, -10, -10 }; 597 const RECT rect_2 = { 0, 0, -10, -10 };
565 gfx::Rect test1(rect_1); 598 gfx::Rect test1(rect_1);
566 gfx::Rect test2(rect_2); 599 gfx::Rect test2(rect_2);
567 } 600 }
568 #endif 601 #endif
569 602
570 TEST(RectTest, ToRectF) { 603 TEST(RectTest, ToRectF) {
571 // Check that implicit conversion from integer to float compiles. 604 // Check that implicit conversion from integer to float compiles.
572 gfx::Rect a(10, 20, 30, 40); 605 gfx::Rect a(10, 20, 30, 40);
573 gfx::RectF b(10, 20, 30, 40); 606 gfx::RectF b(10, 20, 30, 40);
574 607
575 gfx::RectF intersect = b.Intersect(a); 608 gfx::RectF intersect = b.Intersect(a);
576 EXPECT_EQ(b.ToString(), intersect.ToString()); 609 EXPECT_EQ(b.ToString(), intersect.ToString());
577 610
578 EXPECT_EQ(a, b); 611 EXPECT_EQ(a, b);
579 EXPECT_EQ(b, a); 612 EXPECT_EQ(b, a);
580 } 613 }
581 614
582 } // namespace ui 615 } // namespace ui
OLDNEW
« ui/gfx/rect_conversions.h ('K') | « ui/gfx/rect_conversions.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698