Index: webrtc/p2p/base/port_unittest.cc |
diff --git a/webrtc/p2p/base/port_unittest.cc b/webrtc/p2p/base/port_unittest.cc |
index fb7fc17709539679b73d7945b7438564fd961973..0ecddf8a0aa5573d4ba2e4f8eab26358d9ae5fd2 100644 |
--- a/webrtc/p2p/base/port_unittest.cc |
+++ b/webrtc/p2p/base/port_unittest.cc |
@@ -538,6 +538,8 @@ class PortTest : public testing::Test, public sigslot::has_slots<> { |
void TestCrossFamilyPorts(int type); |
+ void TestPortsCanConnect(Port* p1, Port* p2, bool can_connect); |
+ |
// This does all the work and then deletes |port1| and |port2|. |
void TestConnectivity(const char* name1, Port* port1, |
const char* name2, Port* port2, |
@@ -1394,6 +1396,49 @@ TEST_F(PortTest, TestSkipCrossFamilyUdp) { |
TestCrossFamilyPorts(SOCK_DGRAM); |
} |
+void PortTest::TestPortsCanConnect(Port* p1, Port* p2, bool can_connect) { |
pthatcher1
2015/07/07 20:53:24
I'd call this ExpectPortsCanConnect, and make the
bemasc2
2015/07/07 21:00:35
Done.
|
+ Connection* c = p1->CreateConnection(GetCandidate(p2), |
+ Port::ORIGIN_MESSAGE); |
+ if (can_connect) { |
+ EXPECT_FALSE(NULL == c); |
+ EXPECT_EQ(1U, p1->connections().size()); |
+ } else { |
+ EXPECT_TRUE(NULL == c); |
+ EXPECT_EQ(0U, p1->connections().size()); |
+ } |
+} |
+ |
+TEST_F(PortTest, TestUdpV6CrossTypePorts) { |
+ FakePacketSocketFactory factory; |
+ scoped_ptr<Port> ports[4]; |
+ SocketAddress addresses[4] = {SocketAddress("2001:db8::1", 0), |
+ SocketAddress("fe80::1", 0), |
+ SocketAddress("fe80::2", 0), |
+ SocketAddress("::1", 0)}; |
+ for (int i = 0; i < 4; i++) { |
+ FakeAsyncPacketSocket *socket = new FakeAsyncPacketSocket(); |
+ factory.set_next_udp_socket(socket); |
+ ports[i].reset(CreateUdpPort(addresses[i], &factory)); |
+ socket->set_state(AsyncPacketSocket::STATE_BINDING); |
+ socket->SignalAddressReady(socket, addresses[i]); |
+ ports[i]->PrepareAddress(); |
+ } |
+ |
+ Port* standard = ports[0].get(); |
+ Port* link_local1 = ports[1].get(); |
+ Port* link_local2 = ports[2].get(); |
+ Port* localhost = ports[3].get(); |
+ |
+ TestPortsCanConnect(link_local1, standard, false); |
+ TestPortsCanConnect(standard, link_local1, false); |
+ TestPortsCanConnect(link_local1, localhost, false); |
+ TestPortsCanConnect(localhost, link_local1, false); |
+ |
+ TestPortsCanConnect(link_local1, link_local2, true); |
+ TestPortsCanConnect(localhost, standard, true); |
+ TestPortsCanConnect(standard, localhost, true); |
pthatcher1
2015/07/07 20:53:24
Looks nice
|
+} |
+ |
// This test verifies DSCP value set through SetOption interface can be |
// get through DefaultDscpValue. |
TEST_F(PortTest, TestDefaultDscpValue) { |