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 "SkCornerPathEffect.h" 9 #include "SkDashPathEffect.h" 10 #include "SkPathEffect.h" 11 #include "SkRefCnt.h" 12 #include "SkScalar.h" 13 #include "SkTemplates.h" 14 #include "Test.h" 15 16 DEF_TEST(AsADashTest_noneDash, reporter) { 17 sk_sp<SkPathEffect> pe(SkCornerPathEffect::Make(1.0)); 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; 27 sk_sp<SkPathEffect> pe(SkDashPathEffect::Make(inIntervals, 4, phase)); 28 29 SkPathEffect::DashType dashType = pe->asADash(nullptr); 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 38 sk_sp<SkPathEffect> pe(SkDashPathEffect::Make(inIntervals, 4, phase)); 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 } 60