Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: tests/ChecksumTest.cpp

Issue 381253003: Revert of Slim Skia down to just one murmur3 implementation. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkImageFilter.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkChecksum.h" 8 #include "SkChecksum.h"
9 #include "SkRandom.h" 9 #include "SkRandom.h"
10 #include "Test.h" 10 #include "Test.h"
11 11
12 12
13 // Murmur3 has an optional third seed argument, so we wrap it to fit a uniform t ype. 13 // Murmur3 has an optional third seed argument, so we wrap it to fit a uniform t ype.
14 static uint32_t murmur_noseed(const SkChecksum::FourByteAligned* d, size_t l) { 14 static uint32_t murmur_noseed(const uint32_t* d, size_t l) { return SkChecksum:: Murmur3(d, l); }
15 return SkChecksum::Murmur3(d, l);
16 }
17 15
18 #define ASSERT(x) REPORTER_ASSERT(r, x) 16 #define ASSERT(x) REPORTER_ASSERT(r, x)
19 17
20 DEF_TEST(Checksum, r) { 18 DEF_TEST(Checksum, r) {
21 // Algorithms to test. They're currently all uint32_t(const uint32_t*, size _t). 19 // Algorithms to test. They're currently all uint32_t(const uint32_t*, size _t).
22 typedef uint32_t(*algorithmProc)(const SkChecksum::FourByteAligned*, size_t) ; 20 typedef uint32_t(*algorithmProc)(const uint32_t*, size_t);
23 const algorithmProc kAlgorithms[] = { &SkChecksum::Compute, &murmur_noseed } ; 21 const algorithmProc kAlgorithms[] = { &SkChecksum::Compute, &murmur_noseed } ;
24 22
25 // Put 128 random bytes into two identical buffers. Any multiple of 4 will do. 23 // Put 128 random bytes into two identical buffers. Any multiple of 4 will do.
26 const size_t kBytes = SkAlign4(128); 24 const size_t kBytes = SkAlign4(128);
27 SkRandom rand; 25 SkRandom rand;
28 uint32_t data[kBytes/4], tweaked[kBytes/4]; 26 uint32_t data[kBytes/4], tweaked[kBytes/4];
29 for (size_t i = 0; i < SK_ARRAY_COUNT(tweaked); ++i) { 27 for (size_t i = 0; i < SK_ARRAY_COUNT(tweaked); ++i) {
30 data[i] = tweaked[i] = rand.nextU(); 28 data[i] = tweaked[i] = rand.nextU();
31 } 29 }
32 30
(...skipping 12 matching lines...) Expand all
45 for (size_t j = 0; j < SK_ARRAY_COUNT(tweaked); ++j) { 43 for (size_t j = 0; j < SK_ARRAY_COUNT(tweaked); ++j) {
46 const uint32_t saved = tweaked[j]; 44 const uint32_t saved = tweaked[j];
47 tweaked[j] = rand.nextU(); 45 tweaked[j] = rand.nextU();
48 const uint32_t tweakedHash = algorithm(tweaked, kBytes); 46 const uint32_t tweakedHash = algorithm(tweaked, kBytes);
49 ASSERT(tweakedHash != hash); 47 ASSERT(tweakedHash != hash);
50 ASSERT(tweakedHash == algorithm(tweaked, kBytes)); 48 ASSERT(tweakedHash == algorithm(tweaked, kBytes));
51 tweaked[j] = saved; 49 tweaked[j] = saved;
52 } 50 }
53 } 51 }
54 } 52 }
OLDNEW
« no previous file with comments | « src/core/SkImageFilter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698