| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, Reserve) { |
| 192 PortManager mgr(15000, 16000); | 192 PortManager mgr(15000, 16000, false); |
| 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, Reuse) { |
| 204 PortManager mgr(15000, 16000, true); |
| 205 int first_port = 0, port = 1; |
| 206 for (int i = 0; i < 10; i++) |
| 207 { |
| 208 scoped_ptr<PortReservation> reservation; |
| 209 Status status = mgr.ReservePort(&port, &reservation); |
| 210 ASSERT_EQ(kOk, status.code()) << status.message(); |
| 211 ASSERT_TRUE(reservation); |
| 212 ASSERT_GE(port, 15000); |
| 213 ASSERT_LE(port, 16000); |
| 214 if (i == 0) |
| 215 first_port = port; |
| 216 else |
| 217 ASSERT_EQ(port, first_port); |
| 218 } |
| 219 } |
| OLD | NEW |