| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 NET_BASE_TEST_DATA_STREAM_H_ | 5 #ifndef NET_BASE_TEST_DATA_STREAM_H_ |
| 6 #define NET_BASE_TEST_DATA_STREAM_H_ | 6 #define NET_BASE_TEST_DATA_STREAM_H_ |
| 7 | 7 |
| 8 #include <string.h> // for memcpy(). | 8 #include <string.h> // for memcpy(). |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include "net/base/net_export.h" | 10 #include "net/base/net_export.h" |
| 11 | 11 |
| 12 // This is a class for generating an infinite stream of data which can be | 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. | 13 // verified independently to be the correct stream of data. |
| 14 | 14 |
| 15 namespace net { | 15 namespace net { |
| 16 | 16 |
| 17 class NET_EXPORT TestDataStream { | 17 class NET_EXPORT TestDataStream { |
| 18 public: | 18 public: |
| 19 TestDataStream(); | 19 TestDataStream(); |
| 20 | 20 |
| 21 // Fill |buffer| with |length| bytes of data from the stream. | 21 // Fill |buffer| with |length| bytes of data from the stream. |
| 22 void GetBytes(char* buffer, int length); | 22 void GetBytes(char* buffer, int length); |
| 23 | 23 |
| 24 // Verify that |buffer| contains the expected next |length| bytes from the | 24 // Verify that |buffer| contains the expected next |length| bytes from the |
| 25 // stream. Returns true if correct, false otherwise. | 25 // stream. Returns true if correct, false otherwise. |
| 26 bool VerifyBytes(const char *buffer, int length); | 26 bool VerifyBytes(const char* buffer, int length); |
| 27 | 27 |
| 28 // Resets all the data. | 28 // Resets all the data. |
| 29 void Reset(); | 29 void Reset(); |
| 30 | 30 |
| 31 private: | 31 private: |
| 32 // If there is no data spilled over from the previous index, advance the | 32 // If there is no data spilled over from the previous index, advance the |
| 33 // index and fill the buffer. | 33 // index and fill the buffer. |
| 34 void AdvanceIndex(); | 34 void AdvanceIndex(); |
| 35 | 35 |
| 36 // Consume data from the spill buffer. | 36 // Consume data from the spill buffer. |
| 37 void Consume(int bytes); | 37 void Consume(int bytes); |
| 38 | 38 |
| 39 int index_; | 39 int index_; |
| 40 int bytes_remaining_; | 40 int bytes_remaining_; |
| 41 char buffer_[16]; | 41 char buffer_[16]; |
| 42 char* buffer_ptr_; | 42 char* buffer_ptr_; |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 } // namespace net | 45 } // namespace net |
| 46 | 46 |
| 47 #endif // NET_BASE_TEST_DATA_STREAM_H_ | 47 #endif // NET_BASE_TEST_DATA_STREAM_H_ |
| OLD | NEW |