skia2/tests/AsADashTest.cpp
Ben Wagner 1ebeefe246 IWYU for test files starting with 'A'.
While testing some changes to iwyu, started fixing some files. Made it
to AsADashTest.cpp before running into
https://github.com/include-what-you-use/include-what-you-use/issues/364

Change-Id: I42b65df4f1f8116e0ea1b2cd774651990db1b132
Reviewed-on: https://skia-review.googlesource.com/111861
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
2018-03-02 22:39:59 +00:00

60 lines
2.1 KiB
C++

/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkCornerPathEffect.h"
#include "SkDashPathEffect.h"
#include "SkPathEffect.h"
#include "SkRefCnt.h"
#include "SkScalar.h"
#include "SkTemplates.h"
#include "Test.h"
DEF_TEST(AsADashTest_noneDash, reporter) {
sk_sp<SkPathEffect> pe(SkCornerPathEffect::Make(1.0));
SkPathEffect::DashInfo info;
SkPathEffect::DashType dashType = pe->asADash(&info);
REPORTER_ASSERT(reporter, SkPathEffect::kNone_DashType == dashType);
}
DEF_TEST(AsADashTest_nullInfo, reporter) {
SkScalar inIntervals[] = { 4.0, 2.0, 1.0, 3.0 };
const SkScalar phase = 2.0;
sk_sp<SkPathEffect> pe(SkDashPathEffect::Make(inIntervals, 4, phase));
SkPathEffect::DashType dashType = pe->asADash(nullptr);
REPORTER_ASSERT(reporter, SkPathEffect::kDash_DashType == dashType);
}
DEF_TEST(AsADashTest_usingDash, reporter) {
SkScalar inIntervals[] = { 4.0, 2.0, 1.0, 3.0 };
SkScalar totalIntSum = 10.0;
const SkScalar phase = 2.0;
sk_sp<SkPathEffect> pe(SkDashPathEffect::Make(inIntervals, 4, phase));
SkPathEffect::DashInfo info;
SkPathEffect::DashType dashType = pe->asADash(&info);
REPORTER_ASSERT(reporter, SkPathEffect::kDash_DashType == dashType);
REPORTER_ASSERT(reporter, 4 == info.fCount);
REPORTER_ASSERT(reporter, SkScalarMod(phase, totalIntSum) == info.fPhase);
// Since it is a kDash_DashType, allocate space for the intervals and recall asADash
SkAutoTArray<SkScalar> intervals(info.fCount);
info.fIntervals = intervals.get();
pe->asADash(&info);
REPORTER_ASSERT(reporter, inIntervals[0] == info.fIntervals[0]);
REPORTER_ASSERT(reporter, inIntervals[1] == info.fIntervals[1]);
REPORTER_ASSERT(reporter, inIntervals[2] == info.fIntervals[2]);
REPORTER_ASSERT(reporter, inIntervals[3] == info.fIntervals[3]);
// Make sure nothing else has changed on us
REPORTER_ASSERT(reporter, 4 == info.fCount);
REPORTER_ASSERT(reporter, SkScalarMod(phase, totalIntSum) == info.fPhase);
}