2 * Copyright 2013 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "SkBitmapHasher.h"
14 // Word size that is large enough to hold results of any checksum type.
15 typedef uint64_t checksum_result;
17 // Fill in bitmap with test data.
18 static void CreateTestBitmap(SkBitmap* bitmap, int width, int height,
19 SkColor color, skiatest::Reporter* reporter) {
20 bitmap->allocN32Pixels(width, height, kOpaque_SkAlphaType);
21 bitmap->eraseColor(color);
24 DEF_TEST(BitmapHasher, reporter) {
25 // Test SkBitmapHasher
29 CreateTestBitmap(&bitmap, 333, 555, SK_ColorBLUE, reporter);
30 REPORTER_ASSERT(reporter, SkBitmapHasher::ComputeDigest(bitmap, &digest));
31 REPORTER_ASSERT(reporter, digest == 0xfb2903562766ef87ULL);
32 // same pixel data but different dimensions should yield a different checksum
33 CreateTestBitmap(&bitmap, 555, 333, SK_ColorBLUE, reporter);
34 REPORTER_ASSERT(reporter, SkBitmapHasher::ComputeDigest(bitmap, &digest));
35 REPORTER_ASSERT(reporter, digest == 0xfe04023fb97d0f61ULL);
36 // same dimensions but different color should yield a different checksum
37 CreateTestBitmap(&bitmap, 555, 333, SK_ColorGREEN, reporter);
38 REPORTER_ASSERT(reporter, SkBitmapHasher::ComputeDigest(bitmap, &digest));
39 REPORTER_ASSERT(reporter, digest == 0x2423c51cad6d1edcULL);