OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "net/quic/quic_sent_entropy_manager.h" | |
6 | |
7 #include <algorithm> | |
8 #include <vector> | |
9 | |
10 #include "testing/gmock/include/gmock/gmock.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 using std::make_pair; | |
14 using std::pair; | |
15 | |
16 namespace net { | |
17 namespace test { | |
18 namespace { | |
19 | |
20 class QuicSentEntropyManagerTest : public ::testing::Test { | |
21 protected: | |
22 QuicSentEntropyManager entropy_manager_; | |
23 }; | |
24 | |
25 TEST_F(QuicSentEntropyManagerTest, SentEntropyHash) { | |
26 EXPECT_EQ(0, entropy_manager_.GetCumulativeEntropy(0)); | |
27 | |
28 QuicPacketEntropyHash entropies[4] = {12, 1, 33, 3}; | |
29 for (size_t i = 0; i < arraysize(entropies); ++i) { | |
30 entropy_manager_.RecordPacketEntropyHash(i + 1, entropies[i]); | |
31 } | |
32 | |
33 QuicPacketEntropyHash hash = 0; | |
34 for (size_t i = 0; i < arraysize(entropies); ++i) { | |
35 hash ^= entropies[i]; | |
36 EXPECT_EQ(hash, entropy_manager_.GetCumulativeEntropy(i + 1)); | |
37 } | |
38 } | |
39 | |
40 TEST_F(QuicSentEntropyManagerTest, IsValidEntropy) { | |
41 QuicPacketEntropyHash entropies[10] = {12, 1, 33, 3, 32, | |
42 100, 28, 42, 22, 255}; | |
43 for (size_t i = 0; i < arraysize(entropies); ++i) { | |
44 entropy_manager_.RecordPacketEntropyHash(i + 1, entropies[i]); | |
45 } | |
46 | |
47 PacketNumberQueue missing_packets; | |
48 missing_packets.Add(1); | |
49 missing_packets.Add(4); | |
50 missing_packets.Add(7, 9); | |
51 | |
52 QuicPacketEntropyHash entropy_hash = 0; | |
53 for (size_t i = 0; i < arraysize(entropies); ++i) { | |
54 if (!missing_packets.Contains(i + 1)) { | |
55 entropy_hash ^= entropies[i]; | |
56 } | |
57 } | |
58 | |
59 EXPECT_TRUE( | |
60 entropy_manager_.IsValidEntropy(10, missing_packets, entropy_hash)); | |
61 } | |
62 | |
63 TEST_F(QuicSentEntropyManagerTest, ClearEntropiesBefore) { | |
64 QuicPacketEntropyHash entropies[10] = {12, 1, 33, 3, 32, | |
65 100, 28, 42, 22, 255}; | |
66 | |
67 for (size_t i = 0; i < arraysize(entropies); ++i) { | |
68 entropy_manager_.RecordPacketEntropyHash(i + 1, entropies[i]); | |
69 } | |
70 | |
71 // Discard the first 5 entropies and ensure IsValidEntropy and EntropyHash | |
72 // still return correct results. | |
73 entropy_manager_.ClearEntropyBefore(5); | |
74 | |
75 PacketNumberQueue missing_packets; | |
76 missing_packets.Add(7, 9); | |
77 | |
78 QuicPacketEntropyHash entropy_hash = 0; | |
79 for (size_t i = 0; i < arraysize(entropies); ++i) { | |
80 if (!missing_packets.Contains(i + 1)) { | |
81 entropy_hash ^= entropies[i]; | |
82 } | |
83 } | |
84 EXPECT_TRUE( | |
85 entropy_manager_.IsValidEntropy(10, missing_packets, entropy_hash)); | |
86 | |
87 entropy_hash = 0; | |
88 for (size_t i = 0; i < arraysize(entropies); ++i) { | |
89 entropy_hash ^= entropies[i]; | |
90 } | |
91 EXPECT_EQ(entropy_hash, entropy_manager_.GetCumulativeEntropy(10)); | |
92 } | |
93 | |
94 } // namespace | |
95 } // namespace test | |
96 } // namespace net | |
OLD | NEW |