diff options
author | caryclark <caryclark@google.com> | 2016-10-06 11:46:25 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-10-06 11:46:25 -0700 |
commit | 8f1864386734cfa7650a5576ba453745a407ade2 (patch) | |
tree | 413e5df77a872a26e02dc4b64ef191e6df4948f1 /tests | |
parent | 33cbfd75afdd383770bb6253c06ba819a2481a35 (diff) |
remove sprintf
Most uses of sprintf are
in pathops testing.
Replace them with
SkString::appendf
and replace the remaining
with snprintf
R=scroggo@google.com
BUG=skia:2716
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2391133005
Review-Url: https://codereview.chromium.org/2391133005
Diffstat (limited to 'tests')
-rw-r--r-- | tests/PathOpsOpCircleThreadedTest.cpp | 58 | ||||
-rw-r--r-- | tests/PathOpsOpCubicThreadedTest.cpp | 40 | ||||
-rw-r--r-- | tests/PathOpsOpLoopThreadedTest.cpp | 71 | ||||
-rw-r--r-- | tests/PathOpsOpRectThreadedTest.cpp | 67 | ||||
-rw-r--r-- | tests/PathOpsQuadLineIntersectionThreadedTest.cpp | 13 | ||||
-rw-r--r-- | tests/PathOpsSimplifyDegenerateThreadedTest.cpp | 36 | ||||
-rw-r--r-- | tests/PathOpsSimplifyQuadThreadedTest.cpp | 47 | ||||
-rw-r--r-- | tests/PathOpsSimplifyQuadralateralsThreadedTest.cpp | 48 | ||||
-rw-r--r-- | tests/PathOpsSimplifyRectThreadedTest.cpp | 36 | ||||
-rw-r--r-- | tests/PathOpsSimplifyTrianglesThreadedTest.cpp | 36 |
10 files changed, 213 insertions, 239 deletions
diff --git a/tests/PathOpsOpCircleThreadedTest.cpp b/tests/PathOpsOpCircleThreadedTest.cpp index fac767720b..40a02c111e 100644 --- a/tests/PathOpsOpCircleThreadedTest.cpp +++ b/tests/PathOpsOpCircleThreadedTest.cpp @@ -6,16 +6,14 @@ */ #include "PathOpsExtendedTest.h" #include "PathOpsThreadedCommon.h" +#include "SkString.h" + +static int loopNo = 4; static void testOpCirclesMain(PathOpsThreadState* data) { SkASSERT(data); PathOpsThreadState& state = *data; - char pathStr[1024]; - bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter? - if (progress) { - sk_bzero(pathStr, sizeof(pathStr)); - } - + SkString pathStr; for (int a = 0 ; a < 6; ++a) { for (int b = a + 1 ; b < 7; ++b) { for (int c = 0 ; c < 6; ++c) { @@ -23,26 +21,6 @@ static void testOpCirclesMain(PathOpsThreadState* data) { for (int e = SkPath::kWinding_FillType ; e <= SkPath::kEvenOdd_FillType; ++e) { for (int f = SkPath::kWinding_FillType ; f <= SkPath::kEvenOdd_FillType; ++f) { SkPath pathA, pathB; - if (progress) { - char* str = pathStr; - const int loopNo = 4; - str += sprintf(str, "static void circlesOp%d(skiatest::Reporter* reporter," - " const char* filename) {\n", loopNo); - str += sprintf(str, " SkPath path, pathB;\n"); - str += sprintf(str, " path.setFillType(SkPath::k%s_FillType);\n", - e == SkPath::kWinding_FillType ? "Winding" : e == SkPath::kEvenOdd_FillType - ? "EvenOdd" : "?UNDEFINED"); - str += sprintf(str, " path.addCircle(%d, %d, %d, %s);\n", state.fA, state.fB, - state.fC, state.fD ? "SkPath::kCW_Direction" : "SkPath::kCCW_Direction"); - str += sprintf(str, " pathB.setFillType(SkPath::k%s_FillType);\n", - f == SkPath::kWinding_FillType ? "Winding" : f == SkPath::kEvenOdd_FillType - ? "EvenOdd" : "?UNDEFINED"); - str += sprintf(str, " pathB.addCircle(%d, %d, %d, %s);\n", a, b, - c, d ? "SkPath::kCW_Direction" : "SkPath::kCCW_Direction"); - str += sprintf(str, " testPathOp(reporter, path, pathB, kDifference_SkPathOp," - " filename);\n"); - str += sprintf(str, "}\n"); - } pathA.setFillType((SkPath::FillType) e); pathA.addCircle(SkIntToScalar(state.fA), SkIntToScalar(state.fB), SkIntToScalar(state.fC), state.fD ? SkPath::kCW_Direction : SkPath::kCCW_Direction); @@ -50,13 +28,35 @@ static void testOpCirclesMain(PathOpsThreadState* data) { pathB.addCircle(SkIntToScalar(a), SkIntToScalar(b), SkIntToScalar(c), d ? SkPath::kCW_Direction : SkPath::kCCW_Direction); for (int op = 0 ; op <= kXOR_SkPathOp; ++op) { - if (progress) { - outputProgress(state.fPathStr, pathStr, (SkPathOp) op); + if (state.fReporter->verbose()) { + pathStr.printf("static void circlesOp%d(skiatest::Reporter* reporter," + " const char* filename) {\n", loopNo); + pathStr.appendf(" SkPath path, pathB;\n"); + pathStr.appendf(" path.setFillType(SkPath::k%s_FillType);\n", + e == SkPath::kWinding_FillType ? "Winding" : e == SkPath::kEvenOdd_FillType + ? "EvenOdd" : "?UNDEFINED"); + pathStr.appendf(" path.addCircle(%d, %d, %d, %s);\n", state.fA, state.fB, + state.fC, state.fD ? "SkPath::kCW_Direction" : "SkPath::kCCW_Direction"); + pathStr.appendf(" pathB.setFillType(SkPath::k%s_FillType);\n", + f == SkPath::kWinding_FillType ? "Winding" : f == SkPath::kEvenOdd_FillType + ? "EvenOdd" : "?UNDEFINED"); + pathStr.appendf(" pathB.addCircle(%d, %d, %d, %s);\n", a, b, + c, d ? "SkPath::kCW_Direction" : "SkPath::kCCW_Direction"); + pathStr.appendf(" testPathOp(reporter, path, pathB, %s, filename);\n", + SkPathOpsDebug::OpStr((SkPathOp) op)); + pathStr.appendf("}\n"); + outputProgress(state.fPathStr, pathStr.c_str(), (SkPathOp) op); + } + if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, "circles")) { + if (state.fReporter->verbose()) { + ++loopNo; + goto skipToNext; + } } - testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, "circles"); } } } +skipToNext: ; } } } diff --git a/tests/PathOpsOpCubicThreadedTest.cpp b/tests/PathOpsOpCubicThreadedTest.cpp index 2c0c3d372d..e76eb06477 100644 --- a/tests/PathOpsOpCubicThreadedTest.cpp +++ b/tests/PathOpsOpCubicThreadedTest.cpp @@ -6,6 +6,7 @@ */ #include "PathOpsExtendedTest.h" #include "PathOpsThreadedCommon.h" +#include "SkString.h" static int loopNo = 158; @@ -15,11 +16,7 @@ static void testOpCubicsMain(PathOpsThreadState* data) { #endif SkASSERT(data); PathOpsThreadState& state = *data; - char pathStr[1024]; - bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter? - if (progress) { - sk_bzero(pathStr, sizeof(pathStr)); - } + SkString pathStr; for (int a = 0 ; a < 6; ++a) { for (int b = a + 1 ; b < 7; ++b) { for (int c = 0 ; c < 6; ++c) { @@ -38,34 +35,31 @@ static void testOpCubicsMain(PathOpsThreadState* data) { SkIntToScalar(state.fA), SkIntToScalar(state.fD), SkIntToScalar(state.fC)); pathB.close(); for (int op = 0 ; op <= kXOR_SkPathOp; ++op) { - if (progress) { - outputProgress(state.fPathStr, pathStr, (SkPathOp) op); - } - if (progress) { - char* str = pathStr; - str += sprintf(str, "static void cubicOp%d(skiatest::Reporter* reporter," + if (state.fReporter->verbose()) { + pathStr.printf("static void cubicOp%d(skiatest::Reporter* reporter," " const char* filename) {\n", loopNo); - str += sprintf(str, " SkPath path, pathB;\n"); - str += sprintf(str, " path.setFillType(SkPath::k%s_FillType);\n", + pathStr.appendf(" SkPath path, pathB;\n"); + pathStr.appendf(" path.setFillType(SkPath::k%s_FillType);\n", e == SkPath::kWinding_FillType ? "Winding" : e == SkPath::kEvenOdd_FillType ? "EvenOdd" : "?UNDEFINED"); - str += sprintf(str, " path.moveTo(%d,%d);\n", state.fA, state.fB); - str += sprintf(str, " path.cubicTo(%d,%d, %d,%d, %d,%d);\n", state.fC, state.fD, + pathStr.appendf(" path.moveTo(%d,%d);\n", state.fA, state.fB); + pathStr.appendf(" path.cubicTo(%d,%d, %d,%d, %d,%d);\n", state.fC, state.fD, b, a, d, c); - str += sprintf(str, " path.close();\n"); - str += sprintf(str, " pathB.setFillType(SkPath::k%s_FillType);\n", + pathStr.appendf(" path.close();\n"); + pathStr.appendf(" pathB.setFillType(SkPath::k%s_FillType);\n", f == SkPath::kWinding_FillType ? "Winding" : f == SkPath::kEvenOdd_FillType ? "EvenOdd" : "?UNDEFINED"); - str += sprintf(str, " pathB.moveTo(%d,%d);\n", a, b); - str += sprintf(str, " pathB.cubicTo(%d,%d, %d,%d, %d,%d);\n", c, d, + pathStr.appendf(" pathB.moveTo(%d,%d);\n", a, b); + pathStr.appendf(" pathB.cubicTo(%d,%d, %d,%d, %d,%d);\n", c, d, state.fB, state.fA, state.fD, state.fC); - str += sprintf(str, " pathB.close();\n"); - str += sprintf(str, " testPathOp(reporter, path, pathB, %s, filename);\n", + pathStr.appendf(" pathB.close();\n"); + pathStr.appendf(" testPathOp(reporter, path, pathB, %s, filename);\n", SkPathOpsDebug::OpStr((SkPathOp) op)); - str += sprintf(str, "}\n"); + pathStr.appendf("}\n"); + outputProgress(state.fPathStr, pathStr.c_str(), (SkPathOp) op); } if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, "cubics")) { - if (progress) { + if (state.fReporter->verbose()) { ++loopNo; goto skipToNext; } diff --git a/tests/PathOpsOpLoopThreadedTest.cpp b/tests/PathOpsOpLoopThreadedTest.cpp index 56c5068d7a..3854f90b08 100644 --- a/tests/PathOpsOpLoopThreadedTest.cpp +++ b/tests/PathOpsOpLoopThreadedTest.cpp @@ -6,23 +6,24 @@ */ #include "PathOpsExtendedTest.h" #include "PathOpsThreadedCommon.h" +#include "SkString.h" -static int add_point(char* str, SkScalar x, SkScalar y) { - int result; +static int loopNo = 17; + +static void add_point(SkString* str, SkScalar x, SkScalar y) { int asInt = SkScalarRoundToInt(x); if (SkIntToScalar(asInt) == x) { - result = sprintf(str, "%d", asInt); + str->appendf("%d", asInt); } else { - result = sprintf(str, "%1.9gf", x); + str->appendf("%1.9gf", x); } - result += sprintf(str + result, ","); + str->appendf(","); asInt = SkScalarRoundToInt(y); if (SkIntToScalar(asInt) == y) { - result += sprintf(str + result, "%d", asInt); + str->appendf("%d", asInt); } else { - result += sprintf(str + result, "%1.9gf", y); + str->appendf("%1.9gf", y); } - return result; } static void testOpLoopsMain(PathOpsThreadState* data) { @@ -31,11 +32,7 @@ static void testOpLoopsMain(PathOpsThreadState* data) { #endif SkASSERT(data); PathOpsThreadState& state = *data; - char pathStr[1024]; // gdb: set print elements 400 - bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter? - if (progress) { - sk_bzero(pathStr, sizeof(pathStr)); - } + SkString pathStr; for (int a = 0 ; a < 6; ++a) { for (int b = a + 1 ; b < 7; ++b) { for (int c = 0 ; c < 6; ++c) { @@ -51,30 +48,6 @@ static void testOpLoopsMain(PathOpsThreadState* data) { SkPoint endD = { midB.fX - v.fY * state.fD / 3, midB.fY + v.fX * state.fD / 3 }; SkPath pathA, pathB; - if (progress) { - char* str = pathStr; - const int loopNo = 17; - str += sprintf(str, "static void loop%d(skiatest::Reporter* reporter," - " const char* filename) {\n", loopNo); - str += sprintf(str, " SkPath path, pathB;\n"); - str += sprintf(str, " path.moveTo(%d,%d);\n", a, b); - str += sprintf(str, " path.cubicTo(%d,%d, ", c, d); - str += add_point(str, endC.fX, endC.fY); - str += sprintf(str, ", "); - str += add_point(str, endD.fX, endD.fY); - str += sprintf(str, ");\n"); - str += sprintf(str, " path.close();\n"); - str += sprintf(str, " pathB.moveTo(%d,%d);\n", c, d); - str += sprintf(str, " pathB.cubicTo("); - str += add_point(str, endC.fX, endC.fY); - str += sprintf(str, ", "); - str += add_point(str, endD.fX, endD.fY); - str += sprintf(str, ", %d,%d);\n", a, b); - str += sprintf(str, " pathB.close();\n"); - str += sprintf(str, " testPathOp(reporter, path, pathB, kIntersect_SkPathOp," - " filename);\n"); - str += sprintf(str, "}\n"); - } pathA.moveTo(SkIntToScalar(a), SkIntToScalar(b)); pathA.cubicTo(SkIntToScalar(c), SkIntToScalar(d), endC.fX, endC.fY, endD.fX, endD.fY); pathA.close(); @@ -82,8 +55,28 @@ static void testOpLoopsMain(PathOpsThreadState* data) { pathB.cubicTo(endC.fX, endC.fY, endD.fX, endD.fY, SkIntToScalar(a), SkIntToScalar(b)); pathB.close(); // SkDebugf("%s\n", pathStr); - if (progress) { - outputProgress(state.fPathStr, pathStr, kIntersect_SkPathOp); + if (state.fReporter->verbose()) { + pathStr.printf("static void loop%d(skiatest::Reporter* reporter," + " const char* filename) {\n", loopNo); + pathStr.appendf(" SkPath path, pathB;\n"); + pathStr.appendf(" path.moveTo(%d,%d);\n", a, b); + pathStr.appendf(" path.cubicTo(%d,%d, ", c, d); + add_point(&pathStr, endC.fX, endC.fY); + pathStr.appendf(", "); + add_point(&pathStr, endD.fX, endD.fY); + pathStr.appendf(");\n"); + pathStr.appendf(" path.close();\n"); + pathStr.appendf(" pathB.moveTo(%d,%d);\n", c, d); + pathStr.appendf(" pathB.cubicTo("); + add_point(&pathStr, endC.fX, endC.fY); + pathStr.appendf(", "); + add_point(&pathStr, endD.fX, endD.fY); + pathStr.appendf(", %d,%d);\n", a, b); + pathStr.appendf(" pathB.close();\n"); + pathStr.appendf(" testPathOp(reporter, path, pathB, kIntersect_SkPathOp," + " filename);\n"); + pathStr.appendf("}\n"); + outputProgress(state.fPathStr, pathStr.c_str(), kIntersect_SkPathOp); } testPathOp(state.fReporter, pathA, pathB, kIntersect_SkPathOp, "loops"); } diff --git a/tests/PathOpsOpRectThreadedTest.cpp b/tests/PathOpsOpRectThreadedTest.cpp index 4d672e4857..57615727f8 100644 --- a/tests/PathOpsOpRectThreadedTest.cpp +++ b/tests/PathOpsOpRectThreadedTest.cpp @@ -6,6 +6,7 @@ */ #include "PathOpsExtendedTest.h" #include "PathOpsThreadedCommon.h" +#include "SkString.h" // four rects, of four sizes // for 3 smaller sizes, tall, wide @@ -14,46 +15,19 @@ // not included, square, tall, wide (2 bits) // cw or ccw (1 bit) +static int loopNo = 6; + static void testPathOpsRectsMain(PathOpsThreadState* data) { SkASSERT(data); PathOpsThreadState& state = *data; - char pathStr[1024]; // gdb: set print elements 400 - bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter? - if (progress) { - sk_bzero(pathStr, sizeof(pathStr)); - } + SkString pathStr; for (int a = 0 ; a < 6; ++a) { for (int b = a + 1 ; b < 7; ++b) { for (int c = 0 ; c < 6; ++c) { for (int d = c + 1 ; d < 7; ++d) { for (int e = SkPath::kWinding_FillType ; e <= SkPath::kEvenOdd_FillType; ++e) { for (int f = SkPath::kWinding_FillType ; f <= SkPath::kEvenOdd_FillType; ++f) { - static int testNum = 6; - if (progress) { - char* str = pathStr; - str += sprintf(str, - "static void rects%d(skiatest::Reporter* reporter, const char* filename) {\n", - testNum); - str += sprintf(str, " SkPath path, pathB;"); - str += sprintf(str, " path.setFillType(SkPath::k%s_FillType);\n", - e == SkPath::kWinding_FillType ? "Winding" : e == SkPath::kEvenOdd_FillType - ? "EvenOdd" : "?UNDEFINED"); - str += sprintf(str, " path.addRect(%d, %d, %d, %d," - " SkPath::kCW_Direction);\n", state.fA, state.fA, state.fB, state.fB); - str += sprintf(str, " path.addRect(%d, %d, %d, %d," - " SkPath::kCW_Direction);\n", state.fC, state.fC, state.fD, state.fD); - str += sprintf(str, " pathB.setFillType(SkPath::k%s_FillType);\n", - f == SkPath::kWinding_FillType ? "Winding" : f == SkPath::kEvenOdd_FillType - ? "EvenOdd" : "?UNDEFINED"); - str += sprintf(str, " pathB.addRect(%d, %d, %d, %d," - " SkPath::kCW_Direction);\n", a, a, b, b); - str += sprintf(str, " pathB.addRect(%d, %d, %d, %d," - " SkPath::kCW_Direction);\n", c, c, d, d); - str += sprintf(str, - " testPathOp(reporter, path, pathB, kDifference_SkPathOp, filename);\n"); - str += sprintf(str, "}\n\n"); - } SkPath pathA, pathB; pathA.setFillType((SkPath::FillType) e); pathA.addRect(SkIntToScalar(state.fA), SkIntToScalar(state.fA), SkIntToScalar(state.fB), @@ -68,13 +42,40 @@ static void testPathOpsRectsMain(PathOpsThreadState* data) SkIntToScalar(d), SkPath::kCW_Direction); pathB.close(); for (int op = 0 ; op <= kXOR_SkPathOp; ++op) { - if (progress) { - outputProgress(state.fPathStr, pathStr, (SkPathOp) op); + if (state.fReporter->verbose()) { + pathStr.printf( + "static void rects%d(skiatest::Reporter* reporter," + "const char* filename) {\n", loopNo); + pathStr.appendf(" SkPath path, pathB;"); + pathStr.appendf(" path.setFillType(SkPath::k%s_FillType);\n", + e == SkPath::kWinding_FillType ? "Winding" : e == SkPath::kEvenOdd_FillType + ? "EvenOdd" : "?UNDEFINED"); + pathStr.appendf(" path.addRect(%d, %d, %d, %d," + " SkPath::kCW_Direction);\n", state.fA, state.fA, state.fB, state.fB); + pathStr.appendf(" path.addRect(%d, %d, %d, %d," + " SkPath::kCW_Direction);\n", state.fC, state.fC, state.fD, state.fD); + pathStr.appendf(" pathB.setFillType(SkPath::k%s_FillType);\n", + f == SkPath::kWinding_FillType ? "Winding" : f == SkPath::kEvenOdd_FillType + ? "EvenOdd" : "?UNDEFINED"); + pathStr.appendf(" pathB.addRect(%d, %d, %d, %d," + " SkPath::kCW_Direction);\n", a, a, b, b); + pathStr.appendf(" pathB.addRect(%d, %d, %d, %d," + " SkPath::kCW_Direction);\n", c, c, d, d); + pathStr.appendf(" testPathOp(reporter, path, pathB, %s, filename);\n", + SkPathOpsDebug::OpStr((SkPathOp) op)); + pathStr.appendf("}\n\n"); + outputProgress(state.fPathStr, pathStr.c_str(), (SkPathOp) op); + } + if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, "rects")) { + if (state.fReporter->verbose()) { + ++loopNo; + goto skipToNext; + } } - testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, "rects"); } } } +skipToNext: ; } } } diff --git a/tests/PathOpsQuadLineIntersectionThreadedTest.cpp b/tests/PathOpsQuadLineIntersectionThreadedTest.cpp index 9ecc1f052f..7766cfe028 100644 --- a/tests/PathOpsQuadLineIntersectionThreadedTest.cpp +++ b/tests/PathOpsQuadLineIntersectionThreadedTest.cpp @@ -10,6 +10,7 @@ #include "SkPathOpsLine.h" #include "SkPathOpsQuad.h" #include "SkReduceOrder.h" +#include "SkString.h" static int doIntersect(SkIntersections& intersections, const SkDQuad& quad, const SkDLine& line, bool& flipped) { @@ -40,14 +41,12 @@ static int doIntersect(SkIntersections& intersections, const SkDQuad& quad, cons static void testLineIntersect(skiatest::Reporter* reporter, const SkDQuad& quad, const SkDLine& line, const double x, const double y) { - char pathStr[1024]; - sk_bzero(pathStr, sizeof(pathStr)); - char* str = pathStr; - str += sprintf(str, " path.moveTo(%1.9g, %1.9g);\n", quad[0].fX, quad[0].fY); - str += sprintf(str, " path.quadTo(%1.9g, %1.9g, %1.9g, %1.9g);\n", quad[1].fX, + SkString pathStr; + pathStr.appendf(" path.moveTo(%1.9g, %1.9g);\n", quad[0].fX, quad[0].fY); + pathStr.appendf(" path.quadTo(%1.9g, %1.9g, %1.9g, %1.9g);\n", quad[1].fX, quad[1].fY, quad[2].fX, quad[2].fY); - str += sprintf(str, " path.moveTo(%1.9g, %1.9g);\n", line[0].fX, line[0].fY); - str += sprintf(str, " path.lineTo(%1.9g, %1.9g);\n", line[1].fX, line[1].fY); + pathStr.appendf(" path.moveTo(%1.9g, %1.9g);\n", line[0].fX, line[0].fY); + pathStr.appendf(" path.lineTo(%1.9g, %1.9g);\n", line[1].fX, line[1].fY); SkIntersections intersections; bool flipped = false; diff --git a/tests/PathOpsSimplifyDegenerateThreadedTest.cpp b/tests/PathOpsSimplifyDegenerateThreadedTest.cpp index 99a54d8fb6..71933df8c3 100644 --- a/tests/PathOpsSimplifyDegenerateThreadedTest.cpp +++ b/tests/PathOpsSimplifyDegenerateThreadedTest.cpp @@ -6,15 +6,11 @@ */ #include "PathOpsExtendedTest.h" #include "PathOpsThreadedCommon.h" +#include "SkString.h" static void testSimplifyDegeneratesMain(PathOpsThreadState* data) { SkASSERT(data); PathOpsThreadState& state = *data; - char pathStr[1024]; - bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter? - if (progress) { - sk_bzero(pathStr, sizeof(pathStr)); - } int ax = state.fA & 0x03; int ay = state.fA >> 2; int bx = state.fB & 0x03; @@ -34,6 +30,7 @@ static void testSimplifyDegeneratesMain(PathOpsThreadState* data) { != (ey - dy) * (fx - dx)) { continue; } + SkString pathStr; SkPath path, out; path.setFillType(SkPath::kWinding_FillType); path.moveTo(SkIntToScalar(ax), SkIntToScalar(ay)); @@ -44,24 +41,23 @@ static void testSimplifyDegeneratesMain(PathOpsThreadState* data) { path.lineTo(SkIntToScalar(ex), SkIntToScalar(ey)); path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy)); path.close(); - if (progress) { - char* str = pathStr; - str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay); - str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by); - str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy); - str += sprintf(str, " path.close();\n"); - str += sprintf(str, " path.moveTo(%d, %d);\n", dx, dy); - str += sprintf(str, " path.lineTo(%d, %d);\n", ex, ey); - str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy); - str += sprintf(str, " path.close();\n"); - outputProgress(state.fPathStr, pathStr, SkPath::kWinding_FillType); + if (state.fReporter->verbose()) { + pathStr.appendf(" path.moveTo(%d, %d);\n", ax, ay); + pathStr.appendf(" path.lineTo(%d, %d);\n", bx, by); + pathStr.appendf(" path.lineTo(%d, %d);\n", cx, cy); + pathStr.appendf(" path.close();\n"); + pathStr.appendf(" path.moveTo(%d, %d);\n", dx, dy); + pathStr.appendf(" path.lineTo(%d, %d);\n", ex, ey); + pathStr.appendf(" path.lineTo(%d, %d);\n", fx, fy); + pathStr.appendf(" path.close();\n"); + outputProgress(state.fPathStr, pathStr.c_str(), SkPath::kWinding_FillType); } - testSimplify(path, false, out, state, pathStr); + testSimplify(path, false, out, state, pathStr.c_str()); path.setFillType(SkPath::kEvenOdd_FillType); - if (progress) { - outputProgress(state.fPathStr, pathStr, SkPath::kEvenOdd_FillType); + if (state.fReporter->verbose()) { + outputProgress(state.fPathStr, pathStr.c_str(), SkPath::kEvenOdd_FillType); } - testSimplify(path, true, out, state, pathStr); + testSimplify(path, true, out, state, pathStr.c_str()); } } } diff --git a/tests/PathOpsSimplifyQuadThreadedTest.cpp b/tests/PathOpsSimplifyQuadThreadedTest.cpp index 9e9c0103d5..bca8d5a8e4 100644 --- a/tests/PathOpsSimplifyQuadThreadedTest.cpp +++ b/tests/PathOpsSimplifyQuadThreadedTest.cpp @@ -6,16 +6,15 @@ */ #include "PathOpsExtendedTest.h" #include "PathOpsThreadedCommon.h" +#include "SkString.h" + +static int quadTest = 66; static void testSimplifyQuadsMain(PathOpsThreadState* data) { SkASSERT(data); PathOpsThreadState& state = *data; - char pathStr[1024]; - bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter? - if (progress) { - sk_bzero(pathStr, sizeof(pathStr)); - } + SkString pathStr; int ax = state.fA & 0x03; int ay = state.fA >> 2; int bx = state.fB & 0x03; @@ -48,30 +47,28 @@ static void testSimplifyQuadsMain(PathOpsThreadState* data) path.quadTo(SkIntToScalar(gx), SkIntToScalar(gy), SkIntToScalar(hx), SkIntToScalar(hy)); path.close(); - if (progress) { - static int quadTest = 66; - char* str = pathStr; - str += sprintf(str, "static void testQuads%d(skiatest::Reporter* reporter," + if (state.fReporter->verbose()) { + pathStr.printf("static void testQuads%d(skiatest::Reporter* reporter," "const char* filename) {\n", quadTest); - str += sprintf(str, " SkPath path;\n"); - str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay); - str += sprintf(str, " path.quadTo(%d, %d, %d, %d);\n", bx, by, cx, cy); - str += sprintf(str, " path.lineTo(%d, %d);\n", dx, dy); - str += sprintf(str, " path.close();\n"); - str += sprintf(str, " path.moveTo(%d, %d);\n", ex, ey); - str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy); - str += sprintf(str, " path.quadTo(%d, %d, %d, %d);\n", gx, gy, hx, hy); - str += sprintf(str, " path.close();\n"); - str += sprintf(str, " testSimplify(reporter, path, filename);\n"); - str += sprintf(str, "}\n"); - outputProgress(state.fPathStr, pathStr, SkPath::kWinding_FillType); + pathStr.appendf(" SkPath path;\n"); + pathStr.appendf(" path.moveTo(%d, %d);\n", ax, ay); + pathStr.appendf(" path.quadTo(%d, %d, %d, %d);\n", bx, by, cx, cy); + pathStr.appendf(" path.lineTo(%d, %d);\n", dx, dy); + pathStr.appendf(" path.close();\n"); + pathStr.appendf(" path.moveTo(%d, %d);\n", ex, ey); + pathStr.appendf(" path.lineTo(%d, %d);\n", fx, fy); + pathStr.appendf(" path.quadTo(%d, %d, %d, %d);\n", gx, gy, hx, hy); + pathStr.appendf(" path.close();\n"); + pathStr.appendf(" testSimplify(reporter, path, filename);\n"); + pathStr.appendf("}\n"); + outputProgress(state.fPathStr, pathStr.c_str(), SkPath::kWinding_FillType); } - testSimplify(path, false, out, state, pathStr); + testSimplify(path, false, out, state, pathStr.c_str()); path.setFillType(SkPath::kEvenOdd_FillType); - if (progress) { - outputProgress(state.fPathStr, pathStr, SkPath::kEvenOdd_FillType); + if (state.fReporter->verbose()) { + outputProgress(state.fPathStr, pathStr.c_str(), SkPath::kEvenOdd_FillType); } - testSimplify(path, true, out, state, pathStr); + testSimplify(path, true, out, state, pathStr.c_str()); } } } diff --git a/tests/PathOpsSimplifyQuadralateralsThreadedTest.cpp b/tests/PathOpsSimplifyQuadralateralsThreadedTest.cpp index f2c1dfc990..1ea55e24c0 100644 --- a/tests/PathOpsSimplifyQuadralateralsThreadedTest.cpp +++ b/tests/PathOpsSimplifyQuadralateralsThreadedTest.cpp @@ -6,16 +6,15 @@ */ #include "PathOpsExtendedTest.h" #include "PathOpsThreadedCommon.h" +#include "SkString.h" + +static int loopNo = 1; static void testSimplifyQuadralateralsMain(PathOpsThreadState* data) { SkASSERT(data); PathOpsThreadState& state = *data; - char pathStr[1024]; - bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter? - if (progress) { - sk_bzero(pathStr, sizeof(pathStr)); - } + SkString pathStr; int ax = state.fA & 0x03; int ay = state.fA >> 2; int bx = state.fB & 0x03; @@ -48,27 +47,30 @@ static void testSimplifyQuadralateralsMain(PathOpsThreadState* data) path.lineTo(SkIntToScalar(gx), SkIntToScalar(gy)); path.lineTo(SkIntToScalar(hx), SkIntToScalar(hy)); path.close(); - if (progress) { - // gdb: set print elements 400 - char* str = pathStr; - str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay); - str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by); - str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy); - str += sprintf(str, " path.lineTo(%d, %d);\n", dx, dy); - str += sprintf(str, " path.close();\n"); - str += sprintf(str, " path.moveTo(%d, %d);\n", ex, ey); - str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy); - str += sprintf(str, " path.lineTo(%d, %d);\n", gx, gy); - str += sprintf(str, " path.lineTo(%d, %d);\n", hx, hy); - str += sprintf(str, " path.close();\n"); - outputProgress(state.fPathStr, pathStr, SkPath::kWinding_FillType); + if (state.fReporter->verbose()) { + pathStr.printf("static void quadralateralSimplify%d(skiatest::Reporter*" + "reporter, const char* filename) {\n", loopNo); + pathStr.appendf(" SkPath path;\n"); + pathStr.appendf(" path.moveTo(%d, %d);\n", ax, ay); + pathStr.appendf(" path.lineTo(%d, %d);\n", bx, by); + pathStr.appendf(" path.lineTo(%d, %d);\n", cx, cy); + pathStr.appendf(" path.lineTo(%d, %d);\n", dx, dy); + pathStr.appendf(" path.close();\n"); + pathStr.appendf(" path.moveTo(%d, %d);\n", ex, ey); + pathStr.appendf(" path.lineTo(%d, %d);\n", fx, fy); + pathStr.appendf(" path.lineTo(%d, %d);\n", gx, gy); + pathStr.appendf(" path.lineTo(%d, %d);\n", hx, hy); + pathStr.appendf(" path.close();\n"); + pathStr.appendf(" testPathSimplify(reporter, path, filename);\n"); + pathStr.appendf("}\n"); + outputProgress(state.fPathStr, pathStr.c_str(), SkPath::kWinding_FillType); } - testSimplify(path, false, out, state, pathStr); + testSimplify(path, false, out, state, pathStr.c_str()); path.setFillType(SkPath::kEvenOdd_FillType); - if (progress) { - outputProgress(state.fPathStr, pathStr, SkPath::kEvenOdd_FillType); + if (state.fReporter->verbose()) { + outputProgress(state.fPathStr, pathStr.c_str(), SkPath::kEvenOdd_FillType); } - testSimplify(path, true, out, state, pathStr); + testSimplify(path, true, out, state, pathStr.c_str()); } } } diff --git a/tests/PathOpsSimplifyRectThreadedTest.cpp b/tests/PathOpsSimplifyRectThreadedTest.cpp index 7289440e0e..4ddc6f7f34 100644 --- a/tests/PathOpsSimplifyRectThreadedTest.cpp +++ b/tests/PathOpsSimplifyRectThreadedTest.cpp @@ -6,6 +6,7 @@ */ #include "PathOpsExtendedTest.h" #include "PathOpsThreadedCommon.h" +#include "SkString.h" // four rects, of four sizes // for 3 smaller sizes, tall, wide @@ -18,11 +19,6 @@ static void testSimplify4x4RectsMain(PathOpsThreadState* data) { SkASSERT(data); PathOpsThreadState& state = *data; - char pathStr[1024]; // gdb: set print elements 400 - bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter? - if (progress) { - sk_bzero(pathStr, sizeof(pathStr)); - } int aShape = state.fA & 0x03; SkPath::Direction aCW = state.fA >> 2 ? SkPath::kCCW_Direction : SkPath::kCW_Direction; int bShape = state.fB & 0x03; @@ -39,8 +35,8 @@ static void testSimplify4x4RectsMain(PathOpsThreadState* data) for (int cYAlign = 0; cYAlign < 5; ++cYAlign) { for (int dXAlign = 0; dXAlign < 5; ++dXAlign) { for (int dYAlign = 0; dYAlign < 5; ++dYAlign) { + SkString pathStr; SkPath path, out; - char* str = pathStr; path.setFillType(SkPath::kWinding_FillType); int l SK_INIT_TO_AVOID_WARNING, t SK_INIT_TO_AVOID_WARNING, r SK_INIT_TO_AVOID_WARNING, b SK_INIT_TO_AVOID_WARNING; @@ -67,8 +63,8 @@ static void testSimplify4x4RectsMain(PathOpsThreadState* data) } path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b), aCW); - if (progress) { - str += sprintf(str, " path.addRect(%d, %d, %d, %d," + if (state.fReporter->verbose()) { + pathStr.appendf(" path.addRect(%d, %d, %d, %d," " SkPath::kC%sW_Direction);\n", l, t, r, b, aCW ? "C" : ""); } } else { @@ -98,8 +94,8 @@ static void testSimplify4x4RectsMain(PathOpsThreadState* data) } path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b), bCW); - if (progress) { - str += sprintf(str, " path.addRect(%d, %d, %d, %d," + if (state.fReporter->verbose()) { + pathStr.appendf(" path.addRect(%d, %d, %d, %d," " SkPath::kC%sW_Direction);\n", l, t, r, b, bCW ? "C" : ""); } } else { @@ -129,8 +125,8 @@ static void testSimplify4x4RectsMain(PathOpsThreadState* data) } path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b), cCW); - if (progress) { - str += sprintf(str, " path.addRect(%d, %d, %d, %d," + if (state.fReporter->verbose()) { + pathStr.appendf(" path.addRect(%d, %d, %d, %d," " SkPath::kC%sW_Direction);\n", l, t, r, b, cCW ? "C" : ""); } } else { @@ -160,8 +156,8 @@ static void testSimplify4x4RectsMain(PathOpsThreadState* data) } path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b), dCW); - if (progress) { - str += sprintf(str, " path.addRect(%d, %d, %d, %d," + if (state.fReporter->verbose()) { + pathStr.appendf(" path.addRect(%d, %d, %d, %d," " SkPath::kC%sW_Direction);\n", l, t, r, b, dCW ? "C" : ""); } } else { @@ -169,14 +165,14 @@ static void testSimplify4x4RectsMain(PathOpsThreadState* data) dYAlign = 5; } path.close(); - if (progress) { - outputProgress(state.fPathStr, pathStr, SkPath::kWinding_FillType); + if (state.fReporter->verbose()) { + outputProgress(state.fPathStr, pathStr.c_str(), SkPath::kWinding_FillType); } - testSimplify(path, false, out, state, pathStr); - if (progress) { - outputProgress(state.fPathStr, pathStr, SkPath::kEvenOdd_FillType); + testSimplify(path, false, out, state, pathStr.c_str()); + if (state.fReporter->verbose()) { + outputProgress(state.fPathStr, pathStr.c_str(), SkPath::kEvenOdd_FillType); } - testSimplify(path, true, out, state, pathStr); + testSimplify(path, true, out, state, pathStr.c_str()); } } } diff --git a/tests/PathOpsSimplifyTrianglesThreadedTest.cpp b/tests/PathOpsSimplifyTrianglesThreadedTest.cpp index 8d8feee143..671616c2b9 100644 --- a/tests/PathOpsSimplifyTrianglesThreadedTest.cpp +++ b/tests/PathOpsSimplifyTrianglesThreadedTest.cpp @@ -6,15 +6,11 @@ */ #include "PathOpsExtendedTest.h" #include "PathOpsThreadedCommon.h" +#include "SkString.h" static void testSimplifyTrianglesMain(PathOpsThreadState* data) { SkASSERT(data); PathOpsThreadState& state = *data; - char pathStr[1024]; - bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter? - if (progress) { - sk_bzero(pathStr, sizeof(pathStr)); - } state.fKey = "?"; int ax = state.fA & 0x03; int ay = state.fA >> 2; @@ -37,6 +33,7 @@ static void testSimplifyTrianglesMain(PathOpsThreadState* data) { if ((ex - dx) * (fy - dy) == (ey - dy) * (fx - dx)) { continue; } + SkString pathStr; SkPath path, out; path.setFillType(SkPath::kWinding_FillType); path.moveTo(SkIntToScalar(ax), SkIntToScalar(ay)); @@ -47,26 +44,25 @@ static void testSimplifyTrianglesMain(PathOpsThreadState* data) { path.lineTo(SkIntToScalar(ex), SkIntToScalar(ey)); path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy)); path.close(); - if (progress) { - char* str = pathStr; - str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay); - str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by); - str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy); - str += sprintf(str, " path.close();\n"); - str += sprintf(str, " path.moveTo(%d, %d);\n", dx, dy); - str += sprintf(str, " path.lineTo(%d, %d);\n", ex, ey); - str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy); - str += sprintf(str, " path.close();\n"); - outputProgress(state.fPathStr, pathStr, SkPath::kWinding_FillType); + if (state.fReporter->verbose()) { + pathStr.appendf(" path.moveTo(%d, %d);\n", ax, ay); + pathStr.appendf(" path.lineTo(%d, %d);\n", bx, by); + pathStr.appendf(" path.lineTo(%d, %d);\n", cx, cy); + pathStr.appendf(" path.close();\n"); + pathStr.appendf(" path.moveTo(%d, %d);\n", dx, dy); + pathStr.appendf(" path.lineTo(%d, %d);\n", ex, ey); + pathStr.appendf(" path.lineTo(%d, %d);\n", fx, fy); + pathStr.appendf(" path.close();\n"); + outputProgress(state.fPathStr, pathStr.c_str(), SkPath::kWinding_FillType); } ShowTestName(&state, d, e, f, 0); - testSimplify(path, false, out, state, pathStr); + testSimplify(path, false, out, state, pathStr.c_str()); path.setFillType(SkPath::kEvenOdd_FillType); - if (progress) { - outputProgress(state.fPathStr, pathStr, SkPath::kEvenOdd_FillType); + if (state.fReporter->verbose()) { + outputProgress(state.fPathStr, pathStr.c_str(), SkPath::kEvenOdd_FillType); } ShowTestName(&state, d, e, f, 1); - testSimplify(path, true, out, state, pathStr); + testSimplify(path, true, out, state, pathStr.c_str()); } } } |