blob: 6d47a93fb732e83ae746fecdf50df1c4671f8395 [file] [log] [blame]
caryclark@google.comb45a1b42012-05-18 20:50:33 +00001/*
2 * Copyright 2012 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 "Simplify.h"
9
10namespace SimplifyFindNextTest {
11
12#include "Simplify.cpp"
13
14} // end of SimplifyFindNextTest namespace
15
16#include "Intersection_Tests.h"
17
18static const SimplifyFindNextTest::Segment* testCommon(
19 int start, int winding, int step,
20 SkTArray<SimplifyFindNextTest::Contour>& contours,
21 SimplifyFindNextTest::EdgeBuilder& builder, const SkPath& path) {
22 SkTDArray<SimplifyFindNextTest::Contour*> contourList;
23 SimplifyFindNextTest::Contour sentinel;
24 sentinel.reset();
25 makeContourList(contours, sentinel, contourList);
26 addIntersectTs(contourList[0], contourList[0], -1);
27 if (contours.count() > 1) {
28 SkASSERT(contours.count() == 2);
29 addIntersectTs(contourList[0], contourList[1], -1);
30 addIntersectTs(contourList[1], contourList[1], -1);
31 }
32 fixOtherTIndex(contourList);
33 SimplifyFindNextTest::Segment& segment = contours[0].fSegments[0];
34 int spanIndex;
35 SimplifyFindNextTest::Segment* next = segment.findNext(start, winding,
36 step, spanIndex);
37 SkASSERT(spanIndex == 1);
38 return next;
39}
40
41static void test(const SkPath& path) {
42 SkTArray<SimplifyFindNextTest::Contour> contours;
43 SimplifyFindNextTest::EdgeBuilder builder(path, contours);
44 int start = 0;
45 int winding = 0;
46 int step = 1;
47 testCommon(start, winding, step, contours, builder, path);
48}
49
50static void testLine1() {
51 SkPath path;
52 path.moveTo(2,0);
53 path.lineTo(1,1);
54 path.lineTo(0,0);
55 path.close();
56 test(path);
57}
58
59static void (*tests[])() = {
60 testLine1,
61};
62
63static const size_t testCount = sizeof(tests) / sizeof(tests[0]);
64
65static void (*firstTest)() = 0;
66static bool skipAll = false;
67
68void SimplifyFindNext_Test() {
69 if (skipAll) {
70 return;
71 }
72 size_t index = 0;
73 if (firstTest) {
74 while (index < testCount && tests[index] != firstTest) {
75 ++index;
76 }
77 }
78 bool firstTestComplete = false;
79 for ( ; index < testCount; ++index) {
80 (*tests[index])();
81 firstTestComplete = true;
82 }
83}