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"
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
19 class QuicSentEntropyManagerTest
: public ::testing::Test
{
21 QuicSentEntropyManager entropy_manager_
;
24 TEST_F(QuicSentEntropyManagerTest
, SentEntropyHash
) {
25 EXPECT_EQ(0, entropy_manager_
.GetCumulativeEntropy(0));
27 QuicPacketEntropyHash entropies
[4] = {12, 1, 33, 3};
28 for (size_t i
= 0; i
< arraysize(entropies
); ++i
) {
29 entropy_manager_
.RecordPacketEntropyHash(i
+ 1, entropies
[i
]);
32 QuicPacketEntropyHash hash
= 0;
33 for (size_t i
= 0; i
< arraysize(entropies
); ++i
) {
35 EXPECT_EQ(hash
, entropy_manager_
.GetCumulativeEntropy(i
+ 1));
39 TEST_F(QuicSentEntropyManagerTest
, IsValidEntropy
) {
40 QuicPacketEntropyHash entropies
[10] =
41 {12, 1, 33, 3, 32, 100, 28, 42, 22, 255};
42 for (size_t i
= 0; i
< arraysize(entropies
); ++i
) {
43 entropy_manager_
.RecordPacketEntropyHash(i
+ 1, entropies
[i
]);
46 PacketNumberSet missing_packets
;
47 missing_packets
.insert(1);
48 missing_packets
.insert(4);
49 missing_packets
.insert(7);
50 missing_packets
.insert(8);
52 QuicPacketEntropyHash entropy_hash
= 0;
53 for (size_t i
= 0; i
< arraysize(entropies
); ++i
) {
54 if (missing_packets
.find(i
+ 1) == missing_packets
.end()) {
55 entropy_hash
^= entropies
[i
];
59 EXPECT_TRUE(entropy_manager_
.IsValidEntropy(10, missing_packets
,
63 TEST_F(QuicSentEntropyManagerTest
, ClearEntropiesBefore
) {
64 QuicPacketEntropyHash entropies
[10] =
65 {12, 1, 33, 3, 32, 100, 28, 42, 22, 255};
67 for (size_t i
= 0; i
< arraysize(entropies
); ++i
) {
68 entropy_manager_
.RecordPacketEntropyHash(i
+ 1, entropies
[i
]);
71 // Discard the first 5 entropies and ensure IsValidEntropy and EntropyHash
72 // still return correct results.
73 entropy_manager_
.ClearEntropyBefore(5);
75 PacketNumberSet missing_packets
;
76 missing_packets
.insert(7);
77 missing_packets
.insert(8);
79 QuicPacketEntropyHash entropy_hash
= 0;
80 for (size_t i
= 0; i
< arraysize(entropies
); ++i
) {
81 if (missing_packets
.find(i
+ 1) == missing_packets
.end()) {
82 entropy_hash
^= entropies
[i
];
85 EXPECT_TRUE(entropy_manager_
.IsValidEntropy(10, missing_packets
,
89 for (size_t i
= 0; i
< arraysize(entropies
); ++i
) {
90 entropy_hash
^= entropies
[i
];
92 EXPECT_EQ(entropy_hash
, entropy_manager_
.GetCumulativeEntropy(10));