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

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

Issue 1535363003: Switch to standard integer types in net/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stddef Created 5 years 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/port_suggester.cc ('k') | net/quic/quic_ack_listener_interface.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/port_suggester.h" 5 #include "net/quic/port_suggester.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/basictypes.h"
10 #include "net/base/host_port_pair.h" 9 #include "net/base/host_port_pair.h"
11 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
12 11
13 namespace net { 12 namespace net {
14 namespace test { 13 namespace test {
15 14
16 class PortSuggesterTest : public ::testing::Test { 15 class PortSuggesterTest : public ::testing::Test {
17 protected: 16 protected:
18 PortSuggesterTest() 17 PortSuggesterTest()
19 : entropy_(1345689), 18 : entropy_(1345689),
20 min_ephemeral_port_(1025), 19 min_ephemeral_port_(1025),
21 max_ephemeral_port_(65535) {} 20 max_ephemeral_port_(65535) {}
22 21
23 uint64 entropy_; 22 uint64_t entropy_;
24 int min_ephemeral_port_; 23 int min_ephemeral_port_;
25 int max_ephemeral_port_; 24 int max_ephemeral_port_;
26 }; 25 };
27 26
28 TEST_F(PortSuggesterTest, SmallRangeTest) { 27 TEST_F(PortSuggesterTest, SmallRangeTest) {
29 // When the range is small (one wide), we always get that as our answer. 28 // When the range is small (one wide), we always get that as our answer.
30 scoped_refptr<PortSuggester> port_suggester = 29 scoped_refptr<PortSuggester> port_suggester =
31 new PortSuggester(HostPortPair("www.example.com", 443), entropy_); 30 new PortSuggester(HostPortPair("www.example.com", 443), entropy_);
32 // Test this for a few different (small) ranges. 31 // Test this for a few different (small) ranges.
33 for (int port = 2000; port < 2010; ++port) { 32 for (int port = 2000; port < 2010; ++port) {
34 // Use |port| for both |min| and |max| delimiting the suggestion range. 33 // Use |port| for both |min| and |max| delimiting the suggestion range.
35 EXPECT_EQ(port, port_suggester->SuggestPort(port, port)); 34 EXPECT_EQ(port, port_suggester->SuggestPort(port, port));
36 EXPECT_EQ(port, port_suggester->previous_suggestion()); 35 EXPECT_EQ(port, port_suggester->previous_suggestion());
37 } 36 }
38 } 37 }
39 38
40 TEST_F(PortSuggesterTest, SuggestAllPorts) { 39 TEST_F(PortSuggesterTest, SuggestAllPorts) {
41 // We should eventually fill out any range, but we'll just ensure that we 40 // We should eventually fill out any range, but we'll just ensure that we
42 // fill out a small range of ports. 41 // fill out a small range of ports.
43 scoped_refptr<PortSuggester> port_suggester = 42 scoped_refptr<PortSuggester> port_suggester =
44 new PortSuggester(HostPortPair("www.example.com", 443), entropy_); 43 new PortSuggester(HostPortPair("www.example.com", 443), entropy_);
45 std::set<int> ports; 44 std::set<int> ports;
46 const uint32 port_range = 20; 45 const uint32_t port_range = 20;
47 const int insertion_limit = 200; // We should be done by then. 46 const int insertion_limit = 200; // We should be done by then.
48 for (int i = 0; i < insertion_limit; ++i) { 47 for (int i = 0; i < insertion_limit; ++i) {
49 ports.insert(port_suggester->SuggestPort( 48 ports.insert(port_suggester->SuggestPort(
50 min_ephemeral_port_, min_ephemeral_port_ + port_range - 1)); 49 min_ephemeral_port_, min_ephemeral_port_ + port_range - 1));
51 if (ports.size() == port_range) { 50 if (ports.size() == port_range) {
52 break; 51 break;
53 } 52 }
54 } 53 }
55 EXPECT_EQ(port_range, ports.size()); 54 EXPECT_EQ(port_range, ports.size());
56 } 55 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 ports.insert(port_suggester[j]->SuggestPort(min_ephemeral_port_, 100 ports.insert(port_suggester[j]->SuggestPort(min_ephemeral_port_,
102 max_ephemeral_port_)); 101 max_ephemeral_port_));
103 ++insertion_count; 102 ++insertion_count;
104 } 103 }
105 } 104 }
106 EXPECT_EQ(insertion_count, ports.size()); 105 EXPECT_EQ(insertion_count, ports.size());
107 } 106 }
108 107
109 } // namespace test 108 } // namespace test
110 } // namespace net 109 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/port_suggester.cc ('k') | net/quic/quic_ack_listener_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698