blob: e39439a11f468170cf711d4c32f8d1a1a0f3e945 [file] [log] [blame]
epoger@google.com908f5832013-04-12 02:23:55 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
tfarina@chromium.org452eecb2014-01-06 12:43:53 +00007
8#include "SkBitmapHasher.h"
epoger@google.com908f5832013-04-12 02:23:55 +00009
10#include "SkBitmap.h"
epoger@google.com908f5832013-04-12 02:23:55 +000011#include "SkColor.h"
tfarina@chromium.org452eecb2014-01-06 12:43:53 +000012#include "Test.h"
epoger@google.com908f5832013-04-12 02:23:55 +000013
14// Word size that is large enough to hold results of any checksum type.
15typedef uint64_t checksum_result;
16
tfarina@chromium.org452eecb2014-01-06 12:43:53 +000017// Fill in bitmap with test data.
commit-bot@chromium.org8ef51b92014-03-05 13:43:15 +000018static void CreateTestBitmap(SkBitmap* bitmap, int width, int height,
tfarina@chromium.org452eecb2014-01-06 12:43:53 +000019 SkColor color, skiatest::Reporter* reporter) {
commit-bot@chromium.org8ef51b92014-03-05 13:43:15 +000020 SkImageInfo info = SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType);
21 REPORTER_ASSERT(reporter, bitmap->allocPixels(info));
22 bitmap->eraseColor(color);
tfarina@chromium.org452eecb2014-01-06 12:43:53 +000023}
epoger@google.com908f5832013-04-12 02:23:55 +000024
tfarina@chromium.org452eecb2014-01-06 12:43:53 +000025DEF_TEST(BitmapHasher, reporter) {
26 // Test SkBitmapHasher
27 SkBitmap bitmap;
28 uint64_t digest;
29 // initial test case
commit-bot@chromium.org8ef51b92014-03-05 13:43:15 +000030 CreateTestBitmap(&bitmap, 333, 555, SK_ColorBLUE, reporter);
tfarina@chromium.org452eecb2014-01-06 12:43:53 +000031 REPORTER_ASSERT(reporter, SkBitmapHasher::ComputeDigest(bitmap, &digest));
32 REPORTER_ASSERT(reporter, digest == 0xfb2903562766ef87ULL);
33 // same pixel data but different dimensions should yield a different checksum
commit-bot@chromium.org8ef51b92014-03-05 13:43:15 +000034 CreateTestBitmap(&bitmap, 555, 333, SK_ColorBLUE, reporter);
tfarina@chromium.org452eecb2014-01-06 12:43:53 +000035 REPORTER_ASSERT(reporter, SkBitmapHasher::ComputeDigest(bitmap, &digest));
36 REPORTER_ASSERT(reporter, digest == 0xfe04023fb97d0f61ULL);
37 // same dimensions but different color should yield a different checksum
commit-bot@chromium.org8ef51b92014-03-05 13:43:15 +000038 CreateTestBitmap(&bitmap, 555, 333, SK_ColorGREEN, reporter);
tfarina@chromium.org452eecb2014-01-06 12:43:53 +000039 REPORTER_ASSERT(reporter, SkBitmapHasher::ComputeDigest(bitmap, &digest));
40 REPORTER_ASSERT(reporter, digest == 0x2423c51cad6d1edcULL);
epoger@google.com908f5832013-04-12 02:23:55 +000041}