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

Side by Side Diff: chrome/test/chromedriver/net/port_server_unittest.cc

Issue 1548153002: Switch to standard integer types in chrome/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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 unified diff | Download patch
OLDNEW
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 <stddef.h>
6 #include <stdint.h>
7 #include <string.h>
8
5 #include <string> 9 #include <string>
6 10
7 #include "base/bind.h" 11 #include "base/bind.h"
8 #include "base/guid.h" 12 #include "base/guid.h"
9 #include "base/location.h" 13 #include "base/location.h"
10 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
11 #include "base/sync_socket.h" 15 #include "base/sync_socket.h"
12 #include "base/synchronization/waitable_event.h" 16 #include "base/synchronization/waitable_event.h"
13 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
14 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "build/build_config.h"
15 #include "chrome/test/chromedriver/chrome/status.h" 20 #include "chrome/test/chromedriver/chrome/status.h"
16 #include "chrome/test/chromedriver/net/port_server.h" 21 #include "chrome/test/chromedriver/net/port_server.h"
17 #include "net/base/sys_addrinfo.h" 22 #include "net/base/sys_addrinfo.h"
18 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
19 24
20 #if defined(OS_LINUX) 25 #if defined(OS_LINUX)
21 #include <fcntl.h> 26 #include <fcntl.h>
22 #include <sys/socket.h> 27 #include <sys/socket.h>
23 #include <sys/un.h> 28 #include <sys/un.h>
24 #endif 29 #endif
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 base::Thread thread_; 139 base::Thread thread_;
135 }; 140 };
136 141
137 TEST_F(PortServerTest, Reserve) { 142 TEST_F(PortServerTest, Reserve) {
138 std::string path = GenerateRandomPath(); 143 std::string path = GenerateRandomPath();
139 PortServer server(path); 144 PortServer server(path);
140 145
141 std::string request; 146 std::string request;
142 RunServer(path, "12345\n", &request); 147 RunServer(path, "12345\n", &request);
143 148
144 uint16 port = 0; 149 uint16_t port = 0;
145 scoped_ptr<PortReservation> reservation; 150 scoped_ptr<PortReservation> reservation;
146 Status status = server.ReservePort(&port, &reservation); 151 Status status = server.ReservePort(&port, &reservation);
147 ASSERT_EQ(kOk, status.code()) << status.message(); 152 ASSERT_EQ(kOk, status.code()) << status.message();
148 ASSERT_EQ(12345u, port); 153 ASSERT_EQ(12345u, port);
149 } 154 }
150 155
151 TEST_F(PortServerTest, ReserveResetReserve) { 156 TEST_F(PortServerTest, ReserveResetReserve) {
152 std::string path = GenerateRandomPath(); 157 std::string path = GenerateRandomPath();
153 PortServer server(path); 158 PortServer server(path);
154 159
155 std::string request; 160 std::string request;
156 RunServer(path, "12345\n", &request); 161 RunServer(path, "12345\n", &request);
157 162
158 uint16 port = 0; 163 uint16_t port = 0;
159 scoped_ptr<PortReservation> reservation; 164 scoped_ptr<PortReservation> reservation;
160 Status status = server.ReservePort(&port, &reservation); 165 Status status = server.ReservePort(&port, &reservation);
161 ASSERT_EQ(kOk, status.code()) << status.message(); 166 ASSERT_EQ(kOk, status.code()) << status.message();
162 ASSERT_EQ(12345u, port); 167 ASSERT_EQ(12345u, port);
163 168
164 reservation.reset(); 169 reservation.reset();
165 status = server.ReservePort(&port, &reservation); 170 status = server.ReservePort(&port, &reservation);
166 ASSERT_EQ(kOk, status.code()) << status.message(); 171 ASSERT_EQ(kOk, status.code()) << status.message();
167 ASSERT_EQ(12345u, port); 172 ASSERT_EQ(12345u, port);
168 } 173 }
169 174
170 TEST_F(PortServerTest, ReserveReserve) { 175 TEST_F(PortServerTest, ReserveReserve) {
171 std::string path = GenerateRandomPath(); 176 std::string path = GenerateRandomPath();
172 PortServer server(path); 177 PortServer server(path);
173 178
174 std::string request; 179 std::string request;
175 RunServer(path, "12345\n", &request); 180 RunServer(path, "12345\n", &request);
176 181
177 uint16 port = 0; 182 uint16_t port = 0;
178 scoped_ptr<PortReservation> reservation; 183 scoped_ptr<PortReservation> reservation;
179 Status status = server.ReservePort(&port, &reservation); 184 Status status = server.ReservePort(&port, &reservation);
180 ASSERT_EQ(kOk, status.code()) << status.message(); 185 ASSERT_EQ(kOk, status.code()) << status.message();
181 ASSERT_EQ(12345u, port); 186 ASSERT_EQ(12345u, port);
182 187
183 RunServer(path, "12346\n", &request); 188 RunServer(path, "12346\n", &request);
184 status = server.ReservePort(&port, &reservation); 189 status = server.ReservePort(&port, &reservation);
185 ASSERT_EQ(kOk, status.code()) << status.message(); 190 ASSERT_EQ(kOk, status.code()) << status.message();
186 ASSERT_EQ(12346u, port); 191 ASSERT_EQ(12346u, port);
187 } 192 }
188 #endif 193 #endif
189 194
190 TEST(PortManagerTest, ReservePort) { 195 TEST(PortManagerTest, ReservePort) {
191 PortManager mgr(15000, 16000); 196 PortManager mgr(15000, 16000);
192 uint16 port = 0; 197 uint16_t port = 0;
193 scoped_ptr<PortReservation> reservation; 198 scoped_ptr<PortReservation> reservation;
194 Status status = mgr.ReservePort(&port, &reservation); 199 Status status = mgr.ReservePort(&port, &reservation);
195 ASSERT_EQ(kOk, status.code()) << status.message(); 200 ASSERT_EQ(kOk, status.code()) << status.message();
196 201
197 ASSERT_GE(port, 15000); 202 ASSERT_GE(port, 15000);
198 ASSERT_LE(port, 16000); 203 ASSERT_LE(port, 16000);
199 ASSERT_TRUE(reservation); 204 ASSERT_TRUE(reservation);
200 } 205 }
201 206
202 TEST(PortManagerTest, ReservePortFromPool) { 207 TEST(PortManagerTest, ReservePortFromPool) {
203 PortManager mgr(15000, 16000); 208 PortManager mgr(15000, 16000);
204 uint16 first_port = 0, port = 1; 209 uint16_t first_port = 0, port = 1;
205 for (int i = 0; i < 10; i++) { 210 for (int i = 0; i < 10; i++) {
206 scoped_ptr<PortReservation> reservation; 211 scoped_ptr<PortReservation> reservation;
207 Status status = mgr.ReservePortFromPool(&port, &reservation); 212 Status status = mgr.ReservePortFromPool(&port, &reservation);
208 ASSERT_EQ(kOk, status.code()) << status.message(); 213 ASSERT_EQ(kOk, status.code()) << status.message();
209 ASSERT_TRUE(reservation); 214 ASSERT_TRUE(reservation);
210 ASSERT_GE(port, 15000); 215 ASSERT_GE(port, 15000);
211 ASSERT_LE(port, 16000); 216 ASSERT_LE(port, 16000);
212 if (i == 0) 217 if (i == 0)
213 first_port = port; 218 first_port = port;
214 ASSERT_EQ(port, first_port); 219 ASSERT_EQ(port, first_port);
215 } 220 }
216 } 221 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/net/port_server.cc ('k') | chrome/test/chromedriver/net/sync_websocket_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698