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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 void ShowTestArray() { | 315 void ShowTestArray() { |
316 for (int x = gTestFirst; x < gTestNo; ++x) { | 316 for (int x = gTestFirst; x < gTestNo; ++x) { |
317 SkDebugf(" TEST(xOp%d%s),\n", x, opSuffixes[gTestOp[x - gTestFirst]])
; | 317 SkDebugf(" TEST(xOp%d%s),\n", x, opSuffixes[gTestOp[x - gTestFirst]])
; |
318 } | 318 } |
319 } | 319 } |
320 | 320 |
321 SK_DECLARE_STATIC_MUTEX(compareDebugOut3); | 321 SK_DECLARE_STATIC_MUTEX(compareDebugOut3); |
322 SK_DECLARE_STATIC_MUTEX(compareDebugOut4); | 322 SK_DECLARE_STATIC_MUTEX(compareDebugOut4); |
323 static int comparePaths(skiatest::Reporter* reporter, const char* testName, cons
t SkPath& one, | 323 static int comparePaths(skiatest::Reporter* reporter, const char* testName, cons
t SkPath& one, |
324 const SkPath& scaledOne, const SkPath& two, const SkPath& scaledTwo, SkB
itmap& bitmap, | 324 const SkPath& scaledOne, const SkPath& two, const SkPath& scaledTwo, SkB
itmap& bitmap, |
325 const SkPath& a, const SkPath& b, const SkPathOp shapeOp, const SkMatrix
& scale) { | 325 const SkPath& a, const SkPath& b, const SkPathOp shapeOp, const SkMatrix
& scale, |
| 326 bool expectSuccess) { |
326 int errors2x2; | 327 int errors2x2; |
| 328 const int MAX_ERRORS = 8; |
327 (void) pathsDrawTheSame(bitmap, scaledOne, scaledTwo, errors2x2); | 329 (void) pathsDrawTheSame(bitmap, scaledOne, scaledTwo, errors2x2); |
| 330 if (!expectSuccess) { |
| 331 if (errors2x2 <= MAX_ERRORS) { |
| 332 REPORTER_ASSERT(reporter, 0); |
| 333 } |
| 334 return 0; |
| 335 } |
328 if (errors2x2 == 0) { | 336 if (errors2x2 == 0) { |
329 if (gShowPath) { | 337 if (gShowPath) { |
330 showPathOpPath(testName, one, two, a, b, scaledOne, scaledTwo, shape
Op, scale); | 338 showPathOpPath(testName, one, two, a, b, scaledOne, scaledTwo, shape
Op, scale); |
331 } | 339 } |
332 return 0; | 340 return 0; |
333 } | 341 } |
334 const int MAX_ERRORS = 8; | |
335 if (errors2x2 > MAX_ERRORS && gComparePathsAssert) { | 342 if (errors2x2 > MAX_ERRORS && gComparePathsAssert) { |
336 SkAutoMutexAcquire autoM(compareDebugOut3); | 343 SkAutoMutexAcquire autoM(compareDebugOut3); |
337 SkDebugf("\n*** this test fails ***\n"); | 344 SkDebugf("\n*** this test fails ***\n"); |
338 showPathOpPath(testName, one, two, a, b, scaledOne, scaledTwo, shapeOp,
scale); | 345 showPathOpPath(testName, one, two, a, b, scaledOne, scaledTwo, shapeOp,
scale); |
339 REPORTER_ASSERT(reporter, 0); | 346 REPORTER_ASSERT(reporter, 0); |
340 } else if (gShowPath || errors2x2 == MAX_ERRORS || errors2x2 == MAX_ERRORS -
1) { | 347 } else if (gShowPath || errors2x2 == MAX_ERRORS || errors2x2 == MAX_ERRORS -
1) { |
341 SkAutoMutexAcquire autoM(compareDebugOut4); | 348 SkAutoMutexAcquire autoM(compareDebugOut4); |
342 showPathOpPath(testName, one, two, a, b, scaledOne, scaledTwo, shapeOp,
scale); | 349 showPathOpPath(testName, one, two, a, b, scaledOne, scaledTwo, shapeOp,
scale); |
343 } | 350 } |
344 return errors2x2 > MAX_ERRORS ? errors2x2 : 0; | 351 return errors2x2 > MAX_ERRORS ? errors2x2 : 0; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 #if DEBUG_SHOW_TEST_NAME | 472 #if DEBUG_SHOW_TEST_NAME |
466 static void showName(const SkPath& a, const SkPath& b, const SkPathOp shapeOp) { | 473 static void showName(const SkPath& a, const SkPath& b, const SkPathOp shapeOp) { |
467 SkDebugf("\n"); | 474 SkDebugf("\n"); |
468 showPathData(a); | 475 showPathData(a); |
469 showOp(shapeOp); | 476 showOp(shapeOp); |
470 showPathData(b); | 477 showPathData(b); |
471 } | 478 } |
472 #endif | 479 #endif |
473 | 480 |
474 static bool innerPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkP
ath& b, | 481 static bool innerPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkP
ath& b, |
475 const SkPathOp shapeOp, const char* testName, bool threaded) { | 482 const SkPathOp shapeOp, const char* testName, bool threaded, bool expect
Success) { |
476 #if DEBUG_SHOW_TEST_NAME | 483 #if DEBUG_SHOW_TEST_NAME |
477 showName(a, b, shapeOp); | 484 showName(a, b, shapeOp); |
478 #endif | 485 #endif |
479 SkPath out; | 486 SkPath out; |
480 if (!Op(a, b, shapeOp, &out) ) { | 487 if (!Op(a, b, shapeOp, &out) ) { |
481 SkDebugf("%s did not expect failure\n", __FUNCTION__); | 488 SkDebugf("%s did not expect failure\n", __FUNCTION__); |
482 REPORTER_ASSERT(reporter, 0); | 489 REPORTER_ASSERT(reporter, 0); |
483 return false; | 490 return false; |
484 } | 491 } |
485 if (threaded && !reporter->verbose()) { | 492 if (threaded && !reporter->verbose()) { |
(...skipping 17 matching lines...) Expand all Loading... |
503 scaledB.setFillType(b.getFillType()); | 510 scaledB.setFillType(b.getFillType()); |
504 scaledRgnA.setPath(scaledA, openClip); | 511 scaledRgnA.setPath(scaledA, openClip); |
505 scaledRgnB.setPath(scaledB, openClip); | 512 scaledRgnB.setPath(scaledB, openClip); |
506 scaledRgnOut.op(scaledRgnA, scaledRgnB, (SkRegion::Op) shapeOp); | 513 scaledRgnOut.op(scaledRgnA, scaledRgnB, (SkRegion::Op) shapeOp); |
507 scaledRgnOut.getBoundaryPath(&scaledPathOut); | 514 scaledRgnOut.getBoundaryPath(&scaledPathOut); |
508 SkBitmap bitmap; | 515 SkBitmap bitmap; |
509 SkPath scaledOut; | 516 SkPath scaledOut; |
510 scaledOut.addPath(out, scale); | 517 scaledOut.addPath(out, scale); |
511 scaledOut.setFillType(out.getFillType()); | 518 scaledOut.setFillType(out.getFillType()); |
512 int result = comparePaths(reporter, testName, pathOut, scaledPathOut, out, s
caledOut, bitmap, | 519 int result = comparePaths(reporter, testName, pathOut, scaledPathOut, out, s
caledOut, bitmap, |
513 a, b, shapeOp, scale); | 520 a, b, shapeOp, scale, expectSuccess); |
514 if (result && gPathStrAssert) { | 521 if (result && gPathStrAssert) { |
515 REPORTER_ASSERT(reporter, 0); | 522 REPORTER_ASSERT(reporter, 0); |
516 } | 523 } |
517 reporter->bumpTestCount(); | 524 reporter->bumpTestCount(); |
518 return result == 0; | 525 return result == 0; |
519 } | 526 } |
520 | 527 |
521 bool testPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b, | 528 bool testPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b, |
522 const SkPathOp shapeOp, const char* testName) { | 529 const SkPathOp shapeOp, const char* testName) { |
523 return innerPathOp(reporter, a, b, shapeOp, testName, false); | 530 return innerPathOp(reporter, a, b, shapeOp, testName, false, true); |
| 531 } |
| 532 |
| 533 bool testPathOpCheck(skiatest::Reporter* reporter, const SkPath& a, const SkPath
& b, |
| 534 const SkPathOp shapeOp, const char* testName, bool checkFail) { |
| 535 return innerPathOp(reporter, a, b, shapeOp, testName, false, checkFail); |
524 } | 536 } |
525 | 537 |
526 bool testPathFailOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath&
b, | 538 bool testPathFailOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath&
b, |
527 const SkPathOp shapeOp, const char* testName) { | 539 const SkPathOp shapeOp, const char* testName) { |
528 #if DEBUG_SHOW_TEST_NAME | 540 #if DEBUG_SHOW_TEST_NAME |
529 showName(a, b, shapeOp); | 541 showName(a, b, shapeOp); |
530 #endif | 542 #endif |
531 SkPath out; | 543 SkPath out; |
532 if (Op(a, b, shapeOp, &out) ) { | 544 if (Op(a, b, shapeOp, &out) ) { |
533 SkDebugf("%s test is expected to fail\n", __FUNCTION__); | 545 SkDebugf("%s test is expected to fail\n", __FUNCTION__); |
534 REPORTER_ASSERT(reporter, 0); | 546 REPORTER_ASSERT(reporter, 0); |
535 return false; | 547 return false; |
536 } | 548 } |
537 return true; | 549 return true; |
538 } | 550 } |
539 | 551 |
540 bool testThreadedPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkP
ath& b, | 552 bool testThreadedPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkP
ath& b, |
541 const SkPathOp shapeOp, const char* testName) { | 553 const SkPathOp shapeOp, const char* testName) { |
542 return innerPathOp(reporter, a, b, shapeOp, testName, true); | 554 return innerPathOp(reporter, a, b, shapeOp, testName, true, true); |
543 } | 555 } |
544 | 556 |
545 SK_DECLARE_STATIC_MUTEX(gMutex); | 557 SK_DECLARE_STATIC_MUTEX(gMutex); |
546 | 558 |
547 void initializeTests(skiatest::Reporter* reporter, const char* test) { | 559 void initializeTests(skiatest::Reporter* reporter, const char* test) { |
548 #if 0 // doesn't work yet | 560 #if 0 // doesn't work yet |
549 SK_CONF_SET("images.jpeg.suppressDecoderWarnings", true); | 561 SK_CONF_SET("images.jpeg.suppressDecoderWarnings", true); |
550 SK_CONF_SET("images.png.suppressDecoderWarnings", true); | 562 SK_CONF_SET("images.png.suppressDecoderWarnings", true); |
551 #endif | 563 #endif |
552 if (reporter->verbose()) { | 564 if (reporter->verbose()) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 if (tests[index].fun == stopTest) { | 633 if (tests[index].fun == stopTest) { |
622 SkDebugf("lastTest\n"); | 634 SkDebugf("lastTest\n"); |
623 break; | 635 break; |
624 } | 636 } |
625 if (index == last) { | 637 if (index == last) { |
626 break; | 638 break; |
627 } | 639 } |
628 index += reverse ? -1 : 1; | 640 index += reverse ? -1 : 1; |
629 } while (true); | 641 } while (true); |
630 } | 642 } |
OLD | NEW |