| 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/testclient.h" |
| 12 #include "webrtc/base/gunit.h" | 12 #include "webrtc/base/gunit.h" |
| 13 #include "webrtc/base/nethelpers.h" | 13 #include "webrtc/base/nethelpers.h" |
| 14 #include "webrtc/base/physicalsocketserver.h" | 14 #include "webrtc/base/physicalsocketserver.h" |
| 15 #include "webrtc/base/ptr_util.h" | 15 #include "webrtc/base/ptr_util.h" |
| 16 #include "webrtc/base/testechoserver.h" | 16 #include "webrtc/base/testechoserver.h" |
| 17 #include "webrtc/base/thread.h" | 17 #include "webrtc/base/thread.h" |
| 18 | 18 |
| 19 using namespace rtc; | 19 using namespace rtc; |
| 20 | 20 |
| 21 #define MAYBE_SKIP_IPV4 \ |
| 22 if (!HasIPv4Enabled()) { \ |
| 23 LOG(LS_INFO) << "No IPv4... skipping"; \ |
| 24 return; \ |
| 25 } |
| 26 |
| 27 #define MAYBE_SKIP_IPV6 \ |
| 28 if (!HasIPv6Enabled()) { \ |
| 29 LOG(LS_INFO) << "No IPv6... skipping"; \ |
| 30 return; \ |
| 31 } |
| 32 |
| 21 void TestUdpInternal(const SocketAddress& loopback) { | 33 void TestUdpInternal(const SocketAddress& loopback) { |
| 22 Thread *main = Thread::Current(); | 34 Thread *main = Thread::Current(); |
| 23 AsyncSocket* socket = main->socketserver() | 35 AsyncSocket* socket = main->socketserver() |
| 24 ->CreateAsyncSocket(loopback.family(), SOCK_DGRAM); | 36 ->CreateAsyncSocket(loopback.family(), SOCK_DGRAM); |
| 25 socket->Bind(loopback); | 37 socket->Bind(loopback); |
| 26 | 38 |
| 27 TestClient client(MakeUnique<AsyncUDPSocket>(socket)); | 39 TestClient client(MakeUnique<AsyncUDPSocket>(socket)); |
| 28 SocketAddress addr = client.address(), from; | 40 SocketAddress addr = client.address(), from; |
| 29 EXPECT_EQ(3, client.SendTo("foo", 3, addr)); | 41 EXPECT_EQ(3, client.SendTo("foo", 3, addr)); |
| 30 EXPECT_TRUE(client.CheckNextPacket("foo", 3, &from)); | 42 EXPECT_TRUE(client.CheckNextPacket("foo", 3, &from)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 46 SocketAddress addr = client.address(), from; | 58 SocketAddress addr = client.address(), from; |
| 47 EXPECT_TRUE(client.CheckConnected()); | 59 EXPECT_TRUE(client.CheckConnected()); |
| 48 EXPECT_EQ(3, client.Send("foo", 3)); | 60 EXPECT_EQ(3, client.Send("foo", 3)); |
| 49 EXPECT_TRUE(client.CheckNextPacket("foo", 3, &from)); | 61 EXPECT_TRUE(client.CheckNextPacket("foo", 3, &from)); |
| 50 EXPECT_EQ(from, server.address()); | 62 EXPECT_EQ(from, server.address()); |
| 51 EXPECT_TRUE(client.CheckNoPacket()); | 63 EXPECT_TRUE(client.CheckNoPacket()); |
| 52 } | 64 } |
| 53 | 65 |
| 54 // Tests whether the TestClient can send UDP to itself. | 66 // Tests whether the TestClient can send UDP to itself. |
| 55 TEST(TestClientTest, TestUdpIPv4) { | 67 TEST(TestClientTest, TestUdpIPv4) { |
| 68 MAYBE_SKIP_IPV4; |
| 56 TestUdpInternal(SocketAddress("127.0.0.1", 0)); | 69 TestUdpInternal(SocketAddress("127.0.0.1", 0)); |
| 57 } | 70 } |
| 58 | 71 |
| 59 #if defined(WEBRTC_LINUX) | 72 #if defined(WEBRTC_LINUX) |
| 60 #define MAYBE_TestUdpIPv6 DISABLED_TestUdpIPv6 | 73 #define MAYBE_TestUdpIPv6 DISABLED_TestUdpIPv6 |
| 61 #else | 74 #else |
| 62 #define MAYBE_TestUdpIPv6 TestUdpIPv6 | 75 #define MAYBE_TestUdpIPv6 TestUdpIPv6 |
| 63 #endif | 76 #endif |
| 64 TEST(TestClientTest, MAYBE_TestUdpIPv6) { | 77 TEST(TestClientTest, MAYBE_TestUdpIPv6) { |
| 65 if (HasIPv6Enabled()) { | 78 MAYBE_SKIP_IPV6; |
| 66 TestUdpInternal(SocketAddress("::1", 0)); | 79 TestUdpInternal(SocketAddress("::1", 0)); |
| 67 } else { | |
| 68 LOG(LS_INFO) << "Skipping IPv6 test."; | |
| 69 } | |
| 70 } | 80 } |
| 71 | 81 |
| 72 // Tests whether the TestClient can connect to a server and exchange data. | 82 // Tests whether the TestClient can connect to a server and exchange data. |
| 73 TEST(TestClientTest, TestTcpIPv4) { | 83 TEST(TestClientTest, TestTcpIPv4) { |
| 84 MAYBE_SKIP_IPV4; |
| 74 TestTcpInternal(SocketAddress("127.0.0.1", 0)); | 85 TestTcpInternal(SocketAddress("127.0.0.1", 0)); |
| 75 } | 86 } |
| 76 | 87 |
| 77 #if defined(WEBRTC_LINUX) | 88 #if defined(WEBRTC_LINUX) |
| 78 #define MAYBE_TestTcpIPv6 DISABLED_TestTcpIPv6 | 89 #define MAYBE_TestTcpIPv6 DISABLED_TestTcpIPv6 |
| 79 #else | 90 #else |
| 80 #define MAYBE_TestTcpIPv6 TestTcpIPv6 | 91 #define MAYBE_TestTcpIPv6 TestTcpIPv6 |
| 81 #endif | 92 #endif |
| 82 TEST(TestClientTest, MAYBE_TestTcpIPv6) { | 93 TEST(TestClientTest, MAYBE_TestTcpIPv6) { |
| 83 if (HasIPv6Enabled()) { | 94 MAYBE_SKIP_IPV6; |
| 84 TestTcpInternal(SocketAddress("::1", 0)); | 95 TestTcpInternal(SocketAddress("::1", 0)); |
| 85 } else { | |
| 86 LOG(LS_INFO) << "Skipping IPv6 test."; | |
| 87 } | |
| 88 } | 96 } |
| OLD | NEW |