Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / net / base / test_data_stream.h
blob464220e8982954099d2efe39ba04102bafce246d
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_BASE_TEST_DATA_STREAM_H_
6 #define NET_BASE_TEST_DATA_STREAM_H_
8 #include <string.h> // for memcpy().
9 #include <algorithm>
10 #include "net/base/net_export.h"
12 // This is a class for generating an infinite stream of data which can be
13 // verified independently to be the correct stream of data.
15 namespace net {
17 class NET_EXPORT TestDataStream {
18 public:
19 TestDataStream();
21 // Fill |buffer| with |length| bytes of data from the stream.
22 void GetBytes(char* buffer, int length);
24 // Verify that |buffer| contains the expected next |length| bytes from the
25 // stream. Returns true if correct, false otherwise.
26 bool VerifyBytes(const char *buffer, int length);
28 // Resets all the data.
29 void Reset();
31 private:
32 // If there is no data spilled over from the previous index, advance the
33 // index and fill the buffer.
34 void AdvanceIndex();
36 // Consume data from the spill buffer.
37 void Consume(int bytes);
39 int index_;
40 int bytes_remaining_;
41 char buffer_[16];
42 char* buffer_ptr_;
45 } // namespace net
47 #endif // NET_BASE_TEST_DATA_STREAM_H_