OLD | NEW |
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 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 TestCompletionCallback callback; | 519 TestCompletionCallback callback; |
520 IPEndPoint from; | 520 IPEndPoint from; |
521 rv = server.RecvFrom(buffer_, kMaxRead, &from, callback.callback()); | 521 rv = server.RecvFrom(buffer_, kMaxRead, &from, callback.callback()); |
522 EXPECT_EQ(rv, ERR_IO_PENDING); | 522 EXPECT_EQ(rv, ERR_IO_PENDING); |
523 | 523 |
524 server.Close(); | 524 server.Close(); |
525 | 525 |
526 EXPECT_FALSE(callback.have_result()); | 526 EXPECT_FALSE(callback.have_result()); |
527 } | 527 } |
528 | 528 |
| 529 #if defined(OS_ANDROID) |
| 530 // Some Android devices do not support multicast socket. |
| 531 // The ones supporting multicast need WifiManager.MulitcastLock to enable it. |
| 532 // http://goo.gl/jjAk9 |
| 533 #define MAYBE_JoinMulticastGroup DISABLED_JoinMulticastGroup |
| 534 #else |
| 535 #define MAYBE_JoinMulticastGroup JoinMulticastGroup |
| 536 #endif // defined(OS_ANDROID) |
| 537 |
| 538 TEST_F(UDPSocketTest, MAYBE_UDPSocketTest) { |
| 539 const int kPort = 9999; |
| 540 const char* const kGroup = "237.132.100.17"; |
| 541 |
| 542 IPEndPoint bind_address; |
| 543 CreateUDPAddress("0.0.0.0", kPort, &bind_address); |
| 544 IPAddressNumber group_ip; |
| 545 EXPECT_TRUE(ParseIPLiteralToNumber(kGroup, &group_ip)); |
| 546 |
| 547 UDPSocket socket(DatagramSocket::DEFAULT_BIND, |
| 548 RandIntCallback(), |
| 549 NULL, |
| 550 NetLog::Source()); |
| 551 EXPECT_EQ(OK, socket.Bind(bind_address)); |
| 552 EXPECT_EQ(OK, socket.JoinGroup(group_ip)); |
| 553 // Joining group multiple times. |
| 554 EXPECT_NE(OK, socket.JoinGroup(group_ip)); |
| 555 EXPECT_EQ(OK, socket.LeaveGroup(group_ip)); |
| 556 // Leaving group multiple times. |
| 557 EXPECT_NE(OK, socket.LeaveGroup(group_ip)); |
| 558 |
| 559 socket.Close(); |
| 560 } |
| 561 |
| 562 TEST_F(UDPSocketTest, MulticastOptions) { |
| 563 const int kPort = 9999; |
| 564 IPEndPoint bind_address; |
| 565 CreateUDPAddress("0.0.0.0", kPort, &bind_address); |
| 566 |
| 567 UDPSocket socket(DatagramSocket::DEFAULT_BIND, |
| 568 RandIntCallback(), |
| 569 NULL, |
| 570 NetLog::Source()); |
| 571 // Before binding. |
| 572 EXPECT_EQ(OK, socket.SetMulticastLoopbackMode(false)); |
| 573 EXPECT_EQ(OK, socket.SetMulticastLoopbackMode(true)); |
| 574 EXPECT_EQ(OK, socket.SetMulticastTimeToLive(0)); |
| 575 EXPECT_EQ(OK, socket.SetMulticastTimeToLive(3)); |
| 576 EXPECT_NE(OK, socket.SetMulticastTimeToLive(-1)); |
| 577 |
| 578 EXPECT_EQ(OK, socket.Bind(bind_address)); |
| 579 |
| 580 socket.Close(); |
| 581 } |
| 582 |
529 } // namespace | 583 } // namespace |
530 | 584 |
531 } // namespace net | 585 } // namespace net |
OLD | NEW |