1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
|
/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "PathOpsExtendedTest.h"
#include "PathOpsThreadedCommon.h"
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkForceLinking.h"
#include "SkMatrix.h"
#include "SkPaint.h"
#include "SkRTConf.h"
#include "SkStream.h"
#include "SkTaskGroup.h"
#include "SkThread.h"
#ifdef SK_BUILD_FOR_MAC
#include <sys/sysctl.h>
#endif
__SK_FORCE_IMAGE_DECODER_LINKING;
DEFINE_bool2(runFail, f, false, "run tests known to fail.");
static const char marker[] =
"</div>\n"
"\n"
"<script type=\"text/javascript\">\n"
"\n"
"var testDivs = [\n";
static const char* opStrs[] = {
"kDifference_PathOp",
"kIntersect_PathOp",
"kUnion_PathOp",
"kXor_PathOp",
"kReverseDifference_PathOp",
};
static const char* opSuffixes[] = {
"d",
"i",
"u",
"o",
};
static bool gShowPath = false;
static bool gComparePathsAssert = true;
static bool gPathStrAssert = true;
#if DEBUG_SHOW_TEST_NAME
static void showPathData(const SkPath& path) {
SkPath::RawIter iter(path);
uint8_t verb;
SkPoint pts[4];
SkPoint firstPt = {0, 0}, lastPt = {0, 0};
bool firstPtSet = false;
bool lastPtSet = true;
while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
switch (verb) {
case SkPath::kMove_Verb:
if (firstPtSet && lastPtSet && firstPt != lastPt) {
SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", lastPt.fX, lastPt.fY,
firstPt.fX, firstPt.fY);
lastPtSet = false;
}
firstPt = pts[0];
firstPtSet = true;
continue;
case SkPath::kLine_Verb:
SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", pts[0].fX, pts[0].fY,
pts[1].fX, pts[1].fY);
lastPt = pts[1];
lastPtSet = true;
break;
case SkPath::kQuad_Verb:
SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n",
pts[0].fX, pts[0].fY, pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY);
lastPt = pts[2];
lastPtSet = true;
break;
case SkPath::kCubic_Verb:
SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n",
pts[0].fX, pts[0].fY, pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY,
pts[3].fX, pts[3].fY);
lastPt = pts[3];
lastPtSet = true;
break;
case SkPath::kClose_Verb:
if (firstPtSet && lastPtSet && firstPt != lastPt) {
SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", lastPt.fX, lastPt.fY,
firstPt.fX, firstPt.fY);
}
firstPtSet = lastPtSet = false;
break;
default:
SkDEBUGFAIL("bad verb");
return;
}
}
if (firstPtSet && lastPtSet && firstPt != lastPt) {
SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", lastPt.fX, lastPt.fY,
firstPt.fX, firstPt.fY);
}
}
#endif
void showOp(const SkPathOp op) {
switch (op) {
case kDifference_PathOp:
SkDebugf("op difference\n");
break;
case kIntersect_PathOp:
SkDebugf("op intersect\n");
break;
case kUnion_PathOp:
SkDebugf("op union\n");
break;
case kXOR_PathOp:
SkDebugf("op xor\n");
break;
case kReverseDifference_PathOp:
SkDebugf("op reverse difference\n");
break;
default:
SkASSERT(0);
}
}
#if DEBUG_SHOW_TEST_NAME
static char hexorator(int x) {
if (x < 10) {
return x + '0';
}
x -= 10;
SkASSERT(x < 26);
return x + 'A';
}
#endif
void ShowTestName(PathOpsThreadState* state, int a, int b, int c, int d) {
#if DEBUG_SHOW_TEST_NAME
state->fSerialNo[0] = hexorator(state->fA);
state->fSerialNo[1] = hexorator(state->fB);
state->fSerialNo[2] = hexorator(state->fC);
state->fSerialNo[3] = hexorator(state->fD);
state->fSerialNo[4] = hexorator(a);
state->fSerialNo[5] = hexorator(b);
state->fSerialNo[6] = hexorator(c);
state->fSerialNo[7] = hexorator(d);
state->fSerialNo[8] = '\0';
SkDebugf("%s\n", state->fSerialNo);
if (strcmp(state->fSerialNo, state->fKey) == 0) {
SkDebugf("%s\n", state->fPathStr);
}
#endif
}
const int bitWidth = 64;
const int bitHeight = 64;
static void scaleMatrix(const SkPath& one, const SkPath& two, SkMatrix& scale) {
SkRect larger = one.getBounds();
larger.join(two.getBounds());
SkScalar largerWidth = larger.width();
if (largerWidth < 4) {
largerWidth = 4;
}
SkScalar largerHeight = larger.height();
if (largerHeight < 4) {
largerHeight = 4;
}
SkScalar hScale = (bitWidth - 2) / largerWidth;
SkScalar vScale = (bitHeight - 2) / largerHeight;
scale.reset();
scale.preScale(hScale, vScale);
}
static int pathsDrawTheSame(SkBitmap& bits, const SkPath& scaledOne, const SkPath& scaledTwo,
int& error2x2) {
if (bits.width() == 0) {
bits.allocN32Pixels(bitWidth * 2, bitHeight);
}
SkCanvas canvas(bits);
canvas.drawColor(SK_ColorWHITE);
SkPaint paint;
canvas.save();
const SkRect& bounds1 = scaledOne.getBounds();
canvas.translate(-bounds1.fLeft + 1, -bounds1.fTop + 1);
canvas.drawPath(scaledOne, paint);
canvas.restore();
canvas.save();
canvas.translate(-bounds1.fLeft + 1 + bitWidth, -bounds1.fTop + 1);
canvas.drawPath(scaledTwo, paint);
canvas.restore();
int errors2 = 0;
int errors = 0;
for (int y = 0; y < bitHeight - 1; ++y) {
uint32_t* addr1 = bits.getAddr32(0, y);
uint32_t* addr2 = bits.getAddr32(0, y + 1);
uint32_t* addr3 = bits.getAddr32(bitWidth, y);
uint32_t* addr4 = bits.getAddr32(bitWidth, y + 1);
for (int x = 0; x < bitWidth - 1; ++x) {
// count 2x2 blocks
bool err = addr1[x] != addr3[x];
if (err) {
errors2 += addr1[x + 1] != addr3[x + 1]
&& addr2[x] != addr4[x] && addr2[x + 1] != addr4[x + 1];
errors++;
}
}
}
error2x2 = errors2;
return errors;
}
static int pathsDrawTheSame(const SkPath& one, const SkPath& two, SkBitmap& bits, SkPath& scaledOne,
SkPath& scaledTwo, int& error2x2) {
SkMatrix scale;
scaleMatrix(one, two, scale);
one.transform(scale, &scaledOne);
two.transform(scale, &scaledTwo);
return pathsDrawTheSame(bits, scaledOne, scaledTwo, error2x2);
}
bool drawAsciiPaths(const SkPath& one, const SkPath& two, bool drawPaths) {
if (!drawPaths) {
return true;
}
const SkRect& bounds1 = one.getBounds();
const SkRect& bounds2 = two.getBounds();
SkRect larger = bounds1;
larger.join(bounds2);
SkBitmap bits;
char out[256];
int bitWidth = SkScalarCeilToInt(larger.width()) + 2;
if (bitWidth * 2 + 1 >= (int) sizeof(out)) {
return false;
}
int bitHeight = SkScalarCeilToInt(larger.height()) + 2;
if (bitHeight >= (int) sizeof(out)) {
return false;
}
bits.allocN32Pixels(bitWidth * 2, bitHeight);
SkCanvas canvas(bits);
canvas.drawColor(SK_ColorWHITE);
SkPaint paint;
canvas.save();
canvas.translate(-bounds1.fLeft + 1, -bounds1.fTop + 1);
canvas.drawPath(one, paint);
canvas.restore();
canvas.save();
canvas.translate(-bounds1.fLeft + 1 + bitWidth, -bounds1.fTop + 1);
canvas.drawPath(two, paint);
canvas.restore();
for (int y = 0; y < bitHeight; ++y) {
uint32_t* addr1 = bits.getAddr32(0, y);
int x;
char* outPtr = out;
for (x = 0; x < bitWidth; ++x) {
*outPtr++ = addr1[x] == (uint32_t) -1 ? '_' : 'x';
}
*outPtr++ = '|';
for (x = bitWidth; x < bitWidth * 2; ++x) {
*outPtr++ = addr1[x] == (uint32_t) -1 ? '_' : 'x';
}
*outPtr++ = '\0';
SkDebugf("%s\n", out);
}
return true;
}
static int comparePaths(skiatest::Reporter* reporter, const char* filename, const SkPath& one,
const SkPath& two, SkBitmap& bitmap) {
int errors2x2;
SkPath scaledOne, scaledTwo;
(void) pathsDrawTheSame(one, two, bitmap, scaledOne, scaledTwo, errors2x2);
if (errors2x2 == 0) {
return 0;
}
const int MAX_ERRORS = 9;
REPORTER_ASSERT(reporter, errors2x2 <= MAX_ERRORS || !gComparePathsAssert);
return errors2x2 > MAX_ERRORS ? errors2x2 : 0;
}
const int gTestFirst = 4;
static int gTestNo = gTestFirst;
static SkTDArray<SkPathOp> gTestOp;
static void showPathOpPath(const char* testName, const SkPath& one, const SkPath& two,
const SkPath& a, const SkPath& b, const SkPath& scaledOne, const SkPath& scaledTwo,
const SkPathOp shapeOp, const SkMatrix& scale) {
SkASSERT((unsigned) shapeOp < SK_ARRAY_COUNT(opStrs));
SkString defaultTestName;
if (!testName) {
defaultTestName.printf("xOp%d%s", gTestNo, opSuffixes[shapeOp]);
testName = defaultTestName.c_str();
}
SkDebugf("static void %s(skiatest::Reporter* reporter, const char* filename) {\n", testName);
*gTestOp.append() = shapeOp;
++gTestNo;
SkDebugf(" SkPath path, pathB;\n");
#if DEBUG_SHOW_TEST_NAME
SkPathOpsDebug::ShowOnePath(a, "path", false);
SkPathOpsDebug::ShowOnePath(b, "pathB", false);
#endif
SkDebugf(" testPathOp(reporter, path, pathB, %s, filename);\n", opStrs[shapeOp]);
SkDebugf("}\n");
drawAsciiPaths(scaledOne, scaledTwo, true);
}
void ShowTestArray() {
for (int x = gTestFirst; x < gTestNo; ++x) {
SkDebugf(" TEST(xOp%d%s),\n", x, opSuffixes[gTestOp[x - gTestFirst]]);
}
}
SK_DECLARE_STATIC_MUTEX(compareDebugOut3);
SK_DECLARE_STATIC_MUTEX(compareDebugOut4);
static int comparePaths(skiatest::Reporter* reporter, const char* testName, const SkPath& one,
const SkPath& scaledOne, const SkPath& two, const SkPath& scaledTwo, SkBitmap& bitmap,
const SkPath& a, const SkPath& b, const SkPathOp shapeOp, const SkMatrix& scale) {
int errors2x2;
(void) pathsDrawTheSame(bitmap, scaledOne, scaledTwo, errors2x2);
if (errors2x2 == 0) {
if (gShowPath) {
showPathOpPath(testName, one, two, a, b, scaledOne, scaledTwo, shapeOp, scale);
}
return 0;
}
const int MAX_ERRORS = 8;
if (errors2x2 > MAX_ERRORS && gComparePathsAssert) {
SkAutoMutexAcquire autoM(compareDebugOut3);
SkDebugf("\n*** this test fails ***\n");
showPathOpPath(testName, one, two, a, b, scaledOne, scaledTwo, shapeOp, scale);
REPORTER_ASSERT(reporter, 0);
} else if (gShowPath || errors2x2 == MAX_ERRORS || errors2x2 == MAX_ERRORS - 1) {
SkAutoMutexAcquire autoM(compareDebugOut4);
showPathOpPath(testName, one, two, a, b, scaledOne, scaledTwo, shapeOp, scale);
}
return errors2x2 > MAX_ERRORS ? errors2x2 : 0;
}
// Default values for when reporter->verbose() is false.
static int testNumber = 55;
static const char* testName = "pathOpTest";
static void writeTestName(const char* nameSuffix, SkMemoryWStream& outFile) {
outFile.writeText(testName);
outFile.writeDecAsText(testNumber);
++testNumber;
if (nameSuffix) {
outFile.writeText(nameSuffix);
}
}
static void outputToStream(const char* pathStr, const char* pathPrefix, const char* nameSuffix,
const char* testFunction, bool twoPaths, SkMemoryWStream& outFile) {
#if 0
outFile.writeText("<div id=\"");
writeTestName(nameSuffix, outFile);
outFile.writeText("\">\n");
if (pathPrefix) {
outFile.writeText(pathPrefix);
}
outFile.writeText(pathStr);
outFile.writeText("</div>\n\n");
outFile.writeText(marker);
outFile.writeText(" ");
writeTestName(nameSuffix, outFile);
outFile.writeText(",\n\n\n");
#endif
outFile.writeText("static void ");
writeTestName(nameSuffix, outFile);
outFile.writeText("(skiatest::Reporter* reporter) {\n SkPath path");
if (twoPaths) {
outFile.writeText(", pathB");
}
outFile.writeText(";\n");
if (pathPrefix) {
outFile.writeText(pathPrefix);
}
outFile.writeText(pathStr);
outFile.writeText(" ");
outFile.writeText(testFunction);
outFile.writeText("\n}\n\n");
#if 0
outFile.writeText("static void (*firstTest)() = ");
writeTestName(nameSuffix, outFile);
outFile.writeText(";\n\n");
outFile.writeText("static struct {\n");
outFile.writeText(" void (*fun)();\n");
outFile.writeText(" const char* str;\n");
outFile.writeText("} tests[] = {\n");
outFile.writeText(" TEST(");
writeTestName(nameSuffix, outFile);
outFile.writeText("),\n");
#endif
outFile.flush();
}
SK_DECLARE_STATIC_MUTEX(simplifyDebugOut);
bool testSimplify(SkPath& path, bool useXor, SkPath& out, PathOpsThreadState& state,
const char* pathStr) {
SkPath::FillType fillType = useXor ? SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType;
path.setFillType(fillType);
#if DEBUG_SHOW_TEST_NAME
if (gShowPath) {
SkPathOpsDebug::ShowOnePath(path, "path", false);
}
#endif
if (!Simplify(path, &out)) {
SkDebugf("%s did not expect failure\n", __FUNCTION__);
REPORTER_ASSERT(state.fReporter, 0);
return false;
}
if (!state.fReporter->verbose()) {
return true;
}
int result = comparePaths(state.fReporter, NULL, path, out, *state.fBitmap);
if (result && gPathStrAssert) {
SkAutoMutexAcquire autoM(simplifyDebugOut);
char temp[8192];
sk_bzero(temp, sizeof(temp));
SkMemoryWStream stream(temp, sizeof(temp));
const char* pathPrefix = NULL;
const char* nameSuffix = NULL;
if (fillType == SkPath::kEvenOdd_FillType) {
pathPrefix = " path.setFillType(SkPath::kEvenOdd_FillType);\n";
nameSuffix = "x";
}
const char testFunction[] = "testSimplify(reporter, path);";
outputToStream(pathStr, pathPrefix, nameSuffix, testFunction, false, stream);
SkDebugf(temp);
REPORTER_ASSERT(state.fReporter, 0);
}
state.fReporter->bumpTestCount();
return result == 0;
}
bool testSimplify(skiatest::Reporter* reporter, const SkPath& path, const char* filename) {
#if DEBUG_SHOW_TEST_NAME
showPathData(path);
#endif
SkPath out;
if (!Simplify(path, &out)) {
SkDebugf("%s did not expect failure\n", __FUNCTION__);
REPORTER_ASSERT(reporter, 0);
return false;
}
SkBitmap bitmap;
int result = comparePaths(reporter, filename, path, out, bitmap);
if (result && gPathStrAssert) {
REPORTER_ASSERT(reporter, 0);
}
reporter->bumpTestCount();
return result == 0;
}
#if DEBUG_SHOW_TEST_NAME
static void showName(const SkPath& a, const SkPath& b, const SkPathOp shapeOp) {
SkDebugf("\n");
showPathData(a);
showOp(shapeOp);
showPathData(b);
}
#endif
static bool innerPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b,
const SkPathOp shapeOp, const char* testName, bool threaded) {
#if DEBUG_SHOW_TEST_NAME
showName(a, b, shapeOp);
#endif
SkPath out;
if (!Op(a, b, shapeOp, &out) ) {
SkDebugf("%s did not expect failure\n", __FUNCTION__);
REPORTER_ASSERT(reporter, 0);
return false;
}
if (threaded && !reporter->verbose()) {
return true;
}
SkPath pathOut, scaledPathOut;
SkRegion rgnA, rgnB, openClip, rgnOut;
openClip.setRect(-16000, -16000, 16000, 16000);
rgnA.setPath(a, openClip);
rgnB.setPath(b, openClip);
rgnOut.op(rgnA, rgnB, (SkRegion::Op) shapeOp);
rgnOut.getBoundaryPath(&pathOut);
SkMatrix scale;
scaleMatrix(a, b, scale);
SkRegion scaledRgnA, scaledRgnB, scaledRgnOut;
SkPath scaledA, scaledB;
scaledA.addPath(a, scale);
scaledA.setFillType(a.getFillType());
scaledB.addPath(b, scale);
scaledB.setFillType(b.getFillType());
scaledRgnA.setPath(scaledA, openClip);
scaledRgnB.setPath(scaledB, openClip);
scaledRgnOut.op(scaledRgnA, scaledRgnB, (SkRegion::Op) shapeOp);
scaledRgnOut.getBoundaryPath(&scaledPathOut);
SkBitmap bitmap;
SkPath scaledOut;
scaledOut.addPath(out, scale);
scaledOut.setFillType(out.getFillType());
int result = comparePaths(reporter, testName, pathOut, scaledPathOut, out, scaledOut, bitmap,
a, b, shapeOp, scale);
if (result && gPathStrAssert) {
REPORTER_ASSERT(reporter, 0);
}
reporter->bumpTestCount();
return result == 0;
}
bool testPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b,
const SkPathOp shapeOp, const char* testName) {
return innerPathOp(reporter, a, b, shapeOp, testName, false);
}
bool testPathFailOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b,
const SkPathOp shapeOp, const char* testName) {
#if DEBUG_SHOW_TEST_NAME
showName(a, b, shapeOp);
#endif
SkPath out;
if (Op(a, b, shapeOp, &out) ) {
SkDebugf("%s test is expected to fail\n", __FUNCTION__);
REPORTER_ASSERT(reporter, 0);
return false;
}
return true;
}
bool testThreadedPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b,
const SkPathOp shapeOp, const char* testName) {
return innerPathOp(reporter, a, b, shapeOp, testName, true);
}
SK_DECLARE_STATIC_MUTEX(gMutex);
void initializeTests(skiatest::Reporter* reporter, const char* test) {
#if 0 // doesn't work yet
SK_CONF_SET("images.jpeg.suppressDecoderWarnings", true);
SK_CONF_SET("images.png.suppressDecoderWarnings", true);
#endif
if (reporter->verbose()) {
SkAutoMutexAcquire lock(gMutex);
testName = test;
size_t testNameSize = strlen(test);
SkFILEStream inFile("../../experimental/Intersection/op.htm");
if (inFile.isValid()) {
SkTDArray<char> inData;
inData.setCount((int) inFile.getLength());
size_t inLen = inData.count();
inFile.read(inData.begin(), inLen);
inFile.setPath(NULL);
char* insert = strstr(inData.begin(), marker);
if (insert) {
insert += sizeof(marker) - 1;
const char* numLoc = insert + 4 /* indent spaces */ + testNameSize - 1;
testNumber = atoi(numLoc) + 1;
}
}
}
}
void outputProgress(char* ramStr, const char* pathStr, SkPath::FillType pathFillType) {
const char testFunction[] = "testSimplify(path);";
const char* pathPrefix = NULL;
const char* nameSuffix = NULL;
if (pathFillType == SkPath::kEvenOdd_FillType) {
pathPrefix = " path.setFillType(SkPath::kEvenOdd_FillType);\n";
nameSuffix = "x";
}
SkMemoryWStream rRamStream(ramStr, PATH_STR_SIZE);
outputToStream(pathStr, pathPrefix, nameSuffix, testFunction, false, rRamStream);
}
void outputProgress(char* ramStr, const char* pathStr, SkPathOp op) {
const char testFunction[] = "testOp(path);";
SkASSERT((size_t) op < SK_ARRAY_COUNT(opSuffixes));
const char* nameSuffix = opSuffixes[op];
SkMemoryWStream rRamStream(ramStr, PATH_STR_SIZE);
outputToStream(pathStr, NULL, nameSuffix, testFunction, true, rRamStream);
}
void RunTestSet(skiatest::Reporter* reporter, TestDesc tests[], size_t count,
void (*firstTest)(skiatest::Reporter* , const char* filename),
void (*stopTest)(skiatest::Reporter* , const char* filename), bool reverse) {
size_t index;
if (firstTest) {
index = count - 1;
while (index > 0 && tests[index].fun != firstTest) {
--index;
}
#if DEBUG_SHOW_TEST_NAME
SkDebugf("<div id=\"%s\">\n", tests[index].str);
SkDebugf(" %s [%s]\n", __FUNCTION__, tests[index].str);
#endif
(*tests[index].fun)(reporter, tests[index].str);
if (tests[index].fun == stopTest) {
return;
}
}
index = reverse ? count - 1 : 0;
size_t last = reverse ? 0 : count - 1;
do {
if (tests[index].fun != firstTest) {
#if DEBUG_SHOW_TEST_NAME
SkDebugf("<div id=\"%s\">\n", tests[index].str);
SkDebugf(" %s [%s]\n", __FUNCTION__, tests[index].str);
#endif
(*tests[index].fun)(reporter, tests[index].str);
}
if (tests[index].fun == stopTest) {
SkDebugf("lastTest\n");
break;
}
if (index == last) {
break;
}
index += reverse ? -1 : 1;
} while (true);
}
|