blob: b989ebada004f6e18841dbc722fb6a483450bb2e [file] [log] [blame]
caryclark@google.comaf46cff2012-05-22 21:12:00 +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 SimplifyNewTest {
11
12#include "Simplify.cpp"
13
14} // end of SimplifyNewTest namespace
15
16#include "EdgeWalker_Test.h"
17#include "Intersection_Tests.h"
18
19static SkBitmap bitmap;
20
21static bool testSimplifyx(const SkPath& path, bool fill, SkPath& out,
22 SkBitmap& bitmap) {
23 if (false) {
24 showPath(path);
25 }
26 simplifyx(path, fill, out);
27 if (false) {
28 return true;
29 }
30 return comparePaths(path, out, bitmap, 0) == 0;
31}
32
33static void testLine1() {
34 SkPath path, simple;
35 path.moveTo(2,0);
36 path.lineTo(1,1);
37 path.lineTo(0,0);
38 path.close();
39 testSimplifyx(path, true, simple, bitmap);
40}
41
42static void addInnerCWTriangle(SkPath& path) {
43 path.moveTo(3,0);
44 path.lineTo(4,1);
45 path.lineTo(2,1);
46 path.close();
47}
48
49static void addInnerCCWTriangle(SkPath& path) {
50 path.moveTo(3,0);
51 path.lineTo(2,1);
52 path.lineTo(4,1);
53 path.close();
54}
55
56static void addOuterCWTriangle(SkPath& path) {
57 path.moveTo(3,0);
58 path.lineTo(6,2);
59 path.lineTo(0,2);
60 path.close();
61}
62
63static void addOuterCCWTriangle(SkPath& path) {
64 path.moveTo(3,0);
65 path.lineTo(0,2);
66 path.lineTo(6,2);
67 path.close();
68}
69
70static void testLine2() {
71 SkPath path, simple;
72 addInnerCWTriangle(path);
73 addOuterCWTriangle(path);
74 testSimplifyx(path, true, simple, bitmap);
75}
76
77
78static void (*tests[])() = {
79 testLine1,
80 testLine2,
81};
82
83static const size_t testCount = sizeof(tests) / sizeof(tests[0]);
84
85static void (*firstTest)() = testLine2;
86static bool skipAll = false;
87
88void SimplifyNew_Test() {
89 if (skipAll) {
90 return;
91 }
92 size_t index = 0;
93 if (firstTest) {
94 while (index < testCount && tests[index] != firstTest) {
95 ++index;
96 }
97 }
98 bool firstTestComplete = false;
99 for ( ; index < testCount; ++index) {
100 (*tests[index])();
101 firstTestComplete = true;
102 }
103}