| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_TEST_FUZZED_DATA_PROVIDER_H_ | 5 #ifndef BASE_TEST_FUZZED_DATA_PROVIDER_H_ |
| 6 #define BASE_TEST_FUZZED_DATA_PROVIDER_H_ | 6 #define BASE_TEST_FUZZED_DATA_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 ~FuzzedDataProvider(); | 26 ~FuzzedDataProvider(); |
| 27 | 27 |
| 28 // Returns a std::string containing |num_bytes| of input data. If fewer than | 28 // Returns a std::string containing |num_bytes| of input data. If fewer than |
| 29 // |num_bytes| of data remain, returns a shorter std::string containing all | 29 // |num_bytes| of data remain, returns a shorter std::string containing all |
| 30 // of the data that's left. | 30 // of the data that's left. |
| 31 std::string ConsumeBytes(size_t num_bytes); | 31 std::string ConsumeBytes(size_t num_bytes); |
| 32 | 32 |
| 33 // Returns a std::string containing all remaining bytes of the input data. | 33 // Returns a std::string containing all remaining bytes of the input data. |
| 34 std::string ConsumeRemainingBytes(); | 34 std::string ConsumeRemainingBytes(); |
| 35 | 35 |
| 36 // Returns a std::string of length from 0 to |max_length|. When it runs out of |
| 37 // input data, returns what remains of the input. Designed to be more stable |
| 38 // with respect to a fuzzer inserting characters than just picking a random |
| 39 // length and then consuming that many bytes with ConsumeBytes(). |
| 40 std::string ConsumeRandomLengthString(size_t max_length); |
| 41 |
| 36 // Returns a number in the range [min, max] by consuming bytes from the input | 42 // Returns a number in the range [min, max] by consuming bytes from the input |
| 37 // data. The value might not be uniformly distributed in the given range. If | 43 // data. The value might not be uniformly distributed in the given range. If |
| 38 // there's no input data left, always returns |min|. |min| must be less than | 44 // there's no input data left, always returns |min|. |min| must be less than |
| 39 // or equal to |max|. | 45 // or equal to |max|. |
| 40 uint32_t ConsumeUint32InRange(uint32_t min, uint32_t max); | 46 uint32_t ConsumeUint32InRange(uint32_t min, uint32_t max); |
| 41 int ConsumeInt32InRange(int min, int max); | 47 int ConsumeInt32InRange(int min, int max); |
| 42 | 48 |
| 43 // Returns a bool, or false when no data remains. | 49 // Returns a bool, or false when no data remains. |
| 44 bool ConsumeBool(); | 50 bool ConsumeBool(); |
| 45 | 51 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 65 | 71 |
| 66 private: | 72 private: |
| 67 StringPiece remaining_data_; | 73 StringPiece remaining_data_; |
| 68 | 74 |
| 69 DISALLOW_COPY_AND_ASSIGN(FuzzedDataProvider); | 75 DISALLOW_COPY_AND_ASSIGN(FuzzedDataProvider); |
| 70 }; | 76 }; |
| 71 | 77 |
| 72 } // namespace base | 78 } // namespace base |
| 73 | 79 |
| 74 #endif // BASE_TEST_FUZZED_DATA_PROVIDER_H_ | 80 #endif // BASE_TEST_FUZZED_DATA_PROVIDER_H_ |
| OLD | NEW |