From 7df450836969b81e98322c9a09c08b35d1095a25 Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Thu, 24 Aug 2023 15:20:53 +0200 Subject: [PATCH] test: improve sock_tests/move_assignment Use also a socket for the moved-to object and check which one is closed when. --- src/test/sock_tests.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/test/sock_tests.cpp b/src/test/sock_tests.cpp index 9641831e196..5dd73dc1016 100644 --- a/src/test/sock_tests.cpp +++ b/src/test/sock_tests.cpp @@ -58,15 +58,27 @@ BOOST_AUTO_TEST_CASE(move_constructor) BOOST_AUTO_TEST_CASE(move_assignment) { - const SOCKET s = CreateSocket(); - Sock* sock1 = new Sock(s); - Sock* sock2 = new Sock(INVALID_SOCKET); + const SOCKET s1 = CreateSocket(); + const SOCKET s2 = CreateSocket(); + Sock* sock1 = new Sock(s1); + Sock* sock2 = new Sock(s2); + + BOOST_CHECK(!SocketIsClosed(s1)); + BOOST_CHECK(!SocketIsClosed(s2)); + *sock2 = std::move(*sock1); + BOOST_CHECK(!SocketIsClosed(s1)); + BOOST_CHECK(SocketIsClosed(s2)); + BOOST_CHECK(*sock2 == s1); + delete sock1; - BOOST_CHECK(!SocketIsClosed(s)); - BOOST_CHECK(*sock2 == s); + BOOST_CHECK(!SocketIsClosed(s1)); + BOOST_CHECK(SocketIsClosed(s2)); + BOOST_CHECK(*sock2 == s1); + delete sock2; - BOOST_CHECK(SocketIsClosed(s)); + BOOST_CHECK(SocketIsClosed(s1)); + BOOST_CHECK(SocketIsClosed(s2)); } #ifndef WIN32 // Windows does not have socketpair(2).