~ubuntu-branches/debian/experimental/kopete/experimental

« back to all changes in this revision

Viewing changes to protocols/jabber/googletalk/libjingle/talk/base/macsocketserver_unittest.cc

  • Committer: Package Import Robot
  • Author(s): Maximiliano Curia
  • Date: 2015-02-24 11:32:57 UTC
  • mfrom: (1.1.41 vivid)
  • Revision ID: package-import@ubuntu.com-20150224113257-gnupg4v7lzz18ij0
Tags: 4:14.12.2-1
* New upstream release (14.12.2).
* Bump Standards-Version to 3.9.6, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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:
38
 
  WakeThread(SocketServer* ss) : ss_(ss) {
39
 
  }
40
 
  void Run() {
41
 
    ss_->WakeUp();
42
 
  }
43
 
 private:
44
 
  SocketServer* ss_;
45
 
};
46
 
 
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);
53
 
}
54
 
 
55
 
// Test that MacCFSocketServer::Wakeup works as expected.
56
 
TEST(MacCFSocketServerTest, TestWakeup) {
57
 
  MacCFSocketServer server;
58
 
  WakeThread thread(&server);
59
 
  uint32 start = Time();
60
 
  thread.Start();
61
 
  server.Wait(10000, true);
62
 
  EXPECT_LT(TimeSince(start), 10000);
63
 
}
64
 
 
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);
71
 
}
72
 
 
73
 
// Test that MacCarbonSocketServer::Wakeup works as expected.
74
 
TEST(MacCarbonSocketServerTest, TestWakeup) {
75
 
  MacCarbonSocketServer server;
76
 
  WakeThread thread(&server);
77
 
  uint32 start = Time();
78
 
  thread.Start();
79
 
  server.Wait(10000, true);
80
 
  EXPECT_LT(TimeSince(start), 10000);
81
 
}
82
 
 
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);
89
 
}
90
 
 
91
 
// Test that MacCarbonAppSocketServer::Wakeup works as expected.
92
 
TEST(MacCarbonAppSocketServerTest, TestWakeup) {
93
 
  MacCarbonAppSocketServer server;
94
 
  WakeThread thread(&server);
95
 
  uint32 start = Time();
96
 
  thread.Start();
97
 
  server.Wait(10000, true);
98
 
  EXPECT_LT(TimeSince(start), 10000);
99
 
}
100
 
 
101
 
// Test that MacAsyncSocket passes all the generic Socket tests.
102
 
class MacAsyncSocketTest : public SocketTest {
103
 
 protected:
104
 
  MacAsyncSocketTest()
105
 
      : server_(CreateSocketServer()),
106
 
        scope_(server_.get()) {}
107
 
  // Override for other implementations of MacBaseSocketServer.
108
 
  virtual MacBaseSocketServer* CreateSocketServer() {
109
 
    return new MacCFSocketServer();
110
 
  };
111
 
  talk_base::scoped_ptr<MacBaseSocketServer> server_;
112
 
  SocketServerScope scope_;
113
 
};
114
 
 
115
 
TEST_F(MacAsyncSocketTest, TestConnect) {
116
 
  SocketTest::TestConnect();
117
 
}
118
 
 
119
 
TEST_F(MacAsyncSocketTest, TestConnectWithDnsLookup) {
120
 
  SocketTest::TestConnectWithDnsLookup();
121
 
}
122
 
 
123
 
TEST_F(MacAsyncSocketTest, TestConnectFail) {
124
 
  SocketTest::TestConnectFail();
125
 
}
126
 
 
127
 
// Reenable once we have mac async dns
128
 
TEST_F(MacAsyncSocketTest, DISABLED_TestConnectWithDnsLookupFail) {
129
 
  SocketTest::TestConnectWithDnsLookupFail();
130
 
}
131
 
 
132
 
TEST_F(MacAsyncSocketTest, TestConnectWithClosedSocket) {
133
 
  SocketTest::TestConnectWithClosedSocket();
134
 
}
135
 
 
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();
140
 
}
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();
145
 
}
146
 
 
147
 
TEST_F(MacAsyncSocketTest, TestServerClose) {
148
 
  SocketTest::TestServerClose();
149
 
}
150
 
 
151
 
TEST_F(MacAsyncSocketTest, TestCloseInClosedCallback) {
152
 
  SocketTest::TestCloseInClosedCallback();
153
 
}
154
 
 
155
 
TEST_F(MacAsyncSocketTest, TestSocketServerWait) {
156
 
  SocketTest::TestSocketServerWait();
157
 
}
158
 
 
159
 
TEST_F(MacAsyncSocketTest, TestTcp) {
160
 
  SocketTest::TestTcp();
161
 
}
162
 
 
163
 
TEST_F(MacAsyncSocketTest, TestSingleFlowControlCallback) {
164
 
  SocketTest::TestSingleFlowControlCallback();
165
 
}
166
 
 
167
 
TEST_F(MacAsyncSocketTest, DISABLED_TestUdp) {
168
 
  SocketTest::TestUdp();
169
 
}
170
 
 
171
 
TEST_F(MacAsyncSocketTest, DISABLED_TestGetSetOptions) {
172
 
  SocketTest::TestGetSetOptions();
173
 
}
174
 
 
175
 
class MacCarbonAsyncSocketTest : public MacAsyncSocketTest {
176
 
  virtual MacBaseSocketServer* CreateSocketServer() {
177
 
    return new MacCarbonSocketServer();
178
 
  };
179
 
};
180
 
 
181
 
TEST_F(MacCarbonAsyncSocketTest, TestSocketServerWait) {
182
 
  SocketTest::TestSocketServerWait();
183
 
}
184
 
 
185
 
class MacCarbonAppAsyncSocketTest : public MacAsyncSocketTest {
186
 
  virtual MacBaseSocketServer* CreateSocketServer() {
187
 
    return new MacCarbonAppSocketServer();
188
 
  };
189
 
};
190
 
 
191
 
TEST_F(MacCarbonAppAsyncSocketTest, TestSocketServerWait) {
192
 
  SocketTest::TestSocketServerWait();
193
 
}
194
 
 
195
 
}  // namespace talk_base