Index: net/quic/quic_protocol_test.cc |
diff --git a/net/quic/quic_protocol_test.cc b/net/quic/quic_protocol_test.cc |
index b1d9e422518b4e1b13e8af6285f9d179b6fa2f6e..d5ad0e982c4758f3274c50cfb527e92f0d384c90 100644 |
--- a/net/quic/quic_protocol_test.cc |
+++ b/net/quic/quic_protocol_test.cc |
@@ -4,6 +4,8 @@ |
#include "net/quic/quic_protocol.h" |
+#include <sstream> |
+ |
#include "base/stl_util.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -39,22 +41,10 @@ TEST(QuicProtocolTest, IsAawaitingPacket) { |
EXPECT_TRUE(IsAwaitingPacket(ack_frame, 11u)); |
EXPECT_FALSE(IsAwaitingPacket(ack_frame, 1u)); |
- ack_frame.missing_packets.insert(10); |
+ ack_frame.missing_packets.Add(10); |
EXPECT_TRUE(IsAwaitingPacket(ack_frame, 10u)); |
} |
-TEST(QuicProtocolTest, InsertMissingPacketsBetween) { |
- QuicAckFrame ack_frame; |
- InsertMissingPacketsBetween(&ack_frame, 4u, 10u); |
- EXPECT_EQ(6u, ack_frame.missing_packets.size()); |
- |
- QuicPacketNumber i = 4; |
- for (PacketNumberSet::iterator it = ack_frame.missing_packets.begin(); |
- it != ack_frame.missing_packets.end(); ++it, ++i) { |
- EXPECT_EQ(i, *it); |
- } |
-} |
- |
TEST(QuicProtocolTest, QuicVersionToQuicTag) { |
// If you add a new version to the QuicVersion enum you will need to add a new |
// case to QuicVersionToQuicTag, otherwise this test will fail. |
@@ -165,6 +155,99 @@ TEST(QuicProtocolTest, QuicVersionToString) { |
} |
} |
+// Tests that a queue contains the expected data after calls to Add(). |
+TEST(PacketNumberQueueTest, AddRange) { |
+ PacketNumberQueue queue; |
+ queue.Add(1, 51); |
+ queue.Add(53); |
+ |
+ EXPECT_FALSE(queue.Contains(0)); |
+ for (int i = 1; i < 51; ++i) { |
+ EXPECT_TRUE(queue.Contains(i)); |
+ } |
+ EXPECT_FALSE(queue.Contains(51)); |
+ EXPECT_FALSE(queue.Contains(52)); |
+ EXPECT_TRUE(queue.Contains(53)); |
+ EXPECT_FALSE(queue.Contains(54)); |
+ EXPECT_EQ(51u, queue.NumPackets()); |
+ EXPECT_EQ(1u, queue.Min()); |
+ EXPECT_EQ(53u, queue.Max()); |
+ |
+ queue.Add(70); |
+ EXPECT_EQ(70u, queue.Max()); |
+} |
+ |
+// Tests that a queue contains the expected data after calls to Remove(). |
+TEST(PacketNumberQueueTest, Removal) { |
+ PacketNumberQueue queue; |
+ queue.Add(0, 100); |
+ |
+ EXPECT_TRUE(queue.RemoveUpTo(51)); |
+ EXPECT_FALSE(queue.RemoveUpTo(51)); |
+ queue.Remove(53); |
+ |
+ EXPECT_FALSE(queue.Contains(0)); |
+ for (int i = 1; i < 51; ++i) { |
+ EXPECT_FALSE(queue.Contains(i)); |
+ } |
+ EXPECT_TRUE(queue.Contains(51)); |
+ EXPECT_TRUE(queue.Contains(52)); |
+ EXPECT_FALSE(queue.Contains(53)); |
+ EXPECT_TRUE(queue.Contains(54)); |
+ EXPECT_EQ(48u, queue.NumPackets()); |
+ EXPECT_EQ(51u, queue.Min()); |
+ EXPECT_EQ(99u, queue.Max()); |
+ |
+ queue.Remove(51); |
+ EXPECT_EQ(52u, queue.Min()); |
+ queue.Remove(99); |
+ EXPECT_EQ(98u, queue.Max()); |
+} |
+ |
+// Tests that a queue is empty when all of its elements are removed. |
+TEST(PacketNumberQueueTest, Empty) { |
+ PacketNumberQueue queue; |
+ EXPECT_TRUE(queue.Empty()); |
+ EXPECT_EQ(0u, queue.NumPackets()); |
+ |
+ queue.Add(1, 100); |
+ EXPECT_TRUE(queue.RemoveUpTo(100)); |
+ EXPECT_TRUE(queue.Empty()); |
+ EXPECT_EQ(0u, queue.NumPackets()); |
+} |
+ |
+// Tests that logging the state of a PacketNumberQueue does not crash. |
+TEST(PacketNumberQueueTest, LogDoesNotCrash) { |
+ std::ostringstream oss; |
+ PacketNumberQueue queue; |
+ oss << queue; |
+ |
+ queue.Add(1); |
+ queue.Add(50, 100); |
+ oss << queue; |
+} |
+ |
+// Tests that the iterators returned from a packet queue iterate over the queue. |
+TEST(PacketNumberQueueTest, Iterators) { |
+ PacketNumberQueue queue; |
+ queue.Add(1, 100); |
+ |
+ const std::vector<QuicPacketNumber> actual(queue.begin(), queue.end()); |
+ |
+ std::vector<QuicPacketNumber> expected; |
+ for (int i = 1; i < 100; ++i) { |
+ expected.push_back(i); |
+ } |
+ |
+ EXPECT_EQ(expected, actual); |
+ |
+ PacketNumberQueue::const_iterator it_low = queue.lower_bound(10); |
+ EXPECT_EQ(10u, *it_low); |
+ |
+ PacketNumberQueue::const_iterator it_up = queue.upper_bound(60); |
+ EXPECT_EQ(61u, *it_up); |
+} |
+ |
} // namespace |
} // namespace test |
} // namespace net |