| 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 "webrtc/base/testclient.h" |
| 11 #include "webrtc/base/gunit.h" | 12 #include "webrtc/base/gunit.h" |
| 12 #include "webrtc/base/nethelpers.h" | 13 #include "webrtc/base/nethelpers.h" |
| 13 #include "webrtc/base/physicalsocketserver.h" | 14 #include "webrtc/base/physicalsocketserver.h" |
| 14 #include "webrtc/base/testclient.h" | 15 #include "webrtc/base/ptr_util.h" |
| 15 #include "webrtc/base/testechoserver.h" | 16 #include "webrtc/base/testechoserver.h" |
| 16 #include "webrtc/base/thread.h" | 17 #include "webrtc/base/thread.h" |
| 17 | 18 |
| 18 using namespace rtc; | 19 using namespace rtc; |
| 19 | 20 |
| 20 void TestUdpInternal(const SocketAddress& loopback) { | 21 void TestUdpInternal(const SocketAddress& loopback) { |
| 21 Thread *main = Thread::Current(); | 22 Thread *main = Thread::Current(); |
| 22 AsyncSocket* socket = main->socketserver() | 23 AsyncSocket* socket = main->socketserver() |
| 23 ->CreateAsyncSocket(loopback.family(), SOCK_DGRAM); | 24 ->CreateAsyncSocket(loopback.family(), SOCK_DGRAM); |
| 24 socket->Bind(loopback); | 25 socket->Bind(loopback); |
| 25 | 26 |
| 26 TestClient client(new AsyncUDPSocket(socket)); | 27 TestClient client(MakeUnique<AsyncUDPSocket>(socket)); |
| 27 SocketAddress addr = client.address(), from; | 28 SocketAddress addr = client.address(), from; |
| 28 EXPECT_EQ(3, client.SendTo("foo", 3, addr)); | 29 EXPECT_EQ(3, client.SendTo("foo", 3, addr)); |
| 29 EXPECT_TRUE(client.CheckNextPacket("foo", 3, &from)); | 30 EXPECT_TRUE(client.CheckNextPacket("foo", 3, &from)); |
| 30 EXPECT_EQ(from, addr); | 31 EXPECT_EQ(from, addr); |
| 31 EXPECT_TRUE(client.CheckNoPacket()); | 32 EXPECT_TRUE(client.CheckNoPacket()); |
| 32 } | 33 } |
| 33 | 34 |
| 34 void TestTcpInternal(const SocketAddress& loopback) { | 35 void TestTcpInternal(const SocketAddress& loopback) { |
| 35 Thread *main = Thread::Current(); | 36 Thread *main = Thread::Current(); |
| 36 TestEchoServer server(main, loopback); | 37 TestEchoServer server(main, loopback); |
| 37 | 38 |
| 38 AsyncSocket* socket = main->socketserver() | 39 AsyncSocket* socket = main->socketserver() |
| 39 ->CreateAsyncSocket(loopback.family(), SOCK_STREAM); | 40 ->CreateAsyncSocket(loopback.family(), SOCK_STREAM); |
| 40 AsyncTCPSocket* tcp_socket = AsyncTCPSocket::Create( | 41 std::unique_ptr<AsyncTCPSocket> tcp_socket = |
| 41 socket, loopback, server.address()); | 42 WrapUnique(AsyncTCPSocket::Create(socket, loopback, server.address())); |
| 42 ASSERT_TRUE(tcp_socket != nullptr); | 43 ASSERT_TRUE(tcp_socket != nullptr); |
| 43 | 44 |
| 44 TestClient client(tcp_socket); | 45 TestClient client(std::move(tcp_socket)); |
| 45 SocketAddress addr = client.address(), from; | 46 SocketAddress addr = client.address(), from; |
| 46 EXPECT_TRUE(client.CheckConnected()); | 47 EXPECT_TRUE(client.CheckConnected()); |
| 47 EXPECT_EQ(3, client.Send("foo", 3)); | 48 EXPECT_EQ(3, client.Send("foo", 3)); |
| 48 EXPECT_TRUE(client.CheckNextPacket("foo", 3, &from)); | 49 EXPECT_TRUE(client.CheckNextPacket("foo", 3, &from)); |
| 49 EXPECT_EQ(from, server.address()); | 50 EXPECT_EQ(from, server.address()); |
| 50 EXPECT_TRUE(client.CheckNoPacket()); | 51 EXPECT_TRUE(client.CheckNoPacket()); |
| 51 } | 52 } |
| 52 | 53 |
| 53 // Tests whether the TestClient can send UDP to itself. | 54 // Tests whether the TestClient can send UDP to itself. |
| 54 TEST(TestClientTest, TestUdpIPv4) { | 55 TEST(TestClientTest, TestUdpIPv4) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 78 #else | 79 #else |
| 79 #define MAYBE_TestTcpIPv6 TestTcpIPv6 | 80 #define MAYBE_TestTcpIPv6 TestTcpIPv6 |
| 80 #endif | 81 #endif |
| 81 TEST(TestClientTest, MAYBE_TestTcpIPv6) { | 82 TEST(TestClientTest, MAYBE_TestTcpIPv6) { |
| 82 if (HasIPv6Enabled()) { | 83 if (HasIPv6Enabled()) { |
| 83 TestTcpInternal(SocketAddress("::1", 0)); | 84 TestTcpInternal(SocketAddress("::1", 0)); |
| 84 } else { | 85 } else { |
| 85 LOG(LS_INFO) << "Skipping IPv6 test."; | 86 LOG(LS_INFO) << "Skipping IPv6 test."; |
| 86 } | 87 } |
| 87 } | 88 } |
| OLD | NEW |