blob: 7fbe4d06cbe33121875c9c6ae03f8e72afb5ab9e [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
caryclark@google.com65f9f0a2012-05-23 18:09:25 +000021static bool testSimplifyx(const SkPath& path, SkPath& out, SkBitmap& bitmap) {
caryclark@google.comaf46cff2012-05-22 21:12:00 +000022 if (false) {
23 showPath(path);
24 }
caryclark@google.com65f9f0a2012-05-23 18:09:25 +000025 simplifyx(path, out);
caryclark@google.comaf46cff2012-05-22 21:12:00 +000026 if (false) {
27 return true;
28 }
29 return comparePaths(path, out, bitmap, 0) == 0;
30}
31
32static void testLine1() {
33 SkPath path, simple;
34 path.moveTo(2,0);
35 path.lineTo(1,1);
36 path.lineTo(0,0);
37 path.close();
caryclark@google.com65f9f0a2012-05-23 18:09:25 +000038 testSimplifyx(path, simple, bitmap);
caryclark@google.comaf46cff2012-05-22 21:12:00 +000039}
40
41static void addInnerCWTriangle(SkPath& path) {
42 path.moveTo(3,0);
43 path.lineTo(4,1);
44 path.lineTo(2,1);
45 path.close();
46}
47
caryclark@google.com65f9f0a2012-05-23 18:09:25 +000048#if DEBUG_UNUSED
caryclark@google.comaf46cff2012-05-22 21:12:00 +000049static void addInnerCCWTriangle(SkPath& path) {
50 path.moveTo(3,0);
51 path.lineTo(2,1);
52 path.lineTo(4,1);
53 path.close();
54}
caryclark@google.com65f9f0a2012-05-23 18:09:25 +000055#endif
caryclark@google.comaf46cff2012-05-22 21:12:00 +000056
57static void addOuterCWTriangle(SkPath& path) {
58 path.moveTo(3,0);
59 path.lineTo(6,2);
60 path.lineTo(0,2);
61 path.close();
62}
63
caryclark@google.com65f9f0a2012-05-23 18:09:25 +000064#if DEBUG_UNUSED
caryclark@google.comaf46cff2012-05-22 21:12:00 +000065static void addOuterCCWTriangle(SkPath& path) {
66 path.moveTo(3,0);
67 path.lineTo(0,2);
68 path.lineTo(6,2);
69 path.close();
70}
caryclark@google.com65f9f0a2012-05-23 18:09:25 +000071#endif
caryclark@google.comaf46cff2012-05-22 21:12:00 +000072
73static void testLine2() {
74 SkPath path, simple;
75 addInnerCWTriangle(path);
76 addOuterCWTriangle(path);
caryclark@google.com65f9f0a2012-05-23 18:09:25 +000077 testSimplifyx(path, simple, bitmap);
caryclark@google.comaf46cff2012-05-22 21:12:00 +000078}
79
80
81static void (*tests[])() = {
82 testLine1,
83 testLine2,
84};
85
86static const size_t testCount = sizeof(tests) / sizeof(tests[0]);
87
88static void (*firstTest)() = testLine2;
89static bool skipAll = false;
90
91void SimplifyNew_Test() {
92 if (skipAll) {
93 return;
94 }
95 size_t index = 0;
96 if (firstTest) {
97 while (index < testCount && tests[index] != firstTest) {
98 ++index;
99 }
100 }
101 bool firstTestComplete = false;
102 for ( ; index < testCount; ++index) {
103 (*tests[index])();
104 firstTestComplete = true;
105 }
106}