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

Unified Diff: webrtc/base/virtualsocket_unittest.cc

Issue 2859373003: Refactor TestClient to use std::unique_ptr, and fix VirtualSocketServerTest leaks. (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/base/virtualsocket_unittest.cc
diff --git a/webrtc/base/virtualsocket_unittest.cc b/webrtc/base/virtualsocket_unittest.cc
index e2f1d05f16f446fdaf4b95c36074978cff47606f..6d50fdd0bce854dda0a6f3985bc088ff8cd067c0 100644
--- a/webrtc/base/virtualsocket_unittest.cc
+++ b/webrtc/base/virtualsocket_unittest.cc
@@ -17,8 +17,9 @@
#include <memory>
#include "webrtc/base/arraysize.h"
-#include "webrtc/base/logging.h"
#include "webrtc/base/gunit.h"
+#include "webrtc/base/logging.h"
+#include "webrtc/base/ptr_util.h"
#include "webrtc/base/testclient.h"
#include "webrtc/base/testutils.h"
#include "webrtc/base/thread.h"
@@ -180,7 +181,8 @@ class VirtualSocketServerTest : public testing::Test {
socket->Bind(EmptySocketAddressWithFamily(default_route.family()));
SocketAddress client1_any_addr = socket->GetLocalAddress();
EXPECT_TRUE(client1_any_addr.IsAnyIP());
- TestClient* client1 = new TestClient(new AsyncUDPSocket(socket));
+ std::unique_ptr<TestClient> client1(
+ new TestClient(MakeUnique<AsyncUDPSocket>(socket)));
kwiberg-webrtc 2017/05/05 11:04:42 Why not use MakeUnique for TestClient too? auto
nisse-webrtc 2017/05/05 12:12:56 Done. I take it you don't want to see any use of t
kwiberg-webrtc 2017/05/05 12:40:31 No; as I said in an earlier comment, I think consi
// Create client2 bound to the default route.
AsyncSocket* socket2 =
@@ -188,7 +190,8 @@ class VirtualSocketServerTest : public testing::Test {
socket2->Bind(SocketAddress(default_route, 0));
SocketAddress client2_addr = socket2->GetLocalAddress();
EXPECT_FALSE(client2_addr.IsAnyIP());
- TestClient* client2 = new TestClient(new AsyncUDPSocket(socket2));
+ std::unique_ptr<TestClient> client2(
+ new TestClient(MakeUnique<AsyncUDPSocket>(socket2)));
// Client1 sends to client2, client2 should see the default route as
// client1's address.
@@ -211,10 +214,12 @@ class VirtualSocketServerTest : public testing::Test {
// Make sure VSS didn't switch families on us.
EXPECT_EQ(server_addr.family(), initial_addr.family());
- TestClient* client1 = new TestClient(new AsyncUDPSocket(socket));
+ std::unique_ptr<TestClient> client1(
+ new TestClient(MakeUnique<AsyncUDPSocket>(socket)));
AsyncSocket* socket2 =
ss_->CreateAsyncSocket(initial_addr.family(), SOCK_DGRAM);
- TestClient* client2 = new TestClient(new AsyncUDPSocket(socket2));
+ std::unique_ptr<TestClient> client2(
+ new TestClient(MakeUnique<AsyncUDPSocket>(socket2)));
SocketAddress client2_addr;
EXPECT_EQ(3, client2->SendTo("foo", 3, server_addr));
@@ -227,7 +232,8 @@ class VirtualSocketServerTest : public testing::Test {
SocketAddress empty = EmptySocketAddressWithFamily(initial_addr.family());
for (int i = 0; i < 10; i++) {
- client2 = new TestClient(AsyncUDPSocket::Create(ss_, empty));
+ client2.reset(
+ new TestClient(WrapUnique(AsyncUDPSocket::Create(ss_, empty))));
SocketAddress next_client2_addr;
EXPECT_EQ(3, client2->SendTo("foo", 3, server_addr));
@@ -801,11 +807,13 @@ class VirtualSocketServerTest : public testing::Test {
AsyncSocket* socket = ss_->CreateAsyncSocket(SOCK_DGRAM);
socket->Bind(server_addr);
SocketAddress bound_server_addr = socket->GetLocalAddress();
- TestClient* client1 = new TestClient(new AsyncUDPSocket(socket));
+ std::unique_ptr<TestClient> client1(
+ new TestClient(MakeUnique<AsyncUDPSocket>(socket)));
AsyncSocket* socket2 = ss_->CreateAsyncSocket(SOCK_DGRAM);
socket2->Bind(client_addr);
- TestClient* client2 = new TestClient(new AsyncUDPSocket(socket2));
+ std::unique_ptr<TestClient> client2(
+ new TestClient(MakeUnique<AsyncUDPSocket>(socket2)));
SocketAddress client2_addr;
if (shouldSucceed) {
@@ -1030,7 +1038,8 @@ TEST_F(VirtualSocketServerTest, SetSendingBlockedWithUdpSocket) {
ss_->CreateAsyncSocket(kIPv4AnyAddress.family(), SOCK_DGRAM);
socket1->Bind(kIPv4AnyAddress);
socket2->Bind(kIPv4AnyAddress);
- TestClient* client1 = new TestClient(new AsyncUDPSocket(socket1));
+ std::unique_ptr<TestClient> client1(
+ new TestClient(MakeUnique<AsyncUDPSocket>(socket1)));
ss_->SetSendingBlocked(true);
EXPECT_EQ(-1, client1->SendTo("foo", 3, socket2->GetLocalAddress()));

Powered by Google App Engine
This is Rietveld 408576698