| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/quic_stream_sequencer.h" | 5 #include "net/quic/quic_stream_sequencer.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| 11 #include "net/base/ip_endpoint.h" |
| 11 #include "net/quic/reliable_quic_stream.h" | 12 #include "net/quic/reliable_quic_stream.h" |
| 13 #include "net/quic/test_tools/quic_test_utils.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 16 |
| 15 using base::StringPiece; | 17 using base::StringPiece; |
| 16 using std::min; | 18 using std::min; |
| 17 using std::pair; | 19 using std::pair; |
| 18 using std::vector; | 20 using std::vector; |
| 19 using testing::_; | 21 using testing::_; |
| 20 using testing::AnyNumber; | 22 using testing::AnyNumber; |
| 21 using testing::InSequence; | 23 using testing::InSequence; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 }; | 80 }; |
| 79 | 81 |
| 80 namespace { | 82 namespace { |
| 81 | 83 |
| 82 static const char kPayload[] = | 84 static const char kPayload[] = |
| 83 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | 85 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; |
| 84 | 86 |
| 85 class QuicStreamSequencerTest : public ::testing::Test { | 87 class QuicStreamSequencerTest : public ::testing::Test { |
| 86 protected: | 88 protected: |
| 87 QuicStreamSequencerTest() | 89 QuicStreamSequencerTest() |
| 88 : session_(NULL), | 90 : connection_(new MockConnection(1, IPEndPoint(), false)), |
| 89 stream_(session_, 1), | 91 session_(connection_, true), |
| 92 stream_(&session_, 1), |
| 90 sequencer_(new QuicStreamSequencerPeer(&stream_)) { | 93 sequencer_(new QuicStreamSequencerPeer(&stream_)) { |
| 91 } | 94 } |
| 92 | 95 |
| 93 bool VerifyReadableRegions(const char** expected, size_t num_expected) { | 96 bool VerifyReadableRegions(const char** expected, size_t num_expected) { |
| 94 iovec iovecs[5]; | 97 iovec iovecs[5]; |
| 95 size_t num_iovecs = sequencer_->GetReadableRegions(iovecs, | 98 size_t num_iovecs = sequencer_->GetReadableRegions(iovecs, |
| 96 arraysize(iovecs)); | 99 arraysize(iovecs)); |
| 97 return VerifyIovecs(iovecs, num_iovecs, expected, num_expected); | 100 return VerifyIovecs(iovecs, num_iovecs, expected, num_expected); |
| 98 } | 101 } |
| 99 | 102 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 121 return false; | 124 return false; |
| 122 } | 125 } |
| 123 if (memcmp(iovec.iov_base, expected.data(), expected.length()) != 0) { | 126 if (memcmp(iovec.iov_base, expected.data(), expected.length()) != 0) { |
| 124 LOG(ERROR) << "Invalid data: " << static_cast<char*>(iovec.iov_base) | 127 LOG(ERROR) << "Invalid data: " << static_cast<char*>(iovec.iov_base) |
| 125 << " vs " << expected.data(); | 128 << " vs " << expected.data(); |
| 126 return false; | 129 return false; |
| 127 } | 130 } |
| 128 return true; | 131 return true; |
| 129 } | 132 } |
| 130 | 133 |
| 131 QuicSession* session_; | 134 MockConnection* connection_; |
| 135 MockSession session_; |
| 132 testing::StrictMock<MockStream> stream_; | 136 testing::StrictMock<MockStream> stream_; |
| 133 scoped_ptr<QuicStreamSequencerPeer> sequencer_; | 137 scoped_ptr<QuicStreamSequencerPeer> sequencer_; |
| 134 }; | 138 }; |
| 135 | 139 |
| 136 TEST_F(QuicStreamSequencerTest, RejectOldFrame) { | 140 TEST_F(QuicStreamSequencerTest, RejectOldFrame) { |
| 137 EXPECT_CALL(stream_, ProcessData(StrEq("abc"), 3)) | 141 EXPECT_CALL(stream_, ProcessData(StrEq("abc"), 3)) |
| 138 .WillOnce(Return(3)); | 142 .WillOnce(Return(3)); |
| 139 | 143 |
| 140 EXPECT_TRUE(sequencer_->OnFrame(0, "abc")); | 144 EXPECT_TRUE(sequencer_->OnFrame(0, "abc")); |
| 141 EXPECT_EQ(0u, sequencer_->frames()->size()); | 145 EXPECT_EQ(0u, sequencer_->frames()->size()); |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 | 573 |
| 570 if (acked) { | 574 if (acked) { |
| 571 list_.erase(list_.begin() + index); | 575 list_.erase(list_.begin() + index); |
| 572 } | 576 } |
| 573 } | 577 } |
| 574 } | 578 } |
| 575 | 579 |
| 576 } // namespace | 580 } // namespace |
| 577 } // namespace test | 581 } // namespace test |
| 578 } // namespace net | 582 } // namespace net |
| OLD | NEW |