aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/RoundRectTest.cpp
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2015-02-24 11:18:48 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-02-24 11:18:48 -0800
commitfe1b180bee3f254cb74b5cb2ae383050fc316937 (patch)
tree9550ef71011305bf54b11ad7b2a3a88617f711d5 /tests/RoundRectTest.cpp
parent1a2979af0846cc05679c1038eb62851c3af9dd8c (diff)
Fix radii scaling bug in SkRRect::setNinePatch
Diffstat (limited to 'tests/RoundRectTest.cpp')
-rw-r--r--tests/RoundRectTest.cpp52
1 files changed, 35 insertions, 17 deletions
diff --git a/tests/RoundRectTest.cpp b/tests/RoundRectTest.cpp
index cff3e8f35a..9920d1013b 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