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

Unified Diff: tests/DashPathEffectTest.cpp

Issue 701133002: Add unit test for SkDashPathEffect::asPoints' culling (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add cast Created 6 years, 1 month 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/DashPathEffectTest.cpp
diff --git a/tests/DashPathEffectTest.cpp b/tests/DashPathEffectTest.cpp
index 1e53058de8e65f1730934da17459d57f8ef25ac6..228aee9031881bc2c33ee05d59972ec902518d0e 100644
--- a/tests/DashPathEffectTest.cpp
+++ b/tests/DashPathEffectTest.cpp
@@ -1,3 +1,10 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
#include "Test.h"
#include "SkDashPathEffect.h"
@@ -19,3 +26,63 @@ DEF_TEST(DashPathEffectTest_crbug_348821, r) {
buffer.writeFlattenable(dash);
REPORTER_ASSERT(r, buffer.bytesWritten() > 12); // We'd write 12 if broken, >=40 if not.
}
+
+// Test out the asPoint culling behavior.
+DEF_TEST(DashPathEffectTest_asPoints, r) {
+
+ const SkScalar intervals[] = { 1.0f, 1.0f };
+ const int count = 2;
+ SkAutoTUnref<SkDashPathEffect> dash(SkDashPathEffect::Create(intervals, count, 0.0f));
+
+ SkRect cull = SkRect::MakeWH(1.0f, 1.0f);
+
+ const struct {
+ SkPoint fPts[2];
+ bool fExpectedResult;
+ } testCases[] = {
+ { { { -5.0f, 0.5f }, { -4.0f, 0.5f } }, false }, // off to the left
+ { { { 4.0f, 0.5f }, { 5.0f, 0.5f } }, false }, // off to the right
+ { { { 0.5f, 4.0f }, { 0.5f, 5.0f } }, false }, // off the bottom
+ { { { 0.5f, -5.0f }, { 0.5f, -4.0f } }, false }, // off the top
+ { { { 0.5f, 0.2f }, { 0.5f, 0.8f } }, true }, // entirely inside vertical
+ { { { 0.2f, 0.5f }, { 0.8f, 0.5f } }, true }, // entirely inside horizontal
+ { { { 0.5f, -5.0f }, { 0.5f, 5.0f } }, true }, // straddles both sides vertically
+ { { { -5.0f, 0.5f }, { 5.0f, 0.5f } }, true }, // straddles both sides horizontally
+ { { { 0.5f, -5.0f }, { 0.5f, 0.5f } }, true }, // straddles top
+ { { { 0.5f, 5.0f }, { 0.5f, 0.5f } }, true }, // straddles bottom
+ { { { -5.0f, 0.5f }, { 0.5f, 0.5f } }, true }, // straddles left
+ { { { 5.0f, 0.5f }, { 0.5f, 0.5f } }, true }, // straddles right
+ { { { 0.5f, 0.5f }, { 0.5f, 0.5f } }, false }, // zero length
+ };
+
+ SkPaint paint;
+ paint.setStyle(SkPaint::kStroke_Style);
+ paint.setStrokeWidth(1.0f);
+ SkStrokeRec rec(paint);
+
+ static const int kNumMats = 3;
+ SkMatrix mats[kNumMats];
+ mats[0].reset();
+ mats[1].setRotate(90, 0.5f, 0.5f);
+ mats[2].setTranslate(10.0f, 10.0f);
+
+ for (int i = 0; i < kNumMats; ++i) {
+ for (int j = 0; j < (int)SK_ARRAY_COUNT(testCases); ++j) {
+ for (int k = 0; k < 2; ++k) { // exercise alternating endpoints
+ SkPathEffect::PointData results;
+ SkPath src;
+
+ src.moveTo(testCases[j].fPts[k]);
+ src.lineTo(testCases[j].fPts[(k+1)%2]);
+
+ bool actualResult = dash->asPoints(&results, src, rec, mats[i], &cull);
+ if (i < 2) {
+ REPORTER_ASSERT(r, actualResult == testCases[j].fExpectedResult);
+ } else {
+ // On the third pass all the lines should be outside the translated cull rect
+ REPORTER_ASSERT(r, !actualResult);
+ }
+ }
+ }
+ }
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698