henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2009 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #ifndef RTC_BASE_SOCKET_UNITTEST_H_ |
| 12 | #define RTC_BASE_SOCKET_UNITTEST_H_ |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 13 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 14 | #include "rtc_base/gunit.h" |
| 15 | #include "rtc_base/thread.h" |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 16 | |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 17 | namespace rtc { |
| 18 | |
| 19 | // Generic socket tests, to be used when testing individual socketservers. |
| 20 | // Derive your specific test class from SocketTest, install your |
| 21 | // socketserver, and call the SocketTest test methods. |
Mirko Bonadei | 6a489f2 | 2019-04-09 13:11:12 | [diff] [blame] | 22 | class SocketTest : public ::testing::Test { |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 23 | protected: |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 24 | SocketTest() |
| 25 | : kIPv4Loopback(INADDR_LOOPBACK), |
| 26 | kIPv6Loopback(in6addr_loopback), |
| 27 | ss_(nullptr) {} |
Steve Anton | 9de3aac | 2017-10-24 17:08:26 | [diff] [blame] | 28 | void SetUp() override; |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 29 | void TestConnectIPv4(); |
| 30 | void TestConnectIPv6(); |
| 31 | void TestConnectWithDnsLookupIPv4(); |
| 32 | void TestConnectWithDnsLookupIPv6(); |
| 33 | void TestConnectFailIPv4(); |
| 34 | void TestConnectFailIPv6(); |
| 35 | void TestConnectWithDnsLookupFailIPv4(); |
| 36 | void TestConnectWithDnsLookupFailIPv6(); |
| 37 | void TestConnectWithClosedSocketIPv4(); |
| 38 | void TestConnectWithClosedSocketIPv6(); |
| 39 | void TestConnectWhileNotClosedIPv4(); |
| 40 | void TestConnectWhileNotClosedIPv6(); |
| 41 | void TestServerCloseDuringConnectIPv4(); |
| 42 | void TestServerCloseDuringConnectIPv6(); |
| 43 | void TestClientCloseDuringConnectIPv4(); |
| 44 | void TestClientCloseDuringConnectIPv6(); |
| 45 | void TestServerCloseIPv4(); |
| 46 | void TestServerCloseIPv6(); |
| 47 | void TestCloseInClosedCallbackIPv4(); |
| 48 | void TestCloseInClosedCallbackIPv6(); |
Taylor Brandstetter | 7b69a44 | 2020-08-20 23:43:13 | [diff] [blame] | 49 | void TestDeleteInReadCallbackIPv4(); |
| 50 | void TestDeleteInReadCallbackIPv6(); |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 51 | void TestSocketServerWaitIPv4(); |
| 52 | void TestSocketServerWaitIPv6(); |
| 53 | void TestTcpIPv4(); |
| 54 | void TestTcpIPv6(); |
| 55 | void TestSingleFlowControlCallbackIPv4(); |
| 56 | void TestSingleFlowControlCallbackIPv6(); |
| 57 | void TestUdpIPv4(); |
| 58 | void TestUdpIPv6(); |
| 59 | void TestUdpReadyToSendIPv4(); |
| 60 | void TestUdpReadyToSendIPv6(); |
| 61 | void TestGetSetOptionsIPv4(); |
| 62 | void TestGetSetOptionsIPv6(); |
| 63 | void TestSocketRecvTimestampIPv4(); |
| 64 | void TestSocketRecvTimestampIPv6(); |
| 65 | |
| 66 | static const int kTimeout = 5000; // ms |
| 67 | const IPAddress kIPv4Loopback; |
| 68 | const IPAddress kIPv6Loopback; |
| 69 | |
| 70 | protected: |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 71 | void TcpInternal(const IPAddress& loopback, |
| 72 | size_t data_size, |
| 73 | ptrdiff_t max_send_size); |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 74 | |
| 75 | private: |
| 76 | void ConnectInternal(const IPAddress& loopback); |
| 77 | void ConnectWithDnsLookupInternal(const IPAddress& loopback, |
| 78 | const std::string& host); |
| 79 | void ConnectFailInternal(const IPAddress& loopback); |
| 80 | |
| 81 | void ConnectWithDnsLookupFailInternal(const IPAddress& loopback); |
| 82 | void ConnectWithClosedSocketInternal(const IPAddress& loopback); |
| 83 | void ConnectWhileNotClosedInternal(const IPAddress& loopback); |
| 84 | void ServerCloseDuringConnectInternal(const IPAddress& loopback); |
| 85 | void ClientCloseDuringConnectInternal(const IPAddress& loopback); |
| 86 | void ServerCloseInternal(const IPAddress& loopback); |
| 87 | void CloseInClosedCallbackInternal(const IPAddress& loopback); |
Taylor Brandstetter | 7b69a44 | 2020-08-20 23:43:13 | [diff] [blame] | 88 | void DeleteInReadCallbackInternal(const IPAddress& loopback); |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 89 | void SocketServerWaitInternal(const IPAddress& loopback); |
| 90 | void SingleFlowControlCallbackInternal(const IPAddress& loopback); |
| 91 | void UdpInternal(const IPAddress& loopback); |
| 92 | void UdpReadyToSend(const IPAddress& loopback); |
| 93 | void GetSetOptionsInternal(const IPAddress& loopback); |
| 94 | void SocketRecvTimestamp(const IPAddress& loopback); |
| 95 | |
| 96 | SocketServer* ss_; |
| 97 | }; |
| 98 | |
| 99 | // For unbound sockets, GetLocalAddress / GetRemoteAddress return AF_UNSPEC |
| 100 | // values on Windows, but an empty address of the same family on Linux/MacOS X. |
| 101 | bool IsUnspecOrEmptyIP(const IPAddress& address); |
| 102 | |
| 103 | } // namespace rtc |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 104 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 105 | #endif // RTC_BASE_SOCKET_UNITTEST_H_ |