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_protocol.h" | 5 #include "net/quic/quic_protocol.h" |
6 | 6 |
| 7 #include <sstream> |
| 8 |
7 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
9 | 11 |
10 namespace net { | 12 namespace net { |
11 namespace test { | 13 namespace test { |
12 namespace { | 14 namespace { |
13 | 15 |
14 TEST(QuicProtocolTest, AdjustErrorForVersion) { | 16 TEST(QuicProtocolTest, AdjustErrorForVersion) { |
15 ASSERT_EQ(8, QUIC_STREAM_LAST_ERROR) | 17 ASSERT_EQ(8, QUIC_STREAM_LAST_ERROR) |
16 << "Any additions to QuicRstStreamErrorCode require an addition to " | 18 << "Any additions to QuicRstStreamErrorCode require an addition to " |
(...skipping 15 matching lines...) Expand all Loading... |
32 EXPECT_EQ('C', bytes[2]); | 34 EXPECT_EQ('C', bytes[2]); |
33 EXPECT_EQ('D', bytes[3]); | 35 EXPECT_EQ('D', bytes[3]); |
34 } | 36 } |
35 | 37 |
36 TEST(QuicProtocolTest, IsAawaitingPacket) { | 38 TEST(QuicProtocolTest, IsAawaitingPacket) { |
37 QuicAckFrame ack_frame; | 39 QuicAckFrame ack_frame; |
38 ack_frame.largest_observed = 10u; | 40 ack_frame.largest_observed = 10u; |
39 EXPECT_TRUE(IsAwaitingPacket(ack_frame, 11u)); | 41 EXPECT_TRUE(IsAwaitingPacket(ack_frame, 11u)); |
40 EXPECT_FALSE(IsAwaitingPacket(ack_frame, 1u)); | 42 EXPECT_FALSE(IsAwaitingPacket(ack_frame, 1u)); |
41 | 43 |
42 ack_frame.missing_packets.insert(10); | 44 ack_frame.missing_packets.Add(10); |
43 EXPECT_TRUE(IsAwaitingPacket(ack_frame, 10u)); | 45 EXPECT_TRUE(IsAwaitingPacket(ack_frame, 10u)); |
44 } | 46 } |
45 | 47 |
46 TEST(QuicProtocolTest, InsertMissingPacketsBetween) { | |
47 QuicAckFrame ack_frame; | |
48 InsertMissingPacketsBetween(&ack_frame, 4u, 10u); | |
49 EXPECT_EQ(6u, ack_frame.missing_packets.size()); | |
50 | |
51 QuicPacketNumber i = 4; | |
52 for (PacketNumberSet::iterator it = ack_frame.missing_packets.begin(); | |
53 it != ack_frame.missing_packets.end(); ++it, ++i) { | |
54 EXPECT_EQ(i, *it); | |
55 } | |
56 } | |
57 | |
58 TEST(QuicProtocolTest, QuicVersionToQuicTag) { | 48 TEST(QuicProtocolTest, QuicVersionToQuicTag) { |
59 // If you add a new version to the QuicVersion enum you will need to add a new | 49 // If you add a new version to the QuicVersion enum you will need to add a new |
60 // case to QuicVersionToQuicTag, otherwise this test will fail. | 50 // case to QuicVersionToQuicTag, otherwise this test will fail. |
61 | 51 |
62 // TODO(rtenneti): Enable checking of Log(ERROR) messages. | 52 // TODO(rtenneti): Enable checking of Log(ERROR) messages. |
63 #if 0 | 53 #if 0 |
64 // Any logs would indicate an unsupported version which we don't expect. | 54 // Any logs would indicate an unsupported version which we don't expect. |
65 ScopedMockLog log(kDoNotCaptureLogsYet); | 55 ScopedMockLog log(kDoNotCaptureLogsYet); |
66 EXPECT_CALL(log, Log(_, _, _)).Times(0); | 56 EXPECT_CALL(log, Log(_, _, _)).Times(0); |
67 log.StartCapturingLogs(); | 57 log.StartCapturingLogs(); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 EXPECT_EQ("QUIC_VERSION_UNSUPPORTED,QUIC_VERSION_25", | 148 EXPECT_EQ("QUIC_VERSION_UNSUPPORTED,QUIC_VERSION_25", |
159 QuicVersionVectorToString(versions_vector)); | 149 QuicVersionVectorToString(versions_vector)); |
160 | 150 |
161 // Make sure that all supported versions are present in QuicVersionToString. | 151 // Make sure that all supported versions are present in QuicVersionToString. |
162 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { | 152 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { |
163 QuicVersion version = kSupportedQuicVersions[i]; | 153 QuicVersion version = kSupportedQuicVersions[i]; |
164 EXPECT_NE("QUIC_VERSION_UNSUPPORTED", QuicVersionToString(version)); | 154 EXPECT_NE("QUIC_VERSION_UNSUPPORTED", QuicVersionToString(version)); |
165 } | 155 } |
166 } | 156 } |
167 | 157 |
| 158 // Tests that a queue contains the expected data after calls to Add(). |
| 159 TEST(PacketNumberQueueTest, AddRange) { |
| 160 PacketNumberQueue queue; |
| 161 queue.Add(1, 51); |
| 162 queue.Add(53); |
| 163 |
| 164 EXPECT_FALSE(queue.Contains(0)); |
| 165 for (int i = 1; i < 51; ++i) { |
| 166 EXPECT_TRUE(queue.Contains(i)); |
| 167 } |
| 168 EXPECT_FALSE(queue.Contains(51)); |
| 169 EXPECT_FALSE(queue.Contains(52)); |
| 170 EXPECT_TRUE(queue.Contains(53)); |
| 171 EXPECT_FALSE(queue.Contains(54)); |
| 172 EXPECT_EQ(51u, queue.NumPackets()); |
| 173 EXPECT_EQ(1u, queue.Min()); |
| 174 EXPECT_EQ(53u, queue.Max()); |
| 175 |
| 176 queue.Add(70); |
| 177 EXPECT_EQ(70u, queue.Max()); |
| 178 } |
| 179 |
| 180 // Tests that a queue contains the expected data after calls to Remove(). |
| 181 TEST(PacketNumberQueueTest, Removal) { |
| 182 PacketNumberQueue queue; |
| 183 queue.Add(0, 100); |
| 184 |
| 185 EXPECT_TRUE(queue.RemoveUpTo(51)); |
| 186 EXPECT_FALSE(queue.RemoveUpTo(51)); |
| 187 queue.Remove(53); |
| 188 |
| 189 EXPECT_FALSE(queue.Contains(0)); |
| 190 for (int i = 1; i < 51; ++i) { |
| 191 EXPECT_FALSE(queue.Contains(i)); |
| 192 } |
| 193 EXPECT_TRUE(queue.Contains(51)); |
| 194 EXPECT_TRUE(queue.Contains(52)); |
| 195 EXPECT_FALSE(queue.Contains(53)); |
| 196 EXPECT_TRUE(queue.Contains(54)); |
| 197 EXPECT_EQ(48u, queue.NumPackets()); |
| 198 EXPECT_EQ(51u, queue.Min()); |
| 199 EXPECT_EQ(99u, queue.Max()); |
| 200 |
| 201 queue.Remove(51); |
| 202 EXPECT_EQ(52u, queue.Min()); |
| 203 queue.Remove(99); |
| 204 EXPECT_EQ(98u, queue.Max()); |
| 205 } |
| 206 |
| 207 // Tests that a queue is empty when all of its elements are removed. |
| 208 TEST(PacketNumberQueueTest, Empty) { |
| 209 PacketNumberQueue queue; |
| 210 EXPECT_TRUE(queue.Empty()); |
| 211 EXPECT_EQ(0u, queue.NumPackets()); |
| 212 |
| 213 queue.Add(1, 100); |
| 214 EXPECT_TRUE(queue.RemoveUpTo(100)); |
| 215 EXPECT_TRUE(queue.Empty()); |
| 216 EXPECT_EQ(0u, queue.NumPackets()); |
| 217 } |
| 218 |
| 219 // Tests that logging the state of a PacketNumberQueue does not crash. |
| 220 TEST(PacketNumberQueueTest, LogDoesNotCrash) { |
| 221 std::ostringstream oss; |
| 222 PacketNumberQueue queue; |
| 223 oss << queue; |
| 224 |
| 225 queue.Add(1); |
| 226 queue.Add(50, 100); |
| 227 oss << queue; |
| 228 } |
| 229 |
| 230 // Tests that the iterators returned from a packet queue iterate over the queue. |
| 231 TEST(PacketNumberQueueTest, Iterators) { |
| 232 PacketNumberQueue queue; |
| 233 queue.Add(1, 100); |
| 234 |
| 235 const std::vector<QuicPacketNumber> actual(queue.begin(), queue.end()); |
| 236 |
| 237 std::vector<QuicPacketNumber> expected; |
| 238 for (int i = 1; i < 100; ++i) { |
| 239 expected.push_back(i); |
| 240 } |
| 241 |
| 242 EXPECT_EQ(expected, actual); |
| 243 |
| 244 PacketNumberQueue::const_iterator it_low = queue.lower_bound(10); |
| 245 EXPECT_EQ(10u, *it_low); |
| 246 |
| 247 PacketNumberQueue::const_iterator it_up = queue.upper_bound(60); |
| 248 EXPECT_EQ(61u, *it_up); |
| 249 } |
| 250 |
168 } // namespace | 251 } // namespace |
169 } // namespace test | 252 } // namespace test |
170 } // namespace net | 253 } // namespace net |
OLD | NEW |