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.

250 lines
7.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. #include "talk/base/gunit.h"
  28. #include "talk/base/scoped_ptr.h"
  29. #include "talk/base/socket_unittest.h"
  30. #include "talk/base/thread.h"
  31. #include "talk/base/macsocketserver.h"
  32. namespace talk_base {
  33. class WakeThread : public Thread {
  34. public:
  35. WakeThread(SocketServer* ss) : ss_(ss) {
  36. }
  37. void Run() {
  38. ss_->WakeUp();
  39. }
  40. private:
  41. SocketServer* ss_;
  42. };
  43. #ifndef CARBON_DEPRECATED
  44. // Test that MacCFSocketServer::Wait works as expected.
  45. TEST(MacCFSocketServerTest, TestWait) {
  46. MacCFSocketServer server;
  47. uint32 start = Time();
  48. server.Wait(1000, true);
  49. EXPECT_GE(TimeSince(start), 1000);
  50. }
  51. // Test that MacCFSocketServer::Wakeup works as expected.
  52. TEST(MacCFSocketServerTest, TestWakeup) {
  53. MacCFSocketServer server;
  54. WakeThread thread(&server);
  55. uint32 start = Time();
  56. thread.Start();
  57. server.Wait(10000, true);
  58. EXPECT_LT(TimeSince(start), 10000);
  59. }
  60. // Test that MacCarbonSocketServer::Wait works as expected.
  61. TEST(MacCarbonSocketServerTest, TestWait) {
  62. MacCarbonSocketServer server;
  63. uint32 start = Time();
  64. server.Wait(1000, true);
  65. EXPECT_GE(TimeSince(start), 1000);
  66. }
  67. // Test that MacCarbonSocketServer::Wakeup works as expected.
  68. TEST(MacCarbonSocketServerTest, TestWakeup) {
  69. MacCarbonSocketServer server;
  70. WakeThread thread(&server);
  71. uint32 start = Time();
  72. thread.Start();
  73. server.Wait(10000, true);
  74. EXPECT_LT(TimeSince(start), 10000);
  75. }
  76. // Test that MacCarbonAppSocketServer::Wait works as expected.
  77. TEST(MacCarbonAppSocketServerTest, TestWait) {
  78. MacCarbonAppSocketServer server;
  79. uint32 start = Time();
  80. server.Wait(1000, true);
  81. EXPECT_GE(TimeSince(start), 1000);
  82. }
  83. // Test that MacCarbonAppSocketServer::Wakeup works as expected.
  84. TEST(MacCarbonAppSocketServerTest, TestWakeup) {
  85. MacCarbonAppSocketServer server;
  86. WakeThread thread(&server);
  87. uint32 start = Time();
  88. thread.Start();
  89. server.Wait(10000, true);
  90. EXPECT_LT(TimeSince(start), 10000);
  91. }
  92. #endif
  93. // Test that MacAsyncSocket passes all the generic Socket tests.
  94. class MacAsyncSocketTest : public SocketTest {
  95. protected:
  96. MacAsyncSocketTest()
  97. : server_(CreateSocketServer()),
  98. scope_(server_.get()) {}
  99. // Override for other implementations of MacBaseSocketServer.
  100. virtual MacBaseSocketServer* CreateSocketServer() {
  101. return new MacCFSocketServer();
  102. };
  103. talk_base::scoped_ptr<MacBaseSocketServer> server_;
  104. SocketServerScope scope_;
  105. };
  106. TEST_F(MacAsyncSocketTest, TestConnectIPv4) {
  107. SocketTest::TestConnectIPv4();
  108. }
  109. TEST_F(MacAsyncSocketTest, TestConnectIPv6) {
  110. SocketTest::TestConnectIPv6();
  111. }
  112. TEST_F(MacAsyncSocketTest, TestConnectWithDnsLookupIPv4) {
  113. SocketTest::TestConnectWithDnsLookupIPv4();
  114. }
  115. TEST_F(MacAsyncSocketTest, TestConnectWithDnsLookupIPv6) {
  116. SocketTest::TestConnectWithDnsLookupIPv6();
  117. }
  118. TEST_F(MacAsyncSocketTest, TestConnectFailIPv4) {
  119. SocketTest::TestConnectFailIPv4();
  120. }
  121. TEST_F(MacAsyncSocketTest, TestConnectFailIPv6) {
  122. SocketTest::TestConnectFailIPv6();
  123. }
  124. // Reenable once we have mac async dns
  125. TEST_F(MacAsyncSocketTest, DISABLED_TestConnectWithDnsLookupFailIPv4) {
  126. SocketTest::TestConnectWithDnsLookupFailIPv4();
  127. }
  128. TEST_F(MacAsyncSocketTest, DISABLED_TestConnectWithDnsLookupFailIPv6) {
  129. SocketTest::TestConnectWithDnsLookupFailIPv6();
  130. }
  131. TEST_F(MacAsyncSocketTest, TestConnectWithClosedSocketIPv4) {
  132. SocketTest::TestConnectWithClosedSocketIPv4();
  133. }
  134. TEST_F(MacAsyncSocketTest, TestConnectWithClosedSocketIPv6) {
  135. SocketTest::TestConnectWithClosedSocketIPv6();
  136. }
  137. // Flaky at the moment (10% failure rate). Seems the client doesn't get
  138. // signalled in a timely manner...
  139. TEST_F(MacAsyncSocketTest, DISABLED_TestServerCloseDuringConnectIPv4) {
  140. SocketTest::TestServerCloseDuringConnectIPv4();
  141. }
  142. TEST_F(MacAsyncSocketTest, DISABLED_TestServerCloseDuringConnectIPv6) {
  143. SocketTest::TestServerCloseDuringConnectIPv6();
  144. }
  145. // Flaky at the moment (0.5% failure rate). Seems the client doesn't get
  146. // signalled in a timely manner...
  147. TEST_F(MacAsyncSocketTest, TestClientCloseDuringConnectIPv4) {
  148. SocketTest::TestClientCloseDuringConnectIPv4();
  149. }
  150. TEST_F(MacAsyncSocketTest, TestClientCloseDuringConnectIPv6) {
  151. SocketTest::TestClientCloseDuringConnectIPv6();
  152. }
  153. TEST_F(MacAsyncSocketTest, TestServerCloseIPv4) {
  154. SocketTest::TestServerCloseIPv4();
  155. }
  156. TEST_F(MacAsyncSocketTest, TestServerCloseIPv6) {
  157. SocketTest::TestServerCloseIPv6();
  158. }
  159. TEST_F(MacAsyncSocketTest, TestCloseInClosedCallbackIPv4) {
  160. SocketTest::TestCloseInClosedCallbackIPv4();
  161. }
  162. TEST_F(MacAsyncSocketTest, TestCloseInClosedCallbackIPv6) {
  163. SocketTest::TestCloseInClosedCallbackIPv6();
  164. }
  165. TEST_F(MacAsyncSocketTest, TestSocketServerWaitIPv4) {
  166. SocketTest::TestSocketServerWaitIPv4();
  167. }
  168. TEST_F(MacAsyncSocketTest, TestSocketServerWaitIPv6) {
  169. SocketTest::TestSocketServerWaitIPv6();
  170. }
  171. TEST_F(MacAsyncSocketTest, TestTcpIPv4) {
  172. SocketTest::TestTcpIPv4();
  173. }
  174. TEST_F(MacAsyncSocketTest, TestTcpIPv6) {
  175. SocketTest::TestTcpIPv6();
  176. }
  177. TEST_F(MacAsyncSocketTest, TestSingleFlowControlCallbackIPv4) {
  178. SocketTest::TestSingleFlowControlCallbackIPv4();
  179. }
  180. TEST_F(MacAsyncSocketTest, TestSingleFlowControlCallbackIPv6) {
  181. SocketTest::TestSingleFlowControlCallbackIPv6();
  182. }
  183. TEST_F(MacAsyncSocketTest, DISABLED_TestUdpIPv4) {
  184. SocketTest::TestUdpIPv4();
  185. }
  186. TEST_F(MacAsyncSocketTest, DISABLED_TestUdpIPv6) {
  187. SocketTest::TestUdpIPv6();
  188. }
  189. TEST_F(MacAsyncSocketTest, DISABLED_TestGetSetOptionsIPv4) {
  190. SocketTest::TestGetSetOptionsIPv4();
  191. }
  192. TEST_F(MacAsyncSocketTest, DISABLED_TestGetSetOptionsIPv6) {
  193. SocketTest::TestGetSetOptionsIPv6();
  194. }
  195. #ifndef CARBON_DEPRECATED
  196. class MacCarbonAppAsyncSocketTest : public MacAsyncSocketTest {
  197. virtual MacBaseSocketServer* CreateSocketServer() {
  198. return new MacCarbonAppSocketServer();
  199. };
  200. };
  201. TEST_F(MacCarbonAppAsyncSocketTest, TestSocketServerWaitIPv4) {
  202. SocketTest::TestSocketServerWaitIPv4();
  203. }
  204. TEST_F(MacCarbonAppAsyncSocketTest, TestSocketServerWaitIPv6) {
  205. SocketTest::TestSocketServerWaitIPv6();
  206. }
  207. #endif
  208. } // namespace talk_base