AsADashTest.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #include "include/core/SkPathEffect.h"
  8. #include "include/core/SkRefCnt.h"
  9. #include "include/core/SkScalar.h"
  10. #include "include/effects/SkCornerPathEffect.h"
  11. #include "include/effects/SkDashPathEffect.h"
  12. #include "include/private/SkTemplates.h"
  13. #include "tests/Test.h"
  14. DEF_TEST(AsADashTest_noneDash, reporter) {
  15. sk_sp<SkPathEffect> pe(SkCornerPathEffect::Make(1.0));
  16. SkPathEffect::DashInfo info;
  17. SkPathEffect::DashType dashType = pe->asADash(&info);
  18. REPORTER_ASSERT(reporter, SkPathEffect::kNone_DashType == dashType);
  19. }
  20. DEF_TEST(AsADashTest_nullInfo, reporter) {
  21. SkScalar inIntervals[] = { 4.0, 2.0, 1.0, 3.0 };
  22. const SkScalar phase = 2.0;
  23. sk_sp<SkPathEffect> pe(SkDashPathEffect::Make(inIntervals, 4, phase));
  24. SkPathEffect::DashType dashType = pe->asADash(nullptr);
  25. REPORTER_ASSERT(reporter, SkPathEffect::kDash_DashType == dashType);
  26. }
  27. DEF_TEST(AsADashTest_usingDash, reporter) {
  28. SkScalar inIntervals[] = { 4.0, 2.0, 1.0, 3.0 };
  29. SkScalar totalIntSum = 10.0;
  30. const SkScalar phase = 2.0;
  31. sk_sp<SkPathEffect> pe(SkDashPathEffect::Make(inIntervals, 4, phase));
  32. SkPathEffect::DashInfo info;
  33. SkPathEffect::DashType dashType = pe->asADash(&info);
  34. REPORTER_ASSERT(reporter, SkPathEffect::kDash_DashType == dashType);
  35. REPORTER_ASSERT(reporter, 4 == info.fCount);
  36. REPORTER_ASSERT(reporter, SkScalarMod(phase, totalIntSum) == info.fPhase);
  37. // Since it is a kDash_DashType, allocate space for the intervals and recall asADash
  38. SkAutoTArray<SkScalar> intervals(info.fCount);
  39. info.fIntervals = intervals.get();
  40. pe->asADash(&info);
  41. REPORTER_ASSERT(reporter, inIntervals[0] == info.fIntervals[0]);
  42. REPORTER_ASSERT(reporter, inIntervals[1] == info.fIntervals[1]);
  43. REPORTER_ASSERT(reporter, inIntervals[2] == info.fIntervals[2]);
  44. REPORTER_ASSERT(reporter, inIntervals[3] == info.fIntervals[3]);
  45. // Make sure nothing else has changed on us
  46. REPORTER_ASSERT(reporter, 4 == info.fCount);
  47. REPORTER_ASSERT(reporter, SkScalarMod(phase, totalIntSum) == info.fPhase);
  48. }