You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
4.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #ifndef TALK_BASE_SOCKET_UNITTEST_H_
  28. #define TALK_BASE_SOCKET_UNITTEST_H_
  29. #include "talk/base/gunit.h"
  30. #include "talk/base/thread.h"
  31. namespace talk_base {
  32. // Generic socket tests, to be used when testing individual socketservers.
  33. // Derive your specific test class from SocketTest, install your
  34. // socketserver, and call the SocketTest test methods.
  35. class SocketTest : public testing::Test {
  36. protected:
  37. SocketTest() : ss_(NULL), kIPv4Loopback(INADDR_LOOPBACK),
  38. kIPv6Loopback(in6addr_loopback) {}
  39. virtual void SetUp() { ss_ = Thread::Current()->socketserver(); }
  40. void TestConnectIPv4();
  41. void TestConnectIPv6();
  42. void TestConnectWithDnsLookupIPv4();
  43. void TestConnectWithDnsLookupIPv6();
  44. void TestConnectFailIPv4();
  45. void TestConnectFailIPv6();
  46. void TestConnectWithDnsLookupFailIPv4();
  47. void TestConnectWithDnsLookupFailIPv6();
  48. void TestConnectWithClosedSocketIPv4();
  49. void TestConnectWithClosedSocketIPv6();
  50. void TestConnectWhileNotClosedIPv4();
  51. void TestConnectWhileNotClosedIPv6();
  52. void TestServerCloseDuringConnectIPv4();
  53. void TestServerCloseDuringConnectIPv6();
  54. void TestClientCloseDuringConnectIPv4();
  55. void TestClientCloseDuringConnectIPv6();
  56. void TestServerCloseIPv4();
  57. void TestServerCloseIPv6();
  58. void TestCloseInClosedCallbackIPv4();
  59. void TestCloseInClosedCallbackIPv6();
  60. void TestSocketServerWaitIPv4();
  61. void TestSocketServerWaitIPv6();
  62. void TestTcpIPv4();
  63. void TestTcpIPv6();
  64. void TestSingleFlowControlCallbackIPv4();
  65. void TestSingleFlowControlCallbackIPv6();
  66. void TestUdpIPv4();
  67. void TestUdpIPv6();
  68. void TestGetSetOptionsIPv4();
  69. void TestGetSetOptionsIPv6();
  70. 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. void ConnectWithDnsLookupFailInternal(const IPAddress& loopback);
  76. void ConnectWithClosedSocketInternal(const IPAddress& loopback);
  77. void ConnectWhileNotClosedInternal(const IPAddress& loopback);
  78. void ServerCloseDuringConnectInternal(const IPAddress& loopback);
  79. void ClientCloseDuringConnectInternal(const IPAddress& loopback);
  80. void ServerCloseInternal(const IPAddress& loopback);
  81. void CloseInClosedCallbackInternal(const IPAddress& loopback);
  82. void SocketServerWaitInternal(const IPAddress& loopback);
  83. void TcpInternal(const IPAddress& loopback);
  84. void SingleFlowControlCallbackInternal(const IPAddress& loopback);
  85. void UdpInternal(const IPAddress& loopback);
  86. void GetSetOptionsInternal(const IPAddress& loopback);
  87. static const int kTimeout = 5000; // ms
  88. SocketServer* ss_;
  89. const IPAddress kIPv4Loopback;
  90. const IPAddress kIPv6Loopback;
  91. };
  92. } // namespace talk_base
  93. #endif // TALK_BASE_SOCKET_UNITTEST_H_