3 * Copyright 2009, Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
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.
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.
28 #include "talk/base/gunit.h"
29 #include "talk/base/scoped_ptr.h"
30 #include "talk/base/socket_unittest.h"
31 #include "talk/base/thread.h"
32 #include "talk/base/macsocketserver.h"
36 class WakeThread : public Thread {
38 WakeThread(SocketServer* ss) : ss_(ss) {
40 virtual ~WakeThread() {
50 #ifndef CARBON_DEPRECATED
52 // Test that MacCFSocketServer::Wait works as expected.
53 TEST(MacCFSocketServerTest, TestWait) {
54 MacCFSocketServer server;
55 uint32 start = Time();
56 server.Wait(1000, true);
57 EXPECT_GE(TimeSince(start), 1000);
60 // Test that MacCFSocketServer::Wakeup works as expected.
61 TEST(MacCFSocketServerTest, TestWakeup) {
62 MacCFSocketServer server;
63 WakeThread thread(&server);
64 uint32 start = Time();
66 server.Wait(10000, true);
67 EXPECT_LT(TimeSince(start), 10000);
70 // Test that MacCarbonSocketServer::Wait works as expected.
71 TEST(MacCarbonSocketServerTest, TestWait) {
72 MacCarbonSocketServer server;
73 uint32 start = Time();
74 server.Wait(1000, true);
75 EXPECT_GE(TimeSince(start), 1000);
78 // Test that MacCarbonSocketServer::Wakeup works as expected.
79 TEST(MacCarbonSocketServerTest, TestWakeup) {
80 MacCarbonSocketServer server;
81 WakeThread thread(&server);
82 uint32 start = Time();
84 server.Wait(10000, true);
85 EXPECT_LT(TimeSince(start), 10000);
88 // Test that MacCarbonAppSocketServer::Wait works as expected.
89 TEST(MacCarbonAppSocketServerTest, TestWait) {
90 MacCarbonAppSocketServer server;
91 uint32 start = Time();
92 server.Wait(1000, true);
93 EXPECT_GE(TimeSince(start), 1000);
96 // Test that MacCarbonAppSocketServer::Wakeup works as expected.
97 TEST(MacCarbonAppSocketServerTest, TestWakeup) {
98 MacCarbonAppSocketServer server;
99 WakeThread thread(&server);
100 uint32 start = Time();
102 server.Wait(10000, true);
103 EXPECT_LT(TimeSince(start), 10000);
108 // Test that MacAsyncSocket passes all the generic Socket tests.
109 class MacAsyncSocketTest : public SocketTest {
112 : server_(CreateSocketServer()),
113 scope_(server_.get()) {}
114 // Override for other implementations of MacBaseSocketServer.
115 virtual MacBaseSocketServer* CreateSocketServer() {
116 return new MacCFSocketServer();
118 talk_base::scoped_ptr<MacBaseSocketServer> server_;
119 SocketServerScope scope_;
122 TEST_F(MacAsyncSocketTest, TestConnectIPv4) {
123 SocketTest::TestConnectIPv4();
126 TEST_F(MacAsyncSocketTest, TestConnectIPv6) {
127 SocketTest::TestConnectIPv6();
130 TEST_F(MacAsyncSocketTest, TestConnectWithDnsLookupIPv4) {
131 SocketTest::TestConnectWithDnsLookupIPv4();
134 TEST_F(MacAsyncSocketTest, TestConnectWithDnsLookupIPv6) {
135 SocketTest::TestConnectWithDnsLookupIPv6();
138 // BUG=https://code.google.com/p/webrtc/issues/detail?id=2272
139 TEST_F(MacAsyncSocketTest, DISABLED_TestConnectFailIPv4) {
140 SocketTest::TestConnectFailIPv4();
143 TEST_F(MacAsyncSocketTest, TestConnectFailIPv6) {
144 SocketTest::TestConnectFailIPv6();
147 // Reenable once we have mac async dns
148 TEST_F(MacAsyncSocketTest, DISABLED_TestConnectWithDnsLookupFailIPv4) {
149 SocketTest::TestConnectWithDnsLookupFailIPv4();
152 TEST_F(MacAsyncSocketTest, DISABLED_TestConnectWithDnsLookupFailIPv6) {
153 SocketTest::TestConnectWithDnsLookupFailIPv6();
156 TEST_F(MacAsyncSocketTest, TestConnectWithClosedSocketIPv4) {
157 SocketTest::TestConnectWithClosedSocketIPv4();
160 TEST_F(MacAsyncSocketTest, TestConnectWithClosedSocketIPv6) {
161 SocketTest::TestConnectWithClosedSocketIPv6();
164 // Flaky at the moment (10% failure rate). Seems the client doesn't get
165 // signalled in a timely manner...
166 TEST_F(MacAsyncSocketTest, DISABLED_TestServerCloseDuringConnectIPv4) {
167 SocketTest::TestServerCloseDuringConnectIPv4();
170 TEST_F(MacAsyncSocketTest, DISABLED_TestServerCloseDuringConnectIPv6) {
171 SocketTest::TestServerCloseDuringConnectIPv6();
173 // Flaky at the moment (0.5% failure rate). Seems the client doesn't get
174 // signalled in a timely manner...
175 TEST_F(MacAsyncSocketTest, TestClientCloseDuringConnectIPv4) {
176 SocketTest::TestClientCloseDuringConnectIPv4();
179 TEST_F(MacAsyncSocketTest, TestClientCloseDuringConnectIPv6) {
180 SocketTest::TestClientCloseDuringConnectIPv6();
183 TEST_F(MacAsyncSocketTest, TestServerCloseIPv4) {
184 SocketTest::TestServerCloseIPv4();
187 TEST_F(MacAsyncSocketTest, TestServerCloseIPv6) {
188 SocketTest::TestServerCloseIPv6();
191 TEST_F(MacAsyncSocketTest, TestCloseInClosedCallbackIPv4) {
192 SocketTest::TestCloseInClosedCallbackIPv4();
195 TEST_F(MacAsyncSocketTest, TestCloseInClosedCallbackIPv6) {
196 SocketTest::TestCloseInClosedCallbackIPv6();
199 TEST_F(MacAsyncSocketTest, TestSocketServerWaitIPv4) {
200 SocketTest::TestSocketServerWaitIPv4();
203 TEST_F(MacAsyncSocketTest, TestSocketServerWaitIPv6) {
204 SocketTest::TestSocketServerWaitIPv6();
207 TEST_F(MacAsyncSocketTest, TestTcpIPv4) {
208 SocketTest::TestTcpIPv4();
211 TEST_F(MacAsyncSocketTest, TestTcpIPv6) {
212 SocketTest::TestTcpIPv6();
215 TEST_F(MacAsyncSocketTest, TestSingleFlowControlCallbackIPv4) {
216 SocketTest::TestSingleFlowControlCallbackIPv4();
219 TEST_F(MacAsyncSocketTest, TestSingleFlowControlCallbackIPv6) {
220 SocketTest::TestSingleFlowControlCallbackIPv6();
223 TEST_F(MacAsyncSocketTest, DISABLED_TestUdpIPv4) {
224 SocketTest::TestUdpIPv4();
227 TEST_F(MacAsyncSocketTest, DISABLED_TestUdpIPv6) {
228 SocketTest::TestUdpIPv6();
231 TEST_F(MacAsyncSocketTest, DISABLED_TestGetSetOptionsIPv4) {
232 SocketTest::TestGetSetOptionsIPv4();
235 TEST_F(MacAsyncSocketTest, DISABLED_TestGetSetOptionsIPv6) {
236 SocketTest::TestGetSetOptionsIPv6();
239 #ifndef CARBON_DEPRECATED
240 class MacCarbonAppAsyncSocketTest : public MacAsyncSocketTest {
241 virtual MacBaseSocketServer* CreateSocketServer() {
242 return new MacCarbonAppSocketServer();
246 TEST_F(MacCarbonAppAsyncSocketTest, TestSocketServerWaitIPv4) {
247 SocketTest::TestSocketServerWaitIPv4();
250 TEST_F(MacCarbonAppAsyncSocketTest, TestSocketServerWaitIPv6) {
251 SocketTest::TestSocketServerWaitIPv6();
254 } // namespace talk_base