Chromium Code Reviews| 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 |
| 11 #include <math.h> | 11 #include <math.h> |
| 12 #include <time.h> | 12 #include <time.h> |
| 13 #if defined(WEBRTC_POSIX) | 13 #if defined(WEBRTC_POSIX) |
| 14 #include <netinet/in.h> | 14 #include <netinet/in.h> |
| 15 #endif | 15 #endif |
| 16 | 16 |
| 17 #include <memory> | 17 #include <memory> |
| 18 | 18 |
| 19 #include "webrtc/base/arraysize.h" | 19 #include "webrtc/base/arraysize.h" |
| 20 #include "webrtc/base/gunit.h" | |
| 20 #include "webrtc/base/logging.h" | 21 #include "webrtc/base/logging.h" |
| 21 #include "webrtc/base/gunit.h" | 22 #include "webrtc/base/ptr_util.h" |
| 22 #include "webrtc/base/testclient.h" | 23 #include "webrtc/base/testclient.h" |
| 23 #include "webrtc/base/testutils.h" | 24 #include "webrtc/base/testutils.h" |
| 24 #include "webrtc/base/thread.h" | 25 #include "webrtc/base/thread.h" |
| 25 #include "webrtc/base/timeutils.h" | 26 #include "webrtc/base/timeutils.h" |
| 26 #include "webrtc/base/virtualsocketserver.h" | 27 #include "webrtc/base/virtualsocketserver.h" |
| 27 | 28 |
| 28 using namespace rtc; | 29 using namespace rtc; |
| 29 | 30 |
| 30 using webrtc::testing::SSE_CLOSE; | 31 using webrtc::testing::SSE_CLOSE; |
| 31 using webrtc::testing::SSE_ERROR; | 32 using webrtc::testing::SSE_ERROR; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 // to the default route. | 174 // to the default route. |
| 174 void TestDefaultRoute(const IPAddress& default_route) { | 175 void TestDefaultRoute(const IPAddress& default_route) { |
| 175 ss_->SetDefaultRoute(default_route); | 176 ss_->SetDefaultRoute(default_route); |
| 176 | 177 |
| 177 // Create client1 bound to the any address. | 178 // Create client1 bound to the any address. |
| 178 AsyncSocket* socket = | 179 AsyncSocket* socket = |
| 179 ss_->CreateAsyncSocket(default_route.family(), SOCK_DGRAM); | 180 ss_->CreateAsyncSocket(default_route.family(), SOCK_DGRAM); |
| 180 socket->Bind(EmptySocketAddressWithFamily(default_route.family())); | 181 socket->Bind(EmptySocketAddressWithFamily(default_route.family())); |
| 181 SocketAddress client1_any_addr = socket->GetLocalAddress(); | 182 SocketAddress client1_any_addr = socket->GetLocalAddress(); |
| 182 EXPECT_TRUE(client1_any_addr.IsAnyIP()); | 183 EXPECT_TRUE(client1_any_addr.IsAnyIP()); |
| 183 TestClient* client1 = new TestClient(new AsyncUDPSocket(socket)); | 184 std::unique_ptr<TestClient> client1( |
| 185 new TestClient(MakeUnique<AsyncUDPSocket>(socket))); | |
|
kwiberg-webrtc
2017/05/05 11:04:42
Why not use MakeUnique for TestClient too?
auto
nisse-webrtc
2017/05/05 12:12:56
Done. I take it you don't want to see any use of t
kwiberg-webrtc
2017/05/05 12:40:31
No; as I said in an earlier comment, I think consi
| |
| 184 | 186 |
| 185 // Create client2 bound to the default route. | 187 // Create client2 bound to the default route. |
| 186 AsyncSocket* socket2 = | 188 AsyncSocket* socket2 = |
| 187 ss_->CreateAsyncSocket(default_route.family(), SOCK_DGRAM); | 189 ss_->CreateAsyncSocket(default_route.family(), SOCK_DGRAM); |
| 188 socket2->Bind(SocketAddress(default_route, 0)); | 190 socket2->Bind(SocketAddress(default_route, 0)); |
| 189 SocketAddress client2_addr = socket2->GetLocalAddress(); | 191 SocketAddress client2_addr = socket2->GetLocalAddress(); |
| 190 EXPECT_FALSE(client2_addr.IsAnyIP()); | 192 EXPECT_FALSE(client2_addr.IsAnyIP()); |
| 191 TestClient* client2 = new TestClient(new AsyncUDPSocket(socket2)); | 193 std::unique_ptr<TestClient> client2( |
| 194 new TestClient(MakeUnique<AsyncUDPSocket>(socket2))); | |
| 192 | 195 |
| 193 // Client1 sends to client2, client2 should see the default route as | 196 // Client1 sends to client2, client2 should see the default route as |
| 194 // client1's address. | 197 // client1's address. |
| 195 SocketAddress client1_addr; | 198 SocketAddress client1_addr; |
| 196 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, client2_addr)); | 199 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, client2_addr)); |
| 197 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &client1_addr)); | 200 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &client1_addr)); |
| 198 EXPECT_EQ(client1_addr, | 201 EXPECT_EQ(client1_addr, |
| 199 SocketAddress(default_route, client1_any_addr.port())); | 202 SocketAddress(default_route, client1_any_addr.port())); |
| 200 | 203 |
| 201 // Client2 can send back to client1's default route address. | 204 // Client2 can send back to client1's default route address. |
| 202 EXPECT_EQ(3, client2->SendTo("foo", 3, client1_addr)); | 205 EXPECT_EQ(3, client2->SendTo("foo", 3, client1_addr)); |
| 203 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &client2_addr)); | 206 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &client2_addr)); |
| 204 } | 207 } |
| 205 | 208 |
| 206 void BasicTest(const SocketAddress& initial_addr) { | 209 void BasicTest(const SocketAddress& initial_addr) { |
| 207 AsyncSocket* socket = ss_->CreateAsyncSocket(initial_addr.family(), | 210 AsyncSocket* socket = ss_->CreateAsyncSocket(initial_addr.family(), |
| 208 SOCK_DGRAM); | 211 SOCK_DGRAM); |
| 209 socket->Bind(initial_addr); | 212 socket->Bind(initial_addr); |
| 210 SocketAddress server_addr = socket->GetLocalAddress(); | 213 SocketAddress server_addr = socket->GetLocalAddress(); |
| 211 // Make sure VSS didn't switch families on us. | 214 // Make sure VSS didn't switch families on us. |
| 212 EXPECT_EQ(server_addr.family(), initial_addr.family()); | 215 EXPECT_EQ(server_addr.family(), initial_addr.family()); |
| 213 | 216 |
| 214 TestClient* client1 = new TestClient(new AsyncUDPSocket(socket)); | 217 std::unique_ptr<TestClient> client1( |
| 218 new TestClient(MakeUnique<AsyncUDPSocket>(socket))); | |
| 215 AsyncSocket* socket2 = | 219 AsyncSocket* socket2 = |
| 216 ss_->CreateAsyncSocket(initial_addr.family(), SOCK_DGRAM); | 220 ss_->CreateAsyncSocket(initial_addr.family(), SOCK_DGRAM); |
| 217 TestClient* client2 = new TestClient(new AsyncUDPSocket(socket2)); | 221 std::unique_ptr<TestClient> client2( |
| 222 new TestClient(MakeUnique<AsyncUDPSocket>(socket2))); | |
| 218 | 223 |
| 219 SocketAddress client2_addr; | 224 SocketAddress client2_addr; |
| 220 EXPECT_EQ(3, client2->SendTo("foo", 3, server_addr)); | 225 EXPECT_EQ(3, client2->SendTo("foo", 3, server_addr)); |
| 221 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &client2_addr)); | 226 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &client2_addr)); |
| 222 | 227 |
| 223 SocketAddress client1_addr; | 228 SocketAddress client1_addr; |
| 224 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, client2_addr)); | 229 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, client2_addr)); |
| 225 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &client1_addr)); | 230 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &client1_addr)); |
| 226 EXPECT_EQ(client1_addr, server_addr); | 231 EXPECT_EQ(client1_addr, server_addr); |
| 227 | 232 |
| 228 SocketAddress empty = EmptySocketAddressWithFamily(initial_addr.family()); | 233 SocketAddress empty = EmptySocketAddressWithFamily(initial_addr.family()); |
| 229 for (int i = 0; i < 10; i++) { | 234 for (int i = 0; i < 10; i++) { |
| 230 client2 = new TestClient(AsyncUDPSocket::Create(ss_, empty)); | 235 client2.reset( |
| 236 new TestClient(WrapUnique(AsyncUDPSocket::Create(ss_, empty)))); | |
| 231 | 237 |
| 232 SocketAddress next_client2_addr; | 238 SocketAddress next_client2_addr; |
| 233 EXPECT_EQ(3, client2->SendTo("foo", 3, server_addr)); | 239 EXPECT_EQ(3, client2->SendTo("foo", 3, server_addr)); |
| 234 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &next_client2_addr)); | 240 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &next_client2_addr)); |
| 235 CheckPortIncrementalization(next_client2_addr, client2_addr); | 241 CheckPortIncrementalization(next_client2_addr, client2_addr); |
| 236 // EXPECT_EQ(next_client2_addr.port(), client2_addr.port() + 1); | 242 // EXPECT_EQ(next_client2_addr.port(), client2_addr.port() + 1); |
| 237 | 243 |
| 238 SocketAddress server_addr2; | 244 SocketAddress server_addr2; |
| 239 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, next_client2_addr)); | 245 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, next_client2_addr)); |
| 240 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &server_addr2)); | 246 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &server_addr2)); |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 794 | 800 |
| 795 // Test cross-family datagram sending between a client bound to client_addr | 801 // Test cross-family datagram sending between a client bound to client_addr |
| 796 // and a server bound to server_addr. shouldSucceed indicates if sending is | 802 // and a server bound to server_addr. shouldSucceed indicates if sending is |
| 797 // expected to succeed or not. | 803 // expected to succeed or not. |
| 798 void CrossFamilyDatagramTest(const SocketAddress& client_addr, | 804 void CrossFamilyDatagramTest(const SocketAddress& client_addr, |
| 799 const SocketAddress& server_addr, | 805 const SocketAddress& server_addr, |
| 800 bool shouldSucceed) { | 806 bool shouldSucceed) { |
| 801 AsyncSocket* socket = ss_->CreateAsyncSocket(SOCK_DGRAM); | 807 AsyncSocket* socket = ss_->CreateAsyncSocket(SOCK_DGRAM); |
| 802 socket->Bind(server_addr); | 808 socket->Bind(server_addr); |
| 803 SocketAddress bound_server_addr = socket->GetLocalAddress(); | 809 SocketAddress bound_server_addr = socket->GetLocalAddress(); |
| 804 TestClient* client1 = new TestClient(new AsyncUDPSocket(socket)); | 810 std::unique_ptr<TestClient> client1( |
| 811 new TestClient(MakeUnique<AsyncUDPSocket>(socket))); | |
| 805 | 812 |
| 806 AsyncSocket* socket2 = ss_->CreateAsyncSocket(SOCK_DGRAM); | 813 AsyncSocket* socket2 = ss_->CreateAsyncSocket(SOCK_DGRAM); |
| 807 socket2->Bind(client_addr); | 814 socket2->Bind(client_addr); |
| 808 TestClient* client2 = new TestClient(new AsyncUDPSocket(socket2)); | 815 std::unique_ptr<TestClient> client2( |
| 816 new TestClient(MakeUnique<AsyncUDPSocket>(socket2))); | |
| 809 SocketAddress client2_addr; | 817 SocketAddress client2_addr; |
| 810 | 818 |
| 811 if (shouldSucceed) { | 819 if (shouldSucceed) { |
| 812 EXPECT_EQ(3, client2->SendTo("foo", 3, bound_server_addr)); | 820 EXPECT_EQ(3, client2->SendTo("foo", 3, bound_server_addr)); |
| 813 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &client2_addr)); | 821 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &client2_addr)); |
| 814 SocketAddress client1_addr; | 822 SocketAddress client1_addr; |
| 815 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, client2_addr)); | 823 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, client2_addr)); |
| 816 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &client1_addr)); | 824 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &client1_addr)); |
| 817 EXPECT_EQ(client1_addr, bound_server_addr); | 825 EXPECT_EQ(client1_addr, bound_server_addr); |
| 818 } else { | 826 } else { |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1023 true); | 1031 true); |
| 1024 } | 1032 } |
| 1025 | 1033 |
| 1026 TEST_F(VirtualSocketServerTest, SetSendingBlockedWithUdpSocket) { | 1034 TEST_F(VirtualSocketServerTest, SetSendingBlockedWithUdpSocket) { |
| 1027 AsyncSocket* socket1 = | 1035 AsyncSocket* socket1 = |
| 1028 ss_->CreateAsyncSocket(kIPv4AnyAddress.family(), SOCK_DGRAM); | 1036 ss_->CreateAsyncSocket(kIPv4AnyAddress.family(), SOCK_DGRAM); |
| 1029 AsyncSocket* socket2 = | 1037 AsyncSocket* socket2 = |
| 1030 ss_->CreateAsyncSocket(kIPv4AnyAddress.family(), SOCK_DGRAM); | 1038 ss_->CreateAsyncSocket(kIPv4AnyAddress.family(), SOCK_DGRAM); |
| 1031 socket1->Bind(kIPv4AnyAddress); | 1039 socket1->Bind(kIPv4AnyAddress); |
| 1032 socket2->Bind(kIPv4AnyAddress); | 1040 socket2->Bind(kIPv4AnyAddress); |
| 1033 TestClient* client1 = new TestClient(new AsyncUDPSocket(socket1)); | 1041 std::unique_ptr<TestClient> client1( |
| 1042 new TestClient(MakeUnique<AsyncUDPSocket>(socket1))); | |
| 1034 | 1043 |
| 1035 ss_->SetSendingBlocked(true); | 1044 ss_->SetSendingBlocked(true); |
| 1036 EXPECT_EQ(-1, client1->SendTo("foo", 3, socket2->GetLocalAddress())); | 1045 EXPECT_EQ(-1, client1->SendTo("foo", 3, socket2->GetLocalAddress())); |
| 1037 EXPECT_TRUE(socket1->IsBlocking()); | 1046 EXPECT_TRUE(socket1->IsBlocking()); |
| 1038 EXPECT_EQ(0, client1->ready_to_send_count()); | 1047 EXPECT_EQ(0, client1->ready_to_send_count()); |
| 1039 | 1048 |
| 1040 ss_->SetSendingBlocked(false); | 1049 ss_->SetSendingBlocked(false); |
| 1041 EXPECT_EQ(1, client1->ready_to_send_count()); | 1050 EXPECT_EQ(1, client1->ready_to_send_count()); |
| 1042 EXPECT_EQ(3, client1->SendTo("foo", 3, socket2->GetLocalAddress())); | 1051 EXPECT_EQ(3, client1->SendTo("foo", 3, socket2->GetLocalAddress())); |
| 1043 } | 1052 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1120 << " N=" << kTestSamples[sidx]; | 1129 << " N=" << kTestSamples[sidx]; |
| 1121 EXPECT_NEAR(kStdDev, stddev, 0.1 * kStdDev) | 1130 EXPECT_NEAR(kStdDev, stddev, 0.1 * kStdDev) |
| 1122 << "M=" << kTestMean[midx] | 1131 << "M=" << kTestMean[midx] |
| 1123 << " SD=" << kStdDev | 1132 << " SD=" << kStdDev |
| 1124 << " N=" << kTestSamples[sidx]; | 1133 << " N=" << kTestSamples[sidx]; |
| 1125 delete f; | 1134 delete f; |
| 1126 } | 1135 } |
| 1127 } | 1136 } |
| 1128 } | 1137 } |
| 1129 } | 1138 } |
| OLD | NEW |