blob: 2077b66425ac8aca39f04268a24ba44afc0e9126 [file] [log] [blame]
commit-bot@chromium.orgaec14382014-04-22 15:21:18 +00001/*
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 "Test.h"
9
10#include "SkPathEffect.h"
11#include "SkDashPathEffect.h"
12#include "SkCornerPathEffect.h"
13
14DEF_TEST(AsADashTest_noneDash, reporter) {
reeda4393342016-03-18 11:22:57 -070015 sk_sp<SkPathEffect> pe(SkCornerPathEffect::Make(1.0));
commit-bot@chromium.orgaec14382014-04-22 15:21:18 +000016 SkPathEffect::DashInfo info;
17
18 SkPathEffect::DashType dashType = pe->asADash(&info);
19 REPORTER_ASSERT(reporter, SkPathEffect::kNone_DashType == dashType);
20}
21
22DEF_TEST(AsADashTest_nullInfo, reporter) {
23 SkScalar inIntervals[] = { 4.0, 2.0, 1.0, 3.0 };
24 const SkScalar phase = 2.0;
reeda4393342016-03-18 11:22:57 -070025 sk_sp<SkPathEffect> pe(SkDashPathEffect::Make(inIntervals, 4, phase));
commit-bot@chromium.orgaec14382014-04-22 15:21:18 +000026
halcanary96fcdcc2015-08-27 07:41:13 -070027 SkPathEffect::DashType dashType = pe->asADash(nullptr);
commit-bot@chromium.orgaec14382014-04-22 15:21:18 +000028 REPORTER_ASSERT(reporter, SkPathEffect::kDash_DashType == dashType);
29}
30
31DEF_TEST(AsADashTest_usingDash, reporter) {
32 SkScalar inIntervals[] = { 4.0, 2.0, 1.0, 3.0 };
33 SkScalar totalIntSum = 10.0;
34 const SkScalar phase = 2.0;
35
reeda4393342016-03-18 11:22:57 -070036 sk_sp<SkPathEffect> pe(SkDashPathEffect::Make(inIntervals, 4, phase));
commit-bot@chromium.orgaec14382014-04-22 15:21:18 +000037
38 SkPathEffect::DashInfo info;
39
40 SkPathEffect::DashType dashType = pe->asADash(&info);
41 REPORTER_ASSERT(reporter, SkPathEffect::kDash_DashType == dashType);
42 REPORTER_ASSERT(reporter, 4 == info.fCount);
43 REPORTER_ASSERT(reporter, SkScalarMod(phase, totalIntSum) == info.fPhase);
44
45 // Since it is a kDash_DashType, allocate space for the intervals and recall asADash
46 SkAutoTArray<SkScalar> intervals(info.fCount);
47 info.fIntervals = intervals.get();
48 pe->asADash(&info);
49 REPORTER_ASSERT(reporter, inIntervals[0] == info.fIntervals[0]);
50 REPORTER_ASSERT(reporter, inIntervals[1] == info.fIntervals[1]);
51 REPORTER_ASSERT(reporter, inIntervals[2] == info.fIntervals[2]);
52 REPORTER_ASSERT(reporter, inIntervals[3] == info.fIntervals[3]);
53
54 // Make sure nothing else has changed on us
55 REPORTER_ASSERT(reporter, 4 == info.fCount);
56 REPORTER_ASSERT(reporter, SkScalarMod(phase, totalIntSum) == info.fPhase);
57}