caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 10 | namespace SimplifyNewTest { |
| 11 | |
| 12 | #include "Simplify.cpp" |
| 13 | |
| 14 | } // end of SimplifyNewTest namespace |
| 15 | |
| 16 | #include "EdgeWalker_Test.h" |
| 17 | #include "Intersection_Tests.h" |
| 18 | |
| 19 | static SkBitmap bitmap; |
| 20 | |
| 21 | static 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 | |
| 33 | static 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 | |
| 42 | static void addInnerCWTriangle(SkPath& path) { |
| 43 | path.moveTo(3,0); |
| 44 | path.lineTo(4,1); |
| 45 | path.lineTo(2,1); |
| 46 | path.close(); |
| 47 | } |
| 48 | |
| 49 | static void addInnerCCWTriangle(SkPath& path) { |
| 50 | path.moveTo(3,0); |
| 51 | path.lineTo(2,1); |
| 52 | path.lineTo(4,1); |
| 53 | path.close(); |
| 54 | } |
| 55 | |
| 56 | static void addOuterCWTriangle(SkPath& path) { |
| 57 | path.moveTo(3,0); |
| 58 | path.lineTo(6,2); |
| 59 | path.lineTo(0,2); |
| 60 | path.close(); |
| 61 | } |
| 62 | |
| 63 | static void addOuterCCWTriangle(SkPath& path) { |
| 64 | path.moveTo(3,0); |
| 65 | path.lineTo(0,2); |
| 66 | path.lineTo(6,2); |
| 67 | path.close(); |
| 68 | } |
| 69 | |
| 70 | static void testLine2() { |
| 71 | SkPath path, simple; |
| 72 | addInnerCWTriangle(path); |
| 73 | addOuterCWTriangle(path); |
| 74 | testSimplifyx(path, true, simple, bitmap); |
| 75 | } |
| 76 | |
| 77 | |
| 78 | static void (*tests[])() = { |
| 79 | testLine1, |
| 80 | testLine2, |
| 81 | }; |
| 82 | |
| 83 | static const size_t testCount = sizeof(tests) / sizeof(tests[0]); |
| 84 | |
| 85 | static void (*firstTest)() = testLine2; |
| 86 | static bool skipAll = false; |
| 87 | |
| 88 | void 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 | } |