From 364fe389568271e6e6cf920f9fca0cf1da7797d5 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Sat, 26 Aug 2023 23:33:08 -0600 Subject: [PATCH] Add tests for `sf::UdpSocket` --- test/Network/UdpSocket.test.cpp | 38 +++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/test/Network/UdpSocket.test.cpp b/test/Network/UdpSocket.test.cpp index 43e03b30..52ddea1d 100644 --- a/test/Network/UdpSocket.test.cpp +++ b/test/Network/UdpSocket.test.cpp @@ -1,8 +1,38 @@ #include +#include + #include -static_assert(!std::is_copy_constructible_v); -static_assert(!std::is_copy_assignable_v); -static_assert(std::is_nothrow_move_constructible_v); -static_assert(std::is_nothrow_move_assignable_v); +TEST_CASE("[Network] sf::UdpSocket") +{ + SECTION("Type traits") + { + STATIC_CHECK(!std::is_copy_constructible_v); + STATIC_CHECK(!std::is_copy_assignable_v); + STATIC_CHECK(std::is_nothrow_move_constructible_v); + STATIC_CHECK(std::is_nothrow_move_assignable_v); + } + + SECTION("Constants") + { + STATIC_CHECK(sf::UdpSocket::MaxDatagramSize == 65507); + } + + SECTION("Construction") + { + const sf::UdpSocket udpSocket; + CHECK(udpSocket.getLocalPort() == 0); + } + + SECTION("bind()/unbind()") + { + sf::UdpSocket udpSocket; + CHECK(udpSocket.bind(sf::Socket::AnyPort, sf::IpAddress::Broadcast) == sf::Socket::Status::Error); + CHECK(udpSocket.bind(sf::Socket::AnyPort) == sf::Socket::Status::Done); + CHECK(udpSocket.getLocalPort() != 0); + + udpSocket.unbind(); + CHECK(udpSocket.getLocalPort() == 0); + } +}