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

Unified Diff: net/quic/quic_packet_entropy_manager_test.cc

Issue 20227003: Land Recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Land Recent QUIC changes Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/quic_packet_entropy_manager.cc ('k') | net/quic/quic_packet_generator.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/quic_packet_entropy_manager_test.cc
diff --git a/net/quic/quic_packet_entropy_manager_test.cc b/net/quic/quic_packet_entropy_manager_test.cc
deleted file mode 100644
index 00162114e281357558f74894bfd5fff46ca03d2c..0000000000000000000000000000000000000000
--- a/net/quic/quic_packet_entropy_manager_test.cc
+++ /dev/null
@@ -1,144 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "net/quic/quic_packet_entropy_manager.h"
-
-#include <algorithm>
-#include <vector>
-
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-using std::make_pair;
-using std::pair;
-using std::vector;
-
-namespace net {
-namespace test {
-namespace {
-
-class QuicPacketEntropyManagerTest : public ::testing::Test {
- protected:
- QuicPacketEntropyManager entropy_manager_;
-};
-
-TEST_F(QuicPacketEntropyManagerTest, ReceivedPacketEntropyHash) {
- vector<pair<QuicPacketSequenceNumber, QuicPacketEntropyHash> > entropies;
- entropies.push_back(make_pair(1, 12));
- entropies.push_back(make_pair(7, 1));
- entropies.push_back(make_pair(2, 33));
- entropies.push_back(make_pair(5, 3));
- entropies.push_back(make_pair(8, 34));
-
- for (size_t i = 0; i < entropies.size(); ++i) {
- entropy_manager_.RecordReceivedPacketEntropyHash(entropies[i].first,
- entropies[i].second);
- }
-
- sort(entropies.begin(), entropies.end());
-
- QuicPacketEntropyHash hash = 0;
- size_t index = 0;
- for (size_t i = 1; i <= (*entropies.rbegin()).first; ++i) {
- if (entropies[index].first == i) {
- hash ^= entropies[index].second;
- ++index;
- }
- EXPECT_EQ(hash, entropy_manager_.ReceivedEntropyHash(i));
- }
-};
-
-TEST_F(QuicPacketEntropyManagerTest, EntropyHashBelowLeastObserved) {
- EXPECT_EQ(0, entropy_manager_.ReceivedEntropyHash(0));
- entropy_manager_.RecordReceivedPacketEntropyHash(4, 5);
- EXPECT_EQ(0, entropy_manager_.ReceivedEntropyHash(3));
-};
-
-TEST_F(QuicPacketEntropyManagerTest, EntropyHashAboveLargestObserved) {
- EXPECT_EQ(0, entropy_manager_.ReceivedEntropyHash(0));
- entropy_manager_.RecordReceivedPacketEntropyHash(4, 5);
- EXPECT_EQ(0, entropy_manager_.ReceivedEntropyHash(3));
-};
-
-TEST_F(QuicPacketEntropyManagerTest, RecalculateReceivedEntropyHash) {
- vector<pair<QuicPacketSequenceNumber, QuicPacketEntropyHash> > entropies;
- entropies.push_back(make_pair(1, 12));
- entropies.push_back(make_pair(2, 1));
- entropies.push_back(make_pair(3, 33));
- entropies.push_back(make_pair(4, 3));
- entropies.push_back(make_pair(5, 34));
- entropies.push_back(make_pair(6, 29));
-
- QuicPacketEntropyHash entropy_hash = 0;
- for (size_t i = 0; i < entropies.size(); ++i) {
- entropy_manager_.RecordReceivedPacketEntropyHash(entropies[i].first,
- entropies[i].second);
- entropy_hash ^= entropies[i].second;
- }
- EXPECT_EQ(entropy_hash, entropy_manager_.ReceivedEntropyHash(6));
-
- // Now set the entropy hash up to 4 to be 100.
- entropy_hash ^= 100;
- for (size_t i = 0; i < 3; ++i) {
- entropy_hash ^= entropies[i].second;
- }
- entropy_manager_.RecalculateReceivedEntropyHash(4, 100);
- EXPECT_EQ(entropy_hash, entropy_manager_.ReceivedEntropyHash(6));
-
- // Ensure it doesn't change with an old received sequence number or entropy.
- entropy_manager_.RecordReceivedPacketEntropyHash(1, 50);
- EXPECT_EQ(entropy_hash, entropy_manager_.ReceivedEntropyHash(6));
-
- entropy_manager_.RecalculateReceivedEntropyHash(1, 50);
- EXPECT_EQ(entropy_hash, entropy_manager_.ReceivedEntropyHash(6));
-}
-
-TEST_F(QuicPacketEntropyManagerTest, SentEntropyHash) {
- EXPECT_EQ(0, entropy_manager_.SentEntropyHash(0));
-
- vector<pair<QuicPacketSequenceNumber, QuicPacketEntropyHash> > entropies;
- entropies.push_back(make_pair(1, 12));
- entropies.push_back(make_pair(2, 1));
- entropies.push_back(make_pair(3, 33));
- entropies.push_back(make_pair(4, 3));
-
- for (size_t i = 0; i < entropies.size(); ++i) {
- entropy_manager_.RecordSentPacketEntropyHash(entropies[i].first,
- entropies[i].second);
- }
-
- QuicPacketEntropyHash hash = 0;
- for (size_t i = 0; i < entropies.size(); ++i) {
- hash ^= entropies[i].second;
- EXPECT_EQ(hash, entropy_manager_.SentEntropyHash(i + 1));
- }
-}
-
-TEST_F(QuicPacketEntropyManagerTest, IsValidEntropy) {
- QuicPacketEntropyHash entropies[10] =
- {12, 1, 33, 3, 32, 100, 28, 42, 22, 255};
- for (size_t i = 0; i < 10; ++i) {
- entropy_manager_.RecordSentPacketEntropyHash(i + 1, entropies[i]);
- }
-
- SequenceNumberSet missing_packets;
- missing_packets.insert(1);
- missing_packets.insert(4);
- missing_packets.insert(7);
- missing_packets.insert(8);
-
- QuicPacketEntropyHash entropy_hash = 0;
- for (size_t i = 0; i < 10; ++i) {
- if (missing_packets.find(i + 1) == missing_packets.end()) {
- entropy_hash ^= entropies[i];
- }
- }
-
- EXPECT_TRUE(entropy_manager_.IsValidEntropy(10, missing_packets,
- entropy_hash));
-}
-
-} // namespace
-} // namespace test
-} // namespace net
« no previous file with comments | « net/quic/quic_packet_entropy_manager.cc ('k') | net/quic/quic_packet_generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698