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

Side by Side Diff: tests/ChecksumTest.cpp

Issue 14170010: rename SkBitmapChecksummer as SkBitmapHasher, and prepare for it to possibly use (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: sync_to_r8638 Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « tests/BitmapHasherTest.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 /* 2 /*
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "Test.h" 8 #include "Test.h"
9 9
10 #include "SkBitmap.h"
11 #include "SkBitmapChecksummer.h"
12 #include "SkChecksum.h" 10 #include "SkChecksum.h"
13 #include "SkCityHash.h" 11 #include "SkCityHash.h"
14 #include "SkColor.h"
15 12
16 // Word size that is large enough to hold results of any checksum type. 13 // Word size that is large enough to hold results of any checksum type.
17 typedef uint64_t checksum_result; 14 typedef uint64_t checksum_result;
18 15
19 namespace skiatest { 16 namespace skiatest {
20 class ChecksumTestClass : public Test { 17 class ChecksumTestClass : public Test {
21 public: 18 public:
22 static Test* Factory(void*) {return SkNEW(ChecksumTestClass); } 19 static Test* Factory(void*) {return SkNEW(ChecksumTestClass); }
23 protected: 20 protected:
24 virtual void onGetName(SkString* name) { name->set("Checksum"); } 21 virtual void onGetName(SkString* name) { name->set("Checksum"); }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 SkAutoMalloc storage(len); 97 SkAutoMalloc storage(len);
101 char* start = reinterpret_cast<char *>(storage.get()); 98 char* start = reinterpret_cast<char *>(storage.get());
102 char* ptr = start; 99 char* ptr = start;
103 for (size_t i = 0; i < len; ++i) { 100 for (size_t i = 0; i < len; ++i) {
104 *ptr++ = ((seed+i) & 0x7f); 101 *ptr++ = ((seed+i) & 0x7f);
105 } 102 }
106 checksum_result result = ComputeChecksum(start, len); 103 checksum_result result = ComputeChecksum(start, len);
107 return result; 104 return result;
108 } 105 }
109 106
110 // Fill in bitmap with test data.
111 void CreateTestBitmap(SkBitmap &bitmap, SkBitmap::Config config, int wid th, int height,
112 SkColor color) {
113 bitmap.setConfig(config, width, height);
114 REPORTER_ASSERT(fReporter, bitmap.allocPixels());
115 bitmap.setIsOpaque(true);
116 bitmap.eraseColor(color);
117 }
118
119 void RunTest() { 107 void RunTest() {
120 // Test self-consistency of checksum algorithms. 108 // Test self-consistency of checksum algorithms.
121 fWhichAlgorithm = kSkChecksum; 109 fWhichAlgorithm = kSkChecksum;
122 TestChecksumSelfConsistency(128); 110 TestChecksumSelfConsistency(128);
123 fWhichAlgorithm = kSkCityHash32; 111 fWhichAlgorithm = kSkCityHash32;
124 TestChecksumSelfConsistency(128); 112 TestChecksumSelfConsistency(128);
125 fWhichAlgorithm = kSkCityHash64; 113 fWhichAlgorithm = kSkCityHash64;
126 TestChecksumSelfConsistency(128); 114 TestChecksumSelfConsistency(128);
127 115
128 // Test checksum results that should be consistent across 116 // Test checksum results that should be consistent across
(...skipping 20 matching lines...) Expand all
149 // TODO: note the weakness exposed by these collisions... 137 // TODO: note the weakness exposed by these collisions...
150 // We need to improve the SkChecksum algorithm. 138 // We need to improve the SkChecksum algorithm.
151 // We would prefer that these asserts FAIL! 139 // We would prefer that these asserts FAIL!
152 // Filed as https://code.google.com/p/skia/issues/detail?id=981 140 // Filed as https://code.google.com/p/skia/issues/detail?id=981
153 // ('SkChecksum algorithm allows for way too many collisions') 141 // ('SkChecksum algorithm allows for way too many collisions')
154 fWhichAlgorithm = kSkChecksum; 142 fWhichAlgorithm = kSkChecksum;
155 REPORTER_ASSERT(fReporter, 143 REPORTER_ASSERT(fReporter,
156 GetTestDataChecksum(128) == GetTestDataChecksum(256)); 144 GetTestDataChecksum(128) == GetTestDataChecksum(256));
157 REPORTER_ASSERT(fReporter, 145 REPORTER_ASSERT(fReporter,
158 GetTestDataChecksum(132) == GetTestDataChecksum(260)); 146 GetTestDataChecksum(132) == GetTestDataChecksum(260));
159
160 // Test SkBitmapChecksummer
161 SkBitmap bitmap;
162 // initial test case
163 CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 333, 555, SK_C olorBLUE);
164 REPORTER_ASSERT(fReporter,
165 SkBitmapChecksummer::Compute64(bitmap) == 0x18f9df68 b1b02f38ULL);
166 // same pixel data but different dimensions should yield a different checksum
167 CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 555, 333, SK_C olorBLUE);
168 REPORTER_ASSERT(fReporter,
169 SkBitmapChecksummer::Compute64(bitmap) == 0x6b029818 3f786c8eULL);
170 // same dimensions but different color should yield a different chec ksum
171 CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 555, 333, SK_C olorGREEN);
172 REPORTER_ASSERT(fReporter,
173 SkBitmapChecksummer::Compute64(bitmap) == 0xc6b4b3f6 fadaaf37ULL);
174 // same pixel colors in a different config should yield the same che cksum
175 CreateTestBitmap(bitmap, SkBitmap::kARGB_4444_Config, 555, 333, SK_C olorGREEN);
176 REPORTER_ASSERT(fReporter,
177 SkBitmapChecksummer::Compute64(bitmap) == 0xc6b4b3f6 fadaaf37ULL);
178 } 147 }
179 148
180 Reporter* fReporter; 149 Reporter* fReporter;
181 Algorithm fWhichAlgorithm; 150 Algorithm fWhichAlgorithm;
182 }; 151 };
183 152
184 static TestRegistry gReg(ChecksumTestClass::Factory); 153 static TestRegistry gReg(ChecksumTestClass::Factory);
185 } 154 }
OLDNEW
« no previous file with comments | « tests/BitmapHasherTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698