blob: 41f0a653cb8c9b900ad2ca74d53016676f924bb4 [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00001/*
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
11#ifndef WEBRTC_BASE_SOCKET_UNITTEST_H_
12#define WEBRTC_BASE_SOCKET_UNITTEST_H_
13
14#include "webrtc/base/gunit.h"
15#include "webrtc/base/thread.h"
16
17namespace 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.
22class SocketTest : public testing::Test {
23 protected:
jbauch095ae152015-12-18 01:39:55 -080024 SocketTest() : kIPv4Loopback(INADDR_LOOPBACK),
25 kIPv6Loopback(in6addr_loopback),
26 ss_(nullptr) {}
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000027 virtual void SetUp() { ss_ = Thread::Current()->socketserver(); }
28 void TestConnectIPv4();
29 void TestConnectIPv6();
30 void TestConnectWithDnsLookupIPv4();
31 void TestConnectWithDnsLookupIPv6();
32 void TestConnectFailIPv4();
33 void TestConnectFailIPv6();
34 void TestConnectWithDnsLookupFailIPv4();
35 void TestConnectWithDnsLookupFailIPv6();
36 void TestConnectWithClosedSocketIPv4();
37 void TestConnectWithClosedSocketIPv6();
38 void TestConnectWhileNotClosedIPv4();
39 void TestConnectWhileNotClosedIPv6();
40 void TestServerCloseDuringConnectIPv4();
41 void TestServerCloseDuringConnectIPv6();
42 void TestClientCloseDuringConnectIPv4();
43 void TestClientCloseDuringConnectIPv6();
44 void TestServerCloseIPv4();
45 void TestServerCloseIPv6();
46 void TestCloseInClosedCallbackIPv4();
47 void TestCloseInClosedCallbackIPv6();
48 void TestSocketServerWaitIPv4();
49 void TestSocketServerWaitIPv6();
50 void TestTcpIPv4();
51 void TestTcpIPv6();
52 void TestSingleFlowControlCallbackIPv4();
53 void TestSingleFlowControlCallbackIPv6();
54 void TestUdpIPv4();
55 void TestUdpIPv6();
56 void TestUdpReadyToSendIPv4();
57 void TestUdpReadyToSendIPv6();
58 void TestGetSetOptionsIPv4();
59 void TestGetSetOptionsIPv6();
Stefan Holmer9131efd2016-05-23 18:19:26 +020060 void TestSocketRecvTimestamp();
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000061
jbauch095ae152015-12-18 01:39:55 -080062 static const int kTimeout = 5000; // ms
63 const IPAddress kIPv4Loopback;
64 const IPAddress kIPv6Loopback;
65
jbauchf2a2bf42016-02-03 16:45:32 -080066 protected:
67 void TcpInternal(const IPAddress& loopback, size_t data_size,
68 ssize_t max_send_size);
69
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000070 private:
71 void ConnectInternal(const IPAddress& loopback);
72 void ConnectWithDnsLookupInternal(const IPAddress& loopback,
73 const std::string& host);
74 void ConnectFailInternal(const IPAddress& loopback);
75
76 void ConnectWithDnsLookupFailInternal(const IPAddress& loopback);
77 void ConnectWithClosedSocketInternal(const IPAddress& loopback);
78 void ConnectWhileNotClosedInternal(const IPAddress& loopback);
79 void ServerCloseDuringConnectInternal(const IPAddress& loopback);
80 void ClientCloseDuringConnectInternal(const IPAddress& loopback);
81 void ServerCloseInternal(const IPAddress& loopback);
82 void CloseInClosedCallbackInternal(const IPAddress& loopback);
83 void SocketServerWaitInternal(const IPAddress& loopback);
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000084 void SingleFlowControlCallbackInternal(const IPAddress& loopback);
85 void UdpInternal(const IPAddress& loopback);
86 void UdpReadyToSend(const IPAddress& loopback);
87 void GetSetOptionsInternal(const IPAddress& loopback);
Stefan Holmer9131efd2016-05-23 18:19:26 +020088 void SocketRecvTimestamp(const IPAddress& loopback);
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000089
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000090 SocketServer* ss_;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000091};
92
jbauch095ae152015-12-18 01:39:55 -080093// For unbound sockets, GetLocalAddress / GetRemoteAddress return AF_UNSPEC
94// values on Windows, but an empty address of the same family on Linux/MacOS X.
95bool IsUnspecOrEmptyIP(const IPAddress& address);
96
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000097} // namespace rtc
98
99#endif // WEBRTC_BASE_SOCKET_UNITTEST_H_