| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2013 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "wtf/StringHasher.h" | 27 #include "wtf/StringHasher.h" |
| 28 | 28 |
| 29 #include <gtest/gtest.h> | 29 #include <gtest/gtest.h> |
| 30 | 30 |
| 31 namespace WTF { | 31 namespace WTF { |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 const LChar nullLChars[2] = { 0, 0 }; | 35 const LChar nullLChars[2] = {0, 0}; |
| 36 const UChar nullUChars[2] = { 0, 0 }; | 36 const UChar nullUChars[2] = {0, 0}; |
| 37 | 37 |
| 38 const unsigned emptyStringHash = 0x4EC889EU; | 38 const unsigned emptyStringHash = 0x4EC889EU; |
| 39 const unsigned singleNullCharacterHash = 0x3D3ABF44U; | 39 const unsigned singleNullCharacterHash = 0x3D3ABF44U; |
| 40 | 40 |
| 41 const LChar testALChars[6] = { 0x41, 0x95, 0xFF, 0x50, 0x01, 0 }; | 41 const LChar testALChars[6] = {0x41, 0x95, 0xFF, 0x50, 0x01, 0}; |
| 42 const UChar testAUChars[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 }; | 43 const UChar testBUChars[6] = {0x41, 0x95, 0xFFFF, 0x1080, 0x01, 0}; |
| 44 | 44 |
| 45 const unsigned testAHash1 = 0xEA32B004; | 45 const unsigned testAHash1 = 0xEA32B004; |
| 46 const unsigned testAHash2 = 0x93F0F71E; | 46 const unsigned testAHash2 = 0x93F0F71E; |
| 47 const unsigned testAHash3 = 0xCB609EB1; | 47 const unsigned testAHash3 = 0xCB609EB1; |
| 48 const unsigned testAHash4 = 0x7984A706; | 48 const unsigned testAHash4 = 0x7984A706; |
| 49 const unsigned testAHash5 = 0x0427561F; | 49 const unsigned testAHash5 = 0x0427561F; |
| 50 | 50 |
| 51 const unsigned testBHash1 = 0xEA32B004; | 51 const unsigned testBHash1 = 0xEA32B004; |
| 52 const unsigned testBHash2 = 0x93F0F71E; | 52 const unsigned testBHash2 = 0x93F0F71E; |
| 53 const unsigned testBHash3 = 0x59EB1B2C; | 53 const unsigned testBHash3 = 0x59EB1B2C; |
| 54 const unsigned testBHash4 = 0xA7BCCC0A; | 54 const unsigned testBHash4 = 0xA7BCCC0A; |
| 55 const unsigned testBHash5 = 0x79201649; | 55 const unsigned testBHash5 = 0x79201649; |
| 56 | 56 |
| 57 } // anonymous namespace | 57 } // anonymous namespace |
| 58 | 58 |
| 59 TEST(StringHasherTest, StringHasher) | 59 TEST(StringHasherTest, StringHasher) { |
| 60 { | 60 StringHasher hasher; |
| 61 StringHasher hasher; | 61 |
| 62 | 62 // The initial state of the hasher. |
| 63 // The initial state of the hasher. | 63 EXPECT_EQ(emptyStringHash, hasher.hash()); |
| 64 EXPECT_EQ(emptyStringHash, hasher.hash()); | 64 EXPECT_EQ(emptyStringHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 65 EXPECT_EQ(emptyStringHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 65 } |
| 66 } | 66 |
| 67 | 67 TEST(StringHasherTest, StringHasher_addCharacter) { |
| 68 TEST(StringHasherTest, StringHasher_addCharacter) | 68 StringHasher hasher; |
| 69 { | 69 |
| 70 StringHasher hasher; | 70 // Hashing a single character. |
| 71 | 71 hasher = StringHasher(); |
| 72 // Hashing a single character. | 72 hasher.addCharacter(0); |
| 73 hasher = StringHasher(); | 73 EXPECT_EQ(singleNullCharacterHash, hasher.hash()); |
| 74 hasher.addCharacter(0); | 74 EXPECT_EQ(singleNullCharacterHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked())
; |
| 75 EXPECT_EQ(singleNullCharacterHash, hasher.hash()); | 75 |
| 76 EXPECT_EQ(singleNullCharacterHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked(
)); | 76 // Hashing five characters, checking the intermediate state after each is adde
d. |
| 77 | 77 hasher = StringHasher(); |
| 78 // Hashing five characters, checking the intermediate state after each is ad
ded. | 78 hasher.addCharacter(testAUChars[0]); |
| 79 hasher = StringHasher(); | 79 EXPECT_EQ(testAHash1, hasher.hash()); |
| 80 hasher.addCharacter(testAUChars[0]); | 80 EXPECT_EQ(testAHash1 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 81 EXPECT_EQ(testAHash1, hasher.hash()); | 81 hasher.addCharacter(testAUChars[1]); |
| 82 EXPECT_EQ(testAHash1 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 82 EXPECT_EQ(testAHash2, hasher.hash()); |
| 83 hasher.addCharacter(testAUChars[1]); | 83 EXPECT_EQ(testAHash2 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 84 EXPECT_EQ(testAHash2, hasher.hash()); | 84 hasher.addCharacter(testAUChars[2]); |
| 85 EXPECT_EQ(testAHash2 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 85 EXPECT_EQ(testAHash3, hasher.hash()); |
| 86 hasher.addCharacter(testAUChars[2]); | 86 EXPECT_EQ(testAHash3 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 87 EXPECT_EQ(testAHash3, hasher.hash()); | 87 hasher.addCharacter(testAUChars[3]); |
| 88 EXPECT_EQ(testAHash3 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 88 EXPECT_EQ(testAHash4, hasher.hash()); |
| 89 hasher.addCharacter(testAUChars[3]); | 89 EXPECT_EQ(testAHash4 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 90 EXPECT_EQ(testAHash4, hasher.hash()); | 90 hasher.addCharacter(testAUChars[4]); |
| 91 EXPECT_EQ(testAHash4 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 91 EXPECT_EQ(testAHash5, hasher.hash()); |
| 92 hasher.addCharacter(testAUChars[4]); | 92 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 93 EXPECT_EQ(testAHash5, hasher.hash()); | 93 |
| 94 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 94 // Hashing a second set of five characters, including non-Latin-1 characters. |
| 95 | 95 hasher = StringHasher(); |
| 96 // Hashing a second set of five characters, including non-Latin-1 characters
. | 96 hasher.addCharacter(testBUChars[0]); |
| 97 hasher = StringHasher(); | 97 EXPECT_EQ(testBHash1, hasher.hash()); |
| 98 hasher.addCharacter(testBUChars[0]); | 98 EXPECT_EQ(testBHash1 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 99 EXPECT_EQ(testBHash1, hasher.hash()); | 99 hasher.addCharacter(testBUChars[1]); |
| 100 EXPECT_EQ(testBHash1 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 100 EXPECT_EQ(testBHash2, hasher.hash()); |
| 101 hasher.addCharacter(testBUChars[1]); | 101 EXPECT_EQ(testBHash2 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 102 EXPECT_EQ(testBHash2, hasher.hash()); | 102 hasher.addCharacter(testBUChars[2]); |
| 103 EXPECT_EQ(testBHash2 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 103 EXPECT_EQ(testBHash3, hasher.hash()); |
| 104 hasher.addCharacter(testBUChars[2]); | 104 EXPECT_EQ(testBHash3 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 105 EXPECT_EQ(testBHash3, hasher.hash()); | 105 hasher.addCharacter(testBUChars[3]); |
| 106 EXPECT_EQ(testBHash3 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 106 EXPECT_EQ(testBHash4, hasher.hash()); |
| 107 hasher.addCharacter(testBUChars[3]); | 107 EXPECT_EQ(testBHash4 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 108 EXPECT_EQ(testBHash4, hasher.hash()); | 108 hasher.addCharacter(testBUChars[4]); |
| 109 EXPECT_EQ(testBHash4 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 109 EXPECT_EQ(testBHash5, hasher.hash()); |
| 110 hasher.addCharacter(testBUChars[4]); | 110 EXPECT_EQ(testBHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 111 EXPECT_EQ(testBHash5, hasher.hash()); | 111 } |
| 112 EXPECT_EQ(testBHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 112 |
| 113 } | 113 TEST(StringHasherTest, StringHasher_addCharacters) { |
| 114 | 114 StringHasher hasher; |
| 115 TEST(StringHasherTest, StringHasher_addCharacters) | 115 |
| 116 { | 116 // Hashing zero characters. |
| 117 StringHasher hasher; | 117 hasher = StringHasher(); |
| 118 | 118 hasher.addCharacters(static_cast<LChar*>(0), 0); |
| 119 // Hashing zero characters. | 119 EXPECT_EQ(emptyStringHash, hasher.hash()); |
| 120 hasher = StringHasher(); | 120 EXPECT_EQ(emptyStringHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 121 hasher.addCharacters(static_cast<LChar*>(0), 0); | 121 hasher = StringHasher(); |
| 122 EXPECT_EQ(emptyStringHash, hasher.hash()); | 122 hasher.addCharacters(nullLChars, 0); |
| 123 EXPECT_EQ(emptyStringHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 123 EXPECT_EQ(emptyStringHash, hasher.hash()); |
| 124 hasher = StringHasher(); | 124 EXPECT_EQ(emptyStringHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 125 hasher.addCharacters(nullLChars, 0); | 125 hasher = StringHasher(); |
| 126 EXPECT_EQ(emptyStringHash, hasher.hash()); | 126 hasher.addCharacters(static_cast<UChar*>(0), 0); |
| 127 EXPECT_EQ(emptyStringHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 127 EXPECT_EQ(emptyStringHash, hasher.hash()); |
| 128 hasher = StringHasher(); | 128 EXPECT_EQ(emptyStringHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 129 hasher.addCharacters(static_cast<UChar*>(0), 0); | 129 hasher = StringHasher(); |
| 130 EXPECT_EQ(emptyStringHash, hasher.hash()); | 130 hasher.addCharacters(nullUChars, 0); |
| 131 EXPECT_EQ(emptyStringHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 131 EXPECT_EQ(emptyStringHash, hasher.hash()); |
| 132 hasher = StringHasher(); | 132 EXPECT_EQ(emptyStringHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 133 hasher.addCharacters(nullUChars, 0); | 133 |
| 134 EXPECT_EQ(emptyStringHash, hasher.hash()); | 134 // Hashing one character. |
| 135 EXPECT_EQ(emptyStringHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 135 hasher = StringHasher(); |
| 136 | 136 hasher.addCharacters(nullLChars, 1); |
| 137 // Hashing one character. | 137 EXPECT_EQ(singleNullCharacterHash, hasher.hash()); |
| 138 hasher = StringHasher(); | 138 EXPECT_EQ(singleNullCharacterHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked())
; |
| 139 hasher.addCharacters(nullLChars, 1); | 139 hasher = StringHasher(); |
| 140 EXPECT_EQ(singleNullCharacterHash, hasher.hash()); | 140 hasher.addCharacters(nullUChars, 1); |
| 141 EXPECT_EQ(singleNullCharacterHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked(
)); | 141 EXPECT_EQ(singleNullCharacterHash, hasher.hash()); |
| 142 hasher = StringHasher(); | 142 EXPECT_EQ(singleNullCharacterHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked())
; |
| 143 hasher.addCharacters(nullUChars, 1); | 143 |
| 144 EXPECT_EQ(singleNullCharacterHash, hasher.hash()); | 144 // Hashing five characters, all at once. |
| 145 EXPECT_EQ(singleNullCharacterHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked(
)); | 145 hasher = StringHasher(); |
| 146 | 146 hasher.addCharacters(testALChars, 5); |
| 147 // Hashing five characters, all at once. | 147 EXPECT_EQ(testAHash5, hasher.hash()); |
| 148 hasher = StringHasher(); | 148 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 149 hasher.addCharacters(testALChars, 5); | 149 hasher = StringHasher(); |
| 150 EXPECT_EQ(testAHash5, hasher.hash()); | 150 hasher.addCharacters(testAUChars, 5); |
| 151 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 151 EXPECT_EQ(testAHash5, hasher.hash()); |
| 152 hasher = StringHasher(); | 152 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 153 hasher.addCharacters(testAUChars, 5); | 153 hasher = StringHasher(); |
| 154 EXPECT_EQ(testAHash5, hasher.hash()); | 154 hasher.addCharacters(testBUChars, 5); |
| 155 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 155 EXPECT_EQ(testBHash5, hasher.hash()); |
| 156 hasher = StringHasher(); | 156 EXPECT_EQ(testBHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 157 hasher.addCharacters(testBUChars, 5); | 157 |
| 158 EXPECT_EQ(testBHash5, hasher.hash()); | 158 // Hashing five characters, in groups of two, then the last one. |
| 159 EXPECT_EQ(testBHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 159 hasher = StringHasher(); |
| 160 | 160 hasher.addCharacters(testALChars, 2); |
| 161 // Hashing five characters, in groups of two, then the last one. | 161 EXPECT_EQ(testAHash2, hasher.hash()); |
| 162 hasher = StringHasher(); | 162 EXPECT_EQ(testAHash2 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 163 hasher.addCharacters(testALChars, 2); | 163 hasher.addCharacters(testALChars + 2, 2); |
| 164 EXPECT_EQ(testAHash2, hasher.hash()); | 164 EXPECT_EQ(testAHash4, hasher.hash()); |
| 165 EXPECT_EQ(testAHash2 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 165 EXPECT_EQ(testAHash4 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 166 hasher.addCharacters(testALChars + 2, 2); | 166 hasher.addCharacters(testALChars + 4, 1); |
| 167 EXPECT_EQ(testAHash4, hasher.hash()); | 167 EXPECT_EQ(testAHash5, hasher.hash()); |
| 168 EXPECT_EQ(testAHash4 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 168 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 169 hasher.addCharacters(testALChars + 4, 1); | 169 hasher = StringHasher(); |
| 170 EXPECT_EQ(testAHash5, hasher.hash()); | 170 hasher.addCharacters(testALChars, 2); |
| 171 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 171 hasher.addCharacters(testALChars + 2, 2); |
| 172 hasher = StringHasher(); | 172 hasher.addCharacters(testALChars + 4, 1); |
| 173 hasher.addCharacters(testALChars, 2); | 173 EXPECT_EQ(testAHash5, hasher.hash()); |
| 174 hasher.addCharacters(testALChars + 2, 2); | 174 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 175 hasher.addCharacters(testALChars + 4, 1); | 175 hasher = StringHasher(); |
| 176 EXPECT_EQ(testAHash5, hasher.hash()); | 176 hasher.addCharacters(testAUChars, 2); |
| 177 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 177 EXPECT_EQ(testAHash2, hasher.hash()); |
| 178 hasher = StringHasher(); | 178 EXPECT_EQ(testAHash2 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 179 hasher.addCharacters(testAUChars, 2); | 179 hasher.addCharacters(testAUChars + 2, 2); |
| 180 EXPECT_EQ(testAHash2, hasher.hash()); | 180 EXPECT_EQ(testAHash4, hasher.hash()); |
| 181 EXPECT_EQ(testAHash2 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 181 EXPECT_EQ(testAHash4 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 182 hasher.addCharacters(testAUChars + 2, 2); | 182 hasher.addCharacters(testAUChars + 4, 1); |
| 183 EXPECT_EQ(testAHash4, hasher.hash()); | 183 EXPECT_EQ(testAHash5, hasher.hash()); |
| 184 EXPECT_EQ(testAHash4 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 184 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 185 hasher.addCharacters(testAUChars + 4, 1); | 185 hasher = StringHasher(); |
| 186 EXPECT_EQ(testAHash5, hasher.hash()); | 186 hasher.addCharacters(testAUChars, 2); |
| 187 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 187 hasher.addCharacters(testAUChars + 2, 2); |
| 188 hasher = StringHasher(); | 188 hasher.addCharacters(testAUChars + 4, 1); |
| 189 hasher.addCharacters(testAUChars, 2); | 189 EXPECT_EQ(testAHash5, hasher.hash()); |
| 190 hasher.addCharacters(testAUChars + 2, 2); | 190 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 191 hasher.addCharacters(testAUChars + 4, 1); | 191 hasher = StringHasher(); |
| 192 EXPECT_EQ(testAHash5, hasher.hash()); | 192 hasher.addCharacters(testBUChars, 2); |
| 193 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 193 EXPECT_EQ(testBHash2, hasher.hash()); |
| 194 hasher = StringHasher(); | 194 EXPECT_EQ(testBHash2 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 195 hasher.addCharacters(testBUChars, 2); | 195 hasher.addCharacters(testBUChars + 2, 2); |
| 196 EXPECT_EQ(testBHash2, hasher.hash()); | 196 EXPECT_EQ(testBHash4, hasher.hash()); |
| 197 EXPECT_EQ(testBHash2 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 197 EXPECT_EQ(testBHash4 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 198 hasher.addCharacters(testBUChars + 2, 2); | 198 hasher.addCharacters(testBUChars + 4, 1); |
| 199 EXPECT_EQ(testBHash4, hasher.hash()); | 199 EXPECT_EQ(testBHash5, hasher.hash()); |
| 200 EXPECT_EQ(testBHash4 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 200 EXPECT_EQ(testBHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 201 hasher.addCharacters(testBUChars + 4, 1); | 201 hasher = StringHasher(); |
| 202 EXPECT_EQ(testBHash5, hasher.hash()); | 202 hasher.addCharacters(testBUChars, 2); |
| 203 EXPECT_EQ(testBHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 203 hasher.addCharacters(testBUChars + 2, 2); |
| 204 hasher = StringHasher(); | 204 hasher.addCharacters(testBUChars + 4, 1); |
| 205 hasher.addCharacters(testBUChars, 2); | 205 EXPECT_EQ(testBHash5, hasher.hash()); |
| 206 hasher.addCharacters(testBUChars + 2, 2); | 206 EXPECT_EQ(testBHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 207 hasher.addCharacters(testBUChars + 4, 1); | 207 |
| 208 EXPECT_EQ(testBHash5, hasher.hash()); | 208 // Hashing five characters, the first three, then the last two. |
| 209 EXPECT_EQ(testBHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 209 hasher = StringHasher(); |
| 210 | 210 hasher.addCharacters(testALChars, 3); |
| 211 // Hashing five characters, the first three, then the last two. | 211 EXPECT_EQ(testAHash3, hasher.hash()); |
| 212 hasher = StringHasher(); | 212 EXPECT_EQ(testAHash3 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 213 hasher.addCharacters(testALChars, 3); | 213 hasher.addCharacters(testALChars + 3, 2); |
| 214 EXPECT_EQ(testAHash3, hasher.hash()); | 214 EXPECT_EQ(testAHash5, hasher.hash()); |
| 215 EXPECT_EQ(testAHash3 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 215 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 216 hasher.addCharacters(testALChars + 3, 2); | 216 hasher = StringHasher(); |
| 217 EXPECT_EQ(testAHash5, hasher.hash()); | 217 hasher.addCharacters(testALChars, 3); |
| 218 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 218 EXPECT_EQ(testAHash3, hasher.hash()); |
| 219 hasher = StringHasher(); | 219 EXPECT_EQ(testAHash3 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 220 hasher.addCharacters(testALChars, 3); | 220 hasher.addCharacters(testALChars + 3, 2); |
| 221 EXPECT_EQ(testAHash3, hasher.hash()); | 221 EXPECT_EQ(testAHash5, hasher.hash()); |
| 222 EXPECT_EQ(testAHash3 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 222 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 223 hasher.addCharacters(testALChars + 3, 2); | 223 hasher = StringHasher(); |
| 224 EXPECT_EQ(testAHash5, hasher.hash()); | 224 hasher.addCharacters(testAUChars, 3); |
| 225 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 225 EXPECT_EQ(testAHash3, hasher.hash()); |
| 226 hasher = StringHasher(); | 226 EXPECT_EQ(testAHash3 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 227 hasher.addCharacters(testAUChars, 3); | 227 hasher.addCharacters(testAUChars + 3, 2); |
| 228 EXPECT_EQ(testAHash3, hasher.hash()); | 228 EXPECT_EQ(testAHash5, hasher.hash()); |
| 229 EXPECT_EQ(testAHash3 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 229 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 230 hasher.addCharacters(testAUChars + 3, 2); | 230 hasher = StringHasher(); |
| 231 EXPECT_EQ(testAHash5, hasher.hash()); | 231 hasher.addCharacters(testAUChars, 3); |
| 232 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 232 EXPECT_EQ(testAHash3, hasher.hash()); |
| 233 hasher = StringHasher(); | 233 EXPECT_EQ(testAHash3 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 234 hasher.addCharacters(testAUChars, 3); | 234 hasher.addCharacters(testAUChars + 3, 2); |
| 235 EXPECT_EQ(testAHash3, hasher.hash()); | 235 EXPECT_EQ(testAHash5, hasher.hash()); |
| 236 EXPECT_EQ(testAHash3 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 236 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 237 hasher.addCharacters(testAUChars + 3, 2); | 237 hasher = StringHasher(); |
| 238 EXPECT_EQ(testAHash5, hasher.hash()); | 238 hasher.addCharacters(testBUChars, 3); |
| 239 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 239 EXPECT_EQ(testBHash3, hasher.hash()); |
| 240 hasher = StringHasher(); | 240 EXPECT_EQ(testBHash3 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 241 hasher.addCharacters(testBUChars, 3); | 241 hasher.addCharacters(testBUChars + 3, 2); |
| 242 EXPECT_EQ(testBHash3, hasher.hash()); | 242 EXPECT_EQ(testBHash5, hasher.hash()); |
| 243 EXPECT_EQ(testBHash3 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 243 EXPECT_EQ(testBHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 244 hasher.addCharacters(testBUChars + 3, 2); | 244 hasher = StringHasher(); |
| 245 EXPECT_EQ(testBHash5, hasher.hash()); | 245 hasher.addCharacters(testBUChars, 3); |
| 246 EXPECT_EQ(testBHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 246 hasher.addCharacters(testBUChars + 3, 2); |
| 247 hasher = StringHasher(); | 247 EXPECT_EQ(testBHash5, hasher.hash()); |
| 248 hasher.addCharacters(testBUChars, 3); | 248 EXPECT_EQ(testBHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 249 hasher.addCharacters(testBUChars + 3, 2); | 249 } |
| 250 EXPECT_EQ(testBHash5, hasher.hash()); | 250 |
| 251 EXPECT_EQ(testBHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 251 TEST(StringHasherTest, StringHasher_addCharactersAssumingAligned) { |
| 252 } | 252 StringHasher hasher; |
| 253 | 253 |
| 254 TEST(StringHasherTest, StringHasher_addCharactersAssumingAligned) | 254 // Hashing zero characters. |
| 255 { | 255 hasher = StringHasher(); |
| 256 StringHasher hasher; | 256 hasher.addCharactersAssumingAligned(static_cast<LChar*>(0), 0); |
| 257 | 257 EXPECT_EQ(emptyStringHash, hasher.hash()); |
| 258 // Hashing zero characters. | 258 EXPECT_EQ(emptyStringHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 259 hasher = StringHasher(); | 259 hasher = StringHasher(); |
| 260 hasher.addCharactersAssumingAligned(static_cast<LChar*>(0), 0); | 260 hasher.addCharactersAssumingAligned(nullLChars, 0); |
| 261 EXPECT_EQ(emptyStringHash, hasher.hash()); | 261 EXPECT_EQ(emptyStringHash, hasher.hash()); |
| 262 EXPECT_EQ(emptyStringHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 262 EXPECT_EQ(emptyStringHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 263 hasher = StringHasher(); | 263 hasher = StringHasher(); |
| 264 hasher.addCharactersAssumingAligned(nullLChars, 0); | 264 hasher.addCharactersAssumingAligned(static_cast<UChar*>(0), 0); |
| 265 EXPECT_EQ(emptyStringHash, hasher.hash()); | 265 EXPECT_EQ(emptyStringHash, hasher.hash()); |
| 266 EXPECT_EQ(emptyStringHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 266 EXPECT_EQ(emptyStringHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 267 hasher = StringHasher(); | 267 hasher = StringHasher(); |
| 268 hasher.addCharactersAssumingAligned(static_cast<UChar*>(0), 0); | 268 hasher.addCharactersAssumingAligned(nullUChars, 0); |
| 269 EXPECT_EQ(emptyStringHash, hasher.hash()); | 269 EXPECT_EQ(emptyStringHash, hasher.hash()); |
| 270 EXPECT_EQ(emptyStringHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 270 EXPECT_EQ(emptyStringHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 271 hasher = StringHasher(); | 271 |
| 272 hasher.addCharactersAssumingAligned(nullUChars, 0); | 272 // Hashing one character. |
| 273 EXPECT_EQ(emptyStringHash, hasher.hash()); | 273 hasher = StringHasher(); |
| 274 EXPECT_EQ(emptyStringHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 274 hasher.addCharactersAssumingAligned(nullLChars, 1); |
| 275 | 275 EXPECT_EQ(singleNullCharacterHash, hasher.hash()); |
| 276 // Hashing one character. | 276 EXPECT_EQ(singleNullCharacterHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked())
; |
| 277 hasher = StringHasher(); | 277 hasher = StringHasher(); |
| 278 hasher.addCharactersAssumingAligned(nullLChars, 1); | 278 hasher.addCharactersAssumingAligned(nullUChars, 1); |
| 279 EXPECT_EQ(singleNullCharacterHash, hasher.hash()); | 279 EXPECT_EQ(singleNullCharacterHash, hasher.hash()); |
| 280 EXPECT_EQ(singleNullCharacterHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked(
)); | 280 EXPECT_EQ(singleNullCharacterHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked())
; |
| 281 hasher = StringHasher(); | 281 |
| 282 hasher.addCharactersAssumingAligned(nullUChars, 1); | 282 // Hashing five characters, all at once. |
| 283 EXPECT_EQ(singleNullCharacterHash, hasher.hash()); | 283 hasher = StringHasher(); |
| 284 EXPECT_EQ(singleNullCharacterHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked(
)); | 284 hasher.addCharactersAssumingAligned(testALChars, 5); |
| 285 | 285 EXPECT_EQ(testAHash5, hasher.hash()); |
| 286 // Hashing five characters, all at once. | 286 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 287 hasher = StringHasher(); | 287 hasher = StringHasher(); |
| 288 hasher.addCharactersAssumingAligned(testALChars, 5); | 288 hasher.addCharactersAssumingAligned(testAUChars, 5); |
| 289 EXPECT_EQ(testAHash5, hasher.hash()); | 289 EXPECT_EQ(testAHash5, hasher.hash()); |
| 290 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 290 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 291 hasher = StringHasher(); | 291 hasher = StringHasher(); |
| 292 hasher.addCharactersAssumingAligned(testAUChars, 5); | 292 hasher.addCharactersAssumingAligned(testBUChars, 5); |
| 293 EXPECT_EQ(testAHash5, hasher.hash()); | 293 EXPECT_EQ(testBHash5, hasher.hash()); |
| 294 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 294 EXPECT_EQ(testBHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 295 hasher = StringHasher(); | 295 |
| 296 hasher.addCharactersAssumingAligned(testBUChars, 5); | 296 // Hashing five characters, in groups of two, then the last one. |
| 297 EXPECT_EQ(testBHash5, hasher.hash()); | 297 hasher = StringHasher(); |
| 298 EXPECT_EQ(testBHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 298 hasher.addCharactersAssumingAligned(testALChars, 2); |
| 299 | 299 EXPECT_EQ(testAHash2, hasher.hash()); |
| 300 // Hashing five characters, in groups of two, then the last one. | 300 EXPECT_EQ(testAHash2 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 301 hasher = StringHasher(); | 301 hasher.addCharactersAssumingAligned(testALChars + 2, 2); |
| 302 hasher.addCharactersAssumingAligned(testALChars, 2); | 302 EXPECT_EQ(testAHash4, hasher.hash()); |
| 303 EXPECT_EQ(testAHash2, hasher.hash()); | 303 EXPECT_EQ(testAHash4 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 304 EXPECT_EQ(testAHash2 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 304 hasher.addCharactersAssumingAligned(testALChars + 4, 1); |
| 305 hasher.addCharactersAssumingAligned(testALChars + 2, 2); | 305 EXPECT_EQ(testAHash5, hasher.hash()); |
| 306 EXPECT_EQ(testAHash4, hasher.hash()); | 306 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 307 EXPECT_EQ(testAHash4 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 307 hasher = StringHasher(); |
| 308 hasher.addCharactersAssumingAligned(testALChars + 4, 1); | 308 hasher.addCharactersAssumingAligned(testALChars, 2); |
| 309 EXPECT_EQ(testAHash5, hasher.hash()); | 309 hasher.addCharactersAssumingAligned(testALChars + 2, 2); |
| 310 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 310 hasher.addCharactersAssumingAligned(testALChars + 4, 1); |
| 311 hasher = StringHasher(); | 311 EXPECT_EQ(testAHash5, hasher.hash()); |
| 312 hasher.addCharactersAssumingAligned(testALChars, 2); | 312 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 313 hasher.addCharactersAssumingAligned(testALChars + 2, 2); | 313 hasher = StringHasher(); |
| 314 hasher.addCharactersAssumingAligned(testALChars + 4, 1); | 314 hasher.addCharactersAssumingAligned(testAUChars, 2); |
| 315 EXPECT_EQ(testAHash5, hasher.hash()); | 315 EXPECT_EQ(testAHash2, hasher.hash()); |
| 316 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 316 EXPECT_EQ(testAHash2 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 317 hasher = StringHasher(); | 317 hasher.addCharactersAssumingAligned(testAUChars + 2, 2); |
| 318 hasher.addCharactersAssumingAligned(testAUChars, 2); | 318 EXPECT_EQ(testAHash4, hasher.hash()); |
| 319 EXPECT_EQ(testAHash2, hasher.hash()); | 319 EXPECT_EQ(testAHash4 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 320 EXPECT_EQ(testAHash2 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 320 hasher.addCharactersAssumingAligned(testAUChars + 4, 1); |
| 321 hasher.addCharactersAssumingAligned(testAUChars + 2, 2); | 321 EXPECT_EQ(testAHash5, hasher.hash()); |
| 322 EXPECT_EQ(testAHash4, hasher.hash()); | 322 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 323 EXPECT_EQ(testAHash4 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 323 hasher = StringHasher(); |
| 324 hasher.addCharactersAssumingAligned(testAUChars + 4, 1); | 324 hasher.addCharactersAssumingAligned(testAUChars, 2); |
| 325 EXPECT_EQ(testAHash5, hasher.hash()); | 325 hasher.addCharactersAssumingAligned(testAUChars + 2, 2); |
| 326 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 326 hasher.addCharactersAssumingAligned(testAUChars + 4, 1); |
| 327 hasher = StringHasher(); | 327 EXPECT_EQ(testAHash5, hasher.hash()); |
| 328 hasher.addCharactersAssumingAligned(testAUChars, 2); | 328 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 329 hasher.addCharactersAssumingAligned(testAUChars + 2, 2); | 329 hasher = StringHasher(); |
| 330 hasher.addCharactersAssumingAligned(testAUChars + 4, 1); | 330 hasher.addCharactersAssumingAligned(testBUChars, 2); |
| 331 EXPECT_EQ(testAHash5, hasher.hash()); | 331 EXPECT_EQ(testBHash2, hasher.hash()); |
| 332 EXPECT_EQ(testAHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 332 EXPECT_EQ(testBHash2 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 333 hasher = StringHasher(); | 333 hasher.addCharactersAssumingAligned(testBUChars + 2, 2); |
| 334 hasher.addCharactersAssumingAligned(testBUChars, 2); | 334 EXPECT_EQ(testBHash4, hasher.hash()); |
| 335 EXPECT_EQ(testBHash2, hasher.hash()); | 335 EXPECT_EQ(testBHash4 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 336 EXPECT_EQ(testBHash2 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 336 hasher.addCharactersAssumingAligned(testBUChars + 4, 1); |
| 337 hasher.addCharactersAssumingAligned(testBUChars + 2, 2); | 337 EXPECT_EQ(testBHash5, hasher.hash()); |
| 338 EXPECT_EQ(testBHash4, hasher.hash()); | 338 EXPECT_EQ(testBHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 339 EXPECT_EQ(testBHash4 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 339 hasher = StringHasher(); |
| 340 hasher.addCharactersAssumingAligned(testBUChars + 4, 1); | 340 hasher.addCharactersAssumingAligned(testBUChars, 2); |
| 341 EXPECT_EQ(testBHash5, hasher.hash()); | 341 hasher.addCharactersAssumingAligned(testBUChars + 2, 2); |
| 342 EXPECT_EQ(testBHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 342 hasher.addCharactersAssumingAligned(testBUChars + 4, 1); |
| 343 hasher = StringHasher(); | 343 EXPECT_EQ(testBHash5, hasher.hash()); |
| 344 hasher.addCharactersAssumingAligned(testBUChars, 2); | 344 EXPECT_EQ(testBHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 345 hasher.addCharactersAssumingAligned(testBUChars + 2, 2); | 345 |
| 346 hasher.addCharactersAssumingAligned(testBUChars + 4, 1); | 346 // Hashing five characters, first two characters one at a time, |
| 347 EXPECT_EQ(testBHash5, hasher.hash()); | 347 // then two more, then the last one. |
| 348 EXPECT_EQ(testBHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 348 hasher = StringHasher(); |
| 349 | 349 hasher.addCharacter(testBUChars[0]); |
| 350 // Hashing five characters, first two characters one at a time, | 350 EXPECT_EQ(testBHash1, hasher.hash()); |
| 351 // then two more, then the last one. | 351 EXPECT_EQ(testBHash1 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 352 hasher = StringHasher(); | 352 hasher.addCharacter(testBUChars[1]); |
| 353 hasher.addCharacter(testBUChars[0]); | 353 EXPECT_EQ(testBHash2, hasher.hash()); |
| 354 EXPECT_EQ(testBHash1, hasher.hash()); | 354 EXPECT_EQ(testBHash2 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 355 EXPECT_EQ(testBHash1 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 355 hasher.addCharactersAssumingAligned(testBUChars[2], testBUChars[3]); |
| 356 hasher.addCharacter(testBUChars[1]); | 356 EXPECT_EQ(testBHash4, hasher.hash()); |
| 357 EXPECT_EQ(testBHash2, hasher.hash()); | 357 EXPECT_EQ(testBHash4 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 358 EXPECT_EQ(testBHash2 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 358 hasher.addCharactersAssumingAligned(testBUChars + 4, 1); |
| 359 hasher.addCharactersAssumingAligned(testBUChars[2], testBUChars[3]); | 359 EXPECT_EQ(testBHash5, hasher.hash()); |
| 360 EXPECT_EQ(testBHash4, hasher.hash()); | 360 EXPECT_EQ(testBHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); |
| 361 EXPECT_EQ(testBHash4 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 361 } |
| 362 hasher.addCharactersAssumingAligned(testBUChars + 4, 1); | 362 |
| 363 EXPECT_EQ(testBHash5, hasher.hash()); | 363 TEST(StringHasherTest, StringHasher_computeHash) { |
| 364 EXPECT_EQ(testBHash5 & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); | 364 EXPECT_EQ(emptyStringHash, StringHasher::computeHash(static_cast<LChar*>(0), 0
)); |
| 365 } | 365 EXPECT_EQ(emptyStringHash, StringHasher::computeHash(nullLChars, 0)); |
| 366 | 366 EXPECT_EQ(emptyStringHash, StringHasher::computeHash(static_cast<UChar*>(0), 0
)); |
| 367 TEST(StringHasherTest, StringHasher_computeHash) | 367 EXPECT_EQ(emptyStringHash, StringHasher::computeHash(nullUChars, 0)); |
| 368 { | 368 |
| 369 EXPECT_EQ(emptyStringHash, StringHasher::computeHash(static_cast<LChar*>(0),
0)); | 369 EXPECT_EQ(singleNullCharacterHash, StringHasher::computeHash(nullLChars, 1)); |
| 370 EXPECT_EQ(emptyStringHash, StringHasher::computeHash(nullLChars, 0)); | 370 EXPECT_EQ(singleNullCharacterHash, StringHasher::computeHash(nullUChars, 1)); |
| 371 EXPECT_EQ(emptyStringHash, StringHasher::computeHash(static_cast<UChar*>(0),
0)); | 371 |
| 372 EXPECT_EQ(emptyStringHash, StringHasher::computeHash(nullUChars, 0)); | 372 EXPECT_EQ(testAHash5, StringHasher::computeHash(testALChars, 5)); |
| 373 | 373 EXPECT_EQ(testAHash5, StringHasher::computeHash(testAUChars, 5)); |
| 374 EXPECT_EQ(singleNullCharacterHash, StringHasher::computeHash(nullLChars, 1))
; | 374 EXPECT_EQ(testBHash5, StringHasher::computeHash(testBUChars, 5)); |
| 375 EXPECT_EQ(singleNullCharacterHash, StringHasher::computeHash(nullUChars, 1))
; | 375 } |
| 376 | 376 |
| 377 EXPECT_EQ(testAHash5, StringHasher::computeHash(testALChars, 5)); | 377 TEST(StringHasherTest, StringHasher_computeHashAndMaskTop8Bits) { |
| 378 EXPECT_EQ(testAHash5, StringHasher::computeHash(testAUChars, 5)); | 378 EXPECT_EQ(emptyStringHash & 0xFFFFFF, StringHasher::computeHashAndMaskTop8Bits
(static_cast<LChar*>(0), 0)); |
| 379 EXPECT_EQ(testBHash5, StringHasher::computeHash(testBUChars, 5)); | 379 EXPECT_EQ(emptyStringHash & 0xFFFFFF, StringHasher::computeHashAndMaskTop8Bits
(nullLChars, 0)); |
| 380 } | 380 EXPECT_EQ(emptyStringHash & 0xFFFFFF, StringHasher::computeHashAndMaskTop8Bits
(static_cast<UChar*>(0), 0)); |
| 381 | 381 EXPECT_EQ(emptyStringHash & 0xFFFFFF, StringHasher::computeHashAndMaskTop8Bits
(nullUChars, 0)); |
| 382 TEST(StringHasherTest, StringHasher_computeHashAndMaskTop8Bits) | 382 |
| 383 { | 383 EXPECT_EQ(singleNullCharacterHash & 0xFFFFFF, StringHasher::computeHashAndMask
Top8Bits(nullLChars, 1)); |
| 384 EXPECT_EQ(emptyStringHash & 0xFFFFFF, StringHasher::computeHashAndMaskTop8Bi
ts(static_cast<LChar*>(0), 0)); | 384 EXPECT_EQ(singleNullCharacterHash & 0xFFFFFF, StringHasher::computeHashAndMask
Top8Bits(nullUChars, 1)); |
| 385 EXPECT_EQ(emptyStringHash & 0xFFFFFF, StringHasher::computeHashAndMaskTop8Bi
ts(nullLChars, 0)); | 385 |
| 386 EXPECT_EQ(emptyStringHash & 0xFFFFFF, StringHasher::computeHashAndMaskTop8Bi
ts(static_cast<UChar*>(0), 0)); | 386 EXPECT_EQ(testAHash5 & 0xFFFFFF, StringHasher::computeHashAndMaskTop8Bits(test
ALChars, 5)); |
| 387 EXPECT_EQ(emptyStringHash & 0xFFFFFF, StringHasher::computeHashAndMaskTop8Bi
ts(nullUChars, 0)); | 387 EXPECT_EQ(testAHash5 & 0xFFFFFF, StringHasher::computeHashAndMaskTop8Bits(test
AUChars, 5)); |
| 388 | 388 EXPECT_EQ(testBHash5 & 0xFFFFFF, StringHasher::computeHashAndMaskTop8Bits(test
BUChars, 5)); |
| 389 EXPECT_EQ(singleNullCharacterHash & 0xFFFFFF, StringHasher::computeHashAndMa
skTop8Bits(nullLChars, 1)); | 389 } |
| 390 EXPECT_EQ(singleNullCharacterHash & 0xFFFFFF, StringHasher::computeHashAndMa
skTop8Bits(nullUChars, 1)); | 390 |
| 391 | 391 TEST(StringHasherTest, StringHasher_hashMemory) { |
| 392 EXPECT_EQ(testAHash5 & 0xFFFFFF, StringHasher::computeHashAndMaskTop8Bits(te
stALChars, 5)); | 392 EXPECT_EQ(emptyStringHash & 0xFFFFFF, StringHasher::hashMemory(0, 0)); |
| 393 EXPECT_EQ(testAHash5 & 0xFFFFFF, StringHasher::computeHashAndMaskTop8Bits(te
stAUChars, 5)); | 393 EXPECT_EQ(emptyStringHash & 0xFFFFFF, StringHasher::hashMemory(nullUChars, 0))
; |
| 394 EXPECT_EQ(testBHash5 & 0xFFFFFF, StringHasher::computeHashAndMaskTop8Bits(te
stBUChars, 5)); | 394 EXPECT_EQ(emptyStringHash & 0xFFFFFF, StringHasher::hashMemory<0>(0)); |
| 395 } | 395 EXPECT_EQ(emptyStringHash & 0xFFFFFF, StringHasher::hashMemory<0>(nullUChars))
; |
| 396 | 396 |
| 397 TEST(StringHasherTest, StringHasher_hashMemory) | 397 EXPECT_EQ(singleNullCharacterHash & 0xFFFFFF, StringHasher::hashMemory(nullUCh
ars, 2)); |
| 398 { | 398 EXPECT_EQ(singleNullCharacterHash & 0xFFFFFF, StringHasher::hashMemory<2>(null
UChars)); |
| 399 EXPECT_EQ(emptyStringHash & 0xFFFFFF, StringHasher::hashMemory(0, 0)); | 399 |
| 400 EXPECT_EQ(emptyStringHash & 0xFFFFFF, StringHasher::hashMemory(nullUChars, 0
)); | 400 EXPECT_EQ(testAHash5 & 0xFFFFFF, StringHasher::hashMemory(testAUChars, 10)); |
| 401 EXPECT_EQ(emptyStringHash & 0xFFFFFF, StringHasher::hashMemory<0>(0)); | 401 EXPECT_EQ(testAHash5 & 0xFFFFFF, StringHasher::hashMemory<10>(testAUChars)); |
| 402 EXPECT_EQ(emptyStringHash & 0xFFFFFF, StringHasher::hashMemory<0>(nullUChars
)); | 402 EXPECT_EQ(testBHash5 & 0xFFFFFF, StringHasher::hashMemory(testBUChars, 10)); |
| 403 | 403 EXPECT_EQ(testBHash5 & 0xFFFFFF, StringHasher::hashMemory<10>(testBUChars)); |
| 404 EXPECT_EQ(singleNullCharacterHash & 0xFFFFFF, StringHasher::hashMemory(nullU
Chars, 2)); | 404 } |
| 405 EXPECT_EQ(singleNullCharacterHash & 0xFFFFFF, StringHasher::hashMemory<2>(nu
llUChars)); | 405 |
| 406 | 406 } // namespace WTF |
| 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)); | |
| 411 } | |
| 412 | |
| 413 } // namespace WTF | |
| OLD | NEW |