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

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

Issue 754433003: Update from https://crrev.com/305340 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « net/tools/quic/test_tools/quic_test_utils.h ('k') | net/udp/udp_socket_win.cc » ('j') | 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_socket.h" 5 #include "net/udp/udp_socket.h"
6 6
7 #include "net/udp/udp_client_socket.h" 7 #include "net/udp/udp_client_socket.h"
8 #include "net/udp/udp_server_socket.h" 8 #include "net/udp/udp_server_socket.h"
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 return bytes_sent; 112 return bytes_sent;
113 } 113 }
114 114
115 protected: 115 protected:
116 static const int kMaxRead = 1024; 116 static const int kMaxRead = 1024;
117 scoped_refptr<IOBufferWithSize> buffer_; 117 scoped_refptr<IOBufferWithSize> buffer_;
118 IPEndPoint recv_from_address_; 118 IPEndPoint recv_from_address_;
119 }; 119 };
120 120
121 // Creates and address from an ip/port and returns it in |address|. 121 // Creates and address from an ip/port and returns it in |address|.
122 void CreateUDPAddress(std::string ip_str, int port, IPEndPoint* address) { 122 void CreateUDPAddress(std::string ip_str, uint16 port, IPEndPoint* address) {
123 IPAddressNumber ip_number; 123 IPAddressNumber ip_number;
124 bool rv = ParseIPLiteralToNumber(ip_str, &ip_number); 124 bool rv = ParseIPLiteralToNumber(ip_str, &ip_number);
125 if (!rv) 125 if (!rv)
126 return; 126 return;
127 *address = IPEndPoint(ip_number, port); 127 *address = IPEndPoint(ip_number, port);
128 } 128 }
129 129
130 TEST_F(UDPSocketTest, Connect) { 130 TEST_F(UDPSocketTest, Connect) {
131 const int kPort = 9999; 131 const uint16 kPort = 9999;
132 std::string simple_message("hello world!"); 132 std::string simple_message("hello world!");
133 133
134 // Setup the server to listen. 134 // Setup the server to listen.
135 IPEndPoint bind_address; 135 IPEndPoint bind_address;
136 CreateUDPAddress("127.0.0.1", kPort, &bind_address); 136 CreateUDPAddress("127.0.0.1", kPort, &bind_address);
137 CapturingNetLog server_log; 137 CapturingNetLog server_log;
138 scoped_ptr<UDPServerSocket> server( 138 scoped_ptr<UDPServerSocket> server(
139 new UDPServerSocket(&server_log, NetLog::Source())); 139 new UDPServerSocket(&server_log, NetLog::Source()));
140 server->AllowAddressReuse(); 140 server->AllowAddressReuse();
141 int rv = server->Listen(bind_address); 141 int rv = server->Listen(bind_address);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // root permissions on OSX 10.7+. 209 // root permissions on OSX 10.7+.
210 TEST_F(UDPSocketTest, DISABLED_Broadcast) { 210 TEST_F(UDPSocketTest, DISABLED_Broadcast) {
211 #elif defined(OS_ANDROID) 211 #elif defined(OS_ANDROID)
212 // It is also disabled for Android because it is extremely flaky. 212 // It is also disabled for Android because it is extremely flaky.
213 // The first call to SendToSocket returns -109 (Address not reachable) 213 // The first call to SendToSocket returns -109 (Address not reachable)
214 // in some unpredictable cases. crbug.com/139144. 214 // in some unpredictable cases. crbug.com/139144.
215 TEST_F(UDPSocketTest, DISABLED_Broadcast) { 215 TEST_F(UDPSocketTest, DISABLED_Broadcast) {
216 #else 216 #else
217 TEST_F(UDPSocketTest, Broadcast) { 217 TEST_F(UDPSocketTest, Broadcast) {
218 #endif 218 #endif
219 const int kPort = 9999; 219 const uint16 kPort = 9999;
220 std::string first_message("first message"), second_message("second message"); 220 std::string first_message("first message"), second_message("second message");
221 221
222 IPEndPoint broadcast_address; 222 IPEndPoint broadcast_address;
223 CreateUDPAddress("255.255.255.255", kPort, &broadcast_address); 223 CreateUDPAddress("255.255.255.255", kPort, &broadcast_address);
224 IPEndPoint listen_address; 224 IPEndPoint listen_address;
225 CreateUDPAddress("0.0.0.0", kPort, &listen_address); 225 CreateUDPAddress("0.0.0.0", kPort, &listen_address);
226 226
227 CapturingNetLog server1_log, server2_log; 227 CapturingNetLog server1_log, server2_log;
228 scoped_ptr<UDPServerSocket> server1( 228 scoped_ptr<UDPServerSocket> server1(
229 new UDPServerSocket(&server1_log, NetLog::Source())); 229 new UDPServerSocket(&server1_log, NetLog::Source()));
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 362
363 // In this test, we verify that connect() on a socket will have the effect 363 // In this test, we verify that connect() on a socket will have the effect
364 // of filtering reads on this socket only to data read from the destination 364 // of filtering reads on this socket only to data read from the destination
365 // we connected to. 365 // we connected to.
366 // 366 //
367 // The purpose of this test is that some documentation indicates that connect 367 // The purpose of this test is that some documentation indicates that connect
368 // binds the client's sends to send to a particular server endpoint, but does 368 // binds the client's sends to send to a particular server endpoint, but does
369 // not bind the client's reads to only be from that endpoint, and that we need 369 // not bind the client's reads to only be from that endpoint, and that we need
370 // to always use recvfrom() to disambiguate. 370 // to always use recvfrom() to disambiguate.
371 TEST_F(UDPSocketTest, VerifyConnectBindsAddr) { 371 TEST_F(UDPSocketTest, VerifyConnectBindsAddr) {
372 const int kPort1 = 9999; 372 const uint16 kPort1 = 9999;
373 const int kPort2 = 10000; 373 const uint16 kPort2 = 10000;
374 std::string simple_message("hello world!"); 374 std::string simple_message("hello world!");
375 std::string foreign_message("BAD MESSAGE TO GET!!"); 375 std::string foreign_message("BAD MESSAGE TO GET!!");
376 376
377 // Setup the first server to listen. 377 // Setup the first server to listen.
378 IPEndPoint bind_address; 378 IPEndPoint bind_address;
379 CreateUDPAddress("127.0.0.1", kPort1, &bind_address); 379 CreateUDPAddress("127.0.0.1", kPort1, &bind_address);
380 UDPServerSocket server1(NULL, NetLog::Source()); 380 UDPServerSocket server1(NULL, NetLog::Source());
381 server1.AllowAddressReuse(); 381 server1.AllowAddressReuse();
382 int rv = server1.Listen(bind_address); 382 int rv = server1.Listen(bind_address);
383 ASSERT_EQ(OK, rv); 383 ASSERT_EQ(OK, rv);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 #if defined(OS_ANDROID) 531 #if defined(OS_ANDROID)
532 // Some Android devices do not support multicast socket. 532 // Some Android devices do not support multicast socket.
533 // The ones supporting multicast need WifiManager.MulitcastLock to enable it. 533 // The ones supporting multicast need WifiManager.MulitcastLock to enable it.
534 // http://goo.gl/jjAk9 534 // http://goo.gl/jjAk9
535 #define MAYBE_JoinMulticastGroup DISABLED_JoinMulticastGroup 535 #define MAYBE_JoinMulticastGroup DISABLED_JoinMulticastGroup
536 #else 536 #else
537 #define MAYBE_JoinMulticastGroup JoinMulticastGroup 537 #define MAYBE_JoinMulticastGroup JoinMulticastGroup
538 #endif // defined(OS_ANDROID) 538 #endif // defined(OS_ANDROID)
539 539
540 TEST_F(UDPSocketTest, MAYBE_JoinMulticastGroup) { 540 TEST_F(UDPSocketTest, MAYBE_JoinMulticastGroup) {
541 const int kPort = 9999; 541 const uint16 kPort = 9999;
542 const char* const kGroup = "237.132.100.17"; 542 const char* const kGroup = "237.132.100.17";
543 543
544 IPEndPoint bind_address; 544 IPEndPoint bind_address;
545 CreateUDPAddress("0.0.0.0", kPort, &bind_address); 545 CreateUDPAddress("0.0.0.0", kPort, &bind_address);
546 IPAddressNumber group_ip; 546 IPAddressNumber group_ip;
547 EXPECT_TRUE(ParseIPLiteralToNumber(kGroup, &group_ip)); 547 EXPECT_TRUE(ParseIPLiteralToNumber(kGroup, &group_ip));
548 548
549 UDPSocket socket(DatagramSocket::DEFAULT_BIND, 549 UDPSocket socket(DatagramSocket::DEFAULT_BIND,
550 RandIntCallback(), 550 RandIntCallback(),
551 NULL, 551 NULL,
552 NetLog::Source()); 552 NetLog::Source());
553 EXPECT_EQ(OK, socket.Bind(bind_address)); 553 EXPECT_EQ(OK, socket.Bind(bind_address));
554 EXPECT_EQ(OK, socket.JoinGroup(group_ip)); 554 EXPECT_EQ(OK, socket.JoinGroup(group_ip));
555 // Joining group multiple times. 555 // Joining group multiple times.
556 EXPECT_NE(OK, socket.JoinGroup(group_ip)); 556 EXPECT_NE(OK, socket.JoinGroup(group_ip));
557 EXPECT_EQ(OK, socket.LeaveGroup(group_ip)); 557 EXPECT_EQ(OK, socket.LeaveGroup(group_ip));
558 // Leaving group multiple times. 558 // Leaving group multiple times.
559 EXPECT_NE(OK, socket.LeaveGroup(group_ip)); 559 EXPECT_NE(OK, socket.LeaveGroup(group_ip));
560 560
561 socket.Close(); 561 socket.Close();
562 } 562 }
563 563
564 TEST_F(UDPSocketTest, MulticastOptions) { 564 TEST_F(UDPSocketTest, MulticastOptions) {
565 const int kPort = 9999; 565 const uint16 kPort = 9999;
566 IPEndPoint bind_address; 566 IPEndPoint bind_address;
567 CreateUDPAddress("0.0.0.0", kPort, &bind_address); 567 CreateUDPAddress("0.0.0.0", kPort, &bind_address);
568 568
569 UDPSocket socket(DatagramSocket::DEFAULT_BIND, 569 UDPSocket socket(DatagramSocket::DEFAULT_BIND,
570 RandIntCallback(), 570 RandIntCallback(),
571 NULL, 571 NULL,
572 NetLog::Source()); 572 NetLog::Source());
573 // Before binding. 573 // Before binding.
574 EXPECT_EQ(OK, socket.SetMulticastLoopbackMode(false)); 574 EXPECT_EQ(OK, socket.SetMulticastLoopbackMode(false));
575 EXPECT_EQ(OK, socket.SetMulticastLoopbackMode(true)); 575 EXPECT_EQ(OK, socket.SetMulticastLoopbackMode(true));
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 g_expected_traffic_type = QOSTrafficTypeExcellentEffort; 732 g_expected_traffic_type = QOSTrafficTypeExcellentEffort;
733 EXPECT_EQ(OK, client.SetDiffServCodePoint(DSCP_NO_CHANGE)); 733 EXPECT_EQ(OK, client.SetDiffServCodePoint(DSCP_NO_CHANGE));
734 g_expected_dscp = DSCP_DEFAULT; 734 g_expected_dscp = DSCP_DEFAULT;
735 g_expected_traffic_type = QOSTrafficTypeBestEffort; 735 g_expected_traffic_type = QOSTrafficTypeBestEffort;
736 EXPECT_EQ(OK, client.SetDiffServCodePoint(DSCP_DEFAULT)); 736 EXPECT_EQ(OK, client.SetDiffServCodePoint(DSCP_DEFAULT));
737 client.Close(); 737 client.Close();
738 } 738 }
739 #endif 739 #endif
740 740
741 } // namespace net 741 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/test_tools/quic_test_utils.h ('k') | net/udp/udp_socket_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698