aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar epoger@google.com <epoger@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-04-12 02:23:55 +0000
committerGravatar epoger@google.com <epoger@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-04-12 02:23:55 +0000
commit908f5836626d792c5e33ad93f44c6a418a0cc8f5 (patch)
tree2387bc49caeabbd315b34d9973327a5fa310335e /tests
parentbcbf5aa77ddce07c95efc51c567ce737da7f267d (diff)
rename SkBitmapChecksummer as SkBitmapHasher, and prepare for it to possibly use
some algorithm other than CityHash Review URL: https://codereview.chromium.org/14170010 git-svn-id: http://skia.googlecode.com/svn/trunk@8639 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests')
-rw-r--r--tests/BitmapHasherTest.cpp64
-rw-r--r--tests/ChecksumTest.cpp31
2 files changed, 64 insertions, 31 deletions
diff --git a/tests/BitmapHasherTest.cpp b/tests/BitmapHasherTest.cpp
new file mode 100644
index 0000000000..6aa464d106
--- /dev/null
+++ b/tests/BitmapHasherTest.cpp
@@ -0,0 +1,64 @@
+
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "Test.h"
+
+#include "SkBitmap.h"
+#include "SkBitmapHasher.h"
+#include "SkColor.h"
+
+// Word size that is large enough to hold results of any checksum type.
+typedef uint64_t checksum_result;
+
+namespace skiatest {
+ class BitmapHasherTestClass : public Test {
+ public:
+ static Test* Factory(void*) {return SkNEW(BitmapHasherTestClass); }
+ protected:
+ virtual void onGetName(SkString* name) { name->set("BitmapHasher"); }
+ virtual void onRun(Reporter* reporter) {
+ this->fReporter = reporter;
+ RunTest();
+ }
+ private:
+
+ // Fill in bitmap with test data.
+ void CreateTestBitmap(SkBitmap &bitmap, SkBitmap::Config config, int width, int height,
+ SkColor color) {
+ bitmap.setConfig(config, width, height);
+ REPORTER_ASSERT(fReporter, bitmap.allocPixels());
+ bitmap.setIsOpaque(true);
+ bitmap.eraseColor(color);
+ }
+
+ void RunTest() {
+ // Test SkBitmapHasher
+ SkBitmap bitmap;
+ SkHashDigest digest;
+ // initial test case
+ CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 333, 555, SK_ColorBLUE);
+ REPORTER_ASSERT(fReporter, SkBitmapHasher::ComputeDigest(bitmap, &digest));
+ REPORTER_ASSERT(fReporter, digest == 0x18f9df68b1b02f38ULL);
+ // same pixel data but different dimensions should yield a different checksum
+ CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 555, 333, SK_ColorBLUE);
+ REPORTER_ASSERT(fReporter, SkBitmapHasher::ComputeDigest(bitmap, &digest));
+ REPORTER_ASSERT(fReporter, digest == 0x6b0298183f786c8eULL);
+ // same dimensions but different color should yield a different checksum
+ CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 555, 333, SK_ColorGREEN);
+ REPORTER_ASSERT(fReporter, SkBitmapHasher::ComputeDigest(bitmap, &digest));
+ REPORTER_ASSERT(fReporter, digest == 0xc6b4b3f6fadaaf37ULL);
+ // same pixel colors in a different config should yield the same checksum
+ CreateTestBitmap(bitmap, SkBitmap::kARGB_4444_Config, 555, 333, SK_ColorGREEN);
+ REPORTER_ASSERT(fReporter, SkBitmapHasher::ComputeDigest(bitmap, &digest));
+ REPORTER_ASSERT(fReporter, digest == 0xc6b4b3f6fadaaf37ULL);
+ }
+
+ Reporter* fReporter;
+ };
+
+ static TestRegistry gReg(BitmapHasherTestClass::Factory);
+}
diff --git a/tests/ChecksumTest.cpp b/tests/ChecksumTest.cpp
index 03194907f5..81e7ef396c 100644
--- a/tests/ChecksumTest.cpp
+++ b/tests/ChecksumTest.cpp
@@ -7,11 +7,8 @@
*/
#include "Test.h"
-#include "SkBitmap.h"
-#include "SkBitmapChecksummer.h"
#include "SkChecksum.h"
#include "SkCityHash.h"
-#include "SkColor.h"
// Word size that is large enough to hold results of any checksum type.
typedef uint64_t checksum_result;
@@ -107,15 +104,6 @@ namespace skiatest {
return result;
}
- // Fill in bitmap with test data.
- void CreateTestBitmap(SkBitmap &bitmap, SkBitmap::Config config, int width, int height,
- SkColor color) {
- bitmap.setConfig(config, width, height);
- REPORTER_ASSERT(fReporter, bitmap.allocPixels());
- bitmap.setIsOpaque(true);
- bitmap.eraseColor(color);
- }
-
void RunTest() {
// Test self-consistency of checksum algorithms.
fWhichAlgorithm = kSkChecksum;
@@ -156,25 +144,6 @@ namespace skiatest {
GetTestDataChecksum(128) == GetTestDataChecksum(256));
REPORTER_ASSERT(fReporter,
GetTestDataChecksum(132) == GetTestDataChecksum(260));
-
- // Test SkBitmapChecksummer
- SkBitmap bitmap;
- // initial test case
- CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 333, 555, SK_ColorBLUE);
- REPORTER_ASSERT(fReporter,
- SkBitmapChecksummer::Compute64(bitmap) == 0x18f9df68b1b02f38ULL);
- // same pixel data but different dimensions should yield a different checksum
- CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 555, 333, SK_ColorBLUE);
- REPORTER_ASSERT(fReporter,
- SkBitmapChecksummer::Compute64(bitmap) == 0x6b0298183f786c8eULL);
- // same dimensions but different color should yield a different checksum
- CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 555, 333, SK_ColorGREEN);
- REPORTER_ASSERT(fReporter,
- SkBitmapChecksummer::Compute64(bitmap) == 0xc6b4b3f6fadaaf37ULL);
- // same pixel colors in a different config should yield the same checksum
- CreateTestBitmap(bitmap, SkBitmap::kARGB_4444_Config, 555, 333, SK_ColorGREEN);
- REPORTER_ASSERT(fReporter,
- SkBitmapChecksummer::Compute64(bitmap) == 0xc6b4b3f6fadaaf37ULL);
}
Reporter* fReporter;