From 272e99a2df5a1b094fc5442eeb5fb37a3f324151 Mon Sep 17 00:00:00 2001 From: Jesus Perez Date: Mon, 19 Feb 2024 12:23:11 +0100 Subject: [PATCH] Refs #20141: Fix windows tests Signed-off-by: Jesus Perez --- test/unittest/transport/TCPv4Tests.cpp | 18 ++++++++---------- test/unittest/transport/TCPv6Tests.cpp | 18 ++++++++---------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/test/unittest/transport/TCPv4Tests.cpp b/test/unittest/transport/TCPv4Tests.cpp index ed31e75db14..cd57786c746 100644 --- a/test/unittest/transport/TCPv4Tests.cpp +++ b/test/unittest/transport/TCPv4Tests.cpp @@ -2059,12 +2059,12 @@ TEST_F(TCPv4Tests, reconnect_after_open_port_failure) // Create a TCP Server transport TCPv4TransportDescriptor serverDescriptor; serverDescriptor.add_listener_port(port); - TCPv4Transport* serverTransportUnderTest = new TCPv4Transport(serverDescriptor); + std::unique_ptr serverTransportUnderTest(new TCPv4Transport(serverDescriptor)); serverTransportUnderTest->init(); // Create a TCP Client transport TCPv4TransportDescriptor clientDescriptor; - MockTCPv4Transport* clientTransportUnderTest = new MockTCPv4Transport(clientDescriptor); + std::unique_ptr clientTransportUnderTest(new MockTCPv4Transport(clientDescriptor)); clientTransportUnderTest->init(); // Add initial peer to the client @@ -2087,14 +2087,14 @@ TEST_F(TCPv4Tests, reconnect_after_open_port_failure) // Disconnect server EXPECT_TRUE(serverTransportUnderTest->CloseInputChannel(initialPeerLocator)); - delete serverTransportUnderTest; + serverTransportUnderTest.reset(); std::this_thread::sleep_for(std::chrono::milliseconds(300)); // Client should have passed logical port to pending list ASSERT_FALSE(channel->is_logical_port_opened(7410)); ASSERT_TRUE(channel->is_logical_port_added(7410)); // Now try normal reconnection - serverTransportUnderTest = new TCPv4Transport(serverDescriptor); + serverTransportUnderTest.reset(new TCPv4Transport(serverDescriptor)); serverTransportUnderTest->init(); ASSERT_TRUE(serverTransportUnderTest->OpenInputChannel(initialPeerLocator, nullptr, 0x00FF)); clientTransportUnderTest->send(nullptr, 0, channel->locator(), initialPeerLocator); // connect() @@ -2105,7 +2105,7 @@ TEST_F(TCPv4Tests, reconnect_after_open_port_failure) // Disconnect server EXPECT_TRUE(serverTransportUnderTest->CloseInputChannel(initialPeerLocator)); - delete serverTransportUnderTest; + serverTransportUnderTest.reset(); std::this_thread::sleep_for(std::chrono::milliseconds(300)); // Client should have passed logical port to pending list ASSERT_FALSE(channel->is_logical_port_opened(7410)); @@ -2113,18 +2113,18 @@ TEST_F(TCPv4Tests, reconnect_after_open_port_failure) // Now try reconnect the server and close server's input channel before client's open logical // port request, and then delete server and reconnect - serverTransportUnderTest = new TCPv4Transport(serverDescriptor); + serverTransportUnderTest.reset(new TCPv4Transport(serverDescriptor)); serverTransportUnderTest->init(); ASSERT_TRUE(serverTransportUnderTest->OpenInputChannel(initialPeerLocator, nullptr, 0x00FF)); EXPECT_TRUE(serverTransportUnderTest->CloseInputChannel(initialPeerLocator)); clientTransportUnderTest->send(nullptr, 0, channel->locator(), initialPeerLocator); // connect() std::this_thread::sleep_for(std::chrono::milliseconds(300)); - delete serverTransportUnderTest; + serverTransportUnderTest.reset(); ASSERT_FALSE(channel->is_logical_port_opened(7410)); ASSERT_TRUE(channel->is_logical_port_added(7410)); // Now try normal reconnection - serverTransportUnderTest = new TCPv4Transport(serverDescriptor); + serverTransportUnderTest.reset(new TCPv4Transport(serverDescriptor)); serverTransportUnderTest->init(); ASSERT_TRUE(serverTransportUnderTest->OpenInputChannel(initialPeerLocator, nullptr, 0x00FF)); clientTransportUnderTest->send(nullptr, 0, channel->locator(), initialPeerLocator); // connect() @@ -2136,8 +2136,6 @@ TEST_F(TCPv4Tests, reconnect_after_open_port_failure) // Clear test EXPECT_TRUE(serverTransportUnderTest->CloseInputChannel(initialPeerLocator)); client_resource_list.clear(); - delete serverTransportUnderTest; - delete clientTransportUnderTest; } void TCPv4Tests::HELPER_SetDescriptorDefaults() diff --git a/test/unittest/transport/TCPv6Tests.cpp b/test/unittest/transport/TCPv6Tests.cpp index 2fad09db4b4..ca4e91bb3c9 100644 --- a/test/unittest/transport/TCPv6Tests.cpp +++ b/test/unittest/transport/TCPv6Tests.cpp @@ -409,12 +409,12 @@ TEST_F(TCPv6Tests, reconnect_after_open_port_failure) // Create a TCP Server transport TCPv6TransportDescriptor serverDescriptor; serverDescriptor.add_listener_port(port); - TCPv6Transport* serverTransportUnderTest = new TCPv6Transport(serverDescriptor); + std::unique_ptr serverTransportUnderTest(new TCPv6Transport(serverDescriptor)); serverTransportUnderTest->init(); // Create a TCP Client transport TCPv6TransportDescriptor clientDescriptor; - MockTCPv6Transport* clientTransportUnderTest = new MockTCPv6Transport(clientDescriptor); + std::unique_ptr clientTransportUnderTest(new MockTCPv6Transport(clientDescriptor)); clientTransportUnderTest->init(); // Add initial peer to the client @@ -437,14 +437,14 @@ TEST_F(TCPv6Tests, reconnect_after_open_port_failure) // Disconnect server EXPECT_TRUE(serverTransportUnderTest->CloseInputChannel(initialPeerLocator)); - delete serverTransportUnderTest; + serverTransportUnderTest.reset(); std::this_thread::sleep_for(std::chrono::milliseconds(300)); // Client should have passed logical port to pending list ASSERT_FALSE(channel->is_logical_port_opened(7410)); ASSERT_TRUE(channel->is_logical_port_added(7410)); // Now try normal reconnection - serverTransportUnderTest = new TCPv6Transport(serverDescriptor); + serverTransportUnderTest.reset(new TCPv6Transport(serverDescriptor)); serverTransportUnderTest->init(); ASSERT_TRUE(serverTransportUnderTest->OpenInputChannel(initialPeerLocator, nullptr, 0x00FF)); clientTransportUnderTest->send(nullptr, 0, channel->locator(), initialPeerLocator); // connect() @@ -455,7 +455,7 @@ TEST_F(TCPv6Tests, reconnect_after_open_port_failure) // Disconnect server EXPECT_TRUE(serverTransportUnderTest->CloseInputChannel(initialPeerLocator)); - delete serverTransportUnderTest; + serverTransportUnderTest.reset(); std::this_thread::sleep_for(std::chrono::milliseconds(300)); // Client should have passed logical port to pending list ASSERT_FALSE(channel->is_logical_port_opened(7410)); @@ -463,18 +463,18 @@ TEST_F(TCPv6Tests, reconnect_after_open_port_failure) // Now try reconnect the server and close server's input channel before client's open logical // port request, and then delete server and reconnect - serverTransportUnderTest = new TCPv6Transport(serverDescriptor); + serverTransportUnderTest.reset(new TCPv6Transport(serverDescriptor)); serverTransportUnderTest->init(); ASSERT_TRUE(serverTransportUnderTest->OpenInputChannel(initialPeerLocator, nullptr, 0x00FF)); EXPECT_TRUE(serverTransportUnderTest->CloseInputChannel(initialPeerLocator)); clientTransportUnderTest->send(nullptr, 0, channel->locator(), initialPeerLocator); // connect() std::this_thread::sleep_for(std::chrono::milliseconds(300)); - delete serverTransportUnderTest; + serverTransportUnderTest.reset(); ASSERT_FALSE(channel->is_logical_port_opened(7410)); ASSERT_TRUE(channel->is_logical_port_added(7410)); // Now try normal reconnection - serverTransportUnderTest = new TCPv6Transport(serverDescriptor); + serverTransportUnderTest.reset(new TCPv6Transport(serverDescriptor)); serverTransportUnderTest->init(); ASSERT_TRUE(serverTransportUnderTest->OpenInputChannel(initialPeerLocator, nullptr, 0x00FF)); clientTransportUnderTest->send(nullptr, 0, channel->locator(), initialPeerLocator); // connect() @@ -486,8 +486,6 @@ TEST_F(TCPv6Tests, reconnect_after_open_port_failure) // Clear test EXPECT_TRUE(serverTransportUnderTest->CloseInputChannel(initialPeerLocator)); client_resource_list.clear(); - delete serverTransportUnderTest; - delete clientTransportUnderTest; }