fix cubic/line intersection; add skp tests

BUG=skia:2488
TBR=reed

Author: caryclark@google.com

Review URL: https://codereview.chromium.org/252243003

git-svn-id: http://skia.googlecode.com/svn/trunk@14458 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tests/PathOpsCubicLineIntersectionTest.cpp b/tests/PathOpsCubicLineIntersectionTest.cpp
index 8ded198..1a2e188 100644
--- a/tests/PathOpsCubicLineIntersectionTest.cpp
+++ b/tests/PathOpsCubicLineIntersectionTest.cpp
@@ -11,10 +11,45 @@
 #include "SkReduceOrder.h"
 #include "Test.h"
 
-static struct lineCubic {
+struct lineCubic {
     SkDCubic cubic;
     SkDLine line;
-} lineCubicTests[] = {
+};
+
+static lineCubic failLineCubicTests[] = {
+    {{{{37.5273438,-1.44140625}, {37.8736992,-1.69921875}, {38.1640625,-2.140625},
+            {38.3984375,-2.765625}}},
+            {{{40.625,-5.7890625}, {37.7109375,1.3515625}}}},
+};
+
+static const size_t failLineCubicTests_count = SK_ARRAY_COUNT(failLineCubicTests);
+
+static void testFail(skiatest::Reporter* reporter, int iIndex) {
+    const SkDCubic& cubic = failLineCubicTests[iIndex].cubic;
+    SkASSERT(ValidCubic(cubic));
+    const SkDLine& line = failLineCubicTests[iIndex].line;
+    SkASSERT(ValidLine(line));
+    SkReduceOrder reduce1;
+    SkReduceOrder reduce2;
+    int order1 = reduce1.reduce(cubic, SkReduceOrder::kNo_Quadratics);
+    int order2 = reduce2.reduce(line);
+    if (order1 < 4) {
+        SkDebugf("[%d] cubic order=%d\n", iIndex, order1);
+        REPORTER_ASSERT(reporter, 0);
+    }
+    if (order2 < 2) {
+        SkDebugf("[%d] line order=%d\n", iIndex, order2);
+        REPORTER_ASSERT(reporter, 0);
+    }
+    if (order1 == 4 && order2 == 2) {
+        SkIntersections i;
+        int roots = i.intersect(cubic, line);
+        REPORTER_ASSERT(reporter, roots == 0);
+    }
+}
+
+static lineCubic lineCubicTests[] = {
+
     {{{{421, 378}, {421, 380.209137f}, {418.761414f, 382}, {416, 382}}},
             {{{320, 378}, {421, 378.000031f}}}},
 
@@ -97,6 +132,14 @@
     }
 }
 
+DEF_TEST(PathOpsFailCubicLineIntersection, reporter) {
+    for (size_t index = 0; index < failLineCubicTests_count; ++index) {
+        int iIndex = static_cast<int>(index);
+        testFail(reporter, iIndex);
+        reporter->bumpTestCount();
+    }
+}
+
 DEF_TEST(PathOpsCubicLineIntersection, reporter) {
     for (size_t index = 0; index < lineCubicTests_count; ++index) {
         int iIndex = static_cast<int>(index);