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
8 #include "include/core/SkPathEffect.h"
9 #include "include/core/SkRefCnt.h"
10 #include "include/core/SkScalar.h"
11 #include "include/effects/SkCornerPathEffect.h"
12 #include "include/effects/SkDashPathEffect.h"
13 #include "include/private/base/SkTemplates.h"
14 #include "tests/Test.h"
15
16 using namespace skia_private;
17
DEF_TEST(AsADashTest_noneDash,reporter)18 DEF_TEST(AsADashTest_noneDash, reporter) {
19 sk_sp<SkPathEffect> pe(SkCornerPathEffect::Make(1.0));
20 SkPathEffect::DashInfo info;
21
22 SkPathEffect::DashType dashType = pe->asADash(&info);
23 REPORTER_ASSERT(reporter, SkPathEffect::kNone_DashType == dashType);
24 }
25
DEF_TEST(AsADashTest_nullInfo,reporter)26 DEF_TEST(AsADashTest_nullInfo, reporter) {
27 SkScalar inIntervals[] = { 4.0, 2.0, 1.0, 3.0 };
28 const SkScalar phase = 2.0;
29 sk_sp<SkPathEffect> pe(SkDashPathEffect::Make(inIntervals, 4, phase));
30
31 SkPathEffect::DashType dashType = pe->asADash(nullptr);
32 REPORTER_ASSERT(reporter, SkPathEffect::kDash_DashType == dashType);
33 }
34
DEF_TEST(AsADashTest_usingDash,reporter)35 DEF_TEST(AsADashTest_usingDash, reporter) {
36 SkScalar inIntervals[] = { 4.0, 2.0, 1.0, 3.0 };
37 SkScalar totalIntSum = 10.0;
38 const SkScalar phase = 2.0;
39
40 sk_sp<SkPathEffect> pe(SkDashPathEffect::Make(inIntervals, 4, phase));
41
42 SkPathEffect::DashInfo info;
43
44 SkPathEffect::DashType dashType = pe->asADash(&info);
45 REPORTER_ASSERT(reporter, SkPathEffect::kDash_DashType == dashType);
46 REPORTER_ASSERT(reporter, 4 == info.fCount);
47 REPORTER_ASSERT(reporter, SkScalarMod(phase, totalIntSum) == info.fPhase);
48
49 // Since it is a kDash_DashType, allocate space for the intervals and recall asADash
50 AutoTArray<SkScalar> intervals(info.fCount);
51 info.fIntervals = intervals.get();
52 pe->asADash(&info);
53 REPORTER_ASSERT(reporter, inIntervals[0] == info.fIntervals[0]);
54 REPORTER_ASSERT(reporter, inIntervals[1] == info.fIntervals[1]);
55 REPORTER_ASSERT(reporter, inIntervals[2] == info.fIntervals[2]);
56 REPORTER_ASSERT(reporter, inIntervals[3] == info.fIntervals[3]);
57
58 // Make sure nothing else has changed on us
59 REPORTER_ASSERT(reporter, 4 == info.fCount);
60 REPORTER_ASSERT(reporter, SkScalarMod(phase, totalIntSum) == info.fPhase);
61 }
62