1 // Copyright 2016 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 QUICHE_QUIC_TEST_TOOLS_QUIC_STREAM_SEQUENCER_BUFFER_PEER_H_
6 #define QUICHE_QUIC_TEST_TOOLS_QUIC_STREAM_SEQUENCER_BUFFER_PEER_H_
7 
8 #include "quiche/quic/core/quic_stream_sequencer_buffer.h"
9 
10 namespace quic {
11 
12 namespace test {
13 
14 class QuicStreamSequencerBufferPeer {
15  public:
16   explicit QuicStreamSequencerBufferPeer(QuicStreamSequencerBuffer* buffer);
17   QuicStreamSequencerBufferPeer(const QuicStreamSequencerBufferPeer&) = delete;
18   QuicStreamSequencerBufferPeer& operator=(
19       const QuicStreamSequencerBufferPeer&) = delete;
20 
21   // Read from this buffer_ into the given destination buffer_ up to the
22   // size of the destination. Returns the number of bytes read. Reading from
23   // an empty buffer_->returns 0.
24   size_t Read(char* dest_buffer, size_t size);
25 
26   // If buffer is empty, the blocks_ array must be empty, which means all
27   // blocks are deallocated.
28   bool CheckEmptyInvariants();
29 
30   bool IsBlockArrayEmpty();
31 
32   bool CheckInitialState();
33 
34   bool CheckBufferInvariants();
35 
36   size_t GetInBlockOffset(QuicStreamOffset offset);
37 
38   QuicStreamSequencerBuffer::BufferBlock* GetBlock(size_t index);
39 
40   int IntervalSize();
41 
42   size_t max_buffer_capacity();
43 
44   size_t ReadableBytes();
45 
46   void set_total_bytes_read(QuicStreamOffset total_bytes_read);
47 
48   void AddBytesReceived(QuicStreamOffset offset, QuicByteCount length);
49 
50   bool IsBufferAllocated();
51 
52   size_t max_blocks_count();
53 
54   size_t current_blocks_count();
55 
56   const QuicIntervalSet<QuicStreamOffset>& bytes_received();
57 
58  private:
59   QuicStreamSequencerBuffer* buffer_;
60 };
61 
62 }  // namespace test
63 }  // namespace quic
64 
65 #endif  // QUICHE_QUIC_TEST_TOOLS_QUIC_STREAM_SEQUENCER_BUFFER_PEER_H_
66