OLD | NEW |
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 | 7 |
8 #include "PathOpsExtendedTest.h" | 8 #include "PathOpsExtendedTest.h" |
9 #include "PathOpsThreadedCommon.h" | 9 #include "PathOpsThreadedCommon.h" |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 }; | 51 }; |
52 | 52 |
53 static const char* opSuffixes[] = { | 53 static const char* opSuffixes[] = { |
54 "d", | 54 "d", |
55 "i", | 55 "i", |
56 "u", | 56 "u", |
57 "o", | 57 "o", |
58 "r", | 58 "r", |
59 }; | 59 }; |
60 | 60 |
| 61 enum class ExpectSuccess { |
| 62 kNo, |
| 63 kYes, |
| 64 kFlaky |
| 65 }; |
| 66 |
| 67 enum class SkipAssert { |
| 68 kNo, |
| 69 kYes |
| 70 }; |
| 71 |
| 72 enum class ExpectMatch { |
| 73 kNo, |
| 74 kYes, |
| 75 kFlaky |
| 76 }; |
| 77 |
61 #if DEBUG_SHOW_TEST_NAME | 78 #if DEBUG_SHOW_TEST_NAME |
62 static void showPathData(const SkPath& path) { | 79 static void showPathData(const SkPath& path) { |
63 SkPath::RawIter iter(path); | 80 SkPath::RawIter iter(path); |
64 uint8_t verb; | 81 uint8_t verb; |
65 SkPoint pts[4]; | 82 SkPoint pts[4]; |
66 SkPoint firstPt = {0, 0}, lastPt = {0, 0}; | 83 SkPoint firstPt = {0, 0}, lastPt = {0, 0}; |
67 bool firstPtSet = false; | 84 bool firstPtSet = false; |
68 bool lastPtSet = true; | 85 bool lastPtSet = true; |
69 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { | 86 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { |
70 switch (verb) { | 87 switch (verb) { |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 SkDebugf(" testPathOp(reporter, path, pathB, %s, filename);\n", opStrs[sh
apeOp]); | 343 SkDebugf(" testPathOp(reporter, path, pathB, %s, filename);\n", opStrs[sh
apeOp]); |
327 SkDebugf("}\n"); | 344 SkDebugf("}\n"); |
328 drawAsciiPaths(scaledOne, scaledTwo, true); | 345 drawAsciiPaths(scaledOne, scaledTwo, true); |
329 } | 346 } |
330 | 347 |
331 SK_DECLARE_STATIC_MUTEX(compareDebugOut3); | 348 SK_DECLARE_STATIC_MUTEX(compareDebugOut3); |
332 | 349 |
333 static int comparePaths(skiatest::Reporter* reporter, const char* testName, cons
t SkPath& one, | 350 static int comparePaths(skiatest::Reporter* reporter, const char* testName, cons
t SkPath& one, |
334 const SkPath& scaledOne, const SkPath& two, const SkPath& scaledTwo, SkB
itmap& bitmap, | 351 const SkPath& scaledOne, const SkPath& two, const SkPath& scaledTwo, SkB
itmap& bitmap, |
335 const SkPath& a, const SkPath& b, const SkPathOp shapeOp, const SkMatrix
& scale, | 352 const SkPath& a, const SkPath& b, const SkPathOp shapeOp, const SkMatrix
& scale, |
336 bool expectSuccess) { | 353 ExpectMatch expectMatch) { |
337 int errors2x2; | 354 int errors2x2; |
338 const int MAX_ERRORS = 8; | 355 const int MAX_ERRORS = 8; |
339 (void) pathsDrawTheSame(bitmap, scaledOne, scaledTwo, errors2x2); | 356 (void) pathsDrawTheSame(bitmap, scaledOne, scaledTwo, errors2x2); |
340 if (!expectSuccess) { | 357 if (ExpectMatch::kNo == expectMatch) { |
341 if (errors2x2 < MAX_ERRORS) { | 358 if (errors2x2 < MAX_ERRORS) { |
342 REPORTER_ASSERT(reporter, 0); | 359 REPORTER_ASSERT(reporter, 0); |
343 } | 360 } |
344 return 0; | 361 return 0; |
345 } | 362 } |
346 if (errors2x2 == 0) { | 363 if (errors2x2 == 0) { |
347 return 0; | 364 return 0; |
348 } | 365 } |
349 if (errors2x2 >= MAX_ERRORS) { | 366 if (ExpectMatch::kYes == expectMatch && errors2x2 >= MAX_ERRORS) { |
350 SkAutoMutexAcquire autoM(compareDebugOut3); | 367 SkAutoMutexAcquire autoM(compareDebugOut3); |
351 showPathOpPath(testName, one, two, a, b, scaledOne, scaledTwo, shapeOp,
scale); | 368 showPathOpPath(testName, one, two, a, b, scaledOne, scaledTwo, shapeOp,
scale); |
352 SkDebugf("\n/*"); | 369 SkDebugf("\n/*"); |
353 REPORTER_ASSERT(reporter, 0); | 370 REPORTER_ASSERT(reporter, 0); |
354 SkDebugf(" */\n"); | 371 SkDebugf(" */\n"); |
355 } | 372 } |
356 return errors2x2 >= MAX_ERRORS ? errors2x2 : 0; | 373 return errors2x2 >= MAX_ERRORS ? errors2x2 : 0; |
357 } | 374 } |
358 | 375 |
359 // Default values for when reporter->verbose() is false. | 376 // Default values for when reporter->verbose() is false. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 } | 462 } |
446 const char testFunction[] = "testSimplify(reporter, path);"; | 463 const char testFunction[] = "testSimplify(reporter, path);"; |
447 outputToStream(pathStr, pathPrefix, nameSuffix, testFunction, false, str
eam); | 464 outputToStream(pathStr, pathPrefix, nameSuffix, testFunction, false, str
eam); |
448 SkDebugf("%s", temp); | 465 SkDebugf("%s", temp); |
449 REPORTER_ASSERT(state.fReporter, 0); | 466 REPORTER_ASSERT(state.fReporter, 0); |
450 } | 467 } |
451 state.fReporter->bumpTestCount(); | 468 state.fReporter->bumpTestCount(); |
452 return result == 0; | 469 return result == 0; |
453 } | 470 } |
454 | 471 |
455 enum class ExpectSuccess { | |
456 kNo, | |
457 kYes | |
458 }; | |
459 | |
460 enum class SkipAssert { | |
461 kNo, | |
462 kYes | |
463 }; | |
464 | |
465 enum class ExpectMatch { | |
466 kNo, | |
467 kYes | |
468 }; | |
469 | |
470 static bool inner_simplify(skiatest::Reporter* reporter, const SkPath& path, con
st char* filename, | 472 static bool inner_simplify(skiatest::Reporter* reporter, const SkPath& path, con
st char* filename, |
471 ExpectSuccess expectSuccess, SkipAssert skipAssert, ExpectMatch expectMa
tch) { | 473 ExpectSuccess expectSuccess, SkipAssert skipAssert, ExpectMatch expectMa
tch) { |
472 #if 0 && DEBUG_SHOW_TEST_NAME | 474 #if 0 && DEBUG_SHOW_TEST_NAME |
473 showPathData(path); | 475 showPathData(path); |
474 #endif | 476 #endif |
475 SkPath out; | 477 SkPath out; |
476 if (!SimplifyDebug(path, &out SkDEBUGPARAMS(SkipAssert::kYes == skipAssert) | 478 if (!SimplifyDebug(path, &out SkDEBUGPARAMS(SkipAssert::kYes == skipAssert) |
477 SkDEBUGPARAMS(testName))) { | 479 SkDEBUGPARAMS(testName))) { |
478 if (ExpectSuccess::kYes == expectSuccess) { | 480 if (ExpectSuccess::kYes == expectSuccess) { |
479 SkDebugf("%s did not expect %s failure\n", __FUNCTION__, filename); | 481 SkDebugf("%s did not expect %s failure\n", __FUNCTION__, filename); |
480 REPORTER_ASSERT(reporter, 0); | 482 REPORTER_ASSERT(reporter, 0); |
481 } | 483 } |
482 return false; | 484 return false; |
483 } else { | 485 } else { |
484 if (ExpectSuccess::kNo == expectSuccess) { | 486 if (ExpectSuccess::kNo == expectSuccess) { |
485 SkDebugf("%s %s unexpected success\n", __FUNCTION__, filename); | 487 SkDebugf("%s %s unexpected success\n", __FUNCTION__, filename); |
486 REPORTER_ASSERT(reporter, 0); | 488 REPORTER_ASSERT(reporter, 0); |
487 } | 489 } |
488 } | 490 } |
489 SkBitmap bitmap; | 491 SkBitmap bitmap; |
490 int errors = comparePaths(reporter, filename, path, out, bitmap); | 492 int errors = comparePaths(reporter, filename, path, out, bitmap); |
491 if (ExpectMatch::kNo == expectMatch) { | 493 if (ExpectMatch::kNo == expectMatch) { |
492 if (!errors) { | 494 if (!errors) { |
493 SkDebugf("%s failing test %s now succeeds\n", __FUNCTION__, filename
); | 495 SkDebugf("%s failing test %s now succeeds\n", __FUNCTION__, filename
); |
494 REPORTER_ASSERT(reporter, 0); | 496 REPORTER_ASSERT(reporter, 0); |
495 return false; | 497 return false; |
496 } | 498 } |
497 } else if (errors) { | 499 } else if (ExpectMatch::kYes == expectMatch && errors) { |
498 REPORTER_ASSERT(reporter, 0); | 500 REPORTER_ASSERT(reporter, 0); |
499 } | 501 } |
500 reporter->bumpTestCount(); | 502 reporter->bumpTestCount(); |
501 return errors == 0; | 503 return errors == 0; |
502 } | 504 } |
503 | 505 |
504 bool testSimplify(skiatest::Reporter* reporter, const SkPath& path, const char*
filename) { | 506 bool testSimplify(skiatest::Reporter* reporter, const SkPath& path, const char*
filename) { |
505 return inner_simplify(reporter, path, filename, ExpectSuccess::kYes, SkipAss
ert::kNo, | 507 return inner_simplify(reporter, path, filename, ExpectSuccess::kYes, SkipAss
ert::kNo, |
506 ExpectMatch::kYes); | 508 ExpectMatch::kYes); |
507 } | 509 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 scaledB.setFillType(b.getFillType()); | 569 scaledB.setFillType(b.getFillType()); |
568 scaledRgnA.setPath(scaledA, openClip); | 570 scaledRgnA.setPath(scaledA, openClip); |
569 scaledRgnB.setPath(scaledB, openClip); | 571 scaledRgnB.setPath(scaledB, openClip); |
570 scaledRgnOut.op(scaledRgnA, scaledRgnB, (SkRegion::Op) shapeOp); | 572 scaledRgnOut.op(scaledRgnA, scaledRgnB, (SkRegion::Op) shapeOp); |
571 scaledRgnOut.getBoundaryPath(&scaledPathOut); | 573 scaledRgnOut.getBoundaryPath(&scaledPathOut); |
572 SkBitmap bitmap; | 574 SkBitmap bitmap; |
573 SkPath scaledOut; | 575 SkPath scaledOut; |
574 scaledOut.addPath(out, scale); | 576 scaledOut.addPath(out, scale); |
575 scaledOut.setFillType(out.getFillType()); | 577 scaledOut.setFillType(out.getFillType()); |
576 int result = comparePaths(reporter, testName, pathOut, scaledPathOut, out, s
caledOut, bitmap, | 578 int result = comparePaths(reporter, testName, pathOut, scaledPathOut, out, s
caledOut, bitmap, |
577 a, b, shapeOp, scale, ExpectMatch::kYes == expectMatch); | 579 a, b, shapeOp, scale, expectMatch); |
578 reporter->bumpTestCount(); | 580 reporter->bumpTestCount(); |
579 return result == 0; | 581 return result == 0; |
580 } | 582 } |
581 | 583 |
582 bool testPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b, | 584 bool testPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b, |
583 const SkPathOp shapeOp, const char* testName) { | 585 const SkPathOp shapeOp, const char* testName) { |
584 return innerPathOp(reporter, a, b, shapeOp, testName, ExpectSuccess::kYes, S
kipAssert::kNo, | 586 return innerPathOp(reporter, a, b, shapeOp, testName, ExpectSuccess::kYes, S
kipAssert::kNo, |
585 ExpectMatch::kYes); | 587 ExpectMatch::kYes); |
586 } | 588 } |
587 | 589 |
(...skipping 14 matching lines...) Expand all Loading... |
602 return innerPathOp(reporter, a, b, shapeOp, testName, ExpectSuccess::kYes, S
kipAssert::kYes, | 604 return innerPathOp(reporter, a, b, shapeOp, testName, ExpectSuccess::kYes, S
kipAssert::kYes, |
603 ExpectMatch::kYes); | 605 ExpectMatch::kYes); |
604 } | 606 } |
605 | 607 |
606 bool testPathOpFailSkipAssert(skiatest::Reporter* reporter, const SkPath& a, con
st SkPath& b, | 608 bool testPathOpFailSkipAssert(skiatest::Reporter* reporter, const SkPath& a, con
st SkPath& b, |
607 const SkPathOp shapeOp, const char* testName) { | 609 const SkPathOp shapeOp, const char* testName) { |
608 return innerPathOp(reporter, a, b, shapeOp, testName, ExpectSuccess::kNo, Sk
ipAssert::kYes, | 610 return innerPathOp(reporter, a, b, shapeOp, testName, ExpectSuccess::kNo, Sk
ipAssert::kYes, |
609 ExpectMatch::kNo); | 611 ExpectMatch::kNo); |
610 } | 612 } |
611 | 613 |
| 614 bool testPathOpFlakySkipAssert(skiatest::Reporter* reporter, const SkPath& a, co
nst SkPath& b, |
| 615 const SkPathOp shapeOp, const char* testName) { |
| 616 return innerPathOp(reporter, a, b, shapeOp, testName, ExpectSuccess::kFlaky,
SkipAssert::kYes, |
| 617 ExpectMatch::kFlaky); |
| 618 } |
| 619 |
612 bool testPathOpFail(skiatest::Reporter* reporter, const SkPath& a, const SkPath&
b, | 620 bool testPathOpFail(skiatest::Reporter* reporter, const SkPath& a, const SkPath&
b, |
613 const SkPathOp shapeOp, const char* testName) { | 621 const SkPathOp shapeOp, const char* testName) { |
614 #if DEBUG_SHOW_TEST_NAME | 622 #if DEBUG_SHOW_TEST_NAME |
615 showName(a, b, shapeOp); | 623 showName(a, b, shapeOp); |
616 #endif | 624 #endif |
617 SkPath orig; | 625 SkPath orig; |
618 orig.lineTo(54, 43); | 626 orig.lineTo(54, 43); |
619 SkPath out = orig; | 627 SkPath out = orig; |
620 if (Op(a, b, shapeOp, &out) ) { | 628 if (Op(a, b, shapeOp, &out) ) { |
621 SkDebugf("%s test is expected to fail\n", __FUNCTION__); | 629 SkDebugf("%s test is expected to fail\n", __FUNCTION__); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 if (foundSkip && tests[index].fun != firstTest) { | 733 if (foundSkip && tests[index].fun != firstTest) { |
726 SkDebugf(" %s,\n", tests[index].str); | 734 SkDebugf(" %s,\n", tests[index].str); |
727 } | 735 } |
728 if (tests[index].fun == stopTest || index == last) { | 736 if (tests[index].fun == stopTest || index == last) { |
729 break; | 737 break; |
730 } | 738 } |
731 index += reverse ? -1 : 1; | 739 index += reverse ? -1 : 1; |
732 } while (true); | 740 } while (true); |
733 #endif | 741 #endif |
734 } | 742 } |
OLD | NEW |