Chromium Code Reviews| 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 TEST_F(UDPSocketTest, JoinMulticastGroup) { | |
| 530 const int kPort = 9999; | |
| 531 IPEndPoint bind_address; | |
| 532 CreateUDPAddress("0.0.0.0", kPort, &bind_address); | |
| 533 | |
| 534 const char* kGroup = "237.132.100.17"; | |
|
wtc
2013/04/17 22:06:50
This should be
const char* const kGroup = ...;
s
Bei Zhang
2013/04/19 19:40:14
Done.
| |
| 535 net::IPAddressNumber group_ip; | |
|
wtc
2013/04/17 22:06:50
Remove net:: because this is inside the net namesp
Bei Zhang
2013/04/19 19:40:14
Done.
| |
| 536 EXPECT_TRUE(net::ParseIPLiteralToNumber(kGroup, &group_ip)); | |
| 537 | |
| 538 scoped_ptr<UDPSocket> socket( | |
| 539 new UDPSocket(DatagramSocket::DEFAULT_BIND, | |
| 540 RandIntCallback(), | |
| 541 NULL, | |
| 542 NetLog::Source())); | |
|
wtc
2013/04/17 22:06:50
Nit: it doesn't seem necessary to use a scoped_ptr
Bei Zhang
2013/04/19 19:40:14
Done.
| |
| 543 EXPECT_EQ(OK, socket->Bind(bind_address)); | |
| 544 EXPECT_EQ(OK, socket->JoinGroup(group_ip)); | |
| 545 // Joining group multiple times. | |
| 546 EXPECT_EQ(ERR_ADDRESS_IN_USE, socket->JoinGroup(group_ip)); | |
| 547 EXPECT_EQ(OK, socket->LeaveGroup(group_ip)); | |
| 548 // Leaving group multiple times. | |
| 549 EXPECT_EQ(ERR_ADDRESS_INVALID, socket->LeaveGroup(group_ip)); | |
| 550 | |
| 551 socket->Close(); | |
| 552 } | |
| 553 | |
| 554 TEST_F(UDPSocketTest, MulticastOptions) { | |
| 555 const int kPort = 9999; | |
| 556 IPEndPoint bind_address; | |
| 557 CreateUDPAddress("0.0.0.0", kPort, &bind_address); | |
| 558 | |
| 559 scoped_ptr<UDPSocket> socket( | |
| 560 new UDPSocket(DatagramSocket::DEFAULT_BIND, | |
| 561 RandIntCallback(), | |
| 562 NULL, | |
| 563 NetLog::Source())); | |
| 564 // Before binding. | |
| 565 EXPECT_EQ(OK, socket->SetMulticastLoopbackMode(false)); | |
| 566 EXPECT_EQ(OK, socket->SetMulticastLoopbackMode(true)); | |
| 567 EXPECT_EQ(OK, socket->SetMulticastTimeToLive(0)); | |
| 568 EXPECT_EQ(OK, socket->SetMulticastTimeToLive(3)); | |
| 569 EXPECT_EQ(ERR_INVALID_ARGUMENT, socket->SetMulticastTimeToLive(-1)); | |
| 570 | |
| 571 EXPECT_EQ(OK, socket->Bind(bind_address)); | |
| 572 | |
| 573 socket->Close(); | |
| 574 } | |
| 575 | |
| 529 } // namespace | 576 } // namespace |
| 530 | 577 |
| 531 } // namespace net | 578 } // namespace net |
| OLD | NEW |