OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/congestion_control/bandwidth_sampler.h" | 5 #include "net/quic/core/congestion_control/bandwidth_sampler.h" |
6 | 6 |
| 7 #include "net/quic/platform/api/quic_test.h" |
7 #include "net/quic/test_tools/mock_clock.h" | 8 #include "net/quic/test_tools/mock_clock.h" |
8 #include "testing/gmock/include/gmock/gmock.h" | |
9 #include "testing/gtest/include/gtest/gtest.h" | |
10 | 9 |
11 namespace net { | 10 namespace net { |
12 namespace test { | 11 namespace test { |
13 | 12 |
14 class BandwidthSamplerPeer { | 13 class BandwidthSamplerPeer { |
15 public: | 14 public: |
16 static size_t GetNumberOfTrackedPackets(const BandwidthSampler& sampler) { | 15 static size_t GetNumberOfTrackedPackets(const BandwidthSampler& sampler) { |
17 return sampler.connection_state_map_.size(); | 16 return sampler.connection_state_map_.size(); |
18 } | 17 } |
19 | 18 |
20 static QuicByteCount GetPacketSize(const BandwidthSampler& sampler, | 19 static QuicByteCount GetPacketSize(const BandwidthSampler& sampler, |
21 QuicPacketNumber packet_number) { | 20 QuicPacketNumber packet_number) { |
22 auto iterator = sampler.connection_state_map_.find(packet_number); | 21 auto iterator = sampler.connection_state_map_.find(packet_number); |
23 return iterator->second.size; | 22 return iterator->second.size; |
24 } | 23 } |
25 }; | 24 }; |
26 | 25 |
27 const QuicByteCount kRegularPacketSize = 1280; | 26 const QuicByteCount kRegularPacketSize = 1280; |
28 // Enforce divisibility for some of the tests. | 27 // Enforce divisibility for some of the tests. |
29 static_assert((kRegularPacketSize & 31) == 0, | 28 static_assert((kRegularPacketSize & 31) == 0, |
30 "kRegularPacketSize has to be five times divisible by 2"); | 29 "kRegularPacketSize has to be five times divisible by 2"); |
31 | 30 |
32 // A test fixture with utility methods for BandwidthSampler tests. | 31 // A test fixture with utility methods for BandwidthSampler tests. |
33 class BandwidthSamplerTest : public ::testing::Test { | 32 class BandwidthSamplerTest : public QuicTest { |
34 protected: | 33 protected: |
35 BandwidthSamplerTest() : bytes_in_flight_(0) { | 34 BandwidthSamplerTest() : bytes_in_flight_(0) { |
36 // Ensure that the clock does not start at zero. | 35 // Ensure that the clock does not start at zero. |
37 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 36 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
38 } | 37 } |
39 | 38 |
40 MockClock clock_; | 39 MockClock clock_; |
41 BandwidthSampler sampler_; | 40 BandwidthSampler sampler_; |
42 QuicByteCount bytes_in_flight_; | 41 QuicByteCount bytes_in_flight_; |
43 | 42 |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 sampler_.RemoveObsoletePackets(4); | 388 sampler_.RemoveObsoletePackets(4); |
390 EXPECT_EQ(2u, BandwidthSamplerPeer::GetNumberOfTrackedPackets(sampler_)); | 389 EXPECT_EQ(2u, BandwidthSamplerPeer::GetNumberOfTrackedPackets(sampler_)); |
391 sampler_.OnPacketLost(4); | 390 sampler_.OnPacketLost(4); |
392 EXPECT_EQ(1u, BandwidthSamplerPeer::GetNumberOfTrackedPackets(sampler_)); | 391 EXPECT_EQ(1u, BandwidthSamplerPeer::GetNumberOfTrackedPackets(sampler_)); |
393 AckPacket(5); | 392 AckPacket(5); |
394 EXPECT_EQ(0u, BandwidthSamplerPeer::GetNumberOfTrackedPackets(sampler_)); | 393 EXPECT_EQ(0u, BandwidthSamplerPeer::GetNumberOfTrackedPackets(sampler_)); |
395 } | 394 } |
396 | 395 |
397 } // namespace test | 396 } // namespace test |
398 } // namespace net | 397 } // namespace net |
OLD | NEW |