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 | |
caryclark@google.com | 65f9f0a | 2012-05-23 18:09:25 +0000 | [diff] [blame^] | 21 | static bool testSimplifyx(const SkPath& path, SkPath& out, SkBitmap& bitmap) { |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 22 | if (false) { |
| 23 | showPath(path); |
| 24 | } |
caryclark@google.com | 65f9f0a | 2012-05-23 18:09:25 +0000 | [diff] [blame^] | 25 | simplifyx(path, out); |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 26 | if (false) { |
| 27 | return true; |
| 28 | } |
| 29 | return comparePaths(path, out, bitmap, 0) == 0; |
| 30 | } |
| 31 | |
| 32 | static 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.com | 65f9f0a | 2012-05-23 18:09:25 +0000 | [diff] [blame^] | 38 | testSimplifyx(path, simple, bitmap); |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | static 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.com | 65f9f0a | 2012-05-23 18:09:25 +0000 | [diff] [blame^] | 48 | #if DEBUG_UNUSED |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 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 | } |
caryclark@google.com | 65f9f0a | 2012-05-23 18:09:25 +0000 | [diff] [blame^] | 55 | #endif |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 56 | |
| 57 | static 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.com | 65f9f0a | 2012-05-23 18:09:25 +0000 | [diff] [blame^] | 64 | #if DEBUG_UNUSED |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 65 | static 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.com | 65f9f0a | 2012-05-23 18:09:25 +0000 | [diff] [blame^] | 71 | #endif |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 72 | |
| 73 | static void testLine2() { |
| 74 | SkPath path, simple; |
| 75 | addInnerCWTriangle(path); |
| 76 | addOuterCWTriangle(path); |
caryclark@google.com | 65f9f0a | 2012-05-23 18:09:25 +0000 | [diff] [blame^] | 77 | testSimplifyx(path, simple, bitmap); |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | |
| 81 | static void (*tests[])() = { |
| 82 | testLine1, |
| 83 | testLine2, |
| 84 | }; |
| 85 | |
| 86 | static const size_t testCount = sizeof(tests) / sizeof(tests[0]); |
| 87 | |
| 88 | static void (*firstTest)() = testLine2; |
| 89 | static bool skipAll = false; |
| 90 | |
| 91 | void 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 | } |