Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: webrtc/p2p/base/turnport_unittest.cc

Issue 2622413005: Replace use of ASSERT in test code. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 #if defined(WEBRTC_POSIX) 10 #if defined(WEBRTC_POSIX)
11 #include <dirent.h> 11 #include <dirent.h>
12 #endif 12 #endif
13 13
14 #include <memory> 14 #include <memory>
15 15
16 #include "webrtc/p2p/base/basicpacketsocketfactory.h" 16 #include "webrtc/p2p/base/basicpacketsocketfactory.h"
17 #include "webrtc/p2p/base/p2pconstants.h" 17 #include "webrtc/p2p/base/p2pconstants.h"
18 #include "webrtc/p2p/base/portallocator.h" 18 #include "webrtc/p2p/base/portallocator.h"
19 #include "webrtc/p2p/base/tcpport.h" 19 #include "webrtc/p2p/base/tcpport.h"
20 #include "webrtc/p2p/base/testturnserver.h" 20 #include "webrtc/p2p/base/testturnserver.h"
21 #include "webrtc/p2p/base/turnport.h" 21 #include "webrtc/p2p/base/turnport.h"
22 #include "webrtc/p2p/base/udpport.h" 22 #include "webrtc/p2p/base/udpport.h"
23 #include "webrtc/base/asynctcpsocket.h" 23 #include "webrtc/base/asynctcpsocket.h"
24 #include "webrtc/base/buffer.h" 24 #include "webrtc/base/buffer.h"
25 #include "webrtc/base/checks.h"
25 #include "webrtc/base/dscp.h" 26 #include "webrtc/base/dscp.h"
26 #include "webrtc/base/fakeclock.h" 27 #include "webrtc/base/fakeclock.h"
27 #include "webrtc/base/firewallsocketserver.h" 28 #include "webrtc/base/firewallsocketserver.h"
28 #include "webrtc/base/gunit.h" 29 #include "webrtc/base/gunit.h"
29 #include "webrtc/base/helpers.h" 30 #include "webrtc/base/helpers.h"
30 #include "webrtc/base/logging.h" 31 #include "webrtc/base/logging.h"
31 #include "webrtc/base/physicalsocketserver.h" 32 #include "webrtc/base/physicalsocketserver.h"
32 #include "webrtc/base/socketadapters.h" 33 #include "webrtc/base/socketadapters.h"
33 #include "webrtc/base/socketaddress.h" 34 #include "webrtc/base/socketaddress.h"
34 #include "webrtc/base/ssladapter.h" 35 #include "webrtc/base/ssladapter.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 public: 122 public:
122 TestConnectionWrapper(Connection* conn) : connection_(conn) { 123 TestConnectionWrapper(Connection* conn) : connection_(conn) {
123 conn->SignalDestroyed.connect( 124 conn->SignalDestroyed.connect(
124 this, &TestConnectionWrapper::OnConnectionDestroyed); 125 this, &TestConnectionWrapper::OnConnectionDestroyed);
125 } 126 }
126 127
127 Connection* connection() { return connection_; } 128 Connection* connection() { return connection_; }
128 129
129 private: 130 private:
130 void OnConnectionDestroyed(Connection* conn) { 131 void OnConnectionDestroyed(Connection* conn) {
131 ASSERT_TRUE(conn == connection_); 132 ASSERT_TRUE(conn == connection_);
nisse-webrtc 2017/01/17 15:00:03 This could just as well be an EXPECT_TRUE (or EXPE
kwiberg-webrtc 2017/01/18 09:40:35 Acknowledged.
132 connection_ = nullptr; 133 connection_ = nullptr;
133 } 134 }
134 135
135 Connection* connection_; 136 Connection* connection_;
136 }; 137 };
137 138
138 // Note: This test uses a fake clock with a simulated network round trip 139 // Note: This test uses a fake clock with a simulated network round trip
139 // (between local port and TURN server) of kSimulatedRtt. 140 // (between local port and TURN server) of kSimulatedRtt.
140 class TurnPortTest : public testing::Test, 141 class TurnPortTest : public testing::Test,
141 public sigslot::has_slots<>, 142 public sigslot::has_slots<>,
(...skipping 14 matching lines...) Expand all
156 udp_ready_(false), 157 udp_ready_(false),
157 test_finish_(false) { 158 test_finish_(false) {
158 // Some code uses "last received time == 0" to represent "nothing received 159 // Some code uses "last received time == 0" to represent "nothing received
159 // so far", so we need to start the fake clock at a nonzero time... 160 // so far", so we need to start the fake clock at a nonzero time...
160 // TODO(deadbeef): Fix this. 161 // TODO(deadbeef): Fix this.
161 fake_clock_.AdvanceTime(rtc::TimeDelta::FromSeconds(1)); 162 fake_clock_.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
162 network_.AddIP(rtc::IPAddress(INADDR_ANY)); 163 network_.AddIP(rtc::IPAddress(INADDR_ANY));
163 } 164 }
164 165
165 virtual void OnMessage(rtc::Message* msg) { 166 virtual void OnMessage(rtc::Message* msg) {
166 ASSERT(msg->message_id == MSG_TESTFINISH); 167 RTC_CHECK(msg->message_id == MSG_TESTFINISH);
167 if (msg->message_id == MSG_TESTFINISH) 168 if (msg->message_id == MSG_TESTFINISH)
168 test_finish_ = true; 169 test_finish_ = true;
169 } 170 }
170 171
171 void ConnectSignalAddressReadyToSetLocalhostAsAltenertativeLocalAddress() { 172 void ConnectSignalAddressReadyToSetLocalhostAsAltenertativeLocalAddress() {
172 rtc::AsyncPacketSocket* socket = turn_port_->socket(); 173 rtc::AsyncPacketSocket* socket = turn_port_->socket();
173 rtc::VirtualSocket* virtual_socket = 174 rtc::VirtualSocket* virtual_socket =
174 ss_->LookupBinding(socket->GetLocalAddress()); 175 ss_->LookupBinding(socket->GetLocalAddress());
175 virtual_socket->SignalAddressReady.connect( 176 virtual_socket->SignalAddressReady.connect(
176 this, &TurnPortTest::SetLocalhostAsAltenertativeLocalAddress); 177 this, &TurnPortTest::SetLocalhostAsAltenertativeLocalAddress);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 server_address, credentials, 0, 267 server_address, credentials, 0,
267 origin)); 268 origin));
268 // This TURN port will be the controlling. 269 // This TURN port will be the controlling.
269 turn_port_->SetIceRole(ICEROLE_CONTROLLING); 270 turn_port_->SetIceRole(ICEROLE_CONTROLLING);
270 ConnectSignals(); 271 ConnectSignals();
271 } 272 }
272 273
273 void CreateSharedTurnPort(const std::string& username, 274 void CreateSharedTurnPort(const std::string& username,
274 const std::string& password, 275 const std::string& password,
275 const ProtocolAddress& server_address) { 276 const ProtocolAddress& server_address) {
276 ASSERT(server_address.proto == PROTO_UDP); 277 RTC_CHECK(server_address.proto == PROTO_UDP);
kwiberg-webrtc 2017/01/17 09:39:25 ASSERT_* is used elsewhere in this function.
nisse-webrtc 2017/01/17 12:19:21 And that use is probably broken...
kwiberg-webrtc 2017/01/17 13:52:47 In that case, EXPECT_* may be better.
277 278
278 if (!socket_) { 279 if (!socket_) {
279 socket_.reset(socket_factory_.CreateUdpSocket( 280 socket_.reset(socket_factory_.CreateUdpSocket(
280 rtc::SocketAddress(kLocalAddr1.ipaddr(), 0), 0, 0)); 281 rtc::SocketAddress(kLocalAddr1.ipaddr(), 0), 0, 0));
281 ASSERT_TRUE(socket_ != NULL); 282 ASSERT_TRUE(socket_ != NULL);
nisse-webrtc 2017/01/17 15:00:03 While this actually looks like a possibly working
kwiberg-webrtc 2017/01/18 09:40:35 Acknowledged.
282 socket_->SignalReadPacket.connect( 283 socket_->SignalReadPacket.connect(
283 this, &TurnPortTest::OnSocketReadPacket); 284 this, &TurnPortTest::OnSocketReadPacket);
284 } 285 }
285 286
286 RelayCredentials credentials(username, password); 287 RelayCredentials credentials(username, password);
287 turn_port_.reset(TurnPort::Create( 288 turn_port_.reset(TurnPort::Create(
288 main_, &socket_factory_, &network_, socket_.get(), kIceUfrag1, kIcePwd1, 289 main_, &socket_factory_, &network_, socket_.get(), kIceUfrag1, kIcePwd1,
289 server_address, credentials, 0, std::string())); 290 server_address, credentials, 0, std::string()));
290 // This TURN port will be the controlling. 291 // This TURN port will be the controlling.
291 turn_port_->SetIceRole(ICEROLE_CONTROLLING); 292 turn_port_->SetIceRole(ICEROLE_CONTROLLING);
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 EXPECT_TRUE(turn_port_->Candidates().empty()); 1259 EXPECT_TRUE(turn_port_->Candidates().empty());
1259 turn_port_.reset(); 1260 turn_port_.reset();
1260 rtc::Thread::Current()->Post(RTC_FROM_HERE, this, MSG_TESTFINISH); 1261 rtc::Thread::Current()->Post(RTC_FROM_HERE, this, MSG_TESTFINISH);
1261 // Waiting for above message to be processed. 1262 // Waiting for above message to be processed.
1262 ASSERT_TRUE_SIMULATED_WAIT(test_finish_, 1, fake_clock_); 1263 ASSERT_TRUE_SIMULATED_WAIT(test_finish_, 1, fake_clock_);
1263 EXPECT_EQ(last_fd_count, GetFDCount()); 1264 EXPECT_EQ(last_fd_count, GetFDCount());
1264 } 1265 }
1265 #endif 1266 #endif
1266 1267
1267 } // namespace cricket 1268 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698