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