| 214 | } |
| 215 | |
| 216 | TEST(OrderedCode, SkipToNextSpecialByte) { |
| 217 | for (size_t len = 0; len < 256; len++) { |
| 218 | random::PhiloxRandom philox(301, 17); |
| 219 | random::SimplePhilox rnd(&philox); |
| 220 | string x; |
| 221 | while (x.size() < len) { |
| 222 | char c = 1 + rnd.Uniform(254); |
| 223 | ASSERT_NE(c, 0); |
| 224 | ASSERT_NE(c, 255); |
| 225 | x += c; // No 0 bytes, no 255 bytes |
| 226 | } |
| 227 | EXPECT_EQ(FindSpecial(x), x.size()); |
| 228 | for (size_t special_pos = 0; special_pos < len; special_pos++) { |
| 229 | for (size_t special_test = 0; special_test < 2; special_test++) { |
| 230 | const char special_byte = (special_test == 0) ? 0 : 255; |
| 231 | string y = x; |
| 232 | y[special_pos] = special_byte; |
| 233 | EXPECT_EQ(FindSpecial(y), special_pos); |
| 234 | if (special_pos < 16) { |
| 235 | // Add some special bytes after the one at special_pos to make sure |
| 236 | // we still return the earliest special byte in the string |
| 237 | for (size_t rest = special_pos + 1; rest < len; rest++) { |
| 238 | if (rnd.OneIn(3)) { |
| 239 | y[rest] = rnd.OneIn(2) ? 0 : 255; |
| 240 | EXPECT_EQ(FindSpecial(y), special_pos); |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | TEST(OrderedCode, ExhaustiveFindSpecial) { |
| 250 | char buf[16]; |
nothing calls this directly
no test coverage detected