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) {
47
// Test that MacCFSocketServer::Wait works as expected.
48
TEST(MacCFSocketServerTest, TestWait) {
49
MacCFSocketServer server;
50
uint32 start = Time();
51
server.Wait(1000, true);
52
EXPECT_GE(TimeSince(start), 1000);
55
// Test that MacCFSocketServer::Wakeup works as expected.
56
TEST(MacCFSocketServerTest, TestWakeup) {
57
MacCFSocketServer server;
58
WakeThread thread(&server);
59
uint32 start = Time();
61
server.Wait(10000, true);
62
EXPECT_LT(TimeSince(start), 10000);
65
// Test that MacCarbonSocketServer::Wait works as expected.
66
TEST(MacCarbonSocketServerTest, TestWait) {
67
MacCarbonSocketServer server;
68
uint32 start = Time();
69
server.Wait(1000, true);
70
EXPECT_GE(TimeSince(start), 1000);
73
// Test that MacCarbonSocketServer::Wakeup works as expected.
74
TEST(MacCarbonSocketServerTest, TestWakeup) {
75
MacCarbonSocketServer server;
76
WakeThread thread(&server);
77
uint32 start = Time();
79
server.Wait(10000, true);
80
EXPECT_LT(TimeSince(start), 10000);
83
// Test that MacCarbonAppSocketServer::Wait works as expected.
84
TEST(MacCarbonAppSocketServerTest, TestWait) {
85
MacCarbonAppSocketServer server;
86
uint32 start = Time();
87
server.Wait(1000, true);
88
EXPECT_GE(TimeSince(start), 1000);
91
// Test that MacCarbonAppSocketServer::Wakeup works as expected.
92
TEST(MacCarbonAppSocketServerTest, TestWakeup) {
93
MacCarbonAppSocketServer server;
94
WakeThread thread(&server);
95
uint32 start = Time();
97
server.Wait(10000, true);
98
EXPECT_LT(TimeSince(start), 10000);
101
// Test that MacAsyncSocket passes all the generic Socket tests.
102
class MacAsyncSocketTest : public SocketTest {
105
: server_(CreateSocketServer()),
106
scope_(server_.get()) {}
107
// Override for other implementations of MacBaseSocketServer.
108
virtual MacBaseSocketServer* CreateSocketServer() {
109
return new MacCFSocketServer();
111
talk_base::scoped_ptr<MacBaseSocketServer> server_;
112
SocketServerScope scope_;
115
TEST_F(MacAsyncSocketTest, TestConnect) {
116
SocketTest::TestConnect();
119
TEST_F(MacAsyncSocketTest, TestConnectWithDnsLookup) {
120
SocketTest::TestConnectWithDnsLookup();
123
TEST_F(MacAsyncSocketTest, TestConnectFail) {
124
SocketTest::TestConnectFail();
127
// Reenable once we have mac async dns
128
TEST_F(MacAsyncSocketTest, DISABLED_TestConnectWithDnsLookupFail) {
129
SocketTest::TestConnectWithDnsLookupFail();
132
TEST_F(MacAsyncSocketTest, TestConnectWithClosedSocket) {
133
SocketTest::TestConnectWithClosedSocket();
136
// Flaky at the moment (10% failure rate). Seems the client doesn't get
137
// signalled in a timely manner...
138
TEST_F(MacAsyncSocketTest, DISABLED_TestServerCloseDuringConnect) {
139
SocketTest::TestServerCloseDuringConnect();
141
// Flaky at the moment (0.5% failure rate). Seems the client doesn't get
142
// signalled in a timely manner...
143
TEST_F(MacAsyncSocketTest, TestClientCloseDuringConnect) {
144
SocketTest::TestClientCloseDuringConnect();
147
TEST_F(MacAsyncSocketTest, TestServerClose) {
148
SocketTest::TestServerClose();
151
TEST_F(MacAsyncSocketTest, TestCloseInClosedCallback) {
152
SocketTest::TestCloseInClosedCallback();
155
TEST_F(MacAsyncSocketTest, TestSocketServerWait) {
156
SocketTest::TestSocketServerWait();
159
TEST_F(MacAsyncSocketTest, TestTcp) {
160
SocketTest::TestTcp();
163
TEST_F(MacAsyncSocketTest, TestSingleFlowControlCallback) {
164
SocketTest::TestSingleFlowControlCallback();
167
TEST_F(MacAsyncSocketTest, DISABLED_TestUdp) {
168
SocketTest::TestUdp();
171
TEST_F(MacAsyncSocketTest, DISABLED_TestGetSetOptions) {
172
SocketTest::TestGetSetOptions();
175
class MacCarbonAsyncSocketTest : public MacAsyncSocketTest {
176
virtual MacBaseSocketServer* CreateSocketServer() {
177
return new MacCarbonSocketServer();
181
TEST_F(MacCarbonAsyncSocketTest, TestSocketServerWait) {
182
SocketTest::TestSocketServerWait();
185
class MacCarbonAppAsyncSocketTest : public MacAsyncSocketTest {
186
virtual MacBaseSocketServer* CreateSocketServer() {
187
return new MacCarbonAppSocketServer();
191
TEST_F(MacCarbonAppAsyncSocketTest, TestSocketServerWait) {
192
SocketTest::TestSocketServerWait();
195
} // namespace talk_base