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