epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 1 | /* |
| 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.org | 452eecb | 2014-01-06 12:43:53 +0000 | [diff] [blame] | 7 | |
| 8 | #include "SkBitmapHasher.h" |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 9 | |
| 10 | #include "SkBitmap.h" |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 11 | #include "SkColor.h" |
tfarina@chromium.org | 452eecb | 2014-01-06 12:43:53 +0000 | [diff] [blame] | 12 | #include "Test.h" |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 13 | |
| 14 | // Word size that is large enough to hold results of any checksum type. |
| 15 | typedef uint64_t checksum_result; |
| 16 | |
tfarina@chromium.org | 452eecb | 2014-01-06 12:43:53 +0000 | [diff] [blame] | 17 | // Fill in bitmap with test data. |
commit-bot@chromium.org | 8ef51b9 | 2014-03-05 13:43:15 +0000 | [diff] [blame] | 18 | static void CreateTestBitmap(SkBitmap* bitmap, int width, int height, |
tfarina@chromium.org | 452eecb | 2014-01-06 12:43:53 +0000 | [diff] [blame] | 19 | SkColor color, skiatest::Reporter* reporter) { |
reed | 8482504 | 2014-09-02 12:50:45 -0700 | [diff] [blame] | 20 | bitmap->allocN32Pixels(width, height, kOpaque_SkAlphaType); |
commit-bot@chromium.org | 8ef51b9 | 2014-03-05 13:43:15 +0000 | [diff] [blame] | 21 | bitmap->eraseColor(color); |
tfarina@chromium.org | 452eecb | 2014-01-06 12:43:53 +0000 | [diff] [blame] | 22 | } |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 23 | |
tfarina@chromium.org | 452eecb | 2014-01-06 12:43:53 +0000 | [diff] [blame] | 24 | DEF_TEST(BitmapHasher, reporter) { |
| 25 | // Test SkBitmapHasher |
| 26 | SkBitmap bitmap; |
| 27 | uint64_t digest; |
| 28 | // initial test case |
commit-bot@chromium.org | 8ef51b9 | 2014-03-05 13:43:15 +0000 | [diff] [blame] | 29 | CreateTestBitmap(&bitmap, 333, 555, SK_ColorBLUE, reporter); |
tfarina@chromium.org | 452eecb | 2014-01-06 12:43:53 +0000 | [diff] [blame] | 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 |
commit-bot@chromium.org | 8ef51b9 | 2014-03-05 13:43:15 +0000 | [diff] [blame] | 33 | CreateTestBitmap(&bitmap, 555, 333, SK_ColorBLUE, reporter); |
tfarina@chromium.org | 452eecb | 2014-01-06 12:43:53 +0000 | [diff] [blame] | 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 |
commit-bot@chromium.org | 8ef51b9 | 2014-03-05 13:43:15 +0000 | [diff] [blame] | 37 | CreateTestBitmap(&bitmap, 555, 333, SK_ColorGREEN, reporter); |
tfarina@chromium.org | 452eecb | 2014-01-06 12:43:53 +0000 | [diff] [blame] | 38 | REPORTER_ASSERT(reporter, SkBitmapHasher::ComputeDigest(bitmap, &digest)); |
| 39 | REPORTER_ASSERT(reporter, digest == 0x2423c51cad6d1edcULL); |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 40 | } |