OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2009 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 #ifndef WEBRTC_BASE_SOCKET_UNITTEST_H_ | 11 #ifndef WEBRTC_BASE_SOCKET_UNITTEST_H_ |
12 #define WEBRTC_BASE_SOCKET_UNITTEST_H_ | 12 #define WEBRTC_BASE_SOCKET_UNITTEST_H_ |
13 | 13 |
14 #include "webrtc/base/gunit.h" | 14 #include "webrtc/base/gunit.h" |
15 #include "webrtc/base/thread.h" | 15 #include "webrtc/base/thread.h" |
16 | 16 |
17 namespace rtc { | 17 namespace rtc { |
18 | 18 |
19 // Generic socket tests, to be used when testing individual socketservers. | 19 // Generic socket tests, to be used when testing individual socketservers. |
20 // Derive your specific test class from SocketTest, install your | 20 // Derive your specific test class from SocketTest, install your |
21 // socketserver, and call the SocketTest test methods. | 21 // socketserver, and call the SocketTest test methods. |
22 class SocketTest : public testing::Test { | 22 class SocketTest : public testing::Test { |
23 protected: | 23 protected: |
24 SocketTest() : ss_(NULL), kIPv4Loopback(INADDR_LOOPBACK), | 24 SocketTest() : kIPv4Loopback(INADDR_LOOPBACK), |
25 kIPv6Loopback(in6addr_loopback) {} | 25 kIPv6Loopback(in6addr_loopback), |
| 26 ss_(nullptr) {} |
26 virtual void SetUp() { ss_ = Thread::Current()->socketserver(); } | 27 virtual void SetUp() { ss_ = Thread::Current()->socketserver(); } |
27 void TestConnectIPv4(); | 28 void TestConnectIPv4(); |
28 void TestConnectIPv6(); | 29 void TestConnectIPv6(); |
29 void TestConnectWithDnsLookupIPv4(); | 30 void TestConnectWithDnsLookupIPv4(); |
30 void TestConnectWithDnsLookupIPv6(); | 31 void TestConnectWithDnsLookupIPv6(); |
31 void TestConnectFailIPv4(); | 32 void TestConnectFailIPv4(); |
32 void TestConnectFailIPv6(); | 33 void TestConnectFailIPv6(); |
33 void TestConnectWithDnsLookupFailIPv4(); | 34 void TestConnectWithDnsLookupFailIPv4(); |
34 void TestConnectWithDnsLookupFailIPv6(); | 35 void TestConnectWithDnsLookupFailIPv6(); |
35 void TestConnectWithClosedSocketIPv4(); | 36 void TestConnectWithClosedSocketIPv4(); |
(...skipping 14 matching lines...) Expand all Loading... |
50 void TestTcpIPv6(); | 51 void TestTcpIPv6(); |
51 void TestSingleFlowControlCallbackIPv4(); | 52 void TestSingleFlowControlCallbackIPv4(); |
52 void TestSingleFlowControlCallbackIPv6(); | 53 void TestSingleFlowControlCallbackIPv6(); |
53 void TestUdpIPv4(); | 54 void TestUdpIPv4(); |
54 void TestUdpIPv6(); | 55 void TestUdpIPv6(); |
55 void TestUdpReadyToSendIPv4(); | 56 void TestUdpReadyToSendIPv4(); |
56 void TestUdpReadyToSendIPv6(); | 57 void TestUdpReadyToSendIPv6(); |
57 void TestGetSetOptionsIPv4(); | 58 void TestGetSetOptionsIPv4(); |
58 void TestGetSetOptionsIPv6(); | 59 void TestGetSetOptionsIPv6(); |
59 | 60 |
| 61 static const int kTimeout = 5000; // ms |
| 62 const IPAddress kIPv4Loopback; |
| 63 const IPAddress kIPv6Loopback; |
| 64 |
60 private: | 65 private: |
61 void ConnectInternal(const IPAddress& loopback); | 66 void ConnectInternal(const IPAddress& loopback); |
62 void ConnectWithDnsLookupInternal(const IPAddress& loopback, | 67 void ConnectWithDnsLookupInternal(const IPAddress& loopback, |
63 const std::string& host); | 68 const std::string& host); |
64 void ConnectFailInternal(const IPAddress& loopback); | 69 void ConnectFailInternal(const IPAddress& loopback); |
65 | 70 |
66 void ConnectWithDnsLookupFailInternal(const IPAddress& loopback); | 71 void ConnectWithDnsLookupFailInternal(const IPAddress& loopback); |
67 void ConnectWithClosedSocketInternal(const IPAddress& loopback); | 72 void ConnectWithClosedSocketInternal(const IPAddress& loopback); |
68 void ConnectWhileNotClosedInternal(const IPAddress& loopback); | 73 void ConnectWhileNotClosedInternal(const IPAddress& loopback); |
69 void ServerCloseDuringConnectInternal(const IPAddress& loopback); | 74 void ServerCloseDuringConnectInternal(const IPAddress& loopback); |
70 void ClientCloseDuringConnectInternal(const IPAddress& loopback); | 75 void ClientCloseDuringConnectInternal(const IPAddress& loopback); |
71 void ServerCloseInternal(const IPAddress& loopback); | 76 void ServerCloseInternal(const IPAddress& loopback); |
72 void CloseInClosedCallbackInternal(const IPAddress& loopback); | 77 void CloseInClosedCallbackInternal(const IPAddress& loopback); |
73 void SocketServerWaitInternal(const IPAddress& loopback); | 78 void SocketServerWaitInternal(const IPAddress& loopback); |
74 void TcpInternal(const IPAddress& loopback); | 79 void TcpInternal(const IPAddress& loopback); |
75 void SingleFlowControlCallbackInternal(const IPAddress& loopback); | 80 void SingleFlowControlCallbackInternal(const IPAddress& loopback); |
76 void UdpInternal(const IPAddress& loopback); | 81 void UdpInternal(const IPAddress& loopback); |
77 void UdpReadyToSend(const IPAddress& loopback); | 82 void UdpReadyToSend(const IPAddress& loopback); |
78 void GetSetOptionsInternal(const IPAddress& loopback); | 83 void GetSetOptionsInternal(const IPAddress& loopback); |
79 | 84 |
80 static const int kTimeout = 5000; // ms | |
81 SocketServer* ss_; | 85 SocketServer* ss_; |
82 const IPAddress kIPv4Loopback; | |
83 const IPAddress kIPv6Loopback; | |
84 }; | 86 }; |
85 | 87 |
| 88 // For unbound sockets, GetLocalAddress / GetRemoteAddress return AF_UNSPEC |
| 89 // values on Windows, but an empty address of the same family on Linux/MacOS X. |
| 90 bool IsUnspecOrEmptyIP(const IPAddress& address); |
| 91 |
86 } // namespace rtc | 92 } // namespace rtc |
87 | 93 |
88 #endif // WEBRTC_BASE_SOCKET_UNITTEST_H_ | 94 #endif // WEBRTC_BASE_SOCKET_UNITTEST_H_ |
OLD | NEW |