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

Side by Side Diff: webrtc/base/nat_unittest.cc

Issue 2859373003: Refactor TestClient to use std::unique_ptr, and fix VirtualSocketServerTest leaks. (Closed)
Patch Set: Comment fix, 0 -> null. Created 3 years, 7 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
« no previous file with comments | « no previous file | webrtc/base/proxy_unittest.cc » ('j') | webrtc/base/virtualsocket_unittest.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 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 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <memory> 12 #include <memory>
13 #include <string> 13 #include <string>
14 14
15 #include "webrtc/base/asynctcpsocket.h"
15 #include "webrtc/base/gunit.h" 16 #include "webrtc/base/gunit.h"
16 #include "webrtc/base/logging.h" 17 #include "webrtc/base/logging.h"
17 #include "webrtc/base/natserver.h" 18 #include "webrtc/base/natserver.h"
18 #include "webrtc/base/natsocketfactory.h" 19 #include "webrtc/base/natsocketfactory.h"
19 #include "webrtc/base/nethelpers.h" 20 #include "webrtc/base/nethelpers.h"
20 #include "webrtc/base/network.h" 21 #include "webrtc/base/network.h"
21 #include "webrtc/base/physicalsocketserver.h" 22 #include "webrtc/base/physicalsocketserver.h"
23 #include "webrtc/base/ptr_util.h"
22 #include "webrtc/base/testclient.h" 24 #include "webrtc/base/testclient.h"
23 #include "webrtc/base/asynctcpsocket.h"
24 #include "webrtc/base/virtualsocketserver.h" 25 #include "webrtc/base/virtualsocketserver.h"
25 26
26 using namespace rtc; 27 using namespace rtc;
27 28
28 bool CheckReceive( 29 bool CheckReceive(
29 TestClient* client, bool should_receive, const char* buf, size_t size) { 30 TestClient* client, bool should_receive, const char* buf, size_t size) {
30 return (should_receive) ? 31 return (should_receive) ?
31 client->CheckNextPacket(buf, size, 0) : 32 client->CheckNextPacket(buf, size, 0) :
32 client->CheckNoPacket(); 33 client->CheckNoPacket();
33 } 34 }
34 35
35 TestClient* CreateTestClient( 36 TestClient* CreateTestClient(
36 SocketFactory* factory, const SocketAddress& local_addr) { 37 SocketFactory* factory, const SocketAddress& local_addr) {
37 AsyncUDPSocket* socket = AsyncUDPSocket::Create(factory, local_addr); 38 return new TestClient(
38 return new TestClient(socket); 39 WrapUnique(AsyncUDPSocket::Create(factory, local_addr)));
39 } 40 }
40 41
41 TestClient* CreateTCPTestClient(AsyncSocket* socket) { 42 TestClient* CreateTCPTestClient(AsyncSocket* socket) {
42 AsyncTCPSocket* packet_socket = new AsyncTCPSocket(socket, false); 43 return new TestClient(MakeUnique<AsyncTCPSocket>(socket, false));
43 return new TestClient(packet_socket);
44 } 44 }
45 45
46 // Tests that when sending from internal_addr to external_addrs through the 46 // Tests that when sending from internal_addr to external_addrs through the
47 // NAT type specified by nat_type, all external addrs receive the sent packet 47 // NAT type specified by nat_type, all external addrs receive the sent packet
48 // and, if exp_same is true, all use the same mapped-address on the NAT. 48 // and, if exp_same is true, all use the same mapped-address on the NAT.
49 void TestSend( 49 void TestSend(
50 SocketServer* internal, const SocketAddress& internal_addr, 50 SocketServer* internal, const SocketAddress& internal_addr,
51 SocketServer* external, const SocketAddress external_addrs[4], 51 SocketServer* external, const SocketAddress external_addrs[4],
52 NATType nat_type, bool exp_same) { 52 NATType nat_type, bool exp_same) {
53 Thread th_int(internal); 53 Thread th_int(internal);
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 size_t len = strlen(buf); 386 size_t len = strlen(buf);
387 387
388 in->Send(buf, len); 388 in->Send(buf, len);
389 SocketAddress trans_addr; 389 SocketAddress trans_addr;
390 EXPECT_TRUE(out->CheckNextPacket(buf, len, &trans_addr)); 390 EXPECT_TRUE(out->CheckNextPacket(buf, len, &trans_addr));
391 391
392 out->Send(buf, len); 392 out->Send(buf, len);
393 EXPECT_TRUE(in->CheckNextPacket(buf, len, &trans_addr)); 393 EXPECT_TRUE(in->CheckNextPacket(buf, len, &trans_addr));
394 } 394 }
395 // #endif 395 // #endif
OLDNEW
« no previous file with comments | « no previous file | webrtc/base/proxy_unittest.cc » ('j') | webrtc/base/virtualsocket_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698