2013-04-12 02:23:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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());
|
2013-10-21 14:00:07 +00:00
|
|
|
bitmap.setAlphaType(kOpaque_SkAlphaType);
|
2013-04-12 02:23:55 +00:00
|
|
|
bitmap.eraseColor(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RunTest() {
|
|
|
|
// Test SkBitmapHasher
|
|
|
|
SkBitmap bitmap;
|
2013-05-24 14:33:28 +00:00
|
|
|
uint64_t digest;
|
2013-04-12 02:23:55 +00:00
|
|
|
// initial test case
|
|
|
|
CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 333, 555, SK_ColorBLUE);
|
|
|
|
REPORTER_ASSERT(fReporter, SkBitmapHasher::ComputeDigest(bitmap, &digest));
|
2013-05-03 17:35:39 +00:00
|
|
|
REPORTER_ASSERT(fReporter, digest == 0xfb2903562766ef87ULL);
|
2013-04-12 02:23:55 +00:00
|
|
|
// 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));
|
2013-05-03 17:35:39 +00:00
|
|
|
REPORTER_ASSERT(fReporter, digest == 0xfe04023fb97d0f61ULL);
|
2013-04-12 02:23:55 +00:00
|
|
|
// 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));
|
2013-05-03 17:35:39 +00:00
|
|
|
REPORTER_ASSERT(fReporter, digest == 0x2423c51cad6d1edcULL);
|
2013-04-12 02:23:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Reporter* fReporter;
|
|
|
|
};
|
|
|
|
|
|
|
|
static TestRegistry gReg(BitmapHasherTestClass::Factory);
|
|
|
|
}
|