commit-bot@chromium.org | aec1438 | 2014-04-22 15:21:18 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
commit-bot@chromium.org | aec1438 | 2014-04-22 15:21:18 +0000 | [diff] [blame] | 8 | #include "SkCornerPathEffect.h" |
Ben Wagner | 1ebeefe | 2018-03-02 16:59:53 -0500 | [diff] [blame] | 9 | #include "SkDashPathEffect.h" |
| 10 | #include "SkPathEffect.h" |
| 11 | #include "SkRefCnt.h" |
| 12 | #include "SkScalar.h" |
| 13 | #include "SkTemplates.h" |
| 14 | #include "Test.h" |
commit-bot@chromium.org | aec1438 | 2014-04-22 15:21:18 +0000 | [diff] [blame] | 15 | |
| 16 | DEF_TEST(AsADashTest_noneDash, reporter) { |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 17 | sk_sp<SkPathEffect> pe(SkCornerPathEffect::Make(1.0)); |
commit-bot@chromium.org | aec1438 | 2014-04-22 15:21:18 +0000 | [diff] [blame] | 18 | SkPathEffect::DashInfo info; |
| 19 | |
| 20 | SkPathEffect::DashType dashType = pe->asADash(&info); |
| 21 | REPORTER_ASSERT(reporter, SkPathEffect::kNone_DashType == dashType); |
| 22 | } |
| 23 | |
| 24 | DEF_TEST(AsADashTest_nullInfo, reporter) { |
| 25 | SkScalar inIntervals[] = { 4.0, 2.0, 1.0, 3.0 }; |
| 26 | const SkScalar phase = 2.0; |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 27 | sk_sp<SkPathEffect> pe(SkDashPathEffect::Make(inIntervals, 4, phase)); |
commit-bot@chromium.org | aec1438 | 2014-04-22 15:21:18 +0000 | [diff] [blame] | 28 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 29 | SkPathEffect::DashType dashType = pe->asADash(nullptr); |
commit-bot@chromium.org | aec1438 | 2014-04-22 15:21:18 +0000 | [diff] [blame] | 30 | REPORTER_ASSERT(reporter, SkPathEffect::kDash_DashType == dashType); |
| 31 | } |
| 32 | |
| 33 | DEF_TEST(AsADashTest_usingDash, reporter) { |
| 34 | SkScalar inIntervals[] = { 4.0, 2.0, 1.0, 3.0 }; |
| 35 | SkScalar totalIntSum = 10.0; |
| 36 | const SkScalar phase = 2.0; |
| 37 | |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 38 | sk_sp<SkPathEffect> pe(SkDashPathEffect::Make(inIntervals, 4, phase)); |
commit-bot@chromium.org | aec1438 | 2014-04-22 15:21:18 +0000 | [diff] [blame] | 39 | |
| 40 | SkPathEffect::DashInfo info; |
| 41 | |
| 42 | SkPathEffect::DashType dashType = pe->asADash(&info); |
| 43 | REPORTER_ASSERT(reporter, SkPathEffect::kDash_DashType == dashType); |
| 44 | REPORTER_ASSERT(reporter, 4 == info.fCount); |
| 45 | REPORTER_ASSERT(reporter, SkScalarMod(phase, totalIntSum) == info.fPhase); |
| 46 | |
| 47 | // Since it is a kDash_DashType, allocate space for the intervals and recall asADash |
| 48 | SkAutoTArray<SkScalar> intervals(info.fCount); |
| 49 | info.fIntervals = intervals.get(); |
| 50 | pe->asADash(&info); |
| 51 | REPORTER_ASSERT(reporter, inIntervals[0] == info.fIntervals[0]); |
| 52 | REPORTER_ASSERT(reporter, inIntervals[1] == info.fIntervals[1]); |
| 53 | REPORTER_ASSERT(reporter, inIntervals[2] == info.fIntervals[2]); |
| 54 | REPORTER_ASSERT(reporter, inIntervals[3] == info.fIntervals[3]); |
| 55 | |
| 56 | // Make sure nothing else has changed on us |
| 57 | REPORTER_ASSERT(reporter, 4 == info.fCount); |
| 58 | REPORTER_ASSERT(reporter, SkScalarMod(phase, totalIntSum) == info.fPhase); |
| 59 | } |