aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/ChecksumTest.cpp
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-07-23 20:25:34 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-07-23 20:25:34 +0000
commit70d75ca764e16e15f016e423b85a0fa2a29fb8c7 (patch)
tree8c3d2b53e6efdea8987acc7b6fe9db7420107687 /tests/ChecksumTest.cpp
parentd2d9f563be80a6169380b6ac0d2b0306688817e4 (diff)
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
Diffstat (limited to 'tests/ChecksumTest.cpp')
-rw-r--r--tests/ChecksumTest.cpp55
1 files changed, 35 insertions, 20 deletions
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<const uint32_t *>(data), size);
+ case kMurmur3:
+ REPORTER_ASSERT_MESSAGE(fReporter,
+ reinterpret_cast<uintptr_t>(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<const uint32_t *>(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;