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