Add tests for sf::Socket
This commit is contained in:
parent
bbb6f60dda
commit
29ed8bf3a0
@ -1,9 +1,79 @@
|
||||
#include <SFML/Network/Socket.hpp>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(!std::is_constructible_v<sf::Socket>);
|
||||
static_assert(!std::is_copy_constructible_v<sf::Socket>);
|
||||
static_assert(!std::is_copy_assignable_v<sf::Socket>);
|
||||
static_assert(!std::is_nothrow_move_constructible_v<sf::Socket>);
|
||||
static_assert(!std::is_nothrow_move_assignable_v<sf::Socket>);
|
||||
class TestSocket : public sf::Socket
|
||||
{
|
||||
public:
|
||||
TestSocket() : sf::Socket(sf::Socket::Type::Udp)
|
||||
{
|
||||
}
|
||||
|
||||
using sf::Socket::close;
|
||||
using sf::Socket::create;
|
||||
using sf::Socket::getHandle;
|
||||
};
|
||||
|
||||
TEST_CASE("[Network] sf::Socket")
|
||||
{
|
||||
SECTION("Type traits")
|
||||
{
|
||||
STATIC_CHECK(!std::is_constructible_v<sf::Socket>);
|
||||
STATIC_CHECK(!std::is_copy_constructible_v<sf::Socket>);
|
||||
STATIC_CHECK(!std::is_copy_assignable_v<sf::Socket>);
|
||||
STATIC_CHECK(!std::is_nothrow_move_constructible_v<sf::Socket>);
|
||||
STATIC_CHECK(!std::is_nothrow_move_assignable_v<sf::Socket>);
|
||||
}
|
||||
|
||||
SECTION("Constants")
|
||||
{
|
||||
STATIC_CHECK(sf::Socket::AnyPort == 0);
|
||||
}
|
||||
|
||||
const auto invalidHandle = static_cast<sf::SocketHandle>(-1);
|
||||
|
||||
SECTION("Construction")
|
||||
{
|
||||
const TestSocket testSocket;
|
||||
CHECK(testSocket.isBlocking());
|
||||
CHECK(testSocket.getHandle() == invalidHandle);
|
||||
}
|
||||
|
||||
SECTION("Set/get blocking")
|
||||
{
|
||||
TestSocket testSocket;
|
||||
testSocket.setBlocking(false);
|
||||
CHECK(!testSocket.isBlocking());
|
||||
}
|
||||
|
||||
SECTION("create()")
|
||||
{
|
||||
TestSocket testSocket;
|
||||
testSocket.create();
|
||||
CHECK(testSocket.isBlocking());
|
||||
CHECK(testSocket.getHandle() != invalidHandle);
|
||||
|
||||
// Recreate socket to ensure nothing changed
|
||||
testSocket.create();
|
||||
CHECK(testSocket.isBlocking());
|
||||
CHECK(testSocket.getHandle() != invalidHandle);
|
||||
}
|
||||
|
||||
SECTION("close()")
|
||||
{
|
||||
TestSocket testSocket;
|
||||
testSocket.create();
|
||||
CHECK(testSocket.isBlocking());
|
||||
CHECK(testSocket.getHandle() != invalidHandle);
|
||||
testSocket.close();
|
||||
CHECK(testSocket.isBlocking());
|
||||
CHECK(testSocket.getHandle() == invalidHandle);
|
||||
|
||||
// Reclose socket to ensure nothing changed
|
||||
testSocket.close();
|
||||
CHECK(testSocket.isBlocking());
|
||||
CHECK(testSocket.getHandle() == invalidHandle);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user