Home | History | Annotate | Download | only in tests
      1 /*
      2  * Copyright 2014 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 void testOpLoopsMain(PathOpsThreadState* data) {
     11 #if DEBUG_SHOW_TEST_NAME
     12     strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH);
     13 #endif
     14     SkASSERT(data);
     15     PathOpsThreadState& state = *data;
     16     char pathStr[1024];  // gdb: set print elements 400
     17     bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter?
     18     if (progress) {
     19         sk_bzero(pathStr, sizeof(pathStr));
     20     }
     21     for (int a = 0 ; a < 6; ++a) {
     22         for (int b = a + 1 ; b < 7; ++b) {
     23             for (int c = 0 ; c < 6; ++c) {
     24                 for (int d = c + 1 ; d < 7; ++d) {
     25         // define 4 points that form two lines that often cross; one line is (a, b) (c, d)
     26         SkVector v = {SkIntToScalar(a - c), SkIntToScalar(b - d)};
     27         SkPoint midA = { SkIntToScalar(a * state.fA + c * (6 - state.fA)) / 6,
     28                          SkIntToScalar(b * state.fA + d * (6 - state.fA)) / 6 };
     29         SkPoint midB = { SkIntToScalar(a * state.fB + c * (6 - state.fB)) / 6,
     30                          SkIntToScalar(b * state.fB + d * (6 - state.fB)) / 6 };
     31         SkPoint endC = { midA.fX + v.fY * state.fC / 3,
     32                           midA.fY + v.fX * state.fC / 3 };
     33         SkPoint endD = { midB.fX - v.fY * state.fD / 3,
     34                           midB.fY + v.fX * state.fD / 3 };
     35         SkPath pathA, pathB;
     36         if (progress) {
     37             char* str = pathStr;
     38             str += sprintf(str, "    path.moveTo(%d,%d);\n", a, b);
     39             str += sprintf(str, "    path.cubicTo(%d,%d, %1.9gf,%1.9gf, %1.9gf,%1.9gf);\n",
     40                     c, d, endC.fX, endC.fY, endD.fX, endD.fY);
     41             str += sprintf(str, "    path.close();\n");
     42             str += sprintf(str, "    pathB.moveTo(%d,%d);\n", c, d);
     43             str += sprintf(str, "    pathB.cubicTo(%1.9gf,%1.9gf, %1.9gf,%1.9gf, %d,%d);\n",
     44                     endC.fX, endC.fY, endD.fX, endD.fY, a, b);
     45             str += sprintf(str, "    pathB.close();\n");
     46         }
     47         pathA.moveTo(SkIntToScalar(a), SkIntToScalar(b));
     48         pathA.cubicTo(SkIntToScalar(c), SkIntToScalar(d), endC.fX, endC.fY, endD.fX, endD.fY);
     49         pathA.close();
     50         pathB.moveTo(SkIntToScalar(c), SkIntToScalar(d));
     51         pathB.cubicTo(endC.fX, endC.fY, endD.fX, endD.fY, SkIntToScalar(a), SkIntToScalar(b));
     52         pathB.close();
     53 //        SkDebugf("%s\n", pathStr);
     54         if (progress) {
     55             outputProgress(state.fPathStr, pathStr, kIntersect_PathOp);
     56         }
     57         testThreadedPathOp(state.fReporter, pathA, pathB, kIntersect_PathOp, "loops");
     58                 }
     59             }
     60         }
     61     }
     62 }
     63 
     64 DEF_TEST(PathOpsOpLoopsThreaded, reporter) {
     65     if (!FLAGS_runFail) {
     66         return;
     67     }
     68     initializeTests(reporter, "cubicOp");
     69     PathOpsThreadedTestRunner testRunner(reporter);
     70     for (int a = 0; a < 6; ++a) {  // outermost
     71         for (int b = a + 1; b < 7; ++b) {
     72             for (int c = 0 ; c < 6; ++c) {
     73                 for (int d = c + 1; d < 7; ++d) {
     74                     *testRunner.fRunnables.append() = SkNEW_ARGS(PathOpsThreadedRunnable,
     75                             (&testOpLoopsMain, a, b, c, d, &testRunner));
     76                 }
     77             }
     78             if (!reporter->allowExtendedTest()) goto finish;
     79         }
     80     }
     81 finish:
     82     testRunner.render();
     83     ShowTestArray();
     84 }
     85 
     86 DEF_TEST(PathOpsOpLoops, reporter) {
     87     if (!FLAGS_runFail) {
     88         return;
     89     }
     90     initializeTests(reporter, "cubicOp");
     91     PathOpsThreadState state;
     92     state.fReporter = reporter;
     93     SkBitmap bitmap;
     94     state.fBitmap = &bitmap;
     95     char pathStr[PATH_STR_SIZE];
     96     state.fPathStr = pathStr;
     97     for (state.fA = 0; state.fA < 6; ++state.fA) {  // outermost
     98         for (state.fB = state.fA + 1; state.fB < 7; ++state.fB) {
     99             for (state.fC = 0 ; state.fC < 6; ++state.fC) {
    100                 for (state.fD = state.fC + 1; state.fD < 7; ++state.fD) {
    101                     testOpLoopsMain(&state);
    102                 }
    103             }
    104             if (!reporter->allowExtendedTest()) goto finish;
    105         }
    106     }
    107 finish:
    108     ShowTestArray();
    109 }
    110