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 #include "PathOpsExtendedTest.h"
8 #include "PathOpsThreadedCommon.h"
9 
10 static int loopNo = 158;
11 
testOpCubicsMain(PathOpsThreadState * data)12 static void testOpCubicsMain(PathOpsThreadState* data) {
13 #if DEBUG_SHOW_TEST_NAME
14     strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH);
15 #endif
16     SkASSERT(data);
17     PathOpsThreadState& state = *data;
18     char pathStr[1024];
19     bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter?
20     if (progress) {
21         sk_bzero(pathStr, sizeof(pathStr));
22     }
23     for (int a = 0 ; a < 6; ++a) {
24         for (int b = a + 1 ; b < 7; ++b) {
25             for (int c = 0 ; c < 6; ++c) {
26                 for (int d = c + 1 ; d < 7; ++d) {
27                     for (int e = SkPath::kWinding_FillType ; e <= SkPath::kEvenOdd_FillType; ++e) {
28     for (int f = SkPath::kWinding_FillType ; f <= SkPath::kEvenOdd_FillType; ++f) {
29         SkPath pathA, pathB;
30         pathA.setFillType((SkPath::FillType) e);
31         pathA.moveTo(SkIntToScalar(state.fA), SkIntToScalar(state.fB));
32         pathA.cubicTo(SkIntToScalar(state.fC), SkIntToScalar(state.fD), SkIntToScalar(b),
33                 SkIntToScalar(a), SkIntToScalar(d), SkIntToScalar(c));
34         pathA.close();
35         pathB.setFillType((SkPath::FillType) f);
36         pathB.moveTo(SkIntToScalar(a), SkIntToScalar(b));
37         pathB.cubicTo(SkIntToScalar(c), SkIntToScalar(d), SkIntToScalar(state.fB),
38                 SkIntToScalar(state.fA), SkIntToScalar(state.fD), SkIntToScalar(state.fC));
39         pathB.close();
40         for (int op = 0 ; op <= kXOR_SkPathOp; ++op)    {
41             if (progress) {
42                 outputProgress(state.fPathStr, pathStr, (SkPathOp) op);
43             }
44             if (progress) {
45                 char* str = pathStr;
46                 str += sprintf(str, "static void cubicOp%d(skiatest::Reporter* reporter,"
47                         " const char* filename) {\n", loopNo);
48                 str += sprintf(str, "    SkPath path, pathB;\n");
49                 str += sprintf(str, "    path.setFillType(SkPath::k%s_FillType);\n",
50                         e == SkPath::kWinding_FillType ? "Winding" : e == SkPath::kEvenOdd_FillType
51                         ? "EvenOdd" : "?UNDEFINED");
52                 str += sprintf(str, "    path.moveTo(%d,%d);\n", state.fA, state.fB);
53                 str += sprintf(str, "    path.cubicTo(%d,%d, %d,%d, %d,%d);\n", state.fC, state.fD,
54                         b, a, d, c);
55                 str += sprintf(str, "    path.close();\n");
56                 str += sprintf(str, "    pathB.setFillType(SkPath::k%s_FillType);\n",
57                         f == SkPath::kWinding_FillType ? "Winding" : f == SkPath::kEvenOdd_FillType
58                         ? "EvenOdd" : "?UNDEFINED");
59                 str += sprintf(str, "    pathB.moveTo(%d,%d);\n", a, b);
60                 str += sprintf(str, "    pathB.cubicTo(%d,%d, %d,%d, %d,%d);\n", c, d,
61                         state.fB, state.fA, state.fD, state.fC);
62                 str += sprintf(str, "    pathB.close();\n");
63                 str += sprintf(str, "    testPathOp(reporter, path, pathB, %s, filename);\n",
64                         SkPathOpsDebug::OpStr((SkPathOp) op));
65                 str += sprintf(str, "}\n");
66             }
67             if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, "cubics")) {
68                 if (progress) {
69                     ++loopNo;
70                     goto skipToNext;
71                 }
72             }
73         }
74     }
75                     }
76 skipToNext: ;
77                 }
78             }
79         }
80     }
81 }
82 
DEF_TEST(PathOpsOpCubicsThreaded,reporter)83 DEF_TEST(PathOpsOpCubicsThreaded, reporter) {
84     initializeTests(reporter, "cubicOp");
85     PathOpsThreadedTestRunner testRunner(reporter);
86     for (int a = 0; a < 6; ++a) {  // outermost
87         for (int b = a + 1; b < 7; ++b) {
88             for (int c = 0 ; c < 6; ++c) {
89                 for (int d = c + 1; d < 7; ++d) {
90                     *testRunner.fRunnables.append() =
91                             new PathOpsThreadedRunnable(&testOpCubicsMain, a, b, c, d, &testRunner);
92                 }
93             }
94             if (!reporter->allowExtendedTest()) goto finish;
95         }
96     }
97 finish:
98     testRunner.render();
99     ShowTestArray("cubicOp");
100 }
101