blob: a4a71019dd61c1107b75b69c631720035062a4a3 [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
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +0000135// BUG=https://code.google.com/p/webrtc/issues/detail?id=2272
henrike@webrtc.orgc0b1a282013-08-23 14:32:21 +0000136TEST_F(MacAsyncSocketTest, DISABLED_TestConnectFailIPv4) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000137 SocketTest::TestConnectFailIPv4();
138}
139
140TEST_F(MacAsyncSocketTest, TestConnectFailIPv6) {
141 SocketTest::TestConnectFailIPv6();
142}
143
144// Reenable once we have mac async dns
145TEST_F(MacAsyncSocketTest, DISABLED_TestConnectWithDnsLookupFailIPv4) {
146 SocketTest::TestConnectWithDnsLookupFailIPv4();
147}
148
149TEST_F(MacAsyncSocketTest, DISABLED_TestConnectWithDnsLookupFailIPv6) {
150 SocketTest::TestConnectWithDnsLookupFailIPv6();
151}
152
153TEST_F(MacAsyncSocketTest, TestConnectWithClosedSocketIPv4) {
154 SocketTest::TestConnectWithClosedSocketIPv4();
155}
156
157TEST_F(MacAsyncSocketTest, TestConnectWithClosedSocketIPv6) {
158 SocketTest::TestConnectWithClosedSocketIPv6();
159}
160
161// Flaky at the moment (10% failure rate). Seems the client doesn't get
162// signalled in a timely manner...
163TEST_F(MacAsyncSocketTest, DISABLED_TestServerCloseDuringConnectIPv4) {
164 SocketTest::TestServerCloseDuringConnectIPv4();
165}
166
167TEST_F(MacAsyncSocketTest, DISABLED_TestServerCloseDuringConnectIPv6) {
168 SocketTest::TestServerCloseDuringConnectIPv6();
169}
170// Flaky at the moment (0.5% failure rate). Seems the client doesn't get
171// signalled in a timely manner...
172TEST_F(MacAsyncSocketTest, TestClientCloseDuringConnectIPv4) {
173 SocketTest::TestClientCloseDuringConnectIPv4();
174}
175
176TEST_F(MacAsyncSocketTest, TestClientCloseDuringConnectIPv6) {
177 SocketTest::TestClientCloseDuringConnectIPv6();
178}
179
180TEST_F(MacAsyncSocketTest, TestServerCloseIPv4) {
181 SocketTest::TestServerCloseIPv4();
182}
183
184TEST_F(MacAsyncSocketTest, TestServerCloseIPv6) {
185 SocketTest::TestServerCloseIPv6();
186}
187
188TEST_F(MacAsyncSocketTest, TestCloseInClosedCallbackIPv4) {
189 SocketTest::TestCloseInClosedCallbackIPv4();
190}
191
192TEST_F(MacAsyncSocketTest, TestCloseInClosedCallbackIPv6) {
193 SocketTest::TestCloseInClosedCallbackIPv6();
194}
195
196TEST_F(MacAsyncSocketTest, TestSocketServerWaitIPv4) {
197 SocketTest::TestSocketServerWaitIPv4();
198}
199
200TEST_F(MacAsyncSocketTest, TestSocketServerWaitIPv6) {
201 SocketTest::TestSocketServerWaitIPv6();
202}
203
204TEST_F(MacAsyncSocketTest, TestTcpIPv4) {
205 SocketTest::TestTcpIPv4();
206}
207
208TEST_F(MacAsyncSocketTest, TestTcpIPv6) {
209 SocketTest::TestTcpIPv6();
210}
211
212TEST_F(MacAsyncSocketTest, TestSingleFlowControlCallbackIPv4) {
213 SocketTest::TestSingleFlowControlCallbackIPv4();
214}
215
216TEST_F(MacAsyncSocketTest, TestSingleFlowControlCallbackIPv6) {
217 SocketTest::TestSingleFlowControlCallbackIPv6();
218}
219
220TEST_F(MacAsyncSocketTest, DISABLED_TestUdpIPv4) {
221 SocketTest::TestUdpIPv4();
222}
223
224TEST_F(MacAsyncSocketTest, DISABLED_TestUdpIPv6) {
225 SocketTest::TestUdpIPv6();
226}
227
228TEST_F(MacAsyncSocketTest, DISABLED_TestGetSetOptionsIPv4) {
229 SocketTest::TestGetSetOptionsIPv4();
230}
231
232TEST_F(MacAsyncSocketTest, DISABLED_TestGetSetOptionsIPv6) {
233 SocketTest::TestGetSetOptionsIPv6();
234}
235
236#ifndef CARBON_DEPRECATED
237class MacCarbonAppAsyncSocketTest : public MacAsyncSocketTest {
238 virtual MacBaseSocketServer* CreateSocketServer() {
239 return new MacCarbonAppSocketServer();
240 };
241};
242
243TEST_F(MacCarbonAppAsyncSocketTest, TestSocketServerWaitIPv4) {
244 SocketTest::TestSocketServerWaitIPv4();
245}
246
247TEST_F(MacCarbonAppAsyncSocketTest, TestSocketServerWaitIPv6) {
248 SocketTest::TestSocketServerWaitIPv6();
249}
250#endif
251} // namespace talk_base