henrike@webrtc.org | 0e118e7 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2009, Google Inc. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #ifndef TALK_BASE_SOCKET_UNITTEST_H_ |
| 29 | #define TALK_BASE_SOCKET_UNITTEST_H_ |
| 30 | |
| 31 | #include "talk/base/gunit.h" |
| 32 | #include "talk/base/thread.h" |
| 33 | |
| 34 | namespace talk_base { |
| 35 | |
| 36 | // Generic socket tests, to be used when testing individual socketservers. |
| 37 | // Derive your specific test class from SocketTest, install your |
| 38 | // socketserver, and call the SocketTest test methods. |
| 39 | class SocketTest : public testing::Test { |
| 40 | protected: |
| 41 | SocketTest() : ss_(NULL), kIPv4Loopback(INADDR_LOOPBACK), |
| 42 | kIPv6Loopback(in6addr_loopback) {} |
| 43 | virtual void SetUp() { ss_ = Thread::Current()->socketserver(); } |
| 44 | void TestConnectIPv4(); |
| 45 | void TestConnectIPv6(); |
| 46 | void TestConnectWithDnsLookupIPv4(); |
| 47 | void TestConnectWithDnsLookupIPv6(); |
| 48 | void TestConnectFailIPv4(); |
| 49 | void TestConnectFailIPv6(); |
| 50 | void TestConnectWithDnsLookupFailIPv4(); |
| 51 | void TestConnectWithDnsLookupFailIPv6(); |
| 52 | void TestConnectWithClosedSocketIPv4(); |
| 53 | void TestConnectWithClosedSocketIPv6(); |
| 54 | void TestConnectWhileNotClosedIPv4(); |
| 55 | void TestConnectWhileNotClosedIPv6(); |
| 56 | void TestServerCloseDuringConnectIPv4(); |
| 57 | void TestServerCloseDuringConnectIPv6(); |
| 58 | void TestClientCloseDuringConnectIPv4(); |
| 59 | void TestClientCloseDuringConnectIPv6(); |
| 60 | void TestServerCloseIPv4(); |
| 61 | void TestServerCloseIPv6(); |
| 62 | void TestCloseInClosedCallbackIPv4(); |
| 63 | void TestCloseInClosedCallbackIPv6(); |
| 64 | void TestSocketServerWaitIPv4(); |
| 65 | void TestSocketServerWaitIPv6(); |
| 66 | void TestTcpIPv4(); |
| 67 | void TestTcpIPv6(); |
| 68 | void TestSingleFlowControlCallbackIPv4(); |
| 69 | void TestSingleFlowControlCallbackIPv6(); |
| 70 | void TestUdpIPv4(); |
| 71 | void TestUdpIPv6(); |
| 72 | void TestUdpReadyToSendIPv4(); |
| 73 | void TestUdpReadyToSendIPv6(); |
| 74 | void TestGetSetOptionsIPv4(); |
| 75 | void TestGetSetOptionsIPv6(); |
| 76 | |
| 77 | private: |
| 78 | void ConnectInternal(const IPAddress& loopback); |
| 79 | void ConnectWithDnsLookupInternal(const IPAddress& loopback, |
| 80 | const std::string& host); |
| 81 | void ConnectFailInternal(const IPAddress& loopback); |
| 82 | |
| 83 | void ConnectWithDnsLookupFailInternal(const IPAddress& loopback); |
| 84 | void ConnectWithClosedSocketInternal(const IPAddress& loopback); |
| 85 | void ConnectWhileNotClosedInternal(const IPAddress& loopback); |
| 86 | void ServerCloseDuringConnectInternal(const IPAddress& loopback); |
| 87 | void ClientCloseDuringConnectInternal(const IPAddress& loopback); |
| 88 | void ServerCloseInternal(const IPAddress& loopback); |
| 89 | void CloseInClosedCallbackInternal(const IPAddress& loopback); |
| 90 | void SocketServerWaitInternal(const IPAddress& loopback); |
| 91 | void TcpInternal(const IPAddress& loopback); |
| 92 | void SingleFlowControlCallbackInternal(const IPAddress& loopback); |
| 93 | void UdpInternal(const IPAddress& loopback); |
| 94 | void UdpReadyToSend(const IPAddress& loopback); |
| 95 | void GetSetOptionsInternal(const IPAddress& loopback); |
| 96 | |
| 97 | static const int kTimeout = 5000; // ms |
| 98 | SocketServer* ss_; |
| 99 | const IPAddress kIPv4Loopback; |
| 100 | const IPAddress kIPv6Loopback; |
| 101 | }; |
| 102 | |
| 103 | } // namespace talk_base |
| 104 | |
| 105 | #endif // TALK_BASE_SOCKET_UNITTEST_H_ |