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

Side by Side Diff: tests/ImageDecodingTest.cpp

Issue 132843002: Add REPORTF test macro. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: factor Created 6 years, 11 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 "Test.h" 8 #include "Test.h"
9 #include "TestClassDef.h" 9 #include "TestClassDef.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 case kAlpha_8_SkColorType: return "Alpha_8"; 403 case kAlpha_8_SkColorType: return "Alpha_8";
404 case kRGB_565_SkColorType: return "RGB_565"; 404 case kRGB_565_SkColorType: return "RGB_565";
405 case kARGB_4444_SkColorType: return "ARGB_4444"; 405 case kARGB_4444_SkColorType: return "ARGB_4444";
406 case kPMColor_SkColorType: return "PMColor"; 406 case kPMColor_SkColorType: return "PMColor";
407 case kBackwards_SkColorType: return "Backwards"; 407 case kBackwards_SkColorType: return "Backwards";
408 case kIndex_8_SkColorType: return "Index_8"; 408 case kIndex_8_SkColorType: return "Index_8";
409 default: return "ERROR"; 409 default: return "ERROR";
410 } 410 }
411 } 411 }
412 412
413 static inline const char* options_colorType(
414 const SkDecodingImageGenerator::Options& opts) {
415 if (opts.fUseRequestedColorType) {
416 return SkColorType_to_string(opts.fRequestedColorType);
417 } else {
418 return "(none)";
419 }
420 }
421
422 static inline const char* yn(bool value) {
423 if (value) {
424 return "yes";
425 } else {
426 return "no";
427 }
428 }
429
413 /** 430 /**
414 * Given either a SkStream or a SkData, try to decode the encoded 431 * Given either a SkStream or a SkData, try to decode the encoded
415 * image using the specified options and report errors. 432 * image using the specified options and report errors.
416 */ 433 */
417 static void test_options(skiatest::Reporter* reporter, 434 static void test_options(skiatest::Reporter* reporter,
418 const SkDecodingImageGenerator::Options& opts, 435 const SkDecodingImageGenerator::Options& opts,
419 SkStreamRewindable* encodedStream, 436 SkStreamRewindable* encodedStream,
420 SkData* encodedData, 437 SkData* encodedData,
421 bool useData, 438 bool useData,
422 const SkString& path) { 439 const SkString& path) {
(...skipping 13 matching lines...) Expand all
436 SkDecodingImageGenerator::Create(encodedStream->duplicate(), opts), 453 SkDecodingImageGenerator::Create(encodedStream->duplicate(), opts),
437 &bm, NULL); 454 &bm, NULL);
438 } 455 }
439 if (!success) { 456 if (!success) {
440 if (opts.fUseRequestedColorType 457 if (opts.fUseRequestedColorType
441 && (kARGB_4444_SkColorType == opts.fRequestedColorType)) { 458 && (kARGB_4444_SkColorType == opts.fRequestedColorType)) {
442 return; // Ignore known conversion inabilities. 459 return; // Ignore known conversion inabilities.
443 } 460 }
444 // If we get here, it's a failure and we will need more 461 // If we get here, it's a failure and we will need more
445 // information about why it failed. 462 // information about why it failed.
446 reporter->reportFailed(SkStringPrintf( 463 REPORTF(reporter,
447 "Bounds decode failed " 464 ("Bounds decode failed [sampleSize=%d dither=%s colorType=%s"
448 "[sampleSize=%d dither=%s colorType=%s %s] %s:%d", 465 " %s]", opts.fSampleSize, yn(opts.fDitherImage),
449 opts.fSampleSize, (opts.fDitherImage ? "yes" : "no"), 466 options_colorType(opts), path.c_str()));
450 (opts.fUseRequestedColorType
451 ? SkColorType_to_string(opts.fRequestedColorType) : "(none)"),
452 path.c_str(), __FILE__, __LINE__));
453 return; 467 return;
454 } 468 }
455 #if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX) 469 #if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX)
456 // Android is the only system that use Skia's image decoders in 470 // Android is the only system that use Skia's image decoders in
457 // production. For now, we'll only verify that samplesize works 471 // production. For now, we'll only verify that samplesize works
458 // on systems where it already is known to work. 472 // on systems where it already is known to work.
459 REPORTER_ASSERT(reporter, check_rounding(bm.height(), kExpectedHeight, 473 REPORTER_ASSERT(reporter, check_rounding(bm.height(), kExpectedHeight,
460 opts.fSampleSize)); 474 opts.fSampleSize));
461 REPORTER_ASSERT(reporter, check_rounding(bm.width(), kExpectedWidth, 475 REPORTER_ASSERT(reporter, check_rounding(bm.width(), kExpectedWidth,
462 opts.fSampleSize)); 476 opts.fSampleSize));
463 #endif // SK_BUILD_FOR_ANDROID || SK_BUILD_FOR_UNIX 477 #endif // SK_BUILD_FOR_ANDROID || SK_BUILD_FOR_UNIX
464 SkAutoLockPixels alp(bm); 478 SkAutoLockPixels alp(bm);
465 if (bm.getPixels() == NULL) { 479 if (bm.getPixels() == NULL) {
466 reporter->reportFailed(SkStringPrintf( 480 REPORTF(reporter,
467 "Pixel decode failed " 481 ("Pixel decode failed [sampleSize=%d dither=%s colorType=%s"
468 "[sampleSize=%d dither=%s colorType=%s %s] %s:%d", 482 " %s]", opts.fSampleSize, yn(opts.fDitherImage),
469 opts.fSampleSize, (opts.fDitherImage ? "yes" : "no"), 483 options_colorType(opts), path.c_str()));
470 (opts.fUseRequestedColorType
471 ? SkColorType_to_string(opts.fRequestedColorType) : "(none)"),
472 path.c_str(), __FILE__, __LINE__));
473 return; 484 return;
474 } 485 }
475 486
476 SkBitmap::Config requestedConfig 487 SkBitmap::Config requestedConfig
477 = SkColorTypeToBitmapConfig(opts.fRequestedColorType); 488 = SkColorTypeToBitmapConfig(opts.fRequestedColorType);
478 REPORTER_ASSERT(reporter, 489 REPORTER_ASSERT(reporter,
479 (!opts.fUseRequestedColorType) 490 (!opts.fUseRequestedColorType)
480 || (bm.config() == requestedConfig)); 491 || (bm.config() == requestedConfig));
481 492
482 // Condition under which we should check the decoding results: 493 // Condition under which we should check the decoding results:
483 if ((SkBitmap::kARGB_8888_Config == bm.config()) 494 if ((SkBitmap::kARGB_8888_Config == bm.config())
484 && (!path.endsWith(".jpg")) // lossy 495 && (!path.endsWith(".jpg")) // lossy
485 && (opts.fSampleSize == 1)) { // scaled 496 && (opts.fSampleSize == 1)) { // scaled
486 const SkColor* correctPixels = kExpectedPixels; 497 const SkColor* correctPixels = kExpectedPixels;
487 SkASSERT(bm.height() == kExpectedHeight); 498 SkASSERT(bm.height() == kExpectedHeight);
488 SkASSERT(bm.width() == kExpectedWidth); 499 SkASSERT(bm.width() == kExpectedWidth);
489 int pixelErrors = 0; 500 int pixelErrors = 0;
490 for (int y = 0; y < bm.height(); ++y) { 501 for (int y = 0; y < bm.height(); ++y) {
491 for (int x = 0; x < bm.width(); ++x) { 502 for (int x = 0; x < bm.width(); ++x) {
492 if (*correctPixels != bm.getColor(x, y)) { 503 if (*correctPixels != bm.getColor(x, y)) {
493 ++pixelErrors; 504 ++pixelErrors;
494 } 505 }
495 ++correctPixels; 506 ++correctPixels;
496 } 507 }
497 } 508 }
498 if (pixelErrors != 0) { 509 if (pixelErrors != 0) {
499 reporter->reportFailed(SkStringPrintf( 510 REPORTF(reporter,
500 "Pixel-level mismatch (%d of %d) [sampleSize=%d " 511 ("Pixel-level mismatch (%d of %d) [sampleSize=%d "
501 "dither=%s colorType=%s %s] %s:%d", 512 "dither=%s colorType=%s %s]",
502 pixelErrors, kExpectedHeight * kExpectedWidth, 513 pixelErrors, kExpectedHeight * kExpectedWidth,
503 opts.fSampleSize, (opts.fDitherImage ? "yes" : "no"), 514 opts.fSampleSize, yn(opts.fDitherImage),
504 (opts.fUseRequestedColorType 515 options_colorType(opts), path.c_str()));
505 ? SkColorType_to_string(opts.fRequestedColorType)
506 : "(none)"), path.c_str(), __FILE__, __LINE__));
507 } 516 }
508 } 517 }
509 } 518 }
510 519
511 /** 520 /**
512 * SkDecodingImageGenerator has an Options struct which lets the 521 * SkDecodingImageGenerator has an Options struct which lets the
513 * client of the generator set sample size, dithering, and bitmap 522 * client of the generator set sample size, dithering, and bitmap
514 * config. This test loops through many possible options and tries 523 * config. This test loops through many possible options and tries
515 * them on a set of 5 small encoded images (each in a different 524 * them on a set of 5 small encoded images (each in a different
516 * format). We test both SkData and SkStreamRewindable decoding. 525 * format). We test both SkData and SkStreamRewindable decoding.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 SkDecodingImageGenerator::Options options(scaleList[i], 580 SkDecodingImageGenerator::Options options(scaleList[i],
572 ditherList[j]); 581 ditherList[j]);
573 test_options(reporter, options, encodedStream, encodedData, 582 test_options(reporter, options, encodedStream, encodedData,
574 useDataList[m], path); 583 useDataList[m], path);
575 } 584 }
576 } 585 }
577 } 586 }
578 } 587 }
579 } 588 }
580 //////////////////////////////////////////////////////////////////////////////// 589 ////////////////////////////////////////////////////////////////////////////////
OLDNEW
« no previous file with comments | « tests/GpuBitmapCopyTest.cpp ('k') | tests/MathTest.cpp » ('j') | tests/Test.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698