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

Unified Diff: tests/RoundRectTest.cpp

Issue 951323004: Fix radii scaling bug in SkRRect::setNinePatch (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « src/core/SkRRect.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/RoundRectTest.cpp
diff --git a/tests/RoundRectTest.cpp b/tests/RoundRectTest.cpp
index cff3e8f35ad5bc498390c2ddd992f97db2314549..9920d1013ba81eb69f56f42b03fc67ad84d5ccf0 100644
--- a/tests/RoundRectTest.cpp
+++ b/tests/RoundRectTest.cpp
@@ -54,6 +54,32 @@ static void test_inset(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, rr2.isRect());
}
+
+static void test_9patch_rrect(skiatest::Reporter* reporter,
+ const SkRect& rect,
+ SkScalar l, SkScalar t, SkScalar r, SkScalar b,
+ bool checkRadii) {
+ SkRRect rr;
+ rr.setNinePatch(rect, l, t, r, b);
+
+ REPORTER_ASSERT(reporter, SkRRect::kNinePatch_Type == rr.type());
+ REPORTER_ASSERT(reporter, rr.rect() == rect);
+
+ if (checkRadii) {
+ // This test doesn't hold if the radii will be rescaled by SkRRect
+ SkRect ninePatchRadii = { l, t, r, b };
+ SkPoint rquad[4];
+ ninePatchRadii.toQuad(rquad);
+ for (int i = 0; i < 4; ++i) {
+ REPORTER_ASSERT(reporter, rquad[i] == rr.radii((SkRRect::Corner) i));
+ }
+ }
+ SkRRect rr2; // construct the same RR using the most general set function
+ SkVector radii[4] = { { l, t }, { r, t }, { r, b }, { l, b } };
+ rr2.setRectRadii(rect, radii);
+ REPORTER_ASSERT(reporter, rr2 == rr && rr2.getType() == rr.getType());
+}
+
// Test out the basic API entry points
static void test_round_rect_basic(skiatest::Reporter* reporter) {
// Test out initialization methods
@@ -130,24 +156,17 @@ static void test_round_rect_basic(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, rr3_3 == rr3 && rr3_3.getType() == rr3.getType());
//----
- SkRect ninePatchRadii = { 10, 9, 8, 7 };
-
- SkRRect rr4;
- rr4.setNinePatch(rect, ninePatchRadii.fLeft, ninePatchRadii.fTop, ninePatchRadii.fRight,
- ninePatchRadii.fBottom);
+ test_9patch_rrect(reporter, rect, 10, 9, 8, 7, true);
- REPORTER_ASSERT(reporter, SkRRect::kNinePatch_Type == rr4.type());
- REPORTER_ASSERT(reporter, rr4.rect() == rect);
+ {
+ // Test out the rrect from skia:3466
+ SkRect rect2 = SkRect::MakeLTRB(0.358211994f, 0.755430222f, 0.872866154f, 0.806214333f);
- SkPoint rquad[4];
- ninePatchRadii.toQuad(rquad);
- for (int i = 0; i < 4; ++i) {
- REPORTER_ASSERT(reporter, rquad[i] == rr4.radii((SkRRect::Corner) i));
+ test_9patch_rrect(reporter,
+ rect2,
+ 0.926942348f, 0.642850280f, 0.529063463f, 0.587844372f,
+ false);
}
- SkRRect rr4_2; // construct the same RR using the most general set function
- SkVector rr4_2_radii[4] = { { 10, 9 }, { 8, 9 }, {8, 7 }, { 10, 7 } };
- rr4_2.setRectRadii(rect, rr4_2_radii);
- REPORTER_ASSERT(reporter, rr4_2 == rr4 && rr4_2.getType() == rr4.getType());
//----
SkPoint radii2[4] = { { 0, 0 }, { 0, 0 }, { 50, 50 }, { 20, 50 } };
@@ -164,8 +183,7 @@ static void test_round_rect_basic(skiatest::Reporter* reporter) {
// Test out == & !=
REPORTER_ASSERT(reporter, empty != rr3);
- REPORTER_ASSERT(reporter, rr3 != rr4);
- REPORTER_ASSERT(reporter, rr4 != rr5);
+ REPORTER_ASSERT(reporter, rr3 != rr5);
}
// Test out the cases when the RR degenerates to a rect
« no previous file with comments | « src/core/SkRRect.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698