OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 case PROTO_UDP: return "gturn(udp)"; | 531 case PROTO_UDP: return "gturn(udp)"; |
532 case PROTO_TCP: return "gturn(tcp)"; | 532 case PROTO_TCP: return "gturn(tcp)"; |
533 case PROTO_SSLTCP: return "gturn(ssltcp)"; | 533 case PROTO_SSLTCP: return "gturn(ssltcp)"; |
534 default: return "gturn(?)"; | 534 default: return "gturn(?)"; |
535 } | 535 } |
536 } | 536 } |
537 } | 537 } |
538 | 538 |
539 void TestCrossFamilyPorts(int type); | 539 void TestCrossFamilyPorts(int type); |
540 | 540 |
| 541 void ExpectPortsCanConnect(bool can_connect, Port* p1, Port* p2); |
| 542 |
541 // This does all the work and then deletes |port1| and |port2|. | 543 // This does all the work and then deletes |port1| and |port2|. |
542 void TestConnectivity(const char* name1, Port* port1, | 544 void TestConnectivity(const char* name1, Port* port1, |
543 const char* name2, Port* port2, | 545 const char* name2, Port* port2, |
544 bool accept, bool same_addr1, | 546 bool accept, bool same_addr1, |
545 bool same_addr2, bool possible); | 547 bool same_addr2, bool possible); |
546 | 548 |
547 // This connects the provided channels which have already started. |ch1| | 549 // This connects the provided channels which have already started. |ch1| |
548 // should have its Connection created (either through CreateConnection() or | 550 // should have its Connection created (either through CreateConnection() or |
549 // TCP reconnecting mechanism before entering this function. | 551 // TCP reconnecting mechanism before entering this function. |
550 void ConnectStartedChannels(TestChannel* ch1, TestChannel* ch2) { | 552 void ConnectStartedChannels(TestChannel* ch1, TestChannel* ch2) { |
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1387 } | 1389 } |
1388 | 1390 |
1389 TEST_F(PortTest, TestSkipCrossFamilyTcp) { | 1391 TEST_F(PortTest, TestSkipCrossFamilyTcp) { |
1390 TestCrossFamilyPorts(SOCK_STREAM); | 1392 TestCrossFamilyPorts(SOCK_STREAM); |
1391 } | 1393 } |
1392 | 1394 |
1393 TEST_F(PortTest, TestSkipCrossFamilyUdp) { | 1395 TEST_F(PortTest, TestSkipCrossFamilyUdp) { |
1394 TestCrossFamilyPorts(SOCK_DGRAM); | 1396 TestCrossFamilyPorts(SOCK_DGRAM); |
1395 } | 1397 } |
1396 | 1398 |
| 1399 void PortTest::ExpectPortsCanConnect(bool can_connect, Port* p1, Port* p2) { |
| 1400 Connection* c = p1->CreateConnection(GetCandidate(p2), |
| 1401 Port::ORIGIN_MESSAGE); |
| 1402 if (can_connect) { |
| 1403 EXPECT_FALSE(NULL == c); |
| 1404 EXPECT_EQ(1U, p1->connections().size()); |
| 1405 } else { |
| 1406 EXPECT_TRUE(NULL == c); |
| 1407 EXPECT_EQ(0U, p1->connections().size()); |
| 1408 } |
| 1409 } |
| 1410 |
| 1411 TEST_F(PortTest, TestUdpV6CrossTypePorts) { |
| 1412 FakePacketSocketFactory factory; |
| 1413 scoped_ptr<Port> ports[4]; |
| 1414 SocketAddress addresses[4] = {SocketAddress("2001:db8::1", 0), |
| 1415 SocketAddress("fe80::1", 0), |
| 1416 SocketAddress("fe80::2", 0), |
| 1417 SocketAddress("::1", 0)}; |
| 1418 for (int i = 0; i < 4; i++) { |
| 1419 FakeAsyncPacketSocket *socket = new FakeAsyncPacketSocket(); |
| 1420 factory.set_next_udp_socket(socket); |
| 1421 ports[i].reset(CreateUdpPort(addresses[i], &factory)); |
| 1422 socket->set_state(AsyncPacketSocket::STATE_BINDING); |
| 1423 socket->SignalAddressReady(socket, addresses[i]); |
| 1424 ports[i]->PrepareAddress(); |
| 1425 } |
| 1426 |
| 1427 Port* standard = ports[0].get(); |
| 1428 Port* link_local1 = ports[1].get(); |
| 1429 Port* link_local2 = ports[2].get(); |
| 1430 Port* localhost = ports[3].get(); |
| 1431 |
| 1432 ExpectPortsCanConnect(false, link_local1, standard); |
| 1433 ExpectPortsCanConnect(false, standard, link_local1); |
| 1434 ExpectPortsCanConnect(false, link_local1, localhost); |
| 1435 ExpectPortsCanConnect(false, localhost, link_local1); |
| 1436 |
| 1437 ExpectPortsCanConnect(true, link_local1, link_local2); |
| 1438 ExpectPortsCanConnect(true, localhost, standard); |
| 1439 ExpectPortsCanConnect(true, standard, localhost); |
| 1440 } |
| 1441 |
1397 // This test verifies DSCP value set through SetOption interface can be | 1442 // This test verifies DSCP value set through SetOption interface can be |
1398 // get through DefaultDscpValue. | 1443 // get through DefaultDscpValue. |
1399 TEST_F(PortTest, TestDefaultDscpValue) { | 1444 TEST_F(PortTest, TestDefaultDscpValue) { |
1400 int dscp; | 1445 int dscp; |
1401 rtc::scoped_ptr<UDPPort> udpport(CreateUdpPort(kLocalAddr1)); | 1446 rtc::scoped_ptr<UDPPort> udpport(CreateUdpPort(kLocalAddr1)); |
1402 EXPECT_EQ(0, udpport->SetOption(rtc::Socket::OPT_DSCP, | 1447 EXPECT_EQ(0, udpport->SetOption(rtc::Socket::OPT_DSCP, |
1403 rtc::DSCP_CS6)); | 1448 rtc::DSCP_CS6)); |
1404 EXPECT_EQ(0, udpport->GetOption(rtc::Socket::OPT_DSCP, &dscp)); | 1449 EXPECT_EQ(0, udpport->GetOption(rtc::Socket::OPT_DSCP, &dscp)); |
1405 rtc::scoped_ptr<TCPPort> tcpport(CreateTcpPort(kLocalAddr1)); | 1450 rtc::scoped_ptr<TCPPort> tcpport(CreateTcpPort(kLocalAddr1)); |
1406 EXPECT_EQ(0, tcpport->SetOption(rtc::Socket::OPT_DSCP, | 1451 EXPECT_EQ(0, tcpport->SetOption(rtc::Socket::OPT_DSCP, |
(...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2596 // Set up channels and ensure both ports will be deleted. | 2641 // Set up channels and ensure both ports will be deleted. |
2597 TestChannel ch1(port1, port2); | 2642 TestChannel ch1(port1, port2); |
2598 TestChannel ch2(port2, port1); | 2643 TestChannel ch2(port2, port1); |
2599 | 2644 |
2600 // Simulate a connection that succeeds, and then is destroyed. | 2645 // Simulate a connection that succeeds, and then is destroyed. |
2601 StartConnectAndStopChannels(&ch1, &ch2); | 2646 StartConnectAndStopChannels(&ch1, &ch2); |
2602 | 2647 |
2603 // The controlled port should be destroyed after 10 milliseconds. | 2648 // The controlled port should be destroyed after 10 milliseconds. |
2604 EXPECT_TRUE_WAIT(destroyed(), kTimeout); | 2649 EXPECT_TRUE_WAIT(destroyed(), kTimeout); |
2605 } | 2650 } |
OLD | NEW |