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 11#include "webrtc/base/gunit.h" 12#include "webrtc/base/scoped_ptr.h" 13#include "webrtc/base/socket_unittest.h" 14#include "webrtc/base/thread.h" 15#include "webrtc/base/macsocketserver.h" 16 17namespace rtc { 18 19class WakeThread : public Thread { 20 public: 21 WakeThread(SocketServer* ss) : ss_(ss) { 22 } 23 virtual ~WakeThread() { 24 Stop(); 25 } 26 void Run() { 27 ss_->WakeUp(); 28 } 29 private: 30 SocketServer* ss_; 31}; 32 33#ifndef CARBON_DEPRECATED 34 35// Test that MacCFSocketServer::Wait works as expected. 36TEST(MacCFSocketServerTest, DISABLED_TestWait) { 37 MacCFSocketServer server; 38 uint32 start = Time(); 39 server.Wait(1000, true); 40 EXPECT_GE(TimeSince(start), 1000); 41} 42 43// Test that MacCFSocketServer::Wakeup works as expected. 44TEST(MacCFSocketServerTest, DISABLED_TestWakeup) { 45 MacCFSocketServer server; 46 WakeThread thread(&server); 47 uint32 start = Time(); 48 thread.Start(); 49 server.Wait(10000, true); 50 EXPECT_LT(TimeSince(start), 10000); 51} 52 53// Test that MacCarbonSocketServer::Wait works as expected. 54TEST(MacCarbonSocketServerTest, DISABLED_TestWait) { 55 MacCarbonSocketServer server; 56 uint32 start = Time(); 57 server.Wait(1000, true); 58 EXPECT_GE(TimeSince(start), 1000); 59} 60 61// Test that MacCarbonSocketServer::Wakeup works as expected. 62TEST(MacCarbonSocketServerTest, DISABLED_TestWakeup) { 63 MacCarbonSocketServer server; 64 WakeThread thread(&server); 65 uint32 start = Time(); 66 thread.Start(); 67 server.Wait(10000, true); 68 EXPECT_LT(TimeSince(start), 10000); 69} 70 71// Test that MacCarbonAppSocketServer::Wait works as expected. 72TEST(MacCarbonAppSocketServerTest, DISABLED_TestWait) { 73 MacCarbonAppSocketServer server; 74 uint32 start = Time(); 75 server.Wait(1000, true); 76 EXPECT_GE(TimeSince(start), 1000); 77} 78 79// Test that MacCarbonAppSocketServer::Wakeup works as expected. 80TEST(MacCarbonAppSocketServerTest, DISABLED_TestWakeup) { 81 MacCarbonAppSocketServer server; 82 WakeThread thread(&server); 83 uint32 start = Time(); 84 thread.Start(); 85 server.Wait(10000, true); 86 EXPECT_LT(TimeSince(start), 10000); 87} 88 89#endif 90 91// Test that MacAsyncSocket passes all the generic Socket tests. 92class MacAsyncSocketTest : public SocketTest { 93 protected: 94 MacAsyncSocketTest() 95 : server_(CreateSocketServer()), 96 scope_(server_.get()) {} 97 // Override for other implementations of MacBaseSocketServer. 98 virtual MacBaseSocketServer* CreateSocketServer() { 99 return new MacCFSocketServer(); 100 }; 101 rtc::scoped_ptr<MacBaseSocketServer> server_; 102 SocketServerScope scope_; 103}; 104 105TEST_F(MacAsyncSocketTest, DISABLED_TestConnectIPv4) { 106 SocketTest::TestConnectIPv4(); 107} 108 109TEST_F(MacAsyncSocketTest, DISABLED_TestConnectIPv6) { 110 SocketTest::TestConnectIPv6(); 111} 112 113TEST_F(MacAsyncSocketTest, DISABLED_TestConnectWithDnsLookupIPv4) { 114 SocketTest::TestConnectWithDnsLookupIPv4(); 115} 116 117TEST_F(MacAsyncSocketTest, DISABLED_TestConnectWithDnsLookupIPv6) { 118 SocketTest::TestConnectWithDnsLookupIPv6(); 119} 120 121// BUG=https://code.google.com/p/webrtc/issues/detail?id=2272 122TEST_F(MacAsyncSocketTest, DISABLED_TestConnectFailIPv4) { 123 SocketTest::TestConnectFailIPv4(); 124} 125 126TEST_F(MacAsyncSocketTest, DISABLED_TestConnectFailIPv6) { 127 SocketTest::TestConnectFailIPv6(); 128} 129 130// Reenable once we have mac async dns 131TEST_F(MacAsyncSocketTest, DISABLED_TestConnectWithDnsLookupFailIPv4) { 132 SocketTest::TestConnectWithDnsLookupFailIPv4(); 133} 134 135TEST_F(MacAsyncSocketTest, DISABLED_TestConnectWithDnsLookupFailIPv6) { 136 SocketTest::TestConnectWithDnsLookupFailIPv6(); 137} 138 139TEST_F(MacAsyncSocketTest, DISABLED_TestConnectWithClosedSocketIPv4) { 140 SocketTest::TestConnectWithClosedSocketIPv4(); 141} 142 143TEST_F(MacAsyncSocketTest, DISABLED_TestConnectWithClosedSocketIPv6) { 144 SocketTest::TestConnectWithClosedSocketIPv6(); 145} 146 147// Flaky at the moment (10% failure rate). Seems the client doesn't get 148// signalled in a timely manner... 149TEST_F(MacAsyncSocketTest, DISABLED_TestServerCloseDuringConnectIPv4) { 150 SocketTest::TestServerCloseDuringConnectIPv4(); 151} 152 153TEST_F(MacAsyncSocketTest, DISABLED_TestServerCloseDuringConnectIPv6) { 154 SocketTest::TestServerCloseDuringConnectIPv6(); 155} 156// Flaky at the moment (0.5% failure rate). Seems the client doesn't get 157// signalled in a timely manner... 158TEST_F(MacAsyncSocketTest, DISABLED_TestClientCloseDuringConnectIPv4) { 159 SocketTest::TestClientCloseDuringConnectIPv4(); 160} 161 162TEST_F(MacAsyncSocketTest, DISABLED_TestClientCloseDuringConnectIPv6) { 163 SocketTest::TestClientCloseDuringConnectIPv6(); 164} 165 166TEST_F(MacAsyncSocketTest, DISABLED_TestServerCloseIPv4) { 167 SocketTest::TestServerCloseIPv4(); 168} 169 170TEST_F(MacAsyncSocketTest, DISABLED_TestServerCloseIPv6) { 171 SocketTest::TestServerCloseIPv6(); 172} 173 174TEST_F(MacAsyncSocketTest, DISABLED_TestCloseInClosedCallbackIPv4) { 175 SocketTest::TestCloseInClosedCallbackIPv4(); 176} 177 178TEST_F(MacAsyncSocketTest, DISABLED_TestCloseInClosedCallbackIPv6) { 179 SocketTest::TestCloseInClosedCallbackIPv6(); 180} 181 182TEST_F(MacAsyncSocketTest, DISABLED_TestSocketServerWaitIPv4) { 183 SocketTest::TestSocketServerWaitIPv4(); 184} 185 186TEST_F(MacAsyncSocketTest, DISABLED_TestSocketServerWaitIPv6) { 187 SocketTest::TestSocketServerWaitIPv6(); 188} 189 190TEST_F(MacAsyncSocketTest, DISABLED_TestTcpIPv4) { 191 SocketTest::TestTcpIPv4(); 192} 193 194TEST_F(MacAsyncSocketTest, DISABLED_TestTcpIPv6) { 195 SocketTest::TestTcpIPv6(); 196} 197 198TEST_F(MacAsyncSocketTest, DISABLED_TestSingleFlowControlCallbackIPv4) { 199 SocketTest::TestSingleFlowControlCallbackIPv4(); 200} 201 202TEST_F(MacAsyncSocketTest, DISABLED_TestSingleFlowControlCallbackIPv6) { 203 SocketTest::TestSingleFlowControlCallbackIPv6(); 204} 205 206TEST_F(MacAsyncSocketTest, DISABLED_TestUdpIPv4) { 207 SocketTest::TestUdpIPv4(); 208} 209 210TEST_F(MacAsyncSocketTest, DISABLED_TestUdpIPv6) { 211 SocketTest::TestUdpIPv6(); 212} 213 214TEST_F(MacAsyncSocketTest, DISABLED_TestGetSetOptionsIPv4) { 215 SocketTest::TestGetSetOptionsIPv4(); 216} 217 218TEST_F(MacAsyncSocketTest, DISABLED_TestGetSetOptionsIPv6) { 219 SocketTest::TestGetSetOptionsIPv6(); 220} 221 222#ifndef CARBON_DEPRECATED 223class MacCarbonAppAsyncSocketTest : public MacAsyncSocketTest { 224 virtual MacBaseSocketServer* CreateSocketServer() { 225 return new MacCarbonAppSocketServer(); 226 }; 227}; 228 229TEST_F(MacCarbonAppAsyncSocketTest, DISABLED_TestSocketServerWaitIPv4) { 230 SocketTest::TestSocketServerWaitIPv4(); 231} 232 233TEST_F(MacCarbonAppAsyncSocketTest, DISABLED_TestSocketServerWaitIPv6) { 234 SocketTest::TestSocketServerWaitIPv6(); 235} 236#endif 237} // namespace rtc 238