OLD | NEW |
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 } |
OLD | NEW |