Chromium Code Reviews| 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 #include "SkHashDigest.h" |
| 14 // Word size that is large enough to hold results of any checksum type. | |
| 15 typedef uint64_t checksum_result; | |
| 16 | 14 |
| 17 namespace skiatest { | 15 namespace skiatest { |
| 18 class BitmapHasherTestClass : public Test { | 16 class BitmapHasherTestClass : public Test { |
| 19 public: | 17 public: |
| 20 static Test* Factory(void*) {return SkNEW(BitmapHasherTestClass); } | 18 static Test* Factory(void*) {return SkNEW(BitmapHasherTestClass); } |
| 21 protected: | 19 protected: |
| 22 virtual void onGetName(SkString* name) { name->set("BitmapHasher"); } | 20 virtual void onGetName(SkString* name) { name->set("BitmapHasher"); } |
| 23 virtual void onRun(Reporter* reporter) { | 21 virtual void onRun(Reporter* reporter) { |
| 24 this->fReporter = reporter; | 22 this->fReporter = reporter; |
| 25 RunTest(); | 23 RunTest(); |
| 26 } | 24 } |
| 27 private: | 25 private: |
| 28 | 26 |
| 29 // Fill in bitmap with test data. | 27 // Fill in bitmap with test data. |
| 30 void CreateTestBitmap(SkBitmap &bitmap, SkBitmap::Config config, int wid th, int height, | 28 void CreateTestBitmap(SkBitmap &bitmap, SkBitmap::Config config, int wid th, int height, |
| 31 SkColor color) { | 29 SkColor color) { |
| 32 bitmap.setConfig(config, width, height); | 30 bitmap.setConfig(config, width, height); |
| 33 REPORTER_ASSERT(fReporter, bitmap.allocPixels()); | 31 REPORTER_ASSERT(fReporter, bitmap.allocPixels()); |
| 34 bitmap.setIsOpaque(true); | 32 bitmap.setIsOpaque(true); |
| 35 bitmap.eraseColor(color); | 33 bitmap.eraseColor(color); |
| 36 } | 34 } |
| 37 | 35 |
| 38 void RunTest() { | 36 void RunTest() { |
| 39 // Test SkBitmapHasher | 37 // Test SkBitmapHasher |
| 40 SkBitmap bitmap; | 38 SkBitmap bitmap; |
| 41 SkHashDigest digest; | 39 BITMAP_HASH_TYPE actualDigest; |
| 40 | |
| 42 // initial test case | 41 // initial test case |
| 43 CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 333, 555, SK_C olorBLUE); | 42 CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 333, 555, SK_C olorBLUE); |
| 44 REPORTER_ASSERT(fReporter, SkBitmapHasher::ComputeDigest(bitmap, &di gest)); | 43 REPORTER_ASSERT(fReporter, SkBitmapHasher::ComputeDigest(bitmap, &ac tualDigest)); |
| 45 REPORTER_ASSERT(fReporter, digest == 0x18f9df68b1b02f38ULL); | 44 #ifdef BITMAP_HASH_TYPE_SkHashDigest |
| 45 BITMAP_HASH_TYPE expectedDigest; | |
| 46 REPORTER_ASSERT(fReporter, expectedDigest.copyFromHexString("382fb0b 168dff918")); | |
| 47 REPORTER_ASSERT(fReporter, actualDigest == expectedDigest); | |
| 48 REPORTER_ASSERT(fReporter, actualDigest.toHexString().equals("382fb0 b168dff918")); | |
|
epoger
2013/04/18 16:39:34
SkHashDigest.toHexString() displays the bytes in l
| |
| 49 #else | |
| 50 REPORTER_ASSERT(fReporter, actualDigest == 0x18f9df68b1b02f38ULL); | |
| 51 #endif | |
| 52 | |
| 46 // same pixel data but different dimensions should yield a different checksum | 53 // same pixel data but different dimensions should yield a different checksum |
| 47 CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 555, 333, SK_C olorBLUE); | 54 CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 555, 333, SK_C olorBLUE); |
| 48 REPORTER_ASSERT(fReporter, SkBitmapHasher::ComputeDigest(bitmap, &di gest)); | 55 REPORTER_ASSERT(fReporter, SkBitmapHasher::ComputeDigest(bitmap, &ac tualDigest)); |
| 49 REPORTER_ASSERT(fReporter, digest == 0x6b0298183f786c8eULL); | 56 #ifdef BITMAP_HASH_TYPE_SkHashDigest |
| 57 REPORTER_ASSERT(fReporter, actualDigest.toHexString().equals("8e6c78 3f1898026b")); | |
| 58 #else | |
| 59 REPORTER_ASSERT(fReporter, actualDigest == 0x6b0298183f786c8eULL); | |
| 60 #endif | |
| 61 | |
| 50 // same dimensions but different color should yield a different chec ksum | 62 // same dimensions but different color should yield a different chec ksum |
| 51 CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 555, 333, SK_C olorGREEN); | 63 CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 555, 333, SK_C olorGREEN); |
| 52 REPORTER_ASSERT(fReporter, SkBitmapHasher::ComputeDigest(bitmap, &di gest)); | 64 REPORTER_ASSERT(fReporter, SkBitmapHasher::ComputeDigest(bitmap, &ac tualDigest)); |
| 53 REPORTER_ASSERT(fReporter, digest == 0xc6b4b3f6fadaaf37ULL); | 65 #ifdef BITMAP_HASH_TYPE_SkHashDigest |
| 66 REPORTER_ASSERT(fReporter, actualDigest.toHexString().equals("37afda faf6b3b4c6")); | |
| 67 #else | |
| 68 REPORTER_ASSERT(fReporter, actualDigest == 0xc6b4b3f6fadaaf37ULL); | |
| 69 #endif | |
| 70 | |
| 54 // same pixel colors in a different config should yield the same che cksum | 71 // 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); | 72 CreateTestBitmap(bitmap, SkBitmap::kARGB_4444_Config, 555, 333, SK_C olorGREEN); |
| 56 REPORTER_ASSERT(fReporter, SkBitmapHasher::ComputeDigest(bitmap, &di gest)); | 73 REPORTER_ASSERT(fReporter, SkBitmapHasher::ComputeDigest(bitmap, &ac tualDigest)); |
| 57 REPORTER_ASSERT(fReporter, digest == 0xc6b4b3f6fadaaf37ULL); | 74 #ifdef BITMAP_HASH_TYPE_SkHashDigest |
| 75 REPORTER_ASSERT(fReporter, actualDigest.toHexString().equals("37afda faf6b3b4c6")); | |
| 76 #else | |
| 77 REPORTER_ASSERT(fReporter, actualDigest == 0xc6b4b3f6fadaaf37ULL); | |
| 78 #endif | |
| 58 } | 79 } |
| 59 | 80 |
| 60 Reporter* fReporter; | 81 Reporter* fReporter; |
| 61 }; | 82 }; |
| 62 | 83 |
| 63 static TestRegistry gReg(BitmapHasherTestClass::Factory); | 84 static TestRegistry gReg(BitmapHasherTestClass::Factory); |
| 64 } | 85 } |
| OLD | NEW |