| Index: tests/CachedDecodingPixelRefTest.cpp
|
| diff --git a/tests/CachedDecodingPixelRefTest.cpp b/tests/CachedDecodingPixelRefTest.cpp
|
| index 8de7da79a252e54404cd64457dee387234b70f32..b409987392ab36af2e8ea1554f9dfa06048d0d8f 100644
|
| --- a/tests/CachedDecodingPixelRefTest.cpp
|
| +++ b/tests/CachedDecodingPixelRefTest.cpp
|
| @@ -322,3 +322,42 @@ DEF_TEST(DiscardableAndCachingPixelRef, reporter) {
|
| check_pixelref(TestImageGenerator::kSucceedGetPixels_TestType,
|
| reporter, kSkDiscardable_PixelRefType, globalPool);
|
| }
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +
|
| +DEF_TEST(Image_NewFromGenerator, r) {
|
| + TestImageGenerator::TestType testTypes[] = {
|
| + TestImageGenerator::kFailGetInfo_TestType,
|
| + TestImageGenerator::kFailGetPixels_TestType,
|
| + TestImageGenerator::kSucceedGetPixels_TestType,
|
| + };
|
| + for (size_t i = 0; i < SK_ARRAY_COUNT(testTypes); ++i) {
|
| + TestImageGenerator::TestType test = testTypes[i];
|
| + SkImageGenerator* gen = SkNEW_ARGS(TestImageGenerator, (test, r));
|
| + SkAutoTUnref<SkImage> image(SkImage::NewFromGenerator(gen));
|
| + if (TestImageGenerator::kFailGetInfo_TestType == test) {
|
| + REPORTER_ASSERT(r, NULL == image.get());
|
| + continue;
|
| + }
|
| + if (NULL == image.get()) {
|
| + ERRORF(r, "SkImage::NewFromGenerator unexpecedly failed ["
|
| + SK_SIZE_T_SPECIFIER "]", i);
|
| + continue;
|
| + }
|
| + REPORTER_ASSERT(r, TestImageGenerator::Width() == image->width());
|
| + REPORTER_ASSERT(r, TestImageGenerator::Height() == image->height());
|
| +
|
| + SkBitmap bitmap;
|
| + SkAssertResult(bitmap.allocN32Pixels(TestImageGenerator::Width(),
|
| + TestImageGenerator::Height()));
|
| + SkCanvas canvas(bitmap);
|
| + canvas.clear(SK_ColorMAGENTA);
|
| + image->draw(&canvas, 0, 0, NULL);
|
| + SkColor color = bitmap.getColor(0, 0);
|
| + if (TestImageGenerator::kSucceedGetPixels_TestType == test) {
|
| + REPORTER_ASSERT(r, TestImageGenerator::Color() == color);
|
| + } else {
|
| + REPORTER_ASSERT(r, SK_ColorMAGENTA == color);
|
| + }
|
| + }
|
| +}
|
|
|