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