OLD | NEW |
---|---|
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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 size_t sec_count; | 139 size_t sec_count; |
140 double sum; | 140 double sum; |
141 double sum_sq; | 141 double sum_sq; |
142 uint32_t samples; | 142 uint32_t samples; |
143 }; | 143 }; |
144 | 144 |
145 class VirtualSocketServerTest : public testing::Test { | 145 class VirtualSocketServerTest : public testing::Test { |
146 public: | 146 public: |
147 VirtualSocketServerTest() | 147 VirtualSocketServerTest() |
148 : ss_(new VirtualSocketServer(nullptr)), | 148 : ss_(new VirtualSocketServer(nullptr)), |
149 thread_(ss_.get()), | |
149 kIPv4AnyAddress(IPAddress(INADDR_ANY), 0), | 150 kIPv4AnyAddress(IPAddress(INADDR_ANY), 0), |
150 kIPv6AnyAddress(IPAddress(in6addr_any), 0) {} | 151 kIPv6AnyAddress(IPAddress(in6addr_any), 0) {} |
151 | 152 |
152 void CheckPortIncrementalization(const SocketAddress& post, | 153 void CheckPortIncrementalization(const SocketAddress& post, |
153 const SocketAddress& pre) { | 154 const SocketAddress& pre) { |
154 EXPECT_EQ(post.port(), pre.port() + 1); | 155 EXPECT_EQ(post.port(), pre.port() + 1); |
155 IPAddress post_ip = post.ipaddr(); | 156 IPAddress post_ip = post.ipaddr(); |
156 IPAddress pre_ip = pre.ipaddr(); | 157 IPAddress pre_ip = pre.ipaddr(); |
157 EXPECT_EQ(pre_ip.family(), post_ip.family()); | 158 EXPECT_EQ(pre_ip.family(), post_ip.family()); |
158 if (post_ip.family() == AF_INET) { | 159 if (post_ip.family() == AF_INET) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, client2_addr)); | 197 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, client2_addr)); |
197 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &client1_addr)); | 198 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &client1_addr)); |
198 EXPECT_EQ(client1_addr, | 199 EXPECT_EQ(client1_addr, |
199 SocketAddress(default_route, client1_any_addr.port())); | 200 SocketAddress(default_route, client1_any_addr.port())); |
200 | 201 |
201 // Client2 can send back to client1's default route address. | 202 // Client2 can send back to client1's default route address. |
202 EXPECT_EQ(3, client2->SendTo("foo", 3, client1_addr)); | 203 EXPECT_EQ(3, client2->SendTo("foo", 3, client1_addr)); |
203 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &client2_addr)); | 204 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &client2_addr)); |
204 } | 205 } |
205 | 206 |
206 void BasicTest(const SocketAddress& initial_addr) { | 207 void BasicTest(const SocketAddress& initial_addr) { |
nisse-webrtc
2017/05/05 07:58:36
I don't see how this test can ever have passed the
Taylor Brandstetter
2017/05/05 08:47:46
My guess is that Thread indirectly references the
| |
207 AsyncSocket* socket = ss_->CreateAsyncSocket(initial_addr.family(), | 208 AsyncSocket* socket = ss_->CreateAsyncSocket(initial_addr.family(), |
208 SOCK_DGRAM); | 209 SOCK_DGRAM); |
209 socket->Bind(initial_addr); | 210 socket->Bind(initial_addr); |
210 SocketAddress server_addr = socket->GetLocalAddress(); | 211 SocketAddress server_addr = socket->GetLocalAddress(); |
211 // Make sure VSS didn't switch families on us. | 212 // Make sure VSS didn't switch families on us. |
212 EXPECT_EQ(server_addr.family(), initial_addr.family()); | 213 EXPECT_EQ(server_addr.family(), initial_addr.family()); |
213 | 214 |
214 TestClient* client1 = new TestClient(new AsyncUDPSocket(socket)); | 215 TestClient* client1 = new TestClient(new AsyncUDPSocket(socket)); |
215 AsyncSocket* socket2 = | 216 AsyncSocket* socket2 = |
216 ss_->CreateAsyncSocket(initial_addr.family(), SOCK_DGRAM); | 217 ss_->CreateAsyncSocket(initial_addr.family(), SOCK_DGRAM); |
217 TestClient* client2 = new TestClient(new AsyncUDPSocket(socket2)); | 218 TestClient* client2 = new TestClient(new AsyncUDPSocket(socket2)); |
218 | 219 |
219 SocketAddress client2_addr; | 220 SocketAddress client2_addr; |
220 EXPECT_EQ(3, client2->SendTo("foo", 3, server_addr)); | 221 EXPECT_EQ(3, client2->SendTo("foo", 3, server_addr)); |
221 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &client2_addr)); | 222 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &client2_addr)); |
222 | 223 |
223 SocketAddress client1_addr; | 224 SocketAddress client1_addr; |
224 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, client2_addr)); | 225 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, client2_addr)); |
225 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &client1_addr)); | 226 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &client1_addr)); |
226 EXPECT_EQ(client1_addr, server_addr); | 227 EXPECT_EQ(client1_addr, server_addr); |
227 | 228 |
228 SocketAddress empty = EmptySocketAddressWithFamily(initial_addr.family()); | 229 SocketAddress empty = EmptySocketAddressWithFamily(initial_addr.family()); |
229 for (int i = 0; i < 10; i++) { | 230 for (int i = 0; i < 10; i++) { |
230 client2 = new TestClient(AsyncUDPSocket::Create(ss_, empty)); | 231 client2 = new TestClient(AsyncUDPSocket::Create(ss_.get(), empty)); |
231 | 232 |
232 SocketAddress next_client2_addr; | 233 SocketAddress next_client2_addr; |
233 EXPECT_EQ(3, client2->SendTo("foo", 3, server_addr)); | 234 EXPECT_EQ(3, client2->SendTo("foo", 3, server_addr)); |
234 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &next_client2_addr)); | 235 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &next_client2_addr)); |
235 CheckPortIncrementalization(next_client2_addr, client2_addr); | 236 CheckPortIncrementalization(next_client2_addr, client2_addr); |
236 // EXPECT_EQ(next_client2_addr.port(), client2_addr.port() + 1); | 237 // EXPECT_EQ(next_client2_addr.port(), client2_addr.port() + 1); |
237 | 238 |
238 SocketAddress server_addr2; | 239 SocketAddress server_addr2; |
239 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, next_client2_addr)); | 240 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, next_client2_addr)); |
240 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &server_addr2)); | 241 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &server_addr2)); |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
815 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, client2_addr)); | 816 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, client2_addr)); |
816 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &client1_addr)); | 817 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &client1_addr)); |
817 EXPECT_EQ(client1_addr, bound_server_addr); | 818 EXPECT_EQ(client1_addr, bound_server_addr); |
818 } else { | 819 } else { |
819 EXPECT_EQ(-1, client2->SendTo("foo", 3, bound_server_addr)); | 820 EXPECT_EQ(-1, client2->SendTo("foo", 3, bound_server_addr)); |
820 EXPECT_TRUE(client1->CheckNoPacket()); | 821 EXPECT_TRUE(client1->CheckNoPacket()); |
821 } | 822 } |
822 } | 823 } |
823 | 824 |
824 protected: | 825 protected: |
825 virtual void SetUp() { | 826 std::unique_ptr<VirtualSocketServer> ss_; |
826 Thread::Current()->set_socketserver(ss_); | 827 AutoSocketServerThread thread_; |
827 } | |
828 virtual void TearDown() { Thread::Current()->set_socketserver(nullptr); } | |
829 | |
830 VirtualSocketServer* ss_; | |
831 const SocketAddress kIPv4AnyAddress; | 828 const SocketAddress kIPv4AnyAddress; |
832 const SocketAddress kIPv6AnyAddress; | 829 const SocketAddress kIPv6AnyAddress; |
833 }; | 830 }; |
834 | 831 |
835 TEST_F(VirtualSocketServerTest, basic_v4) { | 832 TEST_F(VirtualSocketServerTest, basic_v4) { |
836 SocketAddress ipv4_test_addr(IPAddress(INADDR_ANY), 5000); | 833 SocketAddress ipv4_test_addr(IPAddress(INADDR_ANY), 5000); |
837 BasicTest(ipv4_test_addr); | 834 BasicTest(ipv4_test_addr); |
838 } | 835 } |
839 | 836 |
840 TEST_F(VirtualSocketServerTest, basic_v6) { | 837 TEST_F(VirtualSocketServerTest, basic_v6) { |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1120 << " N=" << kTestSamples[sidx]; | 1117 << " N=" << kTestSamples[sidx]; |
1121 EXPECT_NEAR(kStdDev, stddev, 0.1 * kStdDev) | 1118 EXPECT_NEAR(kStdDev, stddev, 0.1 * kStdDev) |
1122 << "M=" << kTestMean[midx] | 1119 << "M=" << kTestMean[midx] |
1123 << " SD=" << kStdDev | 1120 << " SD=" << kStdDev |
1124 << " N=" << kTestSamples[sidx]; | 1121 << " N=" << kTestSamples[sidx]; |
1125 delete f; | 1122 delete f; |
1126 } | 1123 } |
1127 } | 1124 } |
1128 } | 1125 } |
1129 } | 1126 } |
OLD | NEW |