OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 #include "net/quic/core/quic_stream_sequencer_buffer.h" | 5 #include "net/quic/core/quic_stream_sequencer_buffer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 auto* frame_map = helper_->frame_arrival_time_map(); | 129 auto* frame_map = helper_->frame_arrival_time_map(); |
130 EXPECT_EQ(1u, frame_map->size()); | 130 EXPECT_EQ(1u, frame_map->size()); |
131 EXPECT_EQ(800u, frame_map->begin()->first); | 131 EXPECT_EQ(800u, frame_map->begin()->first); |
132 EXPECT_EQ(t, (*frame_map)[800].timestamp); | 132 EXPECT_EQ(t, (*frame_map)[800].timestamp); |
133 EXPECT_TRUE(helper_->CheckBufferInvariants()); | 133 EXPECT_TRUE(helper_->CheckBufferInvariants()); |
134 EXPECT_TRUE(helper_->IsBufferAllocated()); | 134 EXPECT_TRUE(helper_->IsBufferAllocated()); |
135 } | 135 } |
136 | 136 |
137 TEST_F(QuicStreamSequencerBufferTest, OnStreamDataInvalidSource) { | 137 TEST_F(QuicStreamSequencerBufferTest, OnStreamDataInvalidSource) { |
138 // Pass in an invalid source, expects to return error. | 138 // Pass in an invalid source, expects to return error. |
139 StringPiece source; | 139 QuicStringPiece source; |
140 source = StringPiece(nullptr, 1024); | 140 source = QuicStringPiece(nullptr, 1024); |
141 size_t written; | 141 size_t written; |
142 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 142 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
143 QuicTime t = clock_.ApproximateNow(); | 143 QuicTime t = clock_.ApproximateNow(); |
144 EXPECT_EQ(QUIC_STREAM_SEQUENCER_INVALID_STATE, | 144 EXPECT_EQ(QUIC_STREAM_SEQUENCER_INVALID_STATE, |
145 buffer_->OnStreamData(800, source, t, &written, &error_details_)); | 145 buffer_->OnStreamData(800, source, t, &written, &error_details_)); |
146 EXPECT_EQ(0u, error_details_.find(QuicStrCat( | 146 EXPECT_EQ(0u, error_details_.find(QuicStrCat( |
147 "QuicStreamSequencerBuffer error: OnStreamData() " | 147 "QuicStreamSequencerBuffer error: OnStreamData() " |
148 "dest == nullptr: ", | 148 "dest == nullptr: ", |
149 false, " source == nullptr: ", true))); | 149 false, " source == nullptr: ", true))); |
150 } | 150 } |
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 // because it goes beyond current capacity, move it to the end of | 858 // because it goes beyond current capacity, move it to the end of |
859 // shuffled_buf_ and write it later. | 859 // shuffled_buf_ and write it later. |
860 void WriteNextChunkToBuffer() { | 860 void WriteNextChunkToBuffer() { |
861 OffsetSizePair& chunk = shuffled_buf_.front(); | 861 OffsetSizePair& chunk = shuffled_buf_.front(); |
862 QuicStreamOffset offset = chunk.first; | 862 QuicStreamOffset offset = chunk.first; |
863 const size_t num_to_write = chunk.second; | 863 const size_t num_to_write = chunk.second; |
864 std::unique_ptr<char[]> write_buf{new char[max_chunk_size_bytes_]}; | 864 std::unique_ptr<char[]> write_buf{new char[max_chunk_size_bytes_]}; |
865 for (size_t i = 0; i < num_to_write; ++i) { | 865 for (size_t i = 0; i < num_to_write; ++i) { |
866 write_buf[i] = (offset + i) % 256; | 866 write_buf[i] = (offset + i) % 256; |
867 } | 867 } |
868 base::StringPiece string_piece_w(write_buf.get(), num_to_write); | 868 QuicStringPiece string_piece_w(write_buf.get(), num_to_write); |
869 size_t written; | 869 size_t written; |
870 auto result = | 870 auto result = |
871 buffer_->OnStreamData(offset, string_piece_w, clock_.ApproximateNow(), | 871 buffer_->OnStreamData(offset, string_piece_w, clock_.ApproximateNow(), |
872 &written, &error_details_); | 872 &written, &error_details_); |
873 if (result == QUIC_NO_ERROR) { | 873 if (result == QUIC_NO_ERROR) { |
874 shuffled_buf_.pop_front(); | 874 shuffled_buf_.pop_front(); |
875 total_bytes_written_ += num_to_write; | 875 total_bytes_written_ += num_to_write; |
876 } else { | 876 } else { |
877 // This chunk offset exceeds window size. | 877 // This chunk offset exceeds window size. |
878 shuffled_buf_.push_back(chunk); | 878 shuffled_buf_.push_back(chunk); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 EXPECT_LE(bytes_to_buffer_, total_bytes_read_) << "iterations: " | 1029 EXPECT_LE(bytes_to_buffer_, total_bytes_read_) << "iterations: " |
1030 << iterations; | 1030 << iterations; |
1031 EXPECT_LE(bytes_to_buffer_, total_bytes_written_); | 1031 EXPECT_LE(bytes_to_buffer_, total_bytes_written_); |
1032 } | 1032 } |
1033 | 1033 |
1034 } // anonymous namespace | 1034 } // anonymous namespace |
1035 | 1035 |
1036 } // namespace test | 1036 } // namespace test |
1037 | 1037 |
1038 } // namespace net | 1038 } // namespace net |
OLD | NEW |