OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/guid.h" | 8 #include "base/guid.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 ASSERT_EQ(kOk, status.code()) << status.message(); | 181 ASSERT_EQ(kOk, status.code()) << status.message(); |
182 ASSERT_EQ(port, 12345); | 182 ASSERT_EQ(port, 12345); |
183 | 183 |
184 RunServer(path, "12346\n", &request); | 184 RunServer(path, "12346\n", &request); |
185 status = server.ReservePort(&port, &reservation); | 185 status = server.ReservePort(&port, &reservation); |
186 ASSERT_EQ(kOk, status.code()) << status.message(); | 186 ASSERT_EQ(kOk, status.code()) << status.message(); |
187 ASSERT_EQ(port, 12346); | 187 ASSERT_EQ(port, 12346); |
188 } | 188 } |
189 #endif | 189 #endif |
190 | 190 |
191 TEST(PortManagerTest, Reserve) { | 191 TEST(PortManagerTest, ReservePort) { |
192 PortManager mgr(15000, 16000); | 192 PortManager mgr(15000, 16000); |
193 int port = 0; | 193 int port = 0; |
194 scoped_ptr<PortReservation> reservation; | 194 scoped_ptr<PortReservation> reservation; |
195 Status status = mgr.ReservePort(&port, &reservation); | 195 Status status = mgr.ReservePort(&port, &reservation); |
196 ASSERT_EQ(kOk, status.code()) << status.message(); | 196 ASSERT_EQ(kOk, status.code()) << status.message(); |
197 | 197 |
198 ASSERT_GE(port, 15000); | 198 ASSERT_GE(port, 15000); |
199 ASSERT_LE(port, 16000); | 199 ASSERT_LE(port, 16000); |
200 ASSERT_TRUE(reservation); | 200 ASSERT_TRUE(reservation); |
201 } | 201 } |
| 202 |
| 203 TEST(PortManagerTest, ReservePortFromPool) { |
| 204 PortManager mgr(15000, 16000); |
| 205 int first_port = 0, port = 1; |
| 206 for (int i = 0; i < 10; i++) { |
| 207 scoped_ptr<PortReservation> reservation; |
| 208 Status status = mgr.ReservePortFromPool(&port, &reservation); |
| 209 ASSERT_EQ(kOk, status.code()) << status.message(); |
| 210 ASSERT_TRUE(reservation); |
| 211 ASSERT_GE(port, 15000); |
| 212 ASSERT_LE(port, 16000); |
| 213 if (i == 0) |
| 214 first_port = port; |
| 215 ASSERT_EQ(port, first_port); |
| 216 } |
| 217 } |
OLD | NEW |