Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(486)

Side by Side Diff: tests/PathOpsSimplifyDegenerateThreadedTest.cpp

Issue 2391133005: remove sprintf (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #include "PathOpsExtendedTest.h" 7 #include "PathOpsExtendedTest.h"
8 #include "PathOpsThreadedCommon.h" 8 #include "PathOpsThreadedCommon.h"
9 #include "SkString.h"
9 10
10 static void testSimplifyDegeneratesMain(PathOpsThreadState* data) { 11 static void testSimplifyDegeneratesMain(PathOpsThreadState* data) {
11 SkASSERT(data); 12 SkASSERT(data);
12 PathOpsThreadState& state = *data; 13 PathOpsThreadState& state = *data;
13 char pathStr[1024];
14 bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter?
15 if (progress) {
16 sk_bzero(pathStr, sizeof(pathStr));
17 }
18 int ax = state.fA & 0x03; 14 int ax = state.fA & 0x03;
19 int ay = state.fA >> 2; 15 int ay = state.fA >> 2;
20 int bx = state.fB & 0x03; 16 int bx = state.fB & 0x03;
21 int by = state.fB >> 2; 17 int by = state.fB >> 2;
22 int cx = state.fC & 0x03; 18 int cx = state.fC & 0x03;
23 int cy = state.fC >> 2; 19 int cy = state.fC >> 2;
24 for (int d = 0; d < 16; ++d) { 20 for (int d = 0; d < 16; ++d) {
25 int dx = d & 0x03; 21 int dx = d & 0x03;
26 int dy = d >> 2; 22 int dy = d >> 2;
27 for (int e = d ; e < 16; ++e) { 23 for (int e = d ; e < 16; ++e) {
28 int ex = e & 0x03; 24 int ex = e & 0x03;
29 int ey = e >> 2; 25 int ey = e >> 2;
30 for (int f = d ; f < 16; ++f) { 26 for (int f = d ; f < 16; ++f) {
31 int fx = f & 0x03; 27 int fx = f & 0x03;
32 int fy = f >> 2; 28 int fy = f >> 2;
33 if (state.fD && (ex - dx) * (fy - dy) 29 if (state.fD && (ex - dx) * (fy - dy)
34 != (ey - dy) * (fx - dx)) { 30 != (ey - dy) * (fx - dx)) {
35 continue; 31 continue;
36 } 32 }
33 SkString pathStr;
37 SkPath path, out; 34 SkPath path, out;
38 path.setFillType(SkPath::kWinding_FillType); 35 path.setFillType(SkPath::kWinding_FillType);
39 path.moveTo(SkIntToScalar(ax), SkIntToScalar(ay)); 36 path.moveTo(SkIntToScalar(ax), SkIntToScalar(ay));
40 path.lineTo(SkIntToScalar(bx), SkIntToScalar(by)); 37 path.lineTo(SkIntToScalar(bx), SkIntToScalar(by));
41 path.lineTo(SkIntToScalar(cx), SkIntToScalar(cy)); 38 path.lineTo(SkIntToScalar(cx), SkIntToScalar(cy));
42 path.close(); 39 path.close();
43 path.moveTo(SkIntToScalar(dx), SkIntToScalar(dy)); 40 path.moveTo(SkIntToScalar(dx), SkIntToScalar(dy));
44 path.lineTo(SkIntToScalar(ex), SkIntToScalar(ey)); 41 path.lineTo(SkIntToScalar(ex), SkIntToScalar(ey));
45 path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy)); 42 path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy));
46 path.close(); 43 path.close();
47 if (progress) { 44 if (state.fReporter->verbose()) {
48 char* str = pathStr; 45 pathStr.appendf(" path.moveTo(%d, %d);\n", ax, ay);
49 str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay); 46 pathStr.appendf(" path.lineTo(%d, %d);\n", bx, by);
50 str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by); 47 pathStr.appendf(" path.lineTo(%d, %d);\n", cx, cy);
51 str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy); 48 pathStr.appendf(" path.close();\n");
52 str += sprintf(str, " path.close();\n"); 49 pathStr.appendf(" path.moveTo(%d, %d);\n", dx, dy);
53 str += sprintf(str, " path.moveTo(%d, %d);\n", dx, dy); 50 pathStr.appendf(" path.lineTo(%d, %d);\n", ex, ey);
54 str += sprintf(str, " path.lineTo(%d, %d);\n", ex, ey); 51 pathStr.appendf(" path.lineTo(%d, %d);\n", fx, fy);
55 str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy); 52 pathStr.appendf(" path.close();\n");
56 str += sprintf(str, " path.close();\n"); 53 outputProgress(state.fPathStr, pathStr.c_str(), SkPath::kWin ding_FillType);
57 outputProgress(state.fPathStr, pathStr, SkPath::kWinding_Fil lType);
58 } 54 }
59 testSimplify(path, false, out, state, pathStr); 55 testSimplify(path, false, out, state, pathStr.c_str());
60 path.setFillType(SkPath::kEvenOdd_FillType); 56 path.setFillType(SkPath::kEvenOdd_FillType);
61 if (progress) { 57 if (state.fReporter->verbose()) {
62 outputProgress(state.fPathStr, pathStr, SkPath::kEvenOdd_Fil lType); 58 outputProgress(state.fPathStr, pathStr.c_str(), SkPath::kEve nOdd_FillType);
63 } 59 }
64 testSimplify(path, true, out, state, pathStr); 60 testSimplify(path, true, out, state, pathStr.c_str());
65 } 61 }
66 } 62 }
67 } 63 }
68 } 64 }
69 65
70 DEF_TEST(PathOpsSimplifyDegeneratesThreaded, reporter) { 66 DEF_TEST(PathOpsSimplifyDegeneratesThreaded, reporter) {
71 initializeTests(reporter, "testDegenerates"); 67 initializeTests(reporter, "testDegenerates");
72 PathOpsThreadedTestRunner testRunner(reporter); 68 PathOpsThreadedTestRunner testRunner(reporter);
73 for (int a = 0; a < 16; ++a) { 69 for (int a = 0; a < 16; ++a) {
74 int ax = a & 0x03; 70 int ax = a & 0x03;
75 int ay = a >> 2; 71 int ay = a >> 2;
76 for (int b = a ; b < 16; ++b) { 72 for (int b = a ; b < 16; ++b) {
77 int bx = b & 0x03; 73 int bx = b & 0x03;
78 int by = b >> 2; 74 int by = b >> 2;
79 for (int c = a ; c < 16; ++c) { 75 for (int c = a ; c < 16; ++c) {
80 int cx = c & 0x03; 76 int cx = c & 0x03;
81 int cy = c >> 2; 77 int cy = c >> 2;
82 bool abcIsATriangle = (bx - ax) * (cy - ay) != (by - ay) * (cx - ax); 78 bool abcIsATriangle = (bx - ax) * (cy - ay) != (by - ay) * (cx - ax);
83 *testRunner.fRunnables.append() = new PathOpsThreadedRunnable( 79 *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
84 &testSimplifyDegeneratesMain, a, b, c, abcIsATriangle, & testRunner); 80 &testSimplifyDegeneratesMain, a, b, c, abcIsATriangle, & testRunner);
85 } 81 }
86 if (!reporter->allowExtendedTest()) goto finish; 82 if (!reporter->allowExtendedTest()) goto finish;
87 } 83 }
88 } 84 }
89 finish: 85 finish:
90 testRunner.render(); 86 testRunner.render();
91 } 87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698