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

Side by Side Diff: tests/ImageDecodingTest.cpp

Issue 346453002: Refactor how we handle resources path in Tests. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix rebase conflict Created 6 years, 6 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
« no previous file with comments | « tests/FontHostTest.cpp ('k') | tests/KtxTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "Resources.h"
8 #include "SkBitmap.h" 9 #include "SkBitmap.h"
9 #include "SkCanvas.h" 10 #include "SkCanvas.h"
10 #include "SkColor.h" 11 #include "SkColor.h"
11 #include "SkColorPriv.h" 12 #include "SkColorPriv.h"
12 #include "SkData.h" 13 #include "SkData.h"
13 #include "SkDecodingImageGenerator.h" 14 #include "SkDecodingImageGenerator.h"
14 #include "SkDiscardableMemoryPool.h" 15 #include "SkDiscardableMemoryPool.h"
15 #include "SkForceLinking.h" 16 #include "SkForceLinking.h"
16 #include "SkGradientShader.h" 17 #include "SkGradientShader.h"
17 #include "SkImageDecoder.h" 18 #include "SkImageDecoder.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // Color components may not match exactly due to rounding error. 142 // Color components may not match exactly due to rounding error.
142 REPORTER_ASSERT(reporter, dr <= 1); 143 REPORTER_ASSERT(reporter, dr <= 1);
143 REPORTER_ASSERT(reporter, dg <= 1); 144 REPORTER_ASSERT(reporter, dg <= 1);
144 REPORTER_ASSERT(reporter, db <= 1); 145 REPORTER_ASSERT(reporter, db <= 1);
145 } 146 }
146 } 147 }
147 } 148 }
148 149
149 static void test_unpremul(skiatest::Reporter* reporter) { 150 static void test_unpremul(skiatest::Reporter* reporter) {
150 // This test cannot run if there is no resource path. 151 // This test cannot run if there is no resource path.
151 SkString resourcePath = skiatest::Test::GetResourcePath(); 152 SkString resourcePath = GetResourcePath();
152 if (resourcePath.isEmpty()) { 153 if (resourcePath.isEmpty()) {
153 SkDebugf("Could not run unpremul test because resourcePath not specified ."); 154 SkDebugf("Could not run unpremul test because resourcePath not specified .");
154 return; 155 return;
155 } 156 }
156 SkOSFile::Iter iter(resourcePath.c_str()); 157 SkOSFile::Iter iter(resourcePath.c_str());
157 SkString basename; 158 SkString basename;
158 if (iter.next(&basename)) { 159 if (iter.next(&basename)) {
159 do { 160 do {
160 SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), basen ame.c_str()); 161 SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), basen ame.c_str());
161 // SkDebugf("about to decode \"%s\"\n", filename.c_str()); 162 // SkDebugf("about to decode \"%s\"\n", filename.c_str());
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 224 }
224 225
225 // When decoding the full image, the alpha type should match the one 226 // When decoding the full image, the alpha type should match the one
226 // returned by the bounds decode, unless the full decode determined that 227 // returned by the bounds decode, unless the full decode determined that
227 // the alpha type is actually opaque. 228 // the alpha type is actually opaque.
228 REPORTER_ASSERT(reporter, bm.alphaType() == boundsAlphaType 229 REPORTER_ASSERT(reporter, bm.alphaType() == boundsAlphaType
229 || bm.alphaType() == kOpaque_SkAlphaType); 230 || bm.alphaType() == kOpaque_SkAlphaType);
230 } 231 }
231 232
232 DEF_TEST(ImageDecoding_alphaType, reporter) { 233 DEF_TEST(ImageDecoding_alphaType, reporter) {
233 SkString resourcePath = skiatest::Test::GetResourcePath(); 234 SkString resourcePath = GetResourcePath();
234 if (resourcePath.isEmpty()) { 235 if (resourcePath.isEmpty()) {
235 SkDebugf("Could not run alphaType test because resourcePath not specifie d."); 236 SkDebugf("Could not run alphaType test because resourcePath not specifie d.");
236 return; 237 return;
237 } 238 }
238 239
239 SkOSFile::Iter iter(resourcePath.c_str()); 240 SkOSFile::Iter iter(resourcePath.c_str());
240 SkString basename; 241 SkString basename;
241 if (iter.next(&basename)) { 242 if (iter.next(&basename)) {
242 do { 243 do {
243 SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), basen ame.c_str()); 244 SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), basen ame.c_str());
244 for (int truth = 0; truth <= 1; ++truth) { 245 for (int truth = 0; truth <= 1; ++truth) {
245 test_alphaType(reporter, filename, SkToBool(truth)); 246 test_alphaType(reporter, filename, SkToBool(truth));
246 } 247 }
247 } while (iter.next(&basename)); 248 } while (iter.next(&basename));
248 } else { 249 } else {
249 SkDebugf("Failed to find any files :(\n"); 250 SkDebugf("Failed to find any files :(\n");
250 } 251 }
251 252
252 } 253 }
253 254
254 // Using known images, test that decoding into unpremul and premul behave as exp ected. 255 // Using known images, test that decoding into unpremul and premul behave as exp ected.
255 DEF_TEST(ImageDecoding_unpremul, reporter) { 256 DEF_TEST(ImageDecoding_unpremul, reporter) {
256 SkString resourcePath = skiatest::Test::GetResourcePath(); 257 SkString resourcePath = GetResourcePath();
257 if (resourcePath.isEmpty()) { 258 if (resourcePath.isEmpty()) {
258 SkDebugf("Could not run unpremul test because resourcePath not specified ."); 259 SkDebugf("Could not run unpremul test because resourcePath not specified .");
259 return; 260 return;
260 } 261 }
261 const char* root = "half-transparent-white-pixel"; 262 const char* root = "half-transparent-white-pixel";
262 const char* suffixes[] = { ".png", ".webp" }; 263 const char* suffixes[] = { ".png", ".webp" };
263 264
264 for (size_t i = 0; i < SK_ARRAY_COUNT(suffixes); ++i) { 265 for (size_t i = 0; i < SK_ARRAY_COUNT(suffixes); ++i) {
265 SkString basename = SkStringPrintf("%s%s", root, suffixes[i]); 266 SkString basename = SkStringPrintf("%s%s", root, suffixes[i]);
266 SkString fullName = SkOSPath::SkPathJoin(resourcePath.c_str(), basename. c_str()); 267 SkString fullName = SkOSPath::SkPathJoin(resourcePath.c_str(), basename. c_str());
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 SkDecodingImageGenerator::Create(stream, opts), bitmap)) { 496 SkDecodingImageGenerator::Create(stream, opts), bitmap)) {
496 return bitmap->pixelRef(); 497 return bitmap->pixelRef();
497 } 498 }
498 return NULL; 499 return NULL;
499 } 500 }
500 /** 501 /**
501 * A test for the SkDecodingImageGenerator::Create and 502 * A test for the SkDecodingImageGenerator::Create and
502 * SkInstallDiscardablePixelRef functions. 503 * SkInstallDiscardablePixelRef functions.
503 */ 504 */
504 DEF_TEST(ImprovedBitmapFactory, reporter) { 505 DEF_TEST(ImprovedBitmapFactory, reporter) {
505 SkString resourcePath = skiatest::Test::GetResourcePath(); 506 SkString resourcePath = GetResourcePath();
506 SkString path = SkOSPath::SkPathJoin( 507 SkString path = SkOSPath::SkPathJoin(
507 resourcePath.c_str(), "randPixels.png"); 508 resourcePath.c_str(), "randPixels.png");
508 SkAutoTUnref<SkStreamRewindable> stream( 509 SkAutoTUnref<SkStreamRewindable> stream(
509 SkStream::NewFromFile(path.c_str())); 510 SkStream::NewFromFile(path.c_str()));
510 if (sk_exists(path.c_str())) { 511 if (sk_exists(path.c_str())) {
511 SkBitmap bm; 512 SkBitmap bm;
512 SkAssertResult(bm.setInfo(SkImageInfo::MakeN32Premul(1, 1))); 513 SkAssertResult(bm.setInfo(SkImageInfo::MakeN32Premul(1, 1)));
513 REPORTER_ASSERT(reporter, 514 REPORTER_ASSERT(reporter,
514 NULL != install_pixel_ref(&bm, stream.detach(), 1, true)); 515 NULL != install_pixel_ref(&bm, stream.detach(), 1, true));
515 SkAutoLockPixels alp(bm); 516 SkAutoLockPixels alp(bm);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 "randPixels.bmp", 670 "randPixels.bmp",
670 "randPixels.jpg", 671 "randPixels.jpg",
671 "randPixels.png", 672 "randPixels.png",
672 "randPixels.webp", 673 "randPixels.webp",
673 #if !defined(SK_BUILD_FOR_WIN) 674 #if !defined(SK_BUILD_FOR_WIN)
674 // TODO(halcanary): Find out why this fails sometimes. 675 // TODO(halcanary): Find out why this fails sometimes.
675 "randPixels.gif", 676 "randPixels.gif",
676 #endif 677 #endif
677 }; 678 };
678 679
679 SkString resourceDir = skiatest::Test::GetResourcePath(); 680 SkString resourceDir = GetResourcePath();
680 if (!sk_exists(resourceDir.c_str())) { 681 if (!sk_exists(resourceDir.c_str())) {
681 return; 682 return;
682 } 683 }
683 684
684 int scaleList[] = {1, 2, 3, 4}; 685 int scaleList[] = {1, 2, 3, 4};
685 bool ditherList[] = {true, false}; 686 bool ditherList[] = {true, false};
686 SkColorType colorList[] = { 687 SkColorType colorList[] = {
687 kAlpha_8_SkColorType, 688 kAlpha_8_SkColorType,
688 kRGB_565_SkColorType, 689 kRGB_565_SkColorType,
689 kARGB_4444_SkColorType, // Most decoders will fail on 4444. 690 kARGB_4444_SkColorType, // Most decoders will fail on 4444.
(...skipping 28 matching lines...) Expand all
718 } 719 }
719 SkDecodingImageGenerator::Options options(scaleList[i], 720 SkDecodingImageGenerator::Options options(scaleList[i],
720 ditherList[j]); 721 ditherList[j]);
721 test_options(reporter, options, encodedStream, encodedData, 722 test_options(reporter, options, encodedStream, encodedData,
722 useDataList[m], path); 723 useDataList[m], path);
723 } 724 }
724 } 725 }
725 } 726 }
726 } 727 }
727 } 728 }
OLDNEW
« no previous file with comments | « tests/FontHostTest.cpp ('k') | tests/KtxTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698