Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: net/quic/quic_sent_entropy_manager_test.cc

Issue 992733002: Remove //net (except for Android test stuff) and sdch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_sent_entropy_manager.cc ('k') | net/quic/quic_sent_packet_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 using std::make_pair;
13 using std::pair;
14
15 namespace net {
16 namespace test {
17 namespace {
18
19 class QuicSentEntropyManagerTest : public ::testing::Test {
20 protected:
21 QuicSentEntropyManager entropy_manager_;
22 };
23
24 TEST_F(QuicSentEntropyManagerTest, SentEntropyHash) {
25 EXPECT_EQ(0, entropy_manager_.GetCumulativeEntropy(0));
26
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]);
30 }
31
32 QuicPacketEntropyHash hash = 0;
33 for (size_t i = 0; i < arraysize(entropies); ++i) {
34 hash ^= entropies[i];
35 EXPECT_EQ(hash, entropy_manager_.GetCumulativeEntropy(i + 1));
36 }
37 }
38
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]);
44 }
45
46 SequenceNumberSet missing_packets;
47 missing_packets.insert(1);
48 missing_packets.insert(4);
49 missing_packets.insert(7);
50 missing_packets.insert(8);
51
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];
56 }
57 }
58
59 EXPECT_TRUE(entropy_manager_.IsValidEntropy(10, missing_packets,
60 entropy_hash));
61 }
62
63 TEST_F(QuicSentEntropyManagerTest, ClearEntropiesBefore) {
64 QuicPacketEntropyHash entropies[10] =
65 {12, 1, 33, 3, 32, 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 SequenceNumberSet missing_packets;
76 missing_packets.insert(7);
77 missing_packets.insert(8);
78
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];
83 }
84 }
85 EXPECT_TRUE(entropy_manager_.IsValidEntropy(10, missing_packets,
86 entropy_hash));
87
88 entropy_hash = 0;
89 for (size_t i = 0; i < arraysize(entropies); ++i) {
90 entropy_hash ^= entropies[i];
91 }
92 EXPECT_EQ(entropy_hash, entropy_manager_.GetCumulativeEntropy(10));
93 }
94
95 } // namespace
96 } // namespace test
97 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_sent_entropy_manager.cc ('k') | net/quic/quic_sent_packet_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698