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

Side by Side Diff: tests/PathOpsExtendedTest.cpp

Issue 2128633003: pathops coincidence and security rewrite (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: require resulting t to be between 0 and 1 Created 4 years, 5 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 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"
11 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 #include "SkForceLinking.h" 12 #include "SkForceLinking.h"
13 #include "SkMatrix.h" 13 #include "SkMatrix.h"
14 #include "SkMutex.h" 14 #include "SkMutex.h"
15 #include "SkPaint.h" 15 #include "SkPaint.h"
16 #include "SkRTConf.h" 16 #include "SkRTConf.h"
17 #include "SkStream.h" 17 #include "SkStream.h"
18 18
19 #include <stdlib.h> 19 #include <stdlib.h>
20 20
21 #ifdef SK_BUILD_FOR_MAC 21 #ifdef SK_BUILD_FOR_MAC
22 #include <sys/sysctl.h> 22 #include <sys/sysctl.h>
23 #endif 23 #endif
24 24
25 bool OpDebug(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result
26 SkDEBUGPARAMS(bool skipAssert)
27 SkDEBUGPARAMS(const char* testName));
28
29 bool SimplifyDebug(const SkPath& one, SkPath* result
30 SkDEBUGPARAMS(bool skipAssert)
31 SkDEBUGPARAMS(const char* testName));
32
33
25 __SK_FORCE_IMAGE_DECODER_LINKING; 34 __SK_FORCE_IMAGE_DECODER_LINKING;
26 35
27 DEFINE_bool2(runFail, f, false, "run tests known to fail."); 36 DEFINE_bool2(runFail, f, false, "run tests known to fail.");
28 DEFINE_bool2(runBinary, f, false, "run tests known to fail binary sect."); 37 DEFINE_bool2(runBinary, f, false, "run tests known to fail binary sect.");
29 38
30 static const char marker[] = 39 static const char marker[] =
31 "</div>\n" 40 "</div>\n"
32 "\n" 41 "\n"
33 "<script type=\"text/javascript\">\n" 42 "<script type=\"text/javascript\">\n"
34 "\n" 43 "\n"
35 "var testDivs = [\n"; 44 "var testDivs = [\n";
36 45
37 static const char* opStrs[] = { 46 static const char* opStrs[] = {
38 "kDifference_SkPathOp", 47 "kDifference_SkPathOp",
39 "kIntersect_SkPathOp", 48 "kIntersect_SkPathOp",
40 "kUnion_SkPathOp", 49 "kUnion_SkPathOp",
41 "kXor_PathOp", 50 "kXOR_PathOp",
42 "kReverseDifference_SkPathOp", 51 "kReverseDifference_SkPathOp",
43 }; 52 };
44 53
45 static const char* opSuffixes[] = { 54 static const char* opSuffixes[] = {
46 "d", 55 "d",
47 "i", 56 "i",
48 "u", 57 "u",
49 "o", 58 "o",
59 "r",
50 }; 60 };
51 61
52 #if DEBUG_SHOW_TEST_NAME 62 #if DEBUG_SHOW_TEST_NAME
53 static void showPathData(const SkPath& path) { 63 static void showPathData(const SkPath& path) {
54 SkPath::RawIter iter(path); 64 SkPath::RawIter iter(path);
55 uint8_t verb; 65 uint8_t verb;
56 SkPoint pts[4]; 66 SkPoint pts[4];
57 SkPoint firstPt = {0, 0}, lastPt = {0, 0}; 67 SkPoint firstPt = {0, 0}, lastPt = {0, 0};
58 bool firstPtSet = false; 68 bool firstPtSet = false;
59 bool lastPtSet = true; 69 bool lastPtSet = true;
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 } 446 }
437 const char testFunction[] = "testSimplify(reporter, path);"; 447 const char testFunction[] = "testSimplify(reporter, path);";
438 outputToStream(pathStr, pathPrefix, nameSuffix, testFunction, false, str eam); 448 outputToStream(pathStr, pathPrefix, nameSuffix, testFunction, false, str eam);
439 SkDebugf("%s", temp); 449 SkDebugf("%s", temp);
440 REPORTER_ASSERT(state.fReporter, 0); 450 REPORTER_ASSERT(state.fReporter, 0);
441 } 451 }
442 state.fReporter->bumpTestCount(); 452 state.fReporter->bumpTestCount();
443 return result == 0; 453 return result == 0;
444 } 454 }
445 455
456 enum class ExpectSuccess {
457 kNo,
458 kYes
459 };
460
461 enum class SkipAssert {
462 kNo,
463 kYes
464 };
465
466 enum class ExpectMatch {
467 kNo,
468 kYes
469 };
470
446 static bool inner_simplify(skiatest::Reporter* reporter, const SkPath& path, con st char* filename, 471 static bool inner_simplify(skiatest::Reporter* reporter, const SkPath& path, con st char* filename,
447 bool checkFail) { 472 ExpectSuccess expectSuccess, SkipAssert skipAssert, ExpectMatch expectMa tch) {
448 #if 0 && DEBUG_SHOW_TEST_NAME 473 #if 0 && DEBUG_SHOW_TEST_NAME
449 showPathData(path); 474 showPathData(path);
450 #endif 475 #endif
451 SkPath out; 476 SkPath out;
452 if (!Simplify(path, &out)) { 477 if (!SimplifyDebug(path, &out SkDEBUGPARAMS(SkipAssert::kYes == skipAssert)
453 SkDebugf("%s did not expect %s failure\n", __FUNCTION__, filename); 478 SkDEBUGPARAMS(testName))) {
454 REPORTER_ASSERT(reporter, 0); 479 if (ExpectSuccess::kYes == expectSuccess) {
480 SkDebugf("%s did not expect %s failure\n", __FUNCTION__, filename);
481 REPORTER_ASSERT(reporter, 0);
482 }
455 return false; 483 return false;
484 } else {
485 if (ExpectSuccess::kNo == expectSuccess) {
486 SkDebugf("%s %s unexpected success\n", __FUNCTION__, filename);
487 REPORTER_ASSERT(reporter, 0);
488 }
456 } 489 }
457 SkBitmap bitmap; 490 SkBitmap bitmap;
458 int errors = comparePaths(reporter, filename, path, out, bitmap); 491 int errors = comparePaths(reporter, filename, path, out, bitmap);
459 if (!checkFail) { 492 if (ExpectMatch::kNo == expectMatch) {
460 if (!errors) { 493 if (!errors) {
461 SkDebugf("%s failing test %s now succeeds\n", __FUNCTION__, filename ); 494 SkDebugf("%s failing test %s now succeeds\n", __FUNCTION__, filename );
462 REPORTER_ASSERT(reporter, 0); 495 REPORTER_ASSERT(reporter, 0);
463 return false; 496 return false;
464 } 497 }
465 } else if (errors) { 498 } else if (errors) {
466 REPORTER_ASSERT(reporter, 0); 499 REPORTER_ASSERT(reporter, 0);
467 } 500 }
468 reporter->bumpTestCount(); 501 reporter->bumpTestCount();
469 return errors == 0; 502 return errors == 0;
470 } 503 }
471 504
472 bool testSimplify(skiatest::Reporter* reporter, const SkPath& path, const char* filename) { 505 bool testSimplify(skiatest::Reporter* reporter, const SkPath& path, const char* filename) {
473 return inner_simplify(reporter, path, filename, true); 506 return inner_simplify(reporter, path, filename, ExpectSuccess::kYes, SkipAss ert::kNo,
507 ExpectMatch::kYes);
508 }
509
510 bool testSimplifyFailSkipAssert(skiatest::Reporter* reporter, const SkPath& path , const char* filename) {
511 return inner_simplify(reporter, path, filename, ExpectSuccess::kNo, SkipAsse rt::kYes,
512 ExpectMatch::kNo);
474 } 513 }
475 514
476 bool testSimplifyCheck(skiatest::Reporter* reporter, const SkPath& path, const c har* filename, 515 bool testSimplifyCheck(skiatest::Reporter* reporter, const SkPath& path, const c har* filename,
477 bool checkFail) { 516 bool checkFail) {
478 return inner_simplify(reporter, path, filename, checkFail); 517 return inner_simplify(reporter, path, filename, checkFail ?
518 ExpectSuccess::kYes : ExpectSuccess::kNo, SkipAssert::kNo, ExpectMat ch::kNo);
479 } 519 }
480 520
481 #if DEBUG_SHOW_TEST_NAME 521 #if DEBUG_SHOW_TEST_NAME
482 static void showName(const SkPath& a, const SkPath& b, const SkPathOp shapeOp) { 522 static void showName(const SkPath& a, const SkPath& b, const SkPathOp shapeOp) {
483 SkDebugf("\n"); 523 SkDebugf("\n");
484 showPathData(a); 524 showPathData(a);
485 showOp(shapeOp); 525 showOp(shapeOp);
486 showPathData(b); 526 showPathData(b);
487 } 527 }
488 #endif 528 #endif
489 529
490 bool OpDebug(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result
491 SkDEBUGPARAMS(bool skipAssert)
492 SkDEBUGPARAMS(const char* testName));
493
494 static bool innerPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkP ath& b, 530 static bool innerPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkP ath& b,
495 const SkPathOp shapeOp, const char* testName, bool expectSuccess, bool s kipAssert) { 531 const SkPathOp shapeOp, const char* testName, ExpectSuccess expectSucces s,
532 SkipAssert skipAssert, ExpectMatch expectMatch) {
496 #if 0 && DEBUG_SHOW_TEST_NAME 533 #if 0 && DEBUG_SHOW_TEST_NAME
497 showName(a, b, shapeOp); 534 showName(a, b, shapeOp);
498 #endif 535 #endif
499 SkPath out; 536 SkPath out;
500 if (!OpDebug(a, b, shapeOp, &out SkDEBUGPARAMS(skipAssert) 537 if (!OpDebug(a, b, shapeOp, &out SkDEBUGPARAMS(SkipAssert::kYes == skipAsse rt)
501 SkDEBUGPARAMS(testName))) { 538 SkDEBUGPARAMS(testName))) {
502 if (expectSuccess) { 539 if (ExpectSuccess::kYes == expectSuccess) {
503 SkDebugf("%s did not expect failure\n", __FUNCTION__); 540 SkDebugf("%s %s did not expect failure\n", __FUNCTION__, testName);
504 REPORTER_ASSERT(reporter, 0); 541 REPORTER_ASSERT(reporter, 0);
505 } 542 }
506 return false; 543 return false;
544 } else {
545 if (ExpectSuccess::kNo == expectSuccess) {
546 SkDebugf("%s %s unexpected success\n", __FUNCTION__, testName);
547 REPORTER_ASSERT(reporter, 0);
548 }
507 } 549 }
508 if (!reporter->verbose()) { 550 if (!reporter->verbose()) {
509 return true; 551 return true;
510 } 552 }
511 SkPath pathOut, scaledPathOut; 553 SkPath pathOut, scaledPathOut;
512 SkRegion rgnA, rgnB, openClip, rgnOut; 554 SkRegion rgnA, rgnB, openClip, rgnOut;
513 openClip.setRect(-16000, -16000, 16000, 16000); 555 openClip.setRect(-16000, -16000, 16000, 16000);
514 rgnA.setPath(a, openClip); 556 rgnA.setPath(a, openClip);
515 rgnB.setPath(b, openClip); 557 rgnB.setPath(b, openClip);
516 rgnOut.op(rgnA, rgnB, (SkRegion::Op) shapeOp); 558 rgnOut.op(rgnA, rgnB, (SkRegion::Op) shapeOp);
517 rgnOut.getBoundaryPath(&pathOut); 559 rgnOut.getBoundaryPath(&pathOut);
518 560
519 SkMatrix scale; 561 SkMatrix scale;
520 scaleMatrix(a, b, scale); 562 scaleMatrix(a, b, scale);
521 SkRegion scaledRgnA, scaledRgnB, scaledRgnOut; 563 SkRegion scaledRgnA, scaledRgnB, scaledRgnOut;
522 SkPath scaledA, scaledB; 564 SkPath scaledA, scaledB;
523 scaledA.addPath(a, scale); 565 scaledA.addPath(a, scale);
524 scaledA.setFillType(a.getFillType()); 566 scaledA.setFillType(a.getFillType());
525 scaledB.addPath(b, scale); 567 scaledB.addPath(b, scale);
526 scaledB.setFillType(b.getFillType()); 568 scaledB.setFillType(b.getFillType());
527 scaledRgnA.setPath(scaledA, openClip); 569 scaledRgnA.setPath(scaledA, openClip);
528 scaledRgnB.setPath(scaledB, openClip); 570 scaledRgnB.setPath(scaledB, openClip);
529 scaledRgnOut.op(scaledRgnA, scaledRgnB, (SkRegion::Op) shapeOp); 571 scaledRgnOut.op(scaledRgnA, scaledRgnB, (SkRegion::Op) shapeOp);
530 scaledRgnOut.getBoundaryPath(&scaledPathOut); 572 scaledRgnOut.getBoundaryPath(&scaledPathOut);
531 SkBitmap bitmap; 573 SkBitmap bitmap;
532 SkPath scaledOut; 574 SkPath scaledOut;
533 scaledOut.addPath(out, scale); 575 scaledOut.addPath(out, scale);
534 scaledOut.setFillType(out.getFillType()); 576 scaledOut.setFillType(out.getFillType());
535 int result = comparePaths(reporter, testName, pathOut, scaledPathOut, out, s caledOut, bitmap, 577 int result = comparePaths(reporter, testName, pathOut, scaledPathOut, out, s caledOut, bitmap,
536 a, b, shapeOp, scale, expectSuccess); 578 a, b, shapeOp, scale, ExpectMatch::kYes == expectMatch);
537 reporter->bumpTestCount(); 579 reporter->bumpTestCount();
538 return result == 0; 580 return result == 0;
539 } 581 }
540 582
541 bool testPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b, 583 bool testPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b,
542 const SkPathOp shapeOp, const char* testName) { 584 const SkPathOp shapeOp, const char* testName) {
543 return innerPathOp(reporter, a, b, shapeOp, testName, true, false); 585 return innerPathOp(reporter, a, b, shapeOp, testName, ExpectSuccess::kYes, S kipAssert::kNo,
586 ExpectMatch::kYes);
544 } 587 }
545 588
546 bool testPathOpCheck(skiatest::Reporter* reporter, const SkPath& a, const SkPath & b, 589 bool testPathOpCheck(skiatest::Reporter* reporter, const SkPath& a, const SkPath & b,
547 const SkPathOp shapeOp, const char* testName, bool checkFail) { 590 const SkPathOp shapeOp, const char* testName, bool checkFail) {
548 return innerPathOp(reporter, a, b, shapeOp, testName, checkFail, false); 591 return innerPathOp(reporter, a, b, shapeOp, testName, checkFail ?
592 ExpectSuccess::kYes : ExpectSuccess::kNo, SkipAssert::kNo, ExpectMat ch::kNo);
549 } 593 }
550 594
551 bool testPathOpFailCheck(skiatest::Reporter* reporter, const SkPath& a, const Sk Path& b, 595 bool testPathOpFailCheck(skiatest::Reporter* reporter, const SkPath& a, const Sk Path& b,
552 const SkPathOp shapeOp, const char* testName) { 596 const SkPathOp shapeOp, const char* testName) {
553 return innerPathOp(reporter, a, b, shapeOp, testName, false, false); 597 return innerPathOp(reporter, a, b, shapeOp, testName, ExpectSuccess::kNo, Sk ipAssert::kNo,
598 ExpectMatch::kNo);
554 } 599 }
555 600
556 bool testPathSkipAssertOp(skiatest::Reporter* reporter, const SkPath& a, const S kPath& b, 601 bool testPathOpSkipAssert(skiatest::Reporter* reporter, const SkPath& a, const S kPath& b,
557 const SkPathOp shapeOp, const char* testName) { 602 const SkPathOp shapeOp, const char* testName) {
558 return innerPathOp(reporter, a, b, shapeOp, testName, true, true); 603 return innerPathOp(reporter, a, b, shapeOp, testName, ExpectSuccess::kYes, S kipAssert::kYes,
604 ExpectMatch::kYes);
559 } 605 }
560 606
561 bool testPathFailSkipAssertOp(skiatest::Reporter* reporter, const SkPath& a, con st SkPath& b, 607 bool testPathOpFailSkipAssert(skiatest::Reporter* reporter, const SkPath& a, con st SkPath& b,
562 const SkPathOp shapeOp, const char* testName) { 608 const SkPathOp shapeOp, const char* testName) {
563 return innerPathOp(reporter, a, b, shapeOp, testName, false, true); 609 return innerPathOp(reporter, a, b, shapeOp, testName, ExpectSuccess::kNo, Sk ipAssert::kYes,
610 ExpectMatch::kNo);
564 } 611 }
565 612
566 bool testPathFailOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b, 613 bool testPathOpFail(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b,
567 const SkPathOp shapeOp, const char* testName) { 614 const SkPathOp shapeOp, const char* testName) {
568 #if DEBUG_SHOW_TEST_NAME 615 #if DEBUG_SHOW_TEST_NAME
569 showName(a, b, shapeOp); 616 showName(a, b, shapeOp);
570 #endif 617 #endif
571 SkPath orig; 618 SkPath orig;
572 orig.lineTo(54, 43); 619 orig.lineTo(54, 43);
573 SkPath out = orig; 620 SkPath out = orig;
574 if (Op(a, b, shapeOp, &out) ) { 621 if (Op(a, b, shapeOp, &out) ) {
575 SkDebugf("%s test is expected to fail\n", __FUNCTION__); 622 SkDebugf("%s test is expected to fail\n", __FUNCTION__);
576 REPORTER_ASSERT(reporter, 0); 623 REPORTER_ASSERT(reporter, 0);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 if (foundSkip && tests[index].fun != firstTest) { 730 if (foundSkip && tests[index].fun != firstTest) {
684 SkDebugf(" %s,\n", tests[index].str); 731 SkDebugf(" %s,\n", tests[index].str);
685 } 732 }
686 if (tests[index].fun == stopTest || index == last) { 733 if (tests[index].fun == stopTest || index == last) {
687 break; 734 break;
688 } 735 }
689 index += reverse ? -1 : 1; 736 index += reverse ? -1 : 1;
690 } while (true); 737 } while (true);
691 #endif 738 #endif
692 } 739 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698