test_data_stream.h 1.2 KB

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