| 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 | 8 |
| 9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 | 38 |
| 39 TEST_F(QuicSentEntropyManagerTest, IsValidEntropy) { | 39 TEST_F(QuicSentEntropyManagerTest, IsValidEntropy) { |
| 40 QuicPacketEntropyHash entropies[10] = | 40 QuicPacketEntropyHash entropies[10] = |
| 41 {12, 1, 33, 3, 32, 100, 28, 42, 22, 255}; | 41 {12, 1, 33, 3, 32, 100, 28, 42, 22, 255}; |
| 42 for (size_t i = 0; i < arraysize(entropies); ++i) { | 42 for (size_t i = 0; i < arraysize(entropies); ++i) { |
| 43 entropy_manager_.RecordPacketEntropyHash(i + 1, entropies[i]); | 43 entropy_manager_.RecordPacketEntropyHash(i + 1, entropies[i]); |
| 44 } | 44 } |
| 45 | 45 |
| 46 PacketNumberSet missing_packets; | 46 PacketNumberQueue missing_packets; |
| 47 missing_packets.insert(1); | 47 missing_packets.Add(1); |
| 48 missing_packets.insert(4); | 48 missing_packets.Add(4); |
| 49 missing_packets.insert(7); | 49 missing_packets.Add(7, 9); |
| 50 missing_packets.insert(8); | |
| 51 | 50 |
| 52 QuicPacketEntropyHash entropy_hash = 0; | 51 QuicPacketEntropyHash entropy_hash = 0; |
| 53 for (size_t i = 0; i < arraysize(entropies); ++i) { | 52 for (size_t i = 0; i < arraysize(entropies); ++i) { |
| 54 if (missing_packets.find(i + 1) == missing_packets.end()) { | 53 if (!missing_packets.Contains(i + 1)) { |
| 55 entropy_hash ^= entropies[i]; | 54 entropy_hash ^= entropies[i]; |
| 56 } | 55 } |
| 57 } | 56 } |
| 58 | 57 |
| 59 EXPECT_TRUE(entropy_manager_.IsValidEntropy(10, missing_packets, | 58 EXPECT_TRUE(entropy_manager_.IsValidEntropy(10, missing_packets, |
| 60 entropy_hash)); | 59 entropy_hash)); |
| 61 } | 60 } |
| 62 | 61 |
| 63 TEST_F(QuicSentEntropyManagerTest, ClearEntropiesBefore) { | 62 TEST_F(QuicSentEntropyManagerTest, ClearEntropiesBefore) { |
| 64 QuicPacketEntropyHash entropies[10] = | 63 QuicPacketEntropyHash entropies[10] = |
| 65 {12, 1, 33, 3, 32, 100, 28, 42, 22, 255}; | 64 {12, 1, 33, 3, 32, 100, 28, 42, 22, 255}; |
| 66 | 65 |
| 67 for (size_t i = 0; i < arraysize(entropies); ++i) { | 66 for (size_t i = 0; i < arraysize(entropies); ++i) { |
| 68 entropy_manager_.RecordPacketEntropyHash(i + 1, entropies[i]); | 67 entropy_manager_.RecordPacketEntropyHash(i + 1, entropies[i]); |
| 69 } | 68 } |
| 70 | 69 |
| 71 // Discard the first 5 entropies and ensure IsValidEntropy and EntropyHash | 70 // Discard the first 5 entropies and ensure IsValidEntropy and EntropyHash |
| 72 // still return correct results. | 71 // still return correct results. |
| 73 entropy_manager_.ClearEntropyBefore(5); | 72 entropy_manager_.ClearEntropyBefore(5); |
| 74 | 73 |
| 75 PacketNumberSet missing_packets; | 74 PacketNumberQueue missing_packets; |
| 76 missing_packets.insert(7); | 75 missing_packets.Add(7, 9); |
| 77 missing_packets.insert(8); | |
| 78 | 76 |
| 79 QuicPacketEntropyHash entropy_hash = 0; | 77 QuicPacketEntropyHash entropy_hash = 0; |
| 80 for (size_t i = 0; i < arraysize(entropies); ++i) { | 78 for (size_t i = 0; i < arraysize(entropies); ++i) { |
| 81 if (missing_packets.find(i + 1) == missing_packets.end()) { | 79 if (!missing_packets.Contains(i + 1)) { |
| 82 entropy_hash ^= entropies[i]; | 80 entropy_hash ^= entropies[i]; |
| 83 } | 81 } |
| 84 } | 82 } |
| 85 EXPECT_TRUE(entropy_manager_.IsValidEntropy(10, missing_packets, | 83 EXPECT_TRUE(entropy_manager_.IsValidEntropy(10, missing_packets, |
| 86 entropy_hash)); | 84 entropy_hash)); |
| 87 | 85 |
| 88 entropy_hash = 0; | 86 entropy_hash = 0; |
| 89 for (size_t i = 0; i < arraysize(entropies); ++i) { | 87 for (size_t i = 0; i < arraysize(entropies); ++i) { |
| 90 entropy_hash ^= entropies[i]; | 88 entropy_hash ^= entropies[i]; |
| 91 } | 89 } |
| 92 EXPECT_EQ(entropy_hash, entropy_manager_.GetCumulativeEntropy(10)); | 90 EXPECT_EQ(entropy_hash, entropy_manager_.GetCumulativeEntropy(10)); |
| 93 } | 91 } |
| 94 | 92 |
| 95 } // namespace | 93 } // namespace |
| 96 } // namespace test | 94 } // namespace test |
| 97 } // namespace net | 95 } // namespace net |
| OLD | NEW |