skia2/tests/BitmapHasherTest.cpp
commit-bot@chromium.org e2eac8b2fd Move macros from TestClassDef.h to Test.h
Motivation: those macros don't make any sense without the definitions
in Test.h.

BUG=
R=mtklein@google.com

Author: halcanary@google.com

Review URL: https://codereview.chromium.org/138563004

git-svn-id: http://skia.googlecode.com/svn/trunk@13074 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-14 21:04:37 +00:00

43 lines
1.7 KiB
C++

/*
* 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 "SkBitmapHasher.h"
#include "SkBitmap.h"
#include "SkColor.h"
#include "Test.h"
// Word size that is large enough to hold results of any checksum type.
typedef uint64_t checksum_result;
// Fill in bitmap with test data.
static void CreateTestBitmap(SkBitmap &bitmap, SkBitmap::Config config, int width, int height,
SkColor color, skiatest::Reporter* reporter) {
bitmap.setConfig(config, width, height);
REPORTER_ASSERT(reporter, bitmap.allocPixels());
bitmap.setAlphaType(kOpaque_SkAlphaType);
bitmap.eraseColor(color);
}
DEF_TEST(BitmapHasher, reporter) {
// Test SkBitmapHasher
SkBitmap bitmap;
uint64_t digest;
// initial test case
CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 333, 555, SK_ColorBLUE, reporter);
REPORTER_ASSERT(reporter, SkBitmapHasher::ComputeDigest(bitmap, &digest));
REPORTER_ASSERT(reporter, digest == 0xfb2903562766ef87ULL);
// same pixel data but different dimensions should yield a different checksum
CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 555, 333, SK_ColorBLUE, reporter);
REPORTER_ASSERT(reporter, SkBitmapHasher::ComputeDigest(bitmap, &digest));
REPORTER_ASSERT(reporter, digest == 0xfe04023fb97d0f61ULL);
// same dimensions but different color should yield a different checksum
CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 555, 333, SK_ColorGREEN, reporter);
REPORTER_ASSERT(reporter, SkBitmapHasher::ComputeDigest(bitmap, &digest));
REPORTER_ASSERT(reporter, digest == 0x2423c51cad6d1edcULL);
}