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

Side by Side Diff: webrtc/base/virtualsocket_unittest.cc

Issue 1274013002: Bug 4865: Enable connectivity when the remote peer is on public internet. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « no previous file | webrtc/base/virtualsocketserver.h » ('j') | webrtc/base/virtualsocketserver.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2006 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 EXPECT_EQ(post_ipv4.s_addr, pre_ipv4.s_addr); 142 EXPECT_EQ(post_ipv4.s_addr, pre_ipv4.s_addr);
143 } else if (post_ip.family() == AF_INET6) { 143 } else if (post_ip.family() == AF_INET6) {
144 in6_addr post_ip6 = post_ip.ipv6_address(); 144 in6_addr post_ip6 = post_ip.ipv6_address();
145 in6_addr pre_ip6 = pre_ip.ipv6_address(); 145 in6_addr pre_ip6 = pre_ip.ipv6_address();
146 uint32* post_as_ints = reinterpret_cast<uint32*>(&post_ip6.s6_addr); 146 uint32* post_as_ints = reinterpret_cast<uint32*>(&post_ip6.s6_addr);
147 uint32* pre_as_ints = reinterpret_cast<uint32*>(&pre_ip6.s6_addr); 147 uint32* pre_as_ints = reinterpret_cast<uint32*>(&pre_ip6.s6_addr);
148 EXPECT_EQ(post_as_ints[3], pre_as_ints[3]); 148 EXPECT_EQ(post_as_ints[3], pre_as_ints[3]);
149 } 149 }
150 } 150 }
151 151
152 // Test a client can bind to the any address, and all sent packets will have
153 // the default route as the source address. Also, it can receive packets sent
154 // to the default route.
155 void TestDefaultRoute(const IPAddress& default_route) {
156 ss_->SetDefaultRoute(default_route);
157
158 // Create client1 bound to the any address.
159 AsyncSocket* socket =
160 ss_->CreateAsyncSocket(default_route.family(), SOCK_DGRAM);
161 socket->Bind(EmptySocketAddressWithFamily(default_route.family()));
162 SocketAddress client1_any_addr = socket->GetLocalAddress();
163 EXPECT_TRUE(client1_any_addr.IsAnyIP());
164 TestClient* client1 = new TestClient(new AsyncUDPSocket(socket));
165
166 // Create client2 bound to the default route.
167 AsyncSocket* socket2 =
168 ss_->CreateAsyncSocket(default_route.family(), SOCK_DGRAM);
169 socket2->Bind(SocketAddress(default_route, 0));
170 SocketAddress client2_addr = socket2->GetLocalAddress();
171 EXPECT_FALSE(client2_addr.IsAnyIP());
172 TestClient* client2 = new TestClient(new AsyncUDPSocket(socket2));
173
174 // Client1 sends to client2, client2 should see the default route as
175 // client1's address.
176 SocketAddress client1_addr;
177 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, client2_addr));
178 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &client1_addr));
179 EXPECT_EQ(client1_addr,
180 SocketAddress(default_route, client1_any_addr.port()));
181
182 // Client2 can send back to client1's default route address.
183 EXPECT_EQ(3, client2->SendTo("foo", 3, client1_addr));
184 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &client2_addr));
185 }
186
152 void BasicTest(const SocketAddress& initial_addr) { 187 void BasicTest(const SocketAddress& initial_addr) {
153 AsyncSocket* socket = ss_->CreateAsyncSocket(initial_addr.family(), 188 AsyncSocket* socket = ss_->CreateAsyncSocket(initial_addr.family(),
154 SOCK_DGRAM); 189 SOCK_DGRAM);
155 socket->Bind(initial_addr); 190 socket->Bind(initial_addr);
156 SocketAddress server_addr = socket->GetLocalAddress(); 191 SocketAddress server_addr = socket->GetLocalAddress();
157 // Make sure VSS didn't switch families on us. 192 // Make sure VSS didn't switch families on us.
158 EXPECT_EQ(server_addr.family(), initial_addr.family()); 193 EXPECT_EQ(server_addr.family(), initial_addr.family());
159 194
160 TestClient* client1 = new TestClient(new AsyncUDPSocket(socket)); 195 TestClient* client1 = new TestClient(new AsyncUDPSocket(socket));
161 AsyncSocket* socket2 = 196 AsyncSocket* socket2 =
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 TEST_F(VirtualSocketServerTest, basic_v4) { 819 TEST_F(VirtualSocketServerTest, basic_v4) {
785 SocketAddress ipv4_test_addr(IPAddress(INADDR_ANY), 5000); 820 SocketAddress ipv4_test_addr(IPAddress(INADDR_ANY), 5000);
786 BasicTest(ipv4_test_addr); 821 BasicTest(ipv4_test_addr);
787 } 822 }
788 823
789 TEST_F(VirtualSocketServerTest, basic_v6) { 824 TEST_F(VirtualSocketServerTest, basic_v6) {
790 SocketAddress ipv6_test_addr(IPAddress(in6addr_any), 5000); 825 SocketAddress ipv6_test_addr(IPAddress(in6addr_any), 5000);
791 BasicTest(ipv6_test_addr); 826 BasicTest(ipv6_test_addr);
792 } 827 }
793 828
829 TEST_F(VirtualSocketServerTest, TestDefaultRoute_v4) {
830 IPAddress ipv4_default_addr(0x01020304);
831 TestDefaultRoute(ipv4_default_addr);
832 }
833
834 TEST_F(VirtualSocketServerTest, TestDefaultRoute_v6) {
835 IPAddress ipv6_default_addr;
836 EXPECT_TRUE(
837 IPFromString("2401:fa00:4:1000:be30:5bff:fee5:c3", &ipv6_default_addr));
838 TestDefaultRoute(ipv6_default_addr);
839 }
840
794 TEST_F(VirtualSocketServerTest, connect_v4) { 841 TEST_F(VirtualSocketServerTest, connect_v4) {
795 ConnectTest(kIPv4AnyAddress); 842 ConnectTest(kIPv4AnyAddress);
796 } 843 }
797 844
798 TEST_F(VirtualSocketServerTest, connect_v6) { 845 TEST_F(VirtualSocketServerTest, connect_v6) {
799 ConnectTest(kIPv6AnyAddress); 846 ConnectTest(kIPv6AnyAddress);
800 } 847 }
801 848
802 TEST_F(VirtualSocketServerTest, connect_to_non_listener_v4) { 849 TEST_F(VirtualSocketServerTest, connect_to_non_listener_v4) {
803 ConnectToNonListenerTest(kIPv4AnyAddress); 850 ConnectToNonListenerTest(kIPv4AnyAddress);
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 << " N=" << kTestSamples[sidx]; 1041 << " N=" << kTestSamples[sidx];
995 EXPECT_NEAR(kStdDev, stddev, 0.1 * kStdDev) 1042 EXPECT_NEAR(kStdDev, stddev, 0.1 * kStdDev)
996 << "M=" << kTestMean[midx] 1043 << "M=" << kTestMean[midx]
997 << " SD=" << kStdDev 1044 << " SD=" << kStdDev
998 << " N=" << kTestSamples[sidx]; 1045 << " N=" << kTestSamples[sidx];
999 delete f; 1046 delete f;
1000 } 1047 }
1001 } 1048 }
1002 } 1049 }
1003 } 1050 }
OLDNEW
« no previous file with comments | « no previous file | webrtc/base/virtualsocketserver.h » ('j') | webrtc/base/virtualsocketserver.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698