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.
5 #include "net/quic/quic_sent_entropy_manager.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
21 class QuicSentEntropyManagerTest
: public ::testing::Test
{
23 QuicSentEntropyManager entropy_manager_
;
26 TEST_F(QuicSentEntropyManagerTest
, SentEntropyHash
) {
27 EXPECT_EQ(0, entropy_manager_
.GetCumulativeEntropy(0));
29 QuicPacketEntropyHash entropies
[4] = {12, 1, 33, 3};
30 for (size_t i
= 0; i
< arraysize(entropies
); ++i
) {
31 entropy_manager_
.RecordPacketEntropyHash(i
+ 1, entropies
[i
]);
34 QuicPacketEntropyHash hash
= 0;
35 for (size_t i
= 0; i
< arraysize(entropies
); ++i
) {
37 EXPECT_EQ(hash
, entropy_manager_
.GetCumulativeEntropy(i
+ 1));
41 TEST_F(QuicSentEntropyManagerTest
, IsValidEntropy
) {
42 QuicPacketEntropyHash entropies
[10] =
43 {12, 1, 33, 3, 32, 100, 28, 42, 22, 255};
44 for (size_t i
= 0; i
< arraysize(entropies
); ++i
) {
45 entropy_manager_
.RecordPacketEntropyHash(i
+ 1, entropies
[i
]);
48 SequenceNumberSet missing_packets
;
49 missing_packets
.insert(1);
50 missing_packets
.insert(4);
51 missing_packets
.insert(7);
52 missing_packets
.insert(8);
54 QuicPacketEntropyHash entropy_hash
= 0;
55 for (size_t i
= 0; i
< arraysize(entropies
); ++i
) {
56 if (missing_packets
.find(i
+ 1) == missing_packets
.end()) {
57 entropy_hash
^= entropies
[i
];
61 EXPECT_TRUE(entropy_manager_
.IsValidEntropy(10, missing_packets
,
65 TEST_F(QuicSentEntropyManagerTest
, ClearEntropiesBefore
) {
66 QuicPacketEntropyHash entropies
[10] =
67 {12, 1, 33, 3, 32, 100, 28, 42, 22, 255};
69 for (size_t i
= 0; i
< arraysize(entropies
); ++i
) {
70 entropy_manager_
.RecordPacketEntropyHash(i
+ 1, entropies
[i
]);
73 // Discard the first 5 entropies and ensure IsValidEntropy and EntropyHash
74 // still return correct results.
75 entropy_manager_
.ClearEntropyBefore(5);
77 SequenceNumberSet missing_packets
;
78 missing_packets
.insert(7);
79 missing_packets
.insert(8);
81 QuicPacketEntropyHash entropy_hash
= 0;
82 for (size_t i
= 0; i
< arraysize(entropies
); ++i
) {
83 if (missing_packets
.find(i
+ 1) == missing_packets
.end()) {
84 entropy_hash
^= entropies
[i
];
87 EXPECT_TRUE(entropy_manager_
.IsValidEntropy(10, missing_packets
,
91 for (size_t i
= 0; i
< arraysize(entropies
); ++i
) {
92 entropy_hash
^= entropies
[i
];
94 EXPECT_EQ(entropy_hash
, entropy_manager_
.GetCumulativeEntropy(10));