Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: base/test/fuzzed_data_provider.h

Issue 2308443002: Make FuzzedDataProvider vend std::strings (Closed)
Patch Set: no longer header-only Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/test/fuzzed_data_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <string>
Lei Zhang 2016/10/19 17:49:49 nit: Chromium style still likes to have a separato
Charlie Harrison 2016/10/19 18:00:56 Done.
9 10
10 #include "base/base_export.h" 11 #include "base/base_export.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/strings/string_piece.h" 13 #include "base/strings/string_piece.h"
13 14
14 namespace base { 15 namespace base {
15 16
16 // Utility class to break up fuzzer input for multiple consumers. Whenever run 17 // Utility class to break up fuzzer input for multiple consumers. Whenever run
17 // on the same input, provides the same output, as long as its methods are 18 // on the same input, provides the same output, as long as its methods are
18 // called in the same order, with the same arguments. 19 // called in the same order, with the same arguments.
19 class FuzzedDataProvider { 20 class FuzzedDataProvider {
20 public: 21 public:
21 // |data| is an array of length |size| that the FuzzedDataProvider wraps to 22 // |data| is an array of length |size| that the FuzzedDataProvider wraps to
22 // provide more granular access. |data| must outlive the FuzzedDataProvider. 23 // provide more granular access. |data| must outlive the FuzzedDataProvider.
23 FuzzedDataProvider(const uint8_t* data, size_t size); 24 FuzzedDataProvider(const uint8_t* data, size_t size);
24 ~FuzzedDataProvider(); 25 ~FuzzedDataProvider();
25 26
26 // Returns a StringPiece containing |num_bytes| of input data. If fewer than 27 // Returns a std::string containing |num_bytes| of input data. If fewer than
27 // |num_bytes| of data remain, returns a shorter StringPiece containing all 28 // |num_bytes| of data remain, returns a shorter std::string containing all
28 // of the data that's left. The data pointed at by the returned StringPiece 29 // of the data that's left.
29 // must not be used after the FuzzedDataProvider is destroyed. 30 std::string ConsumeBytes(size_t num_bytes);
30 StringPiece ConsumeBytes(size_t num_bytes);
31 31
32 // Returns a StringPiece containing all remaining bytes of the input data. 32 // Returns a std::string containing all remaining bytes of the input data.
33 // The data pointed at by the returned StringPiece must not be used after the 33 std::string ConsumeRemainingBytes();
34 // FuzzedDataProvider is destroyed.
35 StringPiece ConsumeRemainingBytes();
36 34
37 // Returns a number in the range [min, max] by consuming bytes from the input 35 // Returns a number in the range [min, max] by consuming bytes from the input
38 // data. The value might not be uniformly distributed in the given range. If 36 // data. The value might not be uniformly distributed in the given range. If
39 // there's no input data left, always returns |min|. |min| must be less than 37 // there's no input data left, always returns |min|. |min| must be less than
40 // or equal to |max|. 38 // or equal to |max|.
41 uint32_t ConsumeUint32InRange(uint32_t min, uint32_t max); 39 uint32_t ConsumeUint32InRange(uint32_t min, uint32_t max);
42 int ConsumeInt32InRange(int min, int max); 40 int ConsumeInt32InRange(int min, int max);
43 41
44 // Returns a bool, or false when no data remains. 42 // Returns a bool, or false when no data remains.
45 bool ConsumeBool(); 43 bool ConsumeBool();
(...skipping 20 matching lines...) Expand all
66 64
67 private: 65 private:
68 StringPiece remaining_data_; 66 StringPiece remaining_data_;
69 67
70 DISALLOW_COPY_AND_ASSIGN(FuzzedDataProvider); 68 DISALLOW_COPY_AND_ASSIGN(FuzzedDataProvider);
71 }; 69 };
72 70
73 } // namespace base 71 } // namespace base
74 72
75 #endif // BASE_TEST_FUZZED_DATA_PROVIDER_H_ 73 #endif // BASE_TEST_FUZZED_DATA_PROVIDER_H_
OLDNEW
« no previous file with comments | « no previous file | base/test/fuzzed_data_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698