mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
Add tests for sf::SocketSelector
I added move semantics while I was at it
This commit is contained in:
parent
b3a467678d
commit
63088c1bf1
@ -65,6 +65,28 @@ public:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SocketSelector(const SocketSelector& copy);
|
SocketSelector(const SocketSelector& copy);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Overload of assignment operator
|
||||||
|
///
|
||||||
|
/// \param right Instance to assign
|
||||||
|
///
|
||||||
|
/// \return Reference to self
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
SocketSelector& operator=(const SocketSelector& right);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Move constructor
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
SocketSelector(SocketSelector&&) noexcept;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Move assignment
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
SocketSelector& operator=(SocketSelector&&) noexcept;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Add a new socket to the selector
|
/// \brief Add a new socket to the selector
|
||||||
///
|
///
|
||||||
@ -142,16 +164,6 @@ public:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool isReady(Socket& socket) const;
|
bool isReady(Socket& socket) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Overload of assignment operator
|
|
||||||
///
|
|
||||||
/// \param right Instance to assign
|
|
||||||
///
|
|
||||||
/// \return Reference to self
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SocketSelector& operator=(const SocketSelector& right);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct SocketSelectorImpl;
|
struct SocketSelectorImpl;
|
||||||
|
|
||||||
|
@ -60,6 +60,10 @@ SocketSelector::SocketSelector() : m_impl(std::make_unique<SocketSelectorImpl>()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
SocketSelector::~SocketSelector() = default;
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SocketSelector::SocketSelector(const SocketSelector& copy) : m_impl(std::make_unique<SocketSelectorImpl>(*copy.m_impl))
|
SocketSelector::SocketSelector(const SocketSelector& copy) : m_impl(std::make_unique<SocketSelectorImpl>(*copy.m_impl))
|
||||||
{
|
{
|
||||||
@ -67,7 +71,20 @@ SocketSelector::SocketSelector(const SocketSelector& copy) : m_impl(std::make_un
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SocketSelector::~SocketSelector() = default;
|
SocketSelector& SocketSelector::operator=(const SocketSelector& right)
|
||||||
|
{
|
||||||
|
SocketSelector temp(right);
|
||||||
|
std::swap(m_impl, temp.m_impl);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
SocketSelector::SocketSelector(SocketSelector&&) noexcept = default;
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////]
|
||||||
|
SocketSelector& SocketSelector::operator=(SocketSelector&&) noexcept = default;
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@ -189,15 +206,4 @@ bool SocketSelector::isReady(Socket& socket) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SocketSelector& SocketSelector::operator=(const SocketSelector& right)
|
|
||||||
{
|
|
||||||
SocketSelector temp(right);
|
|
||||||
|
|
||||||
std::swap(m_impl, temp.m_impl);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
@ -1,10 +1,27 @@
|
|||||||
#include <SFML/Network/SocketSelector.hpp>
|
#include <SFML/Network/SocketSelector.hpp>
|
||||||
|
|
||||||
|
// Other 1st party headers
|
||||||
|
#include <SFML/Network/UdpSocket.hpp>
|
||||||
|
|
||||||
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
static_assert(std::is_copy_constructible_v<sf::SocketSelector>);
|
TEST_CASE("[Network] sf::SocketSelector")
|
||||||
static_assert(std::is_copy_assignable_v<sf::SocketSelector>);
|
{
|
||||||
static_assert(std::is_move_constructible_v<sf::SocketSelector>);
|
SECTION("Type traits")
|
||||||
static_assert(!std::is_nothrow_move_constructible_v<sf::SocketSelector>);
|
{
|
||||||
static_assert(std::is_move_assignable_v<sf::SocketSelector>);
|
STATIC_CHECK(std::is_copy_constructible_v<sf::SocketSelector>);
|
||||||
static_assert(!std::is_nothrow_move_assignable_v<sf::SocketSelector>);
|
STATIC_CHECK(std::is_copy_assignable_v<sf::SocketSelector>);
|
||||||
|
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::SocketSelector>);
|
||||||
|
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::SocketSelector>);
|
||||||
|
}
|
||||||
|
|
||||||
|
sf::UdpSocket socket;
|
||||||
|
|
||||||
|
SECTION("Construction")
|
||||||
|
{
|
||||||
|
const sf::SocketSelector socketSelector;
|
||||||
|
CHECK(!socketSelector.isReady(socket));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user