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 { | |
craigdh
2014/01/09 01:45:06
google style guide has { on the same line as the f
frankf
2014/01/09 01:55:19
Done.
| |
208 scoped_ptr<PortReservation> reservation; | |
209 Status status = mgr.ReservePortFromPool(&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 ASSERT_EQ(port, first_port); | |
217 } | |
218 } | |
OLD | NEW |