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_fec_group.h" | 5 #include "net/quic/quic_fec_group.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
14 | 14 |
15 using ::testing::_; | 15 using ::testing::_; |
16 using base::StringPiece; | 16 using base::StringPiece; |
17 | 17 |
18 namespace net { | 18 namespace net { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 const char* kData[] = { | 22 const char* kData[] = { |
23 "abc12345678", | 23 "abc12345678", "987defg", "ghi12345", |
24 "987defg", | 24 "987jlkmno", "mno4567890", "789pqrstuvw", |
25 "ghi12345", | |
26 "987jlkmno", | |
27 "mno4567890", | |
28 "789pqrstuvw", | |
29 }; | 25 }; |
30 | 26 |
31 const bool kEntropyFlag[] = { | 27 const bool kEntropyFlag[] = { |
32 false, | 28 false, true, true, false, true, true, |
33 true, | |
34 true, | |
35 false, | |
36 true, | |
37 true, | |
38 }; | 29 }; |
39 | 30 |
40 } // namespace | 31 } // namespace |
41 | 32 |
42 class QuicFecGroupTest : public ::testing::Test { | 33 class QuicFecGroupTest : public ::testing::Test { |
43 protected: | 34 protected: |
44 void RunTest(size_t num_packets, size_t lost_packet, bool out_of_order) { | 35 void RunTest(size_t num_packets, size_t lost_packet, bool out_of_order) { |
45 size_t max_len = strlen(kData[0]); | 36 size_t max_len = strlen(kData[0]); |
46 scoped_ptr<char[]> redundancy(new char[max_len]); | 37 scoped_ptr<char[]> redundancy(new char[max_len]); |
47 for (size_t packet = 0; packet < num_packets; ++packet) { | 38 for (size_t packet = 0; packet < num_packets; ++packet) { |
(...skipping 24 matching lines...) Expand all Loading... |
72 ASSERT_TRUE(group.UpdateFec(num_packets, fec)); | 63 ASSERT_TRUE(group.UpdateFec(num_packets, fec)); |
73 } else { | 64 } else { |
74 QuicPacketHeader header; | 65 QuicPacketHeader header; |
75 header.packet_sequence_number = packet; | 66 header.packet_sequence_number = packet; |
76 header.entropy_flag = kEntropyFlag[packet]; | 67 header.entropy_flag = kEntropyFlag[packet]; |
77 ASSERT_TRUE(group.Update(header, kData[packet])); | 68 ASSERT_TRUE(group.Update(header, kData[packet])); |
78 } | 69 } |
79 ASSERT_TRUE(group.CanRevive() == (packet == num_packets - 1)); | 70 ASSERT_TRUE(group.CanRevive() == (packet == num_packets - 1)); |
80 } | 71 } |
81 } else { | 72 } else { |
82 // Update the FEC state for each non-lost packet. | 73 // Update the FEC state for each non-lost packet. |
83 for (size_t packet = 0; packet < num_packets; packet++) { | 74 for (size_t packet = 0; packet < num_packets; packet++) { |
84 if (packet == lost_packet) { | 75 if (packet == lost_packet) { |
85 continue; | 76 continue; |
86 } | 77 } |
87 | 78 |
88 QuicPacketHeader header; | 79 QuicPacketHeader header; |
89 header.packet_sequence_number = packet; | 80 header.packet_sequence_number = packet; |
90 header.entropy_flag = kEntropyFlag[packet]; | 81 header.entropy_flag = kEntropyFlag[packet]; |
91 ASSERT_TRUE(group.Update(header, kData[packet])); | 82 ASSERT_TRUE(group.Update(header, kData[packet])); |
92 ASSERT_FALSE(group.CanRevive()); | 83 ASSERT_FALSE(group.CanRevive()); |
93 } | 84 } |
94 | 85 |
95 ASSERT_FALSE(group.IsFinished()); | 86 ASSERT_FALSE(group.IsFinished()); |
96 // Attempt to revive the missing packet. | 87 // Attempt to revive the missing packet. |
97 QuicFecData fec; | 88 QuicFecData fec; |
98 fec.fec_group = 0; | 89 fec.fec_group = 0; |
99 fec.redundancy = StringPiece(redundancy.get(), strlen(kData[0])); | 90 fec.redundancy = StringPiece(redundancy.get(), strlen(kData[0])); |
100 | 91 |
101 ASSERT_TRUE(group.UpdateFec(num_packets, fec)); | 92 ASSERT_TRUE(group.UpdateFec(num_packets, fec)); |
102 } | 93 } |
103 QuicPacketHeader header; | 94 QuicPacketHeader header; |
104 char recovered[kMaxPacketSize]; | 95 char recovered[kMaxPacketSize]; |
105 ASSERT_TRUE(group.CanRevive()); | 96 ASSERT_TRUE(group.CanRevive()); |
106 size_t len = group.Revive(&header, recovered, arraysize(recovered)); | 97 size_t len = group.Revive(&header, recovered, arraysize(recovered)); |
107 ASSERT_NE(0u, len) | 98 ASSERT_NE(0u, len) << "Failed to revive packet " << lost_packet |
108 << "Failed to revive packet " << lost_packet << " out of " | 99 << " out of " << num_packets; |
109 << num_packets; | |
110 EXPECT_EQ(lost_packet, header.packet_sequence_number) | 100 EXPECT_EQ(lost_packet, header.packet_sequence_number) |
111 << "Failed to revive packet " << lost_packet << " out of " | 101 << "Failed to revive packet " << lost_packet << " out of " |
112 << num_packets; | 102 << num_packets; |
113 // Revived packets have an unknown entropy. | 103 // Revived packets have an unknown entropy. |
114 EXPECT_FALSE(header.entropy_flag); | 104 EXPECT_FALSE(header.entropy_flag); |
115 ASSERT_GE(len, strlen(kData[lost_packet])) << "Incorrect length"; | 105 ASSERT_GE(len, strlen(kData[lost_packet])) << "Incorrect length"; |
116 for (size_t i = 0; i < strlen(kData[lost_packet]); i++) { | 106 for (size_t i = 0; i < strlen(kData[lost_packet]); i++) { |
117 EXPECT_EQ(kData[lost_packet][i], recovered[i]); | 107 EXPECT_EQ(kData[lost_packet][i], recovered[i]); |
118 } | 108 } |
119 ASSERT_TRUE(group.IsFinished()); | 109 ASSERT_TRUE(group.IsFinished()); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 | 199 |
210 EXPECT_FALSE(group.ProtectsPacketsBefore(1)); | 200 EXPECT_FALSE(group.ProtectsPacketsBefore(1)); |
211 EXPECT_FALSE(group.ProtectsPacketsBefore(2)); | 201 EXPECT_FALSE(group.ProtectsPacketsBefore(2)); |
212 EXPECT_TRUE(group.ProtectsPacketsBefore(3)); | 202 EXPECT_TRUE(group.ProtectsPacketsBefore(3)); |
213 EXPECT_TRUE(group.ProtectsPacketsBefore(4)); | 203 EXPECT_TRUE(group.ProtectsPacketsBefore(4)); |
214 EXPECT_TRUE(group.ProtectsPacketsBefore(5)); | 204 EXPECT_TRUE(group.ProtectsPacketsBefore(5)); |
215 EXPECT_TRUE(group.ProtectsPacketsBefore(50)); | 205 EXPECT_TRUE(group.ProtectsPacketsBefore(50)); |
216 } | 206 } |
217 | 207 |
218 } // namespace net | 208 } // namespace net |
OLD | NEW |