aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/StrokeTest.cpp
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-11-20 19:00:28 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-11-20 19:00:28 +0000
commit603dbedf293839e6707e2d4dfdd3949b06f9762c (patch)
tree6f8f7ddeb280e0837d1b61fa420da3f384d96da2 /tests/StrokeTest.cpp
parenta544f29496758de6ed2ebf5a53558574019c9da1 (diff)
add specialty strokeRect() to SkStroke, which can return much cleaner results
Review URL: https://codereview.appspot.com/6843093 git-svn-id: http://skia.googlecode.com/svn/trunk@6510 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/StrokeTest.cpp')
-rw-r--r--tests/StrokeTest.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/StrokeTest.cpp b/tests/StrokeTest.cpp
new file mode 100644
index 0000000000..a6c481a136
--- /dev/null
+++ b/tests/StrokeTest.cpp
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2012 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 "SkPaint.h"
+#include "SkPath.h"
+#include "SkRect.h"
+#include "SkStroke.h"
+
+static bool equal(const SkRect& a, const SkRect& b) {
+ return SkScalarNearlyEqual(a.left(), b.left()) &&
+ SkScalarNearlyEqual(a.top(), b.top()) &&
+ SkScalarNearlyEqual(a.right(), b.right()) &&
+ SkScalarNearlyEqual(a.bottom(), b.bottom());
+}
+
+static void test_strokerect(skiatest::Reporter* reporter) {
+ const SkScalar width = SkIntToScalar(10);
+ SkPaint paint;
+
+ paint.setStyle(SkPaint::kStroke_Style);
+ paint.setStrokeWidth(width);
+
+ SkRect r = { 0, 0, SkIntToScalar(200), SkIntToScalar(100) };
+
+ SkRect outer(r);
+ outer.outset(width/2, width/2);
+
+ static const SkPaint::Join joins[] = {
+ SkPaint::kMiter_Join, SkPaint::kRound_Join, SkPaint::kBevel_Join
+ };
+
+ for (size_t i = 0; i < SK_ARRAY_COUNT(joins); ++i) {
+ paint.setStrokeJoin(joins[i]);
+
+ SkPath path, fillPath;
+ path.addRect(r);
+ paint.getFillPath(path, &fillPath);
+
+ REPORTER_ASSERT(reporter, equal(outer, fillPath.getBounds()));
+
+ bool isMiter = SkPaint::kMiter_Join == joins[i];
+ SkRect nested[2];
+ REPORTER_ASSERT(reporter, fillPath.isNestedRects(nested) == isMiter);
+ if (isMiter) {
+ SkRect inner(r);
+ inner.inset(width/2, width/2);
+ REPORTER_ASSERT(reporter, equal(nested[0], outer));
+ REPORTER_ASSERT(reporter, equal(nested[1], inner));
+ }
+ }
+}
+
+static void TestStroke(skiatest::Reporter* reporter) {
+ test_strokerect(reporter);
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("Stroke", TestStrokeClass, TestStroke)
+