Skip to content

Commit

Permalink
Add tests for UDPSocket copy constructor.
Browse files Browse the repository at this point in the history
Add more explicit assertions for TCPSocket copy constructor too.
  • Loading branch information
Kilemonn committed Jul 8, 2024
1 parent 3e01d03 commit cfeb031
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/socket/TCPSocketTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ namespace kt
{
TCPSocket server = serverSocket.acceptTCPConnection();
TCPSocket copiedSocket(socket);

ASSERT_EQ(socket.getHostname(), copiedSocket.getHostname());
ASSERT_EQ(socket.getPort(), copiedSocket.getPort());
ASSERT_EQ(socket.getInternetProtocolVersion(), copiedSocket.getInternetProtocolVersion());
kt::SocketAddress initialAddress = socket.getSocketAddress();
kt::SocketAddress copiedAddress = copiedSocket.getSocketAddress();
ASSERT_EQ(0, std::memcmp(&initialAddress, &copiedAddress, sizeof(initialAddress)));

const std::string testString = "Test";
ASSERT_TRUE(copiedSocket.send(testString));
Expand Down
14 changes: 14 additions & 0 deletions tests/socket/UDPSocketTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ namespace kt
ASSERT_EQ(kt::InternetProtocolVersion::Any, socket.getInternetProtocolVersion());
}

TEST_F(UDPSocketTest, UDPCopyConstructors)
{
socket.bind();
UDPSocket copiedSocket(socket);

ASSERT_EQ(socket.isUdpBound(), copiedSocket.isUdpBound());
ASSERT_NE(std::nullopt, socket.getListeningPort());
ASSERT_NE(std::nullopt, copiedSocket.getListeningPort());
ASSERT_EQ(socket.getListeningPort().value(), copiedSocket.getListeningPort().value());
ASSERT_EQ(socket.getInternetProtocolVersion(), copiedSocket.getInternetProtocolVersion());

copiedSocket.close();
}

/*
* Ensure that multiple calls to UDPSocket.bind() fails if another socket is already bound to that port.
*/
Expand Down

0 comments on commit cfeb031

Please sign in to comment.