| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef NET_BASE_TEST_DATA_STREAM_H_ | |
| 6 #define NET_BASE_TEST_DATA_STREAM_H_ | |
| 7 | |
| 8 #include <string.h> // for memcpy(). | |
| 9 #include <algorithm> | |
| 10 #include "net/base/net_export.h" | |
| 11 | |
| 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. | |
| 14 | |
| 15 namespace net { | |
| 16 | |
| 17 class NET_EXPORT TestDataStream { | |
| 18 public: | |
| 19 TestDataStream(); | |
| 20 | |
| 21 // Fill |buffer| with |length| bytes of data from the stream. | |
| 22 void GetBytes(char* buffer, int length); | |
| 23 | |
| 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); | |
| 27 | |
| 28 // Resets all the data. | |
| 29 void Reset(); | |
| 30 | |
| 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(); | |
| 35 | |
| 36 // Consume data from the spill buffer. | |
| 37 void Consume(int bytes); | |
| 38 | |
| 39 int index_; | |
| 40 int bytes_remaining_; | |
| 41 char buffer_[16]; | |
| 42 char* buffer_ptr_; | |
| 43 }; | |
| 44 | |
| 45 } // namespace net | |
| 46 | |
| 47 #endif // NET_BASE_TEST_DATA_STREAM_H_ | |
| OLD | NEW |