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

Side by Side Diff: third_party/WebKit/Source/platform/testing/FuzzedDataProvider.h

Issue 2731643002: Fuzzer for TextCodecs (Closed)
Patch Set: fuzzer overload Created 3 years, 9 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
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 FuzzedDataProvider_h 5 #ifndef FuzzedDataProvider_h
6 #define FuzzedDataProvider_h 6 #define FuzzedDataProvider_h
7 7
8 #include "base/test/fuzzed_data_provider.h" 8 #include "base/test/fuzzed_data_provider.h"
9 #include "wtf/Noncopyable.h" 9 #include "wtf/Noncopyable.h"
10 #include "wtf/Vector.h"
10 #include "wtf/text/CString.h" 11 #include "wtf/text/CString.h"
11 12
12 namespace blink { 13 namespace blink {
13 14
14 // This class simply wraps //base/test/fuzzed_data_provider and vends Blink 15 // This class simply wraps //base/test/fuzzed_data_provider and vends Blink
15 // friendly types. 16 // friendly types.
16 class FuzzedDataProvider { 17 class FuzzedDataProvider {
17 WTF_MAKE_NONCOPYABLE(FuzzedDataProvider); 18 WTF_MAKE_NONCOPYABLE(FuzzedDataProvider);
18 19
19 public: 20 public:
20 FuzzedDataProvider(const uint8_t* bytes, size_t numBytes); 21 FuzzedDataProvider(const uint8_t* bytes, size_t numBytes);
21 22
22 // Returns a string with length between minBytes and maxBytes. If the 23 // Returns a string with length between minBytes and maxBytes. If the
23 // length is greater than the length of the remaining data this is 24 // length is greater than the length of the remaining data this is
24 // equivalent to ConsumeRemainingBytes(). 25 // equivalent to ConsumeRemainingBytes().
25 CString ConsumeBytesInRange(uint32_t minBytes, uint32_t maxBytes); 26 CString ConsumeBytesInRange(uint32_t minBytes, uint32_t maxBytes);
26 27
27 // Returns a String containing all remaining bytes of the input data. 28 // Returns a String containing all remaining bytes of the input data.
28 CString ConsumeRemainingBytes(); 29 CString ConsumeRemainingBytes();
29 30
30 // Returns a bool, or false when no data remains. 31 // Returns a bool, or false when no data remains.
31 bool ConsumeBool(); 32 bool ConsumeBool();
32 33
34 template <typename Type>
35 Type PickValueInVector(const Vector<Type>& vec) {
36 return vec[m_provider.ConsumeUint32InRange(0, vec.size() - 1)];
37 }
38
33 private: 39 private:
34 base::FuzzedDataProvider m_provider; 40 base::FuzzedDataProvider m_provider;
35 }; 41 };
36 42
37 } // namespace blink 43 } // namespace blink
38 44
39 #endif // FuzzedDataProvider_h 45 #endif // FuzzedDataProvider_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698