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

Side by Side Diff: tests/BitmapCopyTest.cpp

Issue 132843002: Add REPORTF test macro. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: final rebase 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
« no previous file with comments | « no previous file | tests/BlitRowTest.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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
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"
11 #include "SkRect.h" 11 #include "SkRect.h"
12 12
13 static const char* boolStr(bool value) { 13 static const char* boolStr(bool value) {
14 return value ? "true" : "false"; 14 return value ? "true" : "false";
15 } 15 }
16 16
17 // these are in the same order as the SkBitmap::Config enum 17 // these are in the same order as the SkBitmap::Config enum
18 static const char* gConfigName[] = { 18 static const char* gConfigName[] = {
19 "None", "A8", "Index8", "565", "4444", "8888" 19 "None", "A8", "Index8", "565", "4444", "8888"
20 }; 20 };
21 21
22 static void report_opaqueness(skiatest::Reporter* reporter, const SkBitmap& src, 22 static void report_opaqueness(skiatest::Reporter* reporter, const SkBitmap& src,
23 const SkBitmap& dst) { 23 const SkBitmap& dst) {
24 SkString str; 24 ERRORF(reporter, "src %s opaque:%d, dst %s opaque:%d",
25 str.printf("src %s opaque:%d, dst %s opaque:%d", 25 gConfigName[src.config()], src.isOpaque(),
26 gConfigName[src.config()], src.isOpaque(), 26 gConfigName[dst.config()], dst.isOpaque());
27 gConfigName[dst.config()], dst.isOpaque());
28 reporter->reportFailed(str);
29 } 27 }
30 28
31 static bool canHaveAlpha(SkBitmap::Config config) { 29 static bool canHaveAlpha(SkBitmap::Config config) {
32 return config != SkBitmap::kRGB_565_Config; 30 return config != SkBitmap::kRGB_565_Config;
33 } 31 }
34 32
35 // copyTo() should preserve isOpaque when it makes sense 33 // copyTo() should preserve isOpaque when it makes sense
36 static void test_isOpaque(skiatest::Reporter* reporter, 34 static void test_isOpaque(skiatest::Reporter* reporter,
37 const SkBitmap& srcOpaque, const SkBitmap& srcPremul, 35 const SkBitmap& srcOpaque, const SkBitmap& srcPremul,
38 SkBitmap::Config dstConfig) { 36 SkBitmap::Config dstConfig) {
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 bool success = true; 183 bool success = true;
186 184
187 // Confirm all pixels in the list match. 185 // Confirm all pixels in the list match.
188 for (int i = 0; i < coords.length; ++i) { 186 for (int i = 0; i < coords.length; ++i) {
189 success = success && 187 success = success &&
190 (getPixel(coords[i]->fX, coords[i]->fY, bm1) == 188 (getPixel(coords[i]->fX, coords[i]->fY, bm1) ==
191 getPixel(coords[i]->fX, coords[i]->fY, bm2)); 189 getPixel(coords[i]->fX, coords[i]->fY, bm2));
192 } 190 }
193 191
194 if (!success) { 192 if (!success) {
195 SkString str; 193 ERRORF(reporter, "%s [config = %s]", msg, getSkConfigName(bm1));
196 str.printf("%s [config = %s]",
197 msg, getSkConfigName(bm1));
198 reporter->reportFailed(str);
199 } 194 }
200 } 195 }
201 196
202 // Writes unique pixel values at locations specified by coords. 197 // Writes unique pixel values at locations specified by coords.
203 static void writeCoordPixels(SkBitmap& bm, const Coordinates& coords) { 198 static void writeCoordPixels(SkBitmap& bm, const Coordinates& coords) {
204 for (int i = 0; i < coords.length; ++i) 199 for (int i = 0; i < coords.length; ++i)
205 setPixel(coords[i]->fX, coords[i]->fY, i, bm); 200 setPixel(coords[i]->fX, coords[i]->fY, i, bm);
206 } 201 }
207 202
208 DEF_TEST(BitmapCopy, reporter) { 203 DEF_TEST(BitmapCopy, reporter) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 srcPremul.allocPixels(ctPremul); 235 srcPremul.allocPixels(ctPremul);
241 SkSafeUnref(ctOpaque); 236 SkSafeUnref(ctOpaque);
242 SkSafeUnref(ctPremul); 237 SkSafeUnref(ctPremul);
243 } 238 }
244 init_src(srcOpaque); 239 init_src(srcOpaque);
245 init_src(srcPremul); 240 init_src(srcPremul);
246 241
247 bool success = srcPremul.copyTo(&dst, gPairs[j].fConfig); 242 bool success = srcPremul.copyTo(&dst, gPairs[j].fConfig);
248 bool expected = gPairs[i].fValid[j] != '0'; 243 bool expected = gPairs[i].fValid[j] != '0';
249 if (success != expected) { 244 if (success != expected) {
250 SkString str; 245 ERRORF(reporter, "SkBitmap::copyTo from %s to %s. expected %s "
251 str.printf("SkBitmap::copyTo from %s to %s. expected %s returned %s", 246 "returned %s", gConfigName[i], gConfigName[j],
252 gConfigName[i], gConfigName[j], boolStr(expected), 247 boolStr(expected), boolStr(success));
253 boolStr(success));
254 reporter->reportFailed(str);
255 } 248 }
256 249
257 bool canSucceed = srcPremul.canCopyTo(gPairs[j].fConfig); 250 bool canSucceed = srcPremul.canCopyTo(gPairs[j].fConfig);
258 if (success != canSucceed) { 251 if (success != canSucceed) {
259 SkString str; 252 ERRORF(reporter, "SkBitmap::copyTo from %s to %s. returned %s "
260 str.printf("SkBitmap::copyTo from %s to %s. returned %s canCopyT o %s", 253 "canCopyTo %s", gConfigName[i], gConfigName[j],
261 gConfigName[i], gConfigName[j], boolStr(success), 254 boolStr(success), boolStr(canSucceed));
262 boolStr(canSucceed));
263 reporter->reportFailed(str);
264 } 255 }
265 256
266 if (success) { 257 if (success) {
267 REPORTER_ASSERT(reporter, srcPremul.width() == dst.width()); 258 REPORTER_ASSERT(reporter, srcPremul.width() == dst.width());
268 REPORTER_ASSERT(reporter, srcPremul.height() == dst.height()); 259 REPORTER_ASSERT(reporter, srcPremul.height() == dst.height());
269 REPORTER_ASSERT(reporter, dst.config() == gPairs[j].fConfig); 260 REPORTER_ASSERT(reporter, dst.config() == gPairs[j].fConfig);
270 test_isOpaque(reporter, srcOpaque, srcPremul, dst.config()); 261 test_isOpaque(reporter, srcOpaque, srcPremul, dst.config());
271 if (srcPremul.config() == dst.config()) { 262 if (srcPremul.config() == dst.config()) {
272 SkAutoLockPixels srcLock(srcPremul); 263 SkAutoLockPixels srcLock(srcPremul);
273 SkAutoLockPixels dstLock(dst); 264 SkAutoLockPixels dstLock(dst);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 // Please take care if modifying. 329 // Please take care if modifying.
339 330
340 // Tests for getSafeSize64(). 331 // Tests for getSafeSize64().
341 // Test with a very large configuration without pixel buffer 332 // Test with a very large configuration without pixel buffer
342 // attached. 333 // attached.
343 SkBitmap tstSafeSize; 334 SkBitmap tstSafeSize;
344 tstSafeSize.setConfig(gPairs[i].fConfig, 100000000U, 335 tstSafeSize.setConfig(gPairs[i].fConfig, 100000000U,
345 100000000U); 336 100000000U);
346 int64_t safeSize = tstSafeSize.computeSafeSize64(); 337 int64_t safeSize = tstSafeSize.computeSafeSize64();
347 if (safeSize < 0) { 338 if (safeSize < 0) {
348 SkString str; 339 ERRORF(reporter, "getSafeSize64() negative: %s",
349 str.printf("getSafeSize64() negative: %s", 340 getSkConfigName(tstSafeSize));
350 getSkConfigName(tstSafeSize));
351 reporter->reportFailed(str);
352 } 341 }
353 bool sizeFail = false; 342 bool sizeFail = false;
354 // Compare against hand-computed values. 343 // Compare against hand-computed values.
355 switch (gPairs[i].fConfig) { 344 switch (gPairs[i].fConfig) {
356 case SkBitmap::kNo_Config: 345 case SkBitmap::kNo_Config:
357 break; 346 break;
358 347
359 case SkBitmap::kA8_Config: 348 case SkBitmap::kA8_Config:
360 case SkBitmap::kIndex8_Config: 349 case SkBitmap::kIndex8_Config:
361 if (safeSize != 0x2386F26FC10000LL) { 350 if (safeSize != 0x2386F26FC10000LL) {
(...skipping 11 matching lines...) Expand all
373 case SkBitmap::kARGB_8888_Config: 362 case SkBitmap::kARGB_8888_Config:
374 if (safeSize != 0x8E1BC9BF040000LL) { 363 if (safeSize != 0x8E1BC9BF040000LL) {
375 sizeFail = true; 364 sizeFail = true;
376 } 365 }
377 break; 366 break;
378 367
379 default: 368 default:
380 break; 369 break;
381 } 370 }
382 if (sizeFail) { 371 if (sizeFail) {
383 SkString str; 372 ERRORF(reporter, "computeSafeSize64() wrong size: %s",
384 str.printf("computeSafeSize64() wrong size: %s", 373 getSkConfigName(tstSafeSize));
385 getSkConfigName(tstSafeSize));
386 reporter->reportFailed(str);
387 } 374 }
388 375
389 int subW = 2; 376 int subW = 2;
390 int subH = 2; 377 int subH = 2;
391 378
392 // Create bitmap to act as source for copies and subsets. 379 // Create bitmap to act as source for copies and subsets.
393 SkBitmap src, subset; 380 SkBitmap src, subset;
394 SkColorTable* ct = NULL; 381 SkColorTable* ct = NULL;
395 if (isExtracted[copyCase]) { // A larger image to extract from. 382 if (isExtracted[copyCase]) { // A larger image to extract from.
396 src.setConfig(gPairs[i].fConfig, 2 * subW + 1, subH); 383 src.setConfig(gPairs[i].fConfig, 2 * subW + 1, subH);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 // for the transfer. 531 // for the transfer.
545 REPORTER_ASSERT(reporter, 532 REPORTER_ASSERT(reporter,
546 subset.copyPixelsFrom(buf, 1, subset.rowBytes()) == 533 subset.copyPixelsFrom(buf, 1, subset.rowBytes()) ==
547 false); 534 false);
548 535
549 #endif 536 #endif
550 } 537 }
551 } // for (size_t copyCase ... 538 } // for (size_t copyCase ...
552 } 539 }
553 } 540 }
OLDNEW
« no previous file with comments | « no previous file | tests/BlitRowTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698