From 70d75ca764e16e15f016e423b85a0fa2a29fb8c7 Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Tue, 23 Jul 2013 20:25:34 +0000 Subject: Add SkChecksum::Murmur3. BUG= R=reed@google.com Author: mtklein@google.com Review URL: https://chromiumcodereview.appspot.com/19500020 git-svn-id: http://skia.googlecode.com/svn/trunk@10292 2bbb7eff-a529-9590-31e7-b0007b416f81 --- tests/ChecksumTest.cpp | 55 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 20 deletions(-) (limited to 'tests/ChecksumTest.cpp') diff --git a/tests/ChecksumTest.cpp b/tests/ChecksumTest.cpp index ee33d32acd..c2f2be2ae6 100644 --- a/tests/ChecksumTest.cpp +++ b/tests/ChecksumTest.cpp @@ -24,7 +24,8 @@ namespace skiatest { } private: enum Algorithm { - kSkChecksum + kSkChecksum, + kMurmur3, }; // Call Compute(data, size) on the appropriate checksum algorithm, @@ -38,6 +39,13 @@ namespace skiatest { REPORTER_ASSERT_MESSAGE(fReporter, SkIsAlign4(size), "test data size is not 32-bit aligned"); return SkChecksum::Compute(reinterpret_cast(data), size); + case kMurmur3: + REPORTER_ASSERT_MESSAGE(fReporter, + reinterpret_cast(data) % 4 == 0, + "test data pointer is not 32-bit aligned"); + REPORTER_ASSERT_MESSAGE(fReporter, SkIsAlign4(size), + "test data size is not 32-bit aligned"); + return SkChecksum::Murmur3(reinterpret_cast(data), size); default: SkString message("fWhichAlgorithm has unknown value "); message.appendf("%d", fWhichAlgorithm); @@ -98,25 +106,32 @@ namespace skiatest { } void RunTest() { - // Test self-consistency of checksum algorithms. - fWhichAlgorithm = kSkChecksum; - TestChecksumSelfConsistency(128); - - // Test checksum results that should be consistent across - // versions and platforms. - fWhichAlgorithm = kSkChecksum; - REPORTER_ASSERT(fReporter, ComputeChecksum(NULL, 0) == 0); - - // TODO: note the weakness exposed by these collisions... - // We need to improve the SkChecksum algorithm. - // We would prefer that these asserts FAIL! - // Filed as https://code.google.com/p/skia/issues/detail?id=981 - // ('SkChecksum algorithm allows for way too many collisions') - fWhichAlgorithm = kSkChecksum; - REPORTER_ASSERT(fReporter, - GetTestDataChecksum(128) == GetTestDataChecksum(256)); - REPORTER_ASSERT(fReporter, - GetTestDataChecksum(132) == GetTestDataChecksum(260)); + const Algorithm algorithms[] = { kSkChecksum, kMurmur3 }; + for (size_t i = 0; i < SK_ARRAY_COUNT(algorithms); i++) { + fWhichAlgorithm = algorithms[i]; + + // Test self-consistency of checksum algorithms. + TestChecksumSelfConsistency(128); + + // Test checksum results that should be consistent across + // versions and platforms. + REPORTER_ASSERT(fReporter, ComputeChecksum(NULL, 0) == 0); + + const bool colision1 = GetTestDataChecksum(128) == GetTestDataChecksum(256); + const bool colision2 = GetTestDataChecksum(132) == GetTestDataChecksum(260); + if (fWhichAlgorithm == kSkChecksum) { + // TODO: note the weakness exposed by these collisions... + // We need to improve the SkChecksum algorithm. + // We would prefer that these asserts FAIL! + // Filed as https://code.google.com/p/skia/issues/detail?id=981 + // ('SkChecksum algorithm allows for way too many collisions') + REPORTER_ASSERT(fReporter, colision1); + REPORTER_ASSERT(fReporter, colision2); + } else { + REPORTER_ASSERT(fReporter, !colision1); + REPORTER_ASSERT(fReporter, !colision2); + } + } } Reporter* fReporter; -- cgit v1.2.3