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

Side by Side Diff: tests/BitmapHasherTest.cpp

Issue 14265010: Make SkSHA1 and SkM5 use common SkDigestHash result type (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: rename_set_to_copyFrom Created 7 years, 8 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 /* 2 /*
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 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 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
11 #include "SkBitmapHasher.h" 11 #include "SkBitmapHasher.h"
12 #include "SkColor.h" 12 #include "SkColor.h"
13 13
14 // Word size that is large enough to hold results of any checksum type. 14 // Word size that is large enough to hold results of SkUInt64HashDigest.
15 typedef uint64_t checksum_result; 15 typedef uint64_t checksum_result;
16 16
17 namespace skiatest { 17 namespace skiatest {
18 class BitmapHasherTestClass : public Test { 18 class BitmapHasherTestClass : public Test {
19 public: 19 public:
20 static Test* Factory(void*) {return SkNEW(BitmapHasherTestClass); } 20 static Test* Factory(void*) {return SkNEW(BitmapHasherTestClass); }
21 protected: 21 protected:
22 virtual void onGetName(SkString* name) { name->set("BitmapHasher"); } 22 virtual void onGetName(SkString* name) { name->set("BitmapHasher"); }
23 virtual void onRun(Reporter* reporter) { 23 virtual void onRun(Reporter* reporter) {
24 this->fReporter = reporter; 24 this->fReporter = reporter;
25 RunTest(); 25 RunTest();
26 } 26 }
27 private: 27 private:
28 28
29 // Fill in bitmap with test data. 29 // Fill in bitmap with test data.
30 void CreateTestBitmap(SkBitmap &bitmap, SkBitmap::Config config, int wid th, int height, 30 void CreateTestBitmap(SkBitmap &bitmap, SkBitmap::Config config, int wid th, int height,
31 SkColor color) { 31 SkColor color) {
32 bitmap.setConfig(config, width, height); 32 bitmap.setConfig(config, width, height);
33 REPORTER_ASSERT(fReporter, bitmap.allocPixels()); 33 REPORTER_ASSERT(fReporter, bitmap.allocPixels());
34 bitmap.setIsOpaque(true); 34 bitmap.setIsOpaque(true);
35 bitmap.eraseColor(color); 35 bitmap.eraseColor(color);
36 } 36 }
37 37
38 void RunTest() { 38 void RunTest() {
39 // Test SkBitmapHasher 39 // Test SkBitmapHasher
40 SkBitmap bitmap; 40 SkBitmap bitmap;
41 SkHashDigest digest; 41 SkUInt64HashDigest digest;
42 // initial test case 42 // initial test case
43 CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 333, 555, SK_C olorBLUE); 43 CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 333, 555, SK_C olorBLUE);
44 REPORTER_ASSERT(fReporter, SkBitmapHasher::ComputeDigest(bitmap, &di gest)); 44 REPORTER_ASSERT(fReporter, SkBitmapHasher::ComputeDigest(bitmap, &di gest));
45 REPORTER_ASSERT(fReporter, digest == 0x18f9df68b1b02f38ULL); 45 REPORTER_ASSERT(fReporter, digest == 0x18f9df68b1b02f38ULL);
46 // same pixel data but different dimensions should yield a different checksum 46 // same pixel data but different dimensions should yield a different checksum
47 CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 555, 333, SK_C olorBLUE); 47 CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 555, 333, SK_C olorBLUE);
48 REPORTER_ASSERT(fReporter, SkBitmapHasher::ComputeDigest(bitmap, &di gest)); 48 REPORTER_ASSERT(fReporter, SkBitmapHasher::ComputeDigest(bitmap, &di gest));
49 REPORTER_ASSERT(fReporter, digest == 0x6b0298183f786c8eULL); 49 REPORTER_ASSERT(fReporter, digest == 0x6b0298183f786c8eULL);
50 // same dimensions but different color should yield a different chec ksum 50 // same dimensions but different color should yield a different chec ksum
51 CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 555, 333, SK_C olorGREEN); 51 CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 555, 333, SK_C olorGREEN);
52 REPORTER_ASSERT(fReporter, SkBitmapHasher::ComputeDigest(bitmap, &di gest)); 52 REPORTER_ASSERT(fReporter, SkBitmapHasher::ComputeDigest(bitmap, &di gest));
53 REPORTER_ASSERT(fReporter, digest == 0xc6b4b3f6fadaaf37ULL); 53 REPORTER_ASSERT(fReporter, digest == 0xc6b4b3f6fadaaf37ULL);
54 // same pixel colors in a different config should yield the same che cksum 54 // same pixel colors in a different config should yield the same che cksum
55 CreateTestBitmap(bitmap, SkBitmap::kARGB_4444_Config, 555, 333, SK_C olorGREEN); 55 CreateTestBitmap(bitmap, SkBitmap::kARGB_4444_Config, 555, 333, SK_C olorGREEN);
56 REPORTER_ASSERT(fReporter, SkBitmapHasher::ComputeDigest(bitmap, &di gest)); 56 REPORTER_ASSERT(fReporter, SkBitmapHasher::ComputeDigest(bitmap, &di gest));
57 REPORTER_ASSERT(fReporter, digest == 0xc6b4b3f6fadaaf37ULL); 57 REPORTER_ASSERT(fReporter, digest == 0xc6b4b3f6fadaaf37ULL);
58 } 58 }
59 59
60 Reporter* fReporter; 60 Reporter* fReporter;
61 }; 61 };
62 62
63 static TestRegistry gReg(BitmapHasherTestClass::Factory); 63 static TestRegistry gReg(BitmapHasherTestClass::Factory);
64 } 64 }
OLDNEW
« src/utils/SkHashDigest.h ('K') | « src/utils/SkSHA1.cpp ('k') | tests/MD5Test.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698