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_
.EntropyHash(0));
29 vector
<pair
<QuicPacketSequenceNumber
, QuicPacketEntropyHash
> > entropies
;
30 entropies
.push_back(make_pair(1, 12));
31 entropies
.push_back(make_pair(2, 1));
32 entropies
.push_back(make_pair(3, 33));
33 entropies
.push_back(make_pair(4, 3));
35 for (size_t i
= 0; i
< entropies
.size(); ++i
) {
36 entropy_manager_
.RecordPacketEntropyHash(entropies
[i
].first
,
40 QuicPacketEntropyHash hash
= 0;
41 for (size_t i
= 0; i
< entropies
.size(); ++i
) {
42 hash
^= entropies
[i
].second
;
43 EXPECT_EQ(hash
, entropy_manager_
.EntropyHash(i
+ 1));
47 TEST_F(QuicSentEntropyManagerTest
, IsValidEntropy
) {
48 QuicPacketEntropyHash entropies
[10] =
49 {12, 1, 33, 3, 32, 100, 28, 42, 22, 255};
50 for (size_t i
= 0; i
< 10; ++i
) {
51 entropy_manager_
.RecordPacketEntropyHash(i
+ 1, entropies
[i
]);
54 SequenceNumberSet missing_packets
;
55 missing_packets
.insert(1);
56 missing_packets
.insert(4);
57 missing_packets
.insert(7);
58 missing_packets
.insert(8);
60 QuicPacketEntropyHash entropy_hash
= 0;
61 for (size_t i
= 0; i
< 10; ++i
) {
62 if (missing_packets
.find(i
+ 1) == missing_packets
.end()) {
63 entropy_hash
^= entropies
[i
];
67 EXPECT_TRUE(entropy_manager_
.IsValidEntropy(10, missing_packets
,