blob: b612f23c18d8cd3cdbc9bf1da6b35c97908b3921 [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
commit-bot@chromium.orgaec14382014-04-22 15:21:18 +00008#include "SkCornerPathEffect.h"
Ben Wagner1ebeefe2018-03-02 16:59:53 -05009#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.orgaec14382014-04-22 15:21:18 +000015
16DEF_TEST(AsADashTest_noneDash, reporter) {
reeda4393342016-03-18 11:22:57 -070017 sk_sp<SkPathEffect> pe(SkCornerPathEffect::Make(1.0));
commit-bot@chromium.orgaec14382014-04-22 15:21:18 +000018 SkPathEffect::DashInfo info;
19
20 SkPathEffect::DashType dashType = pe->asADash(&info);
21 REPORTER_ASSERT(reporter, SkPathEffect::kNone_DashType == dashType);
22}
23
24DEF_TEST(AsADashTest_nullInfo, reporter) {
25 SkScalar inIntervals[] = { 4.0, 2.0, 1.0, 3.0 };
26 const SkScalar phase = 2.0;
reeda4393342016-03-18 11:22:57 -070027 sk_sp<SkPathEffect> pe(SkDashPathEffect::Make(inIntervals, 4, phase));
commit-bot@chromium.orgaec14382014-04-22 15:21:18 +000028
halcanary96fcdcc2015-08-27 07:41:13 -070029 SkPathEffect::DashType dashType = pe->asADash(nullptr);
commit-bot@chromium.orgaec14382014-04-22 15:21:18 +000030 REPORTER_ASSERT(reporter, SkPathEffect::kDash_DashType == dashType);
31}
32
33DEF_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
reeda4393342016-03-18 11:22:57 -070038 sk_sp<SkPathEffect> pe(SkDashPathEffect::Make(inIntervals, 4, phase));
commit-bot@chromium.orgaec14382014-04-22 15:21:18 +000039
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}