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

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

Issue 12684008: Multicast socket API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix code style Created 7 years, 8 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
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 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
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";
535 net::IPAddressNumber groupIp;
mmenke 2013/04/16 18:09:49 nit: group_ip
Bei Zhang 2013/04/17 17:53:03 Done.
536 EXPECT_TRUE(net::ParseIPLiteralToNumber(kGroup, &groupIp));
537
538 scoped_ptr<UDPSocket> socket(
539 new UDPSocket(DatagramSocket::DEFAULT_BIND,
540 RandIntCallback(),
541 NULL,
542 NetLog::Source()));
543 EXPECT_EQ(OK, socket->Bind(bind_address));
544 EXPECT_EQ(OK, socket->JoinGroup(groupIp));
545 EXPECT_NE(OK, socket->JoinGroup(groupIp)); // Joining group multiple times.
546 EXPECT_EQ(OK, socket->LeaveGroup(groupIp));
547 EXPECT_NE(OK, socket->LeaveGroup(groupIp)); // Leaving group multiple times.
548
549 socket->Close();
550 }
551
552 TEST_F(UDPSocketTest, MulticastOptions) {
553 const int kPort = 9999;
554 IPEndPoint bind_address;
555 CreateUDPAddress("0.0.0.0", kPort, &bind_address);
556
557 scoped_ptr<UDPSocket> socket(
558 new UDPSocket(DatagramSocket::DEFAULT_BIND,
559 RandIntCallback(),
560 NULL,
561 NetLog::Source()));
562 // Before binding.
563 EXPECT_EQ(OK, socket->SetMulticastLoopbackMode(false));
564 EXPECT_EQ(OK, socket->SetMulticastLoopbackMode(true));
565 EXPECT_EQ(OK, socket->SetMulticastTimeToLive(0));
566 EXPECT_EQ(OK, socket->SetMulticastTimeToLive(3));
567 EXPECT_NE(OK, socket->SetMulticastTimeToLive(-1));
568
569 EXPECT_EQ(OK, socket->Bind(bind_address));
570
571 // After 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 socket->Close();
579 }
580
529 } // namespace 581 } // namespace
530 582
531 } // namespace net 583 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698