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

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

Issue 721273002: Remove timing limitation to set Broadcast, ReceiveBuffer, and SendBuffer options from UDPSocket. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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/udp/udp_socket_libevent.cc ('k') | net/udp/udp_socket_win.h » ('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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 346
347 TEST_F(UDPSocketTest, ConnectFail) { 347 TEST_F(UDPSocketTest, ConnectFail) {
348 IPEndPoint peer_address; 348 IPEndPoint peer_address;
349 CreateUDPAddress("0.0.0.0", 53, &peer_address); 349 CreateUDPAddress("0.0.0.0", 53, &peer_address);
350 350
351 scoped_ptr<UDPSocket> socket( 351 scoped_ptr<UDPSocket> socket(
352 new UDPSocket(DatagramSocket::RANDOM_BIND, 352 new UDPSocket(DatagramSocket::RANDOM_BIND,
353 base::Bind(&PrivilegedRand), 353 base::Bind(&PrivilegedRand),
354 NULL, 354 NULL,
355 NetLog::Source())); 355 NetLog::Source()));
356 int rv = socket->Connect(peer_address); 356 int rv = socket->Open(peer_address.GetFamily());
357 EXPECT_EQ(OK, rv);
358 rv = socket->Connect(peer_address);
357 // Connect should have failed since we couldn't bind to that port, 359 // Connect should have failed since we couldn't bind to that port,
358 EXPECT_NE(OK, rv); 360 EXPECT_NE(OK, rv);
359 // Make sure that UDPSocket actually closed the socket. 361 // Make sure that UDPSocket actually closed the socket.
360 EXPECT_FALSE(socket->is_connected()); 362 EXPECT_FALSE(socket->is_connected());
361 } 363 }
362 364
363 // In this test, we verify that connect() on a socket will have the effect 365 // 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 366 // of filtering reads on this socket only to data read from the destination
365 // we connected to. 367 // we connected to.
366 // 368 //
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 545
544 IPEndPoint bind_address; 546 IPEndPoint bind_address;
545 CreateUDPAddress("0.0.0.0", kPort, &bind_address); 547 CreateUDPAddress("0.0.0.0", kPort, &bind_address);
546 IPAddressNumber group_ip; 548 IPAddressNumber group_ip;
547 EXPECT_TRUE(ParseIPLiteralToNumber(kGroup, &group_ip)); 549 EXPECT_TRUE(ParseIPLiteralToNumber(kGroup, &group_ip));
548 550
549 UDPSocket socket(DatagramSocket::DEFAULT_BIND, 551 UDPSocket socket(DatagramSocket::DEFAULT_BIND,
550 RandIntCallback(), 552 RandIntCallback(),
551 NULL, 553 NULL,
552 NetLog::Source()); 554 NetLog::Source());
555 EXPECT_EQ(OK, socket.Open(bind_address.GetFamily()));
553 EXPECT_EQ(OK, socket.Bind(bind_address)); 556 EXPECT_EQ(OK, socket.Bind(bind_address));
554 EXPECT_EQ(OK, socket.JoinGroup(group_ip)); 557 EXPECT_EQ(OK, socket.JoinGroup(group_ip));
555 // Joining group multiple times. 558 // Joining group multiple times.
556 EXPECT_NE(OK, socket.JoinGroup(group_ip)); 559 EXPECT_NE(OK, socket.JoinGroup(group_ip));
557 EXPECT_EQ(OK, socket.LeaveGroup(group_ip)); 560 EXPECT_EQ(OK, socket.LeaveGroup(group_ip));
558 // Leaving group multiple times. 561 // Leaving group multiple times.
559 EXPECT_NE(OK, socket.LeaveGroup(group_ip)); 562 EXPECT_NE(OK, socket.LeaveGroup(group_ip));
560 563
561 socket.Close(); 564 socket.Close();
562 } 565 }
563 566
564 TEST_F(UDPSocketTest, MulticastOptions) { 567 TEST_F(UDPSocketTest, MulticastOptions) {
565 const uint16 kPort = 9999; 568 const uint16 kPort = 9999;
566 IPEndPoint bind_address; 569 IPEndPoint bind_address;
567 CreateUDPAddress("0.0.0.0", kPort, &bind_address); 570 CreateUDPAddress("0.0.0.0", kPort, &bind_address);
568 571
569 UDPSocket socket(DatagramSocket::DEFAULT_BIND, 572 UDPSocket socket(DatagramSocket::DEFAULT_BIND,
570 RandIntCallback(), 573 RandIntCallback(),
571 NULL, 574 NULL,
572 NetLog::Source()); 575 NetLog::Source());
573 // Before binding. 576 // Before binding.
574 EXPECT_EQ(OK, socket.SetMulticastLoopbackMode(false)); 577 EXPECT_EQ(OK, socket.SetMulticastLoopbackMode(false));
575 EXPECT_EQ(OK, socket.SetMulticastLoopbackMode(true)); 578 EXPECT_EQ(OK, socket.SetMulticastLoopbackMode(true));
576 EXPECT_EQ(OK, socket.SetMulticastTimeToLive(0)); 579 EXPECT_EQ(OK, socket.SetMulticastTimeToLive(0));
577 EXPECT_EQ(OK, socket.SetMulticastTimeToLive(3)); 580 EXPECT_EQ(OK, socket.SetMulticastTimeToLive(3));
578 EXPECT_NE(OK, socket.SetMulticastTimeToLive(-1)); 581 EXPECT_NE(OK, socket.SetMulticastTimeToLive(-1));
579 EXPECT_EQ(OK, socket.SetMulticastInterface(0)); 582 EXPECT_EQ(OK, socket.SetMulticastInterface(0));
580 583
584 EXPECT_EQ(OK, socket.Open(bind_address.GetFamily()));
581 EXPECT_EQ(OK, socket.Bind(bind_address)); 585 EXPECT_EQ(OK, socket.Bind(bind_address));
582 586
583 EXPECT_NE(OK, socket.SetMulticastLoopbackMode(false)); 587 EXPECT_NE(OK, socket.SetMulticastLoopbackMode(false));
584 EXPECT_NE(OK, socket.SetMulticastTimeToLive(0)); 588 EXPECT_NE(OK, socket.SetMulticastTimeToLive(0));
585 EXPECT_NE(OK, socket.SetMulticastInterface(0)); 589 EXPECT_NE(OK, socket.SetMulticastInterface(0));
586 590
587 socket.Close(); 591 socket.Close();
588 } 592 }
589 593
590 // Checking that DSCP bits are set correctly is difficult, 594 // Checking that DSCP bits are set correctly is difficult,
591 // but let's check that the code doesn't crash at least. 595 // but let's check that the code doesn't crash at least.
592 TEST_F(UDPSocketTest, SetDSCP) { 596 TEST_F(UDPSocketTest, SetDSCP) {
593 // Setup the server to listen. 597 // Setup the server to listen.
594 IPEndPoint bind_address; 598 IPEndPoint bind_address;
595 UDPSocket client(DatagramSocket::DEFAULT_BIND, 599 UDPSocket client(DatagramSocket::DEFAULT_BIND,
596 RandIntCallback(), 600 RandIntCallback(),
597 NULL, 601 NULL,
598 NetLog::Source()); 602 NetLog::Source());
599 // We need a real IP, but we won't actually send anything to it. 603 // We need a real IP, but we won't actually send anything to it.
600 CreateUDPAddress("8.8.8.8", 9999, &bind_address); 604 CreateUDPAddress("8.8.8.8", 9999, &bind_address);
601 int rv = client.Connect(bind_address); 605 int rv = client.Open(bind_address.GetFamily());
606 EXPECT_EQ(OK, rv);
607
608 rv = client.Connect(bind_address);
602 if (rv != OK) { 609 if (rv != OK) {
603 // Let's try localhost then.. 610 // Let's try localhost then..
604 CreateUDPAddress("127.0.0.1", 9999, &bind_address); 611 CreateUDPAddress("127.0.0.1", 9999, &bind_address);
605 rv = client.Connect(bind_address); 612 rv = client.Connect(bind_address);
606 } 613 }
607 EXPECT_EQ(OK, rv); 614 EXPECT_EQ(OK, rv);
608 615
609 client.SetDiffServCodePoint(DSCP_NO_CHANGE); 616 client.SetDiffServCodePoint(DSCP_NO_CHANGE);
610 client.SetDiffServCodePoint(DSCP_AF41); 617 client.SetDiffServCodePoint(DSCP_AF41);
611 client.SetDiffServCodePoint(DSCP_DEFAULT); 618 client.SetDiffServCodePoint(DSCP_DEFAULT);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 // Setup the server to listen. 705 // Setup the server to listen.
699 IPEndPoint bind_address; 706 IPEndPoint bind_address;
700 // We need a real IP, but we won't actually send anything to it. 707 // We need a real IP, but we won't actually send anything to it.
701 CreateUDPAddress("8.8.8.8", 9999, &bind_address); 708 CreateUDPAddress("8.8.8.8", 9999, &bind_address);
702 UDPSocket client(DatagramSocket::DEFAULT_BIND, 709 UDPSocket client(DatagramSocket::DEFAULT_BIND,
703 RandIntCallback(), 710 RandIntCallback(),
704 NULL, 711 NULL,
705 NetLog::Source()); 712 NetLog::Source());
706 int rv = client.SetDiffServCodePoint(DSCP_AF41); 713 int rv = client.SetDiffServCodePoint(DSCP_AF41);
707 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, rv); 714 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, rv);
715
716 rv = client.Open(bind_address.GetFamily());
717 EXPECT_EQ(OK, rv);
718
708 rv = client.Connect(bind_address); 719 rv = client.Connect(bind_address);
709 EXPECT_EQ(OK, rv); 720 EXPECT_EQ(OK, rv);
710 721
711 QwaveAPI& qos(QwaveAPI::Get()); 722 QwaveAPI& qos(QwaveAPI::Get());
712 qos.create_handle_func_ = FakeQOSCreateHandleFAIL; 723 qos.create_handle_func_ = FakeQOSCreateHandleFAIL;
713 qos.close_handle_func_ = FakeQOSCloseHandle; 724 qos.close_handle_func_ = FakeQOSCloseHandle;
714 qos.add_socket_to_flow_func_ = FakeQOSAddSocketToFlow; 725 qos.add_socket_to_flow_func_ = FakeQOSAddSocketToFlow;
715 qos.remove_socket_from_flow_func_ = FakeQOSRemoveSocketFromFlow; 726 qos.remove_socket_from_flow_func_ = FakeQOSRemoveSocketFromFlow;
716 qos.set_flow_func_ = FakeQOSSetFlow; 727 qos.set_flow_func_ = FakeQOSSetFlow;
717 qos.qwave_supported_ = true; 728 qos.qwave_supported_ = true;
(...skipping 14 matching lines...) Expand all
732 g_expected_traffic_type = QOSTrafficTypeExcellentEffort; 743 g_expected_traffic_type = QOSTrafficTypeExcellentEffort;
733 EXPECT_EQ(OK, client.SetDiffServCodePoint(DSCP_NO_CHANGE)); 744 EXPECT_EQ(OK, client.SetDiffServCodePoint(DSCP_NO_CHANGE));
734 g_expected_dscp = DSCP_DEFAULT; 745 g_expected_dscp = DSCP_DEFAULT;
735 g_expected_traffic_type = QOSTrafficTypeBestEffort; 746 g_expected_traffic_type = QOSTrafficTypeBestEffort;
736 EXPECT_EQ(OK, client.SetDiffServCodePoint(DSCP_DEFAULT)); 747 EXPECT_EQ(OK, client.SetDiffServCodePoint(DSCP_DEFAULT));
737 client.Close(); 748 client.Close();
738 } 749 }
739 #endif 750 #endif
740 751
741 } // namespace net 752 } // namespace net
OLDNEW
« no previous file with comments | « net/udp/udp_socket_libevent.cc ('k') | net/udp/udp_socket_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698