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