From aec143824c9be4e4af6e2cb7cce3d2d2268c0b15 Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Tue, 22 Apr 2014 15:21:18 +0000 Subject: Add asADash entry point into SkPathEffect to allow extracting Dash info from PathEffects BUG=skia: R=bsalomon@google.com, reed@google.com Author: egdaniel@google.com Review URL: https://codereview.chromium.org/212103010 git-svn-id: http://skia.googlecode.com/svn/trunk@14297 2bbb7eff-a529-9590-31e7-b0007b416f81 --- tests/AsADashTest.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/AsADashTest.cpp (limited to 'tests/AsADashTest.cpp') diff --git a/tests/AsADashTest.cpp b/tests/AsADashTest.cpp new file mode 100644 index 0000000000..47f19717a4 --- /dev/null +++ b/tests/AsADashTest.cpp @@ -0,0 +1,57 @@ +/* + * 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 "SkPathEffect.h" +#include "SkDashPathEffect.h" +#include "SkCornerPathEffect.h" + +DEF_TEST(AsADashTest_noneDash, reporter) { + SkAutoTUnref pe(SkCornerPathEffect::Create(1.0)); + SkPathEffect::DashInfo info; + + SkPathEffect::DashType dashType = pe->asADash(&info); + REPORTER_ASSERT(reporter, SkPathEffect::kNone_DashType == dashType); +} + +DEF_TEST(AsADashTest_nullInfo, reporter) { + SkScalar inIntervals[] = { 4.0, 2.0, 1.0, 3.0 }; + const SkScalar phase = 2.0; + SkAutoTUnref pe(SkDashPathEffect::Create(inIntervals, 4, phase)); + + SkPathEffect::DashType dashType = pe->asADash(NULL); + REPORTER_ASSERT(reporter, SkPathEffect::kDash_DashType == dashType); +} + +DEF_TEST(AsADashTest_usingDash, reporter) { + SkScalar inIntervals[] = { 4.0, 2.0, 1.0, 3.0 }; + SkScalar totalIntSum = 10.0; + const SkScalar phase = 2.0; + + SkAutoTUnref pe(SkDashPathEffect::Create(inIntervals, 4, phase)); + + SkPathEffect::DashInfo info; + + SkPathEffect::DashType dashType = pe->asADash(&info); + REPORTER_ASSERT(reporter, SkPathEffect::kDash_DashType == dashType); + REPORTER_ASSERT(reporter, 4 == info.fCount); + REPORTER_ASSERT(reporter, SkScalarMod(phase, totalIntSum) == info.fPhase); + + // Since it is a kDash_DashType, allocate space for the intervals and recall asADash + SkAutoTArray intervals(info.fCount); + info.fIntervals = intervals.get(); + pe->asADash(&info); + REPORTER_ASSERT(reporter, inIntervals[0] == info.fIntervals[0]); + REPORTER_ASSERT(reporter, inIntervals[1] == info.fIntervals[1]); + REPORTER_ASSERT(reporter, inIntervals[2] == info.fIntervals[2]); + REPORTER_ASSERT(reporter, inIntervals[3] == info.fIntervals[3]); + + // Make sure nothing else has changed on us + REPORTER_ASSERT(reporter, 4 == info.fCount); + REPORTER_ASSERT(reporter, SkScalarMod(phase, totalIntSum) == info.fPhase); +} -- cgit v1.2.3