2 * Copyright (C) 2013 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "wtf/StringHasher.h"
29 #include <gtest/gtest.h>
35 const LChar nullLChars
[2] = { 0, 0 };
36 const UChar nullUChars
[2] = { 0, 0 };
38 const unsigned emptyStringHash
= 0x4EC889EU
;
39 const unsigned singleNullCharacterHash
= 0x3D3ABF44U
;
41 const LChar testALChars
[6] = { 0x41, 0x95, 0xFF, 0x50, 0x01, 0 };
42 const UChar testAUChars
[6] = { 0x41, 0x95, 0xFF, 0x50, 0x01, 0 };
43 const UChar testBUChars
[6] = { 0x41, 0x95, 0xFFFF, 0x1080, 0x01, 0 };
45 const unsigned testAHash1
= 0xEA32B004;
46 const unsigned testAHash2
= 0x93F0F71E;
47 const unsigned testAHash3
= 0xCB609EB1;
48 const unsigned testAHash4
= 0x7984A706;
49 const unsigned testAHash5
= 0x0427561F;
51 const unsigned testBHash1
= 0xEA32B004;
52 const unsigned testBHash2
= 0x93F0F71E;
53 const unsigned testBHash3
= 0x59EB1B2C;
54 const unsigned testBHash4
= 0xA7BCCC0A;
55 const unsigned testBHash5
= 0x79201649;
57 } // anonymous namespace
59 TEST(StringHasherTest
, StringHasher
)
63 // The initial state of the hasher.
64 EXPECT_EQ(emptyStringHash
, hasher
.hash());
65 EXPECT_EQ(emptyStringHash
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
68 TEST(StringHasherTest
, StringHasher_addCharacter
)
72 // Hashing a single character.
73 hasher
= StringHasher();
74 hasher
.addCharacter(0);
75 EXPECT_EQ(singleNullCharacterHash
, hasher
.hash());
76 EXPECT_EQ(singleNullCharacterHash
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
78 // Hashing five characters, checking the intermediate state after each is added.
79 hasher
= StringHasher();
80 hasher
.addCharacter(testAUChars
[0]);
81 EXPECT_EQ(testAHash1
, hasher
.hash());
82 EXPECT_EQ(testAHash1
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
83 hasher
.addCharacter(testAUChars
[1]);
84 EXPECT_EQ(testAHash2
, hasher
.hash());
85 EXPECT_EQ(testAHash2
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
86 hasher
.addCharacter(testAUChars
[2]);
87 EXPECT_EQ(testAHash3
, hasher
.hash());
88 EXPECT_EQ(testAHash3
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
89 hasher
.addCharacter(testAUChars
[3]);
90 EXPECT_EQ(testAHash4
, hasher
.hash());
91 EXPECT_EQ(testAHash4
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
92 hasher
.addCharacter(testAUChars
[4]);
93 EXPECT_EQ(testAHash5
, hasher
.hash());
94 EXPECT_EQ(testAHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
96 // Hashing a second set of five characters, including non-Latin-1 characters.
97 hasher
= StringHasher();
98 hasher
.addCharacter(testBUChars
[0]);
99 EXPECT_EQ(testBHash1
, hasher
.hash());
100 EXPECT_EQ(testBHash1
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
101 hasher
.addCharacter(testBUChars
[1]);
102 EXPECT_EQ(testBHash2
, hasher
.hash());
103 EXPECT_EQ(testBHash2
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
104 hasher
.addCharacter(testBUChars
[2]);
105 EXPECT_EQ(testBHash3
, hasher
.hash());
106 EXPECT_EQ(testBHash3
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
107 hasher
.addCharacter(testBUChars
[3]);
108 EXPECT_EQ(testBHash4
, hasher
.hash());
109 EXPECT_EQ(testBHash4
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
110 hasher
.addCharacter(testBUChars
[4]);
111 EXPECT_EQ(testBHash5
, hasher
.hash());
112 EXPECT_EQ(testBHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
115 TEST(StringHasherTest
, StringHasher_addCharacters
)
119 // Hashing zero characters.
120 hasher
= StringHasher();
121 hasher
.addCharacters(static_cast<LChar
*>(0), 0);
122 EXPECT_EQ(emptyStringHash
, hasher
.hash());
123 EXPECT_EQ(emptyStringHash
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
124 hasher
= StringHasher();
125 hasher
.addCharacters(nullLChars
, 0);
126 EXPECT_EQ(emptyStringHash
, hasher
.hash());
127 EXPECT_EQ(emptyStringHash
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
128 hasher
= StringHasher();
129 hasher
.addCharacters(static_cast<UChar
*>(0), 0);
130 EXPECT_EQ(emptyStringHash
, hasher
.hash());
131 EXPECT_EQ(emptyStringHash
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
132 hasher
= StringHasher();
133 hasher
.addCharacters(nullUChars
, 0);
134 EXPECT_EQ(emptyStringHash
, hasher
.hash());
135 EXPECT_EQ(emptyStringHash
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
137 // Hashing one character.
138 hasher
= StringHasher();
139 hasher
.addCharacters(nullLChars
, 1);
140 EXPECT_EQ(singleNullCharacterHash
, hasher
.hash());
141 EXPECT_EQ(singleNullCharacterHash
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
142 hasher
= StringHasher();
143 hasher
.addCharacters(nullUChars
, 1);
144 EXPECT_EQ(singleNullCharacterHash
, hasher
.hash());
145 EXPECT_EQ(singleNullCharacterHash
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
147 // Hashing five characters, all at once.
148 hasher
= StringHasher();
149 hasher
.addCharacters(testALChars
, 5);
150 EXPECT_EQ(testAHash5
, hasher
.hash());
151 EXPECT_EQ(testAHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
152 hasher
= StringHasher();
153 hasher
.addCharacters(testAUChars
, 5);
154 EXPECT_EQ(testAHash5
, hasher
.hash());
155 EXPECT_EQ(testAHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
156 hasher
= StringHasher();
157 hasher
.addCharacters(testBUChars
, 5);
158 EXPECT_EQ(testBHash5
, hasher
.hash());
159 EXPECT_EQ(testBHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
161 // Hashing five characters, in groups of two, then the last one.
162 hasher
= StringHasher();
163 hasher
.addCharacters(testALChars
, 2);
164 EXPECT_EQ(testAHash2
, hasher
.hash());
165 EXPECT_EQ(testAHash2
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
166 hasher
.addCharacters(testALChars
+ 2, 2);
167 EXPECT_EQ(testAHash4
, hasher
.hash());
168 EXPECT_EQ(testAHash4
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
169 hasher
.addCharacters(testALChars
+ 4, 1);
170 EXPECT_EQ(testAHash5
, hasher
.hash());
171 EXPECT_EQ(testAHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
172 hasher
= StringHasher();
173 hasher
.addCharacters(testALChars
, 2);
174 hasher
.addCharacters(testALChars
+ 2, 2);
175 hasher
.addCharacters(testALChars
+ 4, 1);
176 EXPECT_EQ(testAHash5
, hasher
.hash());
177 EXPECT_EQ(testAHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
178 hasher
= StringHasher();
179 hasher
.addCharacters(testAUChars
, 2);
180 EXPECT_EQ(testAHash2
, hasher
.hash());
181 EXPECT_EQ(testAHash2
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
182 hasher
.addCharacters(testAUChars
+ 2, 2);
183 EXPECT_EQ(testAHash4
, hasher
.hash());
184 EXPECT_EQ(testAHash4
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
185 hasher
.addCharacters(testAUChars
+ 4, 1);
186 EXPECT_EQ(testAHash5
, hasher
.hash());
187 EXPECT_EQ(testAHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
188 hasher
= StringHasher();
189 hasher
.addCharacters(testAUChars
, 2);
190 hasher
.addCharacters(testAUChars
+ 2, 2);
191 hasher
.addCharacters(testAUChars
+ 4, 1);
192 EXPECT_EQ(testAHash5
, hasher
.hash());
193 EXPECT_EQ(testAHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
194 hasher
= StringHasher();
195 hasher
.addCharacters(testBUChars
, 2);
196 EXPECT_EQ(testBHash2
, hasher
.hash());
197 EXPECT_EQ(testBHash2
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
198 hasher
.addCharacters(testBUChars
+ 2, 2);
199 EXPECT_EQ(testBHash4
, hasher
.hash());
200 EXPECT_EQ(testBHash4
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
201 hasher
.addCharacters(testBUChars
+ 4, 1);
202 EXPECT_EQ(testBHash5
, hasher
.hash());
203 EXPECT_EQ(testBHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
204 hasher
= StringHasher();
205 hasher
.addCharacters(testBUChars
, 2);
206 hasher
.addCharacters(testBUChars
+ 2, 2);
207 hasher
.addCharacters(testBUChars
+ 4, 1);
208 EXPECT_EQ(testBHash5
, hasher
.hash());
209 EXPECT_EQ(testBHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
211 // Hashing five characters, the first three, then the last two.
212 hasher
= StringHasher();
213 hasher
.addCharacters(testALChars
, 3);
214 EXPECT_EQ(testAHash3
, hasher
.hash());
215 EXPECT_EQ(testAHash3
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
216 hasher
.addCharacters(testALChars
+ 3, 2);
217 EXPECT_EQ(testAHash5
, hasher
.hash());
218 EXPECT_EQ(testAHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
219 hasher
= StringHasher();
220 hasher
.addCharacters(testALChars
, 3);
221 EXPECT_EQ(testAHash3
, hasher
.hash());
222 EXPECT_EQ(testAHash3
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
223 hasher
.addCharacters(testALChars
+ 3, 2);
224 EXPECT_EQ(testAHash5
, hasher
.hash());
225 EXPECT_EQ(testAHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
226 hasher
= StringHasher();
227 hasher
.addCharacters(testAUChars
, 3);
228 EXPECT_EQ(testAHash3
, hasher
.hash());
229 EXPECT_EQ(testAHash3
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
230 hasher
.addCharacters(testAUChars
+ 3, 2);
231 EXPECT_EQ(testAHash5
, hasher
.hash());
232 EXPECT_EQ(testAHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
233 hasher
= StringHasher();
234 hasher
.addCharacters(testAUChars
, 3);
235 EXPECT_EQ(testAHash3
, hasher
.hash());
236 EXPECT_EQ(testAHash3
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
237 hasher
.addCharacters(testAUChars
+ 3, 2);
238 EXPECT_EQ(testAHash5
, hasher
.hash());
239 EXPECT_EQ(testAHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
240 hasher
= StringHasher();
241 hasher
.addCharacters(testBUChars
, 3);
242 EXPECT_EQ(testBHash3
, hasher
.hash());
243 EXPECT_EQ(testBHash3
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
244 hasher
.addCharacters(testBUChars
+ 3, 2);
245 EXPECT_EQ(testBHash5
, hasher
.hash());
246 EXPECT_EQ(testBHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
247 hasher
= StringHasher();
248 hasher
.addCharacters(testBUChars
, 3);
249 hasher
.addCharacters(testBUChars
+ 3, 2);
250 EXPECT_EQ(testBHash5
, hasher
.hash());
251 EXPECT_EQ(testBHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
254 TEST(StringHasherTest
, StringHasher_addCharactersAssumingAligned
)
258 // Hashing zero characters.
259 hasher
= StringHasher();
260 hasher
.addCharactersAssumingAligned(static_cast<LChar
*>(0), 0);
261 EXPECT_EQ(emptyStringHash
, hasher
.hash());
262 EXPECT_EQ(emptyStringHash
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
263 hasher
= StringHasher();
264 hasher
.addCharactersAssumingAligned(nullLChars
, 0);
265 EXPECT_EQ(emptyStringHash
, hasher
.hash());
266 EXPECT_EQ(emptyStringHash
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
267 hasher
= StringHasher();
268 hasher
.addCharactersAssumingAligned(static_cast<UChar
*>(0), 0);
269 EXPECT_EQ(emptyStringHash
, hasher
.hash());
270 EXPECT_EQ(emptyStringHash
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
271 hasher
= StringHasher();
272 hasher
.addCharactersAssumingAligned(nullUChars
, 0);
273 EXPECT_EQ(emptyStringHash
, hasher
.hash());
274 EXPECT_EQ(emptyStringHash
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
276 // Hashing one character.
277 hasher
= StringHasher();
278 hasher
.addCharactersAssumingAligned(nullLChars
, 1);
279 EXPECT_EQ(singleNullCharacterHash
, hasher
.hash());
280 EXPECT_EQ(singleNullCharacterHash
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
281 hasher
= StringHasher();
282 hasher
.addCharactersAssumingAligned(nullUChars
, 1);
283 EXPECT_EQ(singleNullCharacterHash
, hasher
.hash());
284 EXPECT_EQ(singleNullCharacterHash
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
286 // Hashing five characters, all at once.
287 hasher
= StringHasher();
288 hasher
.addCharactersAssumingAligned(testALChars
, 5);
289 EXPECT_EQ(testAHash5
, hasher
.hash());
290 EXPECT_EQ(testAHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
291 hasher
= StringHasher();
292 hasher
.addCharactersAssumingAligned(testAUChars
, 5);
293 EXPECT_EQ(testAHash5
, hasher
.hash());
294 EXPECT_EQ(testAHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
295 hasher
= StringHasher();
296 hasher
.addCharactersAssumingAligned(testBUChars
, 5);
297 EXPECT_EQ(testBHash5
, hasher
.hash());
298 EXPECT_EQ(testBHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
300 // Hashing five characters, in groups of two, then the last one.
301 hasher
= StringHasher();
302 hasher
.addCharactersAssumingAligned(testALChars
, 2);
303 EXPECT_EQ(testAHash2
, hasher
.hash());
304 EXPECT_EQ(testAHash2
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
305 hasher
.addCharactersAssumingAligned(testALChars
+ 2, 2);
306 EXPECT_EQ(testAHash4
, hasher
.hash());
307 EXPECT_EQ(testAHash4
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
308 hasher
.addCharactersAssumingAligned(testALChars
+ 4, 1);
309 EXPECT_EQ(testAHash5
, hasher
.hash());
310 EXPECT_EQ(testAHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
311 hasher
= StringHasher();
312 hasher
.addCharactersAssumingAligned(testALChars
, 2);
313 hasher
.addCharactersAssumingAligned(testALChars
+ 2, 2);
314 hasher
.addCharactersAssumingAligned(testALChars
+ 4, 1);
315 EXPECT_EQ(testAHash5
, hasher
.hash());
316 EXPECT_EQ(testAHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
317 hasher
= StringHasher();
318 hasher
.addCharactersAssumingAligned(testAUChars
, 2);
319 EXPECT_EQ(testAHash2
, hasher
.hash());
320 EXPECT_EQ(testAHash2
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
321 hasher
.addCharactersAssumingAligned(testAUChars
+ 2, 2);
322 EXPECT_EQ(testAHash4
, hasher
.hash());
323 EXPECT_EQ(testAHash4
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
324 hasher
.addCharactersAssumingAligned(testAUChars
+ 4, 1);
325 EXPECT_EQ(testAHash5
, hasher
.hash());
326 EXPECT_EQ(testAHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
327 hasher
= StringHasher();
328 hasher
.addCharactersAssumingAligned(testAUChars
, 2);
329 hasher
.addCharactersAssumingAligned(testAUChars
+ 2, 2);
330 hasher
.addCharactersAssumingAligned(testAUChars
+ 4, 1);
331 EXPECT_EQ(testAHash5
, hasher
.hash());
332 EXPECT_EQ(testAHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
333 hasher
= StringHasher();
334 hasher
.addCharactersAssumingAligned(testBUChars
, 2);
335 EXPECT_EQ(testBHash2
, hasher
.hash());
336 EXPECT_EQ(testBHash2
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
337 hasher
.addCharactersAssumingAligned(testBUChars
+ 2, 2);
338 EXPECT_EQ(testBHash4
, hasher
.hash());
339 EXPECT_EQ(testBHash4
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
340 hasher
.addCharactersAssumingAligned(testBUChars
+ 4, 1);
341 EXPECT_EQ(testBHash5
, hasher
.hash());
342 EXPECT_EQ(testBHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
343 hasher
= StringHasher();
344 hasher
.addCharactersAssumingAligned(testBUChars
, 2);
345 hasher
.addCharactersAssumingAligned(testBUChars
+ 2, 2);
346 hasher
.addCharactersAssumingAligned(testBUChars
+ 4, 1);
347 EXPECT_EQ(testBHash5
, hasher
.hash());
348 EXPECT_EQ(testBHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
350 // Hashing five characters, first two characters one at a time,
351 // then two more, then the last one.
352 hasher
= StringHasher();
353 hasher
.addCharacter(testBUChars
[0]);
354 EXPECT_EQ(testBHash1
, hasher
.hash());
355 EXPECT_EQ(testBHash1
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
356 hasher
.addCharacter(testBUChars
[1]);
357 EXPECT_EQ(testBHash2
, hasher
.hash());
358 EXPECT_EQ(testBHash2
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
359 hasher
.addCharactersAssumingAligned(testBUChars
[2], testBUChars
[3]);
360 EXPECT_EQ(testBHash4
, hasher
.hash());
361 EXPECT_EQ(testBHash4
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
362 hasher
.addCharactersAssumingAligned(testBUChars
+ 4, 1);
363 EXPECT_EQ(testBHash5
, hasher
.hash());
364 EXPECT_EQ(testBHash5
& 0xFFFFFF, hasher
.hashWithTop8BitsMasked());
367 TEST(StringHasherTest
, StringHasher_computeHash
)
369 EXPECT_EQ(emptyStringHash
, StringHasher::computeHash(static_cast<LChar
*>(0), 0));
370 EXPECT_EQ(emptyStringHash
, StringHasher::computeHash(nullLChars
, 0));
371 EXPECT_EQ(emptyStringHash
, StringHasher::computeHash(static_cast<UChar
*>(0), 0));
372 EXPECT_EQ(emptyStringHash
, StringHasher::computeHash(nullUChars
, 0));
374 EXPECT_EQ(singleNullCharacterHash
, StringHasher::computeHash(nullLChars
, 1));
375 EXPECT_EQ(singleNullCharacterHash
, StringHasher::computeHash(nullUChars
, 1));
377 EXPECT_EQ(testAHash5
, StringHasher::computeHash(testALChars
, 5));
378 EXPECT_EQ(testAHash5
, StringHasher::computeHash(testAUChars
, 5));
379 EXPECT_EQ(testBHash5
, StringHasher::computeHash(testBUChars
, 5));
382 TEST(StringHasherTest
, StringHasher_computeHashAndMaskTop8Bits
)
384 EXPECT_EQ(emptyStringHash
& 0xFFFFFF, StringHasher::computeHashAndMaskTop8Bits(static_cast<LChar
*>(0), 0));
385 EXPECT_EQ(emptyStringHash
& 0xFFFFFF, StringHasher::computeHashAndMaskTop8Bits(nullLChars
, 0));
386 EXPECT_EQ(emptyStringHash
& 0xFFFFFF, StringHasher::computeHashAndMaskTop8Bits(static_cast<UChar
*>(0), 0));
387 EXPECT_EQ(emptyStringHash
& 0xFFFFFF, StringHasher::computeHashAndMaskTop8Bits(nullUChars
, 0));
389 EXPECT_EQ(singleNullCharacterHash
& 0xFFFFFF, StringHasher::computeHashAndMaskTop8Bits(nullLChars
, 1));
390 EXPECT_EQ(singleNullCharacterHash
& 0xFFFFFF, StringHasher::computeHashAndMaskTop8Bits(nullUChars
, 1));
392 EXPECT_EQ(testAHash5
& 0xFFFFFF, StringHasher::computeHashAndMaskTop8Bits(testALChars
, 5));
393 EXPECT_EQ(testAHash5
& 0xFFFFFF, StringHasher::computeHashAndMaskTop8Bits(testAUChars
, 5));
394 EXPECT_EQ(testBHash5
& 0xFFFFFF, StringHasher::computeHashAndMaskTop8Bits(testBUChars
, 5));
397 TEST(StringHasherTest
, StringHasher_hashMemory
)
399 EXPECT_EQ(emptyStringHash
& 0xFFFFFF, StringHasher::hashMemory(0, 0));
400 EXPECT_EQ(emptyStringHash
& 0xFFFFFF, StringHasher::hashMemory(nullUChars
, 0));
401 EXPECT_EQ(emptyStringHash
& 0xFFFFFF, StringHasher::hashMemory
<0>(0));
402 EXPECT_EQ(emptyStringHash
& 0xFFFFFF, StringHasher::hashMemory
<0>(nullUChars
));
404 EXPECT_EQ(singleNullCharacterHash
& 0xFFFFFF, StringHasher::hashMemory(nullUChars
, 2));
405 EXPECT_EQ(singleNullCharacterHash
& 0xFFFFFF, StringHasher::hashMemory
<2>(nullUChars
));
407 EXPECT_EQ(testAHash5
& 0xFFFFFF, StringHasher::hashMemory(testAUChars
, 10));
408 EXPECT_EQ(testAHash5
& 0xFFFFFF, StringHasher::hashMemory
<10>(testAUChars
));
409 EXPECT_EQ(testBHash5
& 0xFFFFFF, StringHasher::hashMemory(testBUChars
, 10));
410 EXPECT_EQ(testBHash5
& 0xFFFFFF, StringHasher::hashMemory
<10>(testBUChars
));