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

Side by Side Diff: net/udp/udp_socket_unittest.cc

Issue 10916052: Fixed UDP tests for MacOS X 10.7 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix. Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « chrome/test/ppapi/ppapi_browsertest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/udp/udp_client_socket.h" 5 #include "net/udp/udp_client_socket.h"
6 #include "net/udp/udp_server_socket.h" 6 #include "net/udp/udp_server_socket.h"
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 return; 124 return;
125 *address = IPEndPoint(ip_number, port); 125 *address = IPEndPoint(ip_number, port);
126 } 126 }
127 127
128 TEST_F(UDPSocketTest, Connect) { 128 TEST_F(UDPSocketTest, Connect) {
129 const int kPort = 9999; 129 const int kPort = 9999;
130 std::string simple_message("hello world!"); 130 std::string simple_message("hello world!");
131 131
132 // Setup the server to listen. 132 // Setup the server to listen.
133 IPEndPoint bind_address; 133 IPEndPoint bind_address;
134 CreateUDPAddress("0.0.0.0", kPort, &bind_address); 134 CreateUDPAddress("127.0.0.1", kPort, &bind_address);
135 CapturingNetLog server_log; 135 CapturingNetLog server_log;
136 scoped_ptr<UDPServerSocket> server( 136 scoped_ptr<UDPServerSocket> server(
137 new UDPServerSocket(&server_log, NetLog::Source())); 137 new UDPServerSocket(&server_log, NetLog::Source()));
138 server->AllowAddressReuse();
138 int rv = server->Listen(bind_address); 139 int rv = server->Listen(bind_address);
139 EXPECT_EQ(OK, rv); 140 EXPECT_EQ(OK, rv);
140 141
141 // Setup the client. 142 // Setup the client.
142 IPEndPoint server_address; 143 IPEndPoint server_address;
143 CreateUDPAddress("127.0.0.1", kPort, &server_address); 144 CreateUDPAddress("127.0.0.1", kPort, &server_address);
144 CapturingNetLog client_log; 145 CapturingNetLog client_log;
145 scoped_ptr<UDPClientSocket> client( 146 scoped_ptr<UDPClientSocket> client(
146 new UDPClientSocket(DatagramSocket::DEFAULT_BIND, 147 new UDPClientSocket(DatagramSocket::DEFAULT_BIND,
147 RandIntCallback(), 148 RandIntCallback(),
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 EXPECT_TRUE(LogContainsEndEvent( 195 EXPECT_TRUE(LogContainsEndEvent(
195 client_entries, 2, NetLog::TYPE_UDP_CONNECT)); 196 client_entries, 2, NetLog::TYPE_UDP_CONNECT));
196 EXPECT_TRUE(LogContainsEvent( 197 EXPECT_TRUE(LogContainsEvent(
197 client_entries, 3, NetLog::TYPE_UDP_BYTES_SENT, NetLog::PHASE_NONE)); 198 client_entries, 3, NetLog::TYPE_UDP_BYTES_SENT, NetLog::PHASE_NONE));
198 EXPECT_TRUE(LogContainsEvent( 199 EXPECT_TRUE(LogContainsEvent(
199 client_entries, 4, NetLog::TYPE_UDP_BYTES_RECEIVED, NetLog::PHASE_NONE)); 200 client_entries, 4, NetLog::TYPE_UDP_BYTES_RECEIVED, NetLog::PHASE_NONE));
200 EXPECT_TRUE(LogContainsEndEvent( 201 EXPECT_TRUE(LogContainsEndEvent(
201 client_entries, 5, NetLog::TYPE_SOCKET_ALIVE)); 202 client_entries, 5, NetLog::TYPE_SOCKET_ALIVE));
202 } 203 }
203 204
205 #if !defined(OS_MACOSX)
206
207 // TODO (ygorshenin): crbug.com/145487
Sergey Ulanov 2012/09/04 21:27:32 It's better to keep the test but just skip this te
ygorshenin1 2012/09/05 13:25:45 Done.
204 TEST_F(UDPSocketTest, Broadcast) { 208 TEST_F(UDPSocketTest, Broadcast) {
205 const int kPort = 9999; 209 const int kPort = 9999;
206 std::string first_message("first message"), second_message("second message"); 210 std::string first_message("first message"), second_message("second message");
207 211
208 IPEndPoint broadcast_address; 212 IPEndPoint broadcast_address;
209 CreateUDPAddress("255.255.255.255", kPort, &broadcast_address); 213 CreateUDPAddress("255.255.255.255", kPort, &broadcast_address);
210 IPEndPoint listen_address; 214 IPEndPoint listen_address;
211 CreateUDPAddress("0.0.0.0", kPort, &listen_address); 215 CreateUDPAddress("0.0.0.0", kPort, &listen_address);
212 216
213 CapturingNetLog server1_log, server2_log; 217 CapturingNetLog server1_log, server2_log;
(...skipping 19 matching lines...) Expand all
233 ASSERT_EQ(first_message, str); 237 ASSERT_EQ(first_message, str);
234 238
235 rv = SendToSocket(server2.get(), second_message, broadcast_address); 239 rv = SendToSocket(server2.get(), second_message, broadcast_address);
236 EXPECT_EQ(static_cast<int>(second_message.size()), rv); 240 EXPECT_EQ(static_cast<int>(second_message.size()), rv);
237 str = RecvFromSocket(server1.get()); 241 str = RecvFromSocket(server1.get());
238 ASSERT_EQ(second_message, str); 242 ASSERT_EQ(second_message, str);
239 str = RecvFromSocket(server2.get()); 243 str = RecvFromSocket(server2.get());
240 ASSERT_EQ(second_message, str); 244 ASSERT_EQ(second_message, str);
241 } 245 }
242 246
247 #endif
Sergey Ulanov 2012/09/04 21:27:32 add // !defined (OS_MAXOSX)
ygorshenin1 2012/09/05 13:25:45 Done.
248
243 // In this test, we verify that random binding logic works, which attempts 249 // In this test, we verify that random binding logic works, which attempts
244 // to bind to a random port and returns if succeeds, otherwise retries for 250 // to bind to a random port and returns if succeeds, otherwise retries for
245 // |kBindRetries| number of times. 251 // |kBindRetries| number of times.
246 252
247 // To generate the scenario, we first create |kBindRetries| number of 253 // To generate the scenario, we first create |kBindRetries| number of
248 // UDPClientSockets with default binding policy and connect to the same 254 // UDPClientSockets with default binding policy and connect to the same
249 // peer and save the used port numbers. Then we get rid of the last 255 // peer and save the used port numbers. Then we get rid of the last
250 // socket, making sure that the local port it was bound to is available. 256 // socket, making sure that the local port it was bound to is available.
251 // Finally, we create a socket with random binding policy, passing it a 257 // Finally, we create a socket with random binding policy, passing it a
252 // test PRNG that would serve used port numbers in the array, one after 258 // test PRNG that would serve used port numbers in the array, one after
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 // not bind the client's reads to only be from that endpoint, and that we need 334 // not bind the client's reads to only be from that endpoint, and that we need
329 // to always use recvfrom() to disambiguate. 335 // to always use recvfrom() to disambiguate.
330 TEST_F(UDPSocketTest, VerifyConnectBindsAddr) { 336 TEST_F(UDPSocketTest, VerifyConnectBindsAddr) {
331 const int kPort1 = 9999; 337 const int kPort1 = 9999;
332 const int kPort2 = 10000; 338 const int kPort2 = 10000;
333 std::string simple_message("hello world!"); 339 std::string simple_message("hello world!");
334 std::string foreign_message("BAD MESSAGE TO GET!!"); 340 std::string foreign_message("BAD MESSAGE TO GET!!");
335 341
336 // Setup the first server to listen. 342 // Setup the first server to listen.
337 IPEndPoint bind_address; 343 IPEndPoint bind_address;
338 CreateUDPAddress("0.0.0.0", kPort1, &bind_address); 344 CreateUDPAddress("127.0.0.1", kPort1, &bind_address);
339 UDPServerSocket server1(NULL, NetLog::Source()); 345 UDPServerSocket server1(NULL, NetLog::Source());
346 server1.AllowAddressReuse();
340 int rv = server1.Listen(bind_address); 347 int rv = server1.Listen(bind_address);
341 EXPECT_EQ(OK, rv); 348 EXPECT_EQ(OK, rv);
342 349
343 // Setup the second server to listen. 350 // Setup the second server to listen.
344 CreateUDPAddress("0.0.0.0", kPort2, &bind_address); 351 CreateUDPAddress("127.0.0.1", kPort2, &bind_address);
345 UDPServerSocket server2(NULL, NetLog::Source()); 352 UDPServerSocket server2(NULL, NetLog::Source());
353 server2.AllowAddressReuse();
346 rv = server2.Listen(bind_address); 354 rv = server2.Listen(bind_address);
347 EXPECT_EQ(OK, rv); 355 EXPECT_EQ(OK, rv);
348 356
349 // Setup the client, connected to server 1. 357 // Setup the client, connected to server 1.
350 IPEndPoint server_address; 358 IPEndPoint server_address;
351 CreateUDPAddress("127.0.0.1", kPort1, &server_address); 359 CreateUDPAddress("127.0.0.1", kPort1, &server_address);
352 UDPClientSocket client(DatagramSocket::DEFAULT_BIND, 360 UDPClientSocket client(DatagramSocket::DEFAULT_BIND,
353 RandIntCallback(), 361 RandIntCallback(),
354 NULL, 362 NULL,
355 NetLog::Source()); 363 NetLog::Source());
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 EXPECT_EQ(rv, ERR_IO_PENDING); 486 EXPECT_EQ(rv, ERR_IO_PENDING);
479 487
480 server.Close(); 488 server.Close();
481 489
482 EXPECT_FALSE(callback.have_result()); 490 EXPECT_FALSE(callback.have_result());
483 } 491 }
484 492
485 } // namespace 493 } // namespace
486 494
487 } // namespace net 495 } // namespace net
OLDNEW
« no previous file with comments | « chrome/test/ppapi/ppapi_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698