socket_unittest.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #ifndef RTC_BASE_SOCKET_UNITTEST_H_
  11. #define RTC_BASE_SOCKET_UNITTEST_H_
  12. #include "rtc_base/gunit.h"
  13. #include "rtc_base/thread.h"
  14. namespace rtc {
  15. // Generic socket tests, to be used when testing individual socketservers.
  16. // Derive your specific test class from SocketTest, install your
  17. // socketserver, and call the SocketTest test methods.
  18. class SocketTest : public ::testing::Test {
  19. protected:
  20. SocketTest()
  21. : kIPv4Loopback(INADDR_LOOPBACK),
  22. kIPv6Loopback(in6addr_loopback),
  23. ss_(nullptr) {}
  24. void SetUp() override;
  25. void TestConnectIPv4();
  26. void TestConnectIPv6();
  27. void TestConnectWithDnsLookupIPv4();
  28. void TestConnectWithDnsLookupIPv6();
  29. void TestConnectFailIPv4();
  30. void TestConnectFailIPv6();
  31. void TestConnectWithDnsLookupFailIPv4();
  32. void TestConnectWithDnsLookupFailIPv6();
  33. void TestConnectWithClosedSocketIPv4();
  34. void TestConnectWithClosedSocketIPv6();
  35. void TestConnectWhileNotClosedIPv4();
  36. void TestConnectWhileNotClosedIPv6();
  37. void TestServerCloseDuringConnectIPv4();
  38. void TestServerCloseDuringConnectIPv6();
  39. void TestClientCloseDuringConnectIPv4();
  40. void TestClientCloseDuringConnectIPv6();
  41. void TestServerCloseIPv4();
  42. void TestServerCloseIPv6();
  43. void TestCloseInClosedCallbackIPv4();
  44. void TestCloseInClosedCallbackIPv6();
  45. void TestDeleteInReadCallbackIPv4();
  46. void TestDeleteInReadCallbackIPv6();
  47. void TestSocketServerWaitIPv4();
  48. void TestSocketServerWaitIPv6();
  49. void TestTcpIPv4();
  50. void TestTcpIPv6();
  51. void TestSingleFlowControlCallbackIPv4();
  52. void TestSingleFlowControlCallbackIPv6();
  53. void TestUdpIPv4();
  54. void TestUdpIPv6();
  55. void TestUdpReadyToSendIPv4();
  56. void TestUdpReadyToSendIPv6();
  57. void TestGetSetOptionsIPv4();
  58. void TestGetSetOptionsIPv6();
  59. void TestSocketRecvTimestampIPv4();
  60. void TestSocketRecvTimestampIPv6();
  61. static const int kTimeout = 5000; // ms
  62. const IPAddress kIPv4Loopback;
  63. const IPAddress kIPv6Loopback;
  64. protected:
  65. void TcpInternal(const IPAddress& loopback,
  66. size_t data_size,
  67. ptrdiff_t max_send_size);
  68. private:
  69. void ConnectInternal(const IPAddress& loopback);
  70. void ConnectWithDnsLookupInternal(const IPAddress& loopback,
  71. const std::string& host);
  72. void ConnectFailInternal(const IPAddress& loopback);
  73. void ConnectWithDnsLookupFailInternal(const IPAddress& loopback);
  74. void ConnectWithClosedSocketInternal(const IPAddress& loopback);
  75. void ConnectWhileNotClosedInternal(const IPAddress& loopback);
  76. void ServerCloseDuringConnectInternal(const IPAddress& loopback);
  77. void ClientCloseDuringConnectInternal(const IPAddress& loopback);
  78. void ServerCloseInternal(const IPAddress& loopback);
  79. void CloseInClosedCallbackInternal(const IPAddress& loopback);
  80. void DeleteInReadCallbackInternal(const IPAddress& loopback);
  81. void SocketServerWaitInternal(const IPAddress& loopback);
  82. void SingleFlowControlCallbackInternal(const IPAddress& loopback);
  83. void UdpInternal(const IPAddress& loopback);
  84. void UdpReadyToSend(const IPAddress& loopback);
  85. void GetSetOptionsInternal(const IPAddress& loopback);
  86. void SocketRecvTimestamp(const IPAddress& loopback);
  87. SocketServer* ss_;
  88. };
  89. // For unbound sockets, GetLocalAddress / GetRemoteAddress return AF_UNSPEC
  90. // values on Windows, but an empty address of the same family on Linux/MacOS X.
  91. bool IsUnspecOrEmptyIP(const IPAddress& address);
  92. } // namespace rtc
  93. #endif // RTC_BASE_SOCKET_UNITTEST_H_