OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_sent_entropy_manager.h" | 5 #include "net/quic/quic_sent_entropy_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 for (size_t i = 0; i < 10; ++i) { | 61 for (size_t i = 0; i < 10; ++i) { |
62 if (missing_packets.find(i + 1) == missing_packets.end()) { | 62 if (missing_packets.find(i + 1) == missing_packets.end()) { |
63 entropy_hash ^= entropies[i]; | 63 entropy_hash ^= entropies[i]; |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 EXPECT_TRUE(entropy_manager_.IsValidEntropy(10, missing_packets, | 67 EXPECT_TRUE(entropy_manager_.IsValidEntropy(10, missing_packets, |
68 entropy_hash)); | 68 entropy_hash)); |
69 } | 69 } |
70 | 70 |
| 71 TEST_F(QuicSentEntropyManagerTest, ClearEntropiesBefore) { |
| 72 QuicPacketEntropyHash entropies[10] = |
| 73 {12, 1, 33, 3, 32, 100, 28, 42, 22, 255}; |
| 74 |
| 75 for (size_t i = 0; i < 10; ++i) { |
| 76 entropy_manager_.RecordPacketEntropyHash(i + 1, entropies[i]); |
| 77 } |
| 78 |
| 79 // Discard the first 5 entropies and ensure IsValidEntropy and EntropyHash |
| 80 // still return correct results. |
| 81 entropy_manager_.ClearEntropyBefore(5); |
| 82 |
| 83 SequenceNumberSet missing_packets; |
| 84 missing_packets.insert(7); |
| 85 missing_packets.insert(8); |
| 86 |
| 87 QuicPacketEntropyHash entropy_hash = 0; |
| 88 for (size_t i = 0; i < 10; ++i) { |
| 89 if (missing_packets.find(i + 1) == missing_packets.end()) { |
| 90 entropy_hash ^= entropies[i]; |
| 91 } |
| 92 } |
| 93 EXPECT_TRUE(entropy_manager_.IsValidEntropy(10, missing_packets, |
| 94 entropy_hash)); |
| 95 |
| 96 entropy_hash = 0; |
| 97 for (size_t i = 0; i < 10; ++i) { |
| 98 entropy_hash ^= entropies[i]; |
| 99 } |
| 100 EXPECT_EQ(entropy_hash, entropy_manager_.EntropyHash(10)); |
| 101 } |
| 102 |
71 } // namespace | 103 } // namespace |
72 } // namespace test | 104 } // namespace test |
73 } // namespace net | 105 } // namespace net |
OLD | NEW |