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

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

Issue 2250263003: Move FuzzedDataProvider to //base and expose to blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ... also remove PLATFORM_EXPORT Created 4 years, 4 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 | « base/test/fuzzed_data_provider.h ('k') | net/BUILD.gn » ('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 #include "net/base/fuzzed_data_provider.h" 5 #include "base/test/fuzzed_data_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 11
12 namespace net { 12 namespace base {
13 13
14 FuzzedDataProvider::FuzzedDataProvider(const uint8_t* data, size_t size) 14 FuzzedDataProvider::FuzzedDataProvider(const uint8_t* data, size_t size)
15 : remaining_data_(reinterpret_cast<const char*>(data), size) {} 15 : remaining_data_(reinterpret_cast<const char*>(data), size) {}
16 16
17 FuzzedDataProvider::~FuzzedDataProvider() {} 17 FuzzedDataProvider::~FuzzedDataProvider() {}
18 18
19 base::StringPiece FuzzedDataProvider::ConsumeBytes(size_t num_bytes) { 19 StringPiece FuzzedDataProvider::ConsumeBytes(size_t num_bytes) {
20 num_bytes = std::min(num_bytes, remaining_data_.length()); 20 num_bytes = std::min(num_bytes, remaining_data_.length());
21 base::StringPiece result(remaining_data_.data(), num_bytes); 21 StringPiece result(remaining_data_.data(), num_bytes);
22 remaining_data_ = remaining_data_.substr(num_bytes); 22 remaining_data_ = remaining_data_.substr(num_bytes);
23 return result; 23 return result;
24 } 24 }
25 25
26 base::StringPiece FuzzedDataProvider::ConsumeRemainingBytes() { 26 StringPiece FuzzedDataProvider::ConsumeRemainingBytes() {
27 return ConsumeBytes(remaining_data_.length()); 27 return ConsumeBytes(remaining_data_.length());
28 } 28 }
29 29
30 uint32_t FuzzedDataProvider::ConsumeUint32InRange(uint32_t min, uint32_t max) { 30 uint32_t FuzzedDataProvider::ConsumeUint32InRange(uint32_t min, uint32_t max) {
31 CHECK_LE(min, max); 31 CHECK_LE(min, max);
32 32
33 uint32_t range = max - min; 33 uint32_t range = max - min;
34 uint32_t offset = 0; 34 uint32_t offset = 0;
35 uint32_t result = 0; 35 uint32_t result = 0;
36 36
(...skipping 29 matching lines...) Expand all
66 } 66 }
67 67
68 uint8_t FuzzedDataProvider::ConsumeUint8() { 68 uint8_t FuzzedDataProvider::ConsumeUint8() {
69 return ConsumeUint32InRange(0, 0xFF); 69 return ConsumeUint32InRange(0, 0xFF);
70 } 70 }
71 71
72 uint16_t FuzzedDataProvider::ConsumeUint16() { 72 uint16_t FuzzedDataProvider::ConsumeUint16() {
73 return ConsumeUint32InRange(0, 0xFFFF); 73 return ConsumeUint32InRange(0, 0xFFFF);
74 } 74 }
75 75
76 } // namespace net 76 } // namespace base
OLDNEW
« no previous file with comments | « base/test/fuzzed_data_provider.h ('k') | net/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698