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