2021-12-06 06:27:48 +08:00
|
|
|
#include <SFML/Network.hpp>
|
|
|
|
|
2022-07-18 06:18:40 +08:00
|
|
|
#include <doctest/doctest.h>
|
2022-07-05 00:20:58 +08:00
|
|
|
|
2021-12-06 06:27:48 +08:00
|
|
|
#include <limits>
|
|
|
|
|
|
|
|
template <typename IntegerType>
|
|
|
|
static void testPacketStreamOperators(IntegerType expected)
|
|
|
|
{
|
|
|
|
sf::Packet packet;
|
|
|
|
packet << expected;
|
|
|
|
IntegerType received;
|
|
|
|
packet >> received;
|
|
|
|
CHECK(expected == received);
|
|
|
|
}
|
|
|
|
|
2021-12-24 21:31:27 +08:00
|
|
|
TEST_CASE("sf::Packet class - [network]")
|
2021-12-06 06:27:48 +08:00
|
|
|
{
|
2021-12-24 21:31:27 +08:00
|
|
|
SUBCASE("Stream operators")
|
2021-12-06 06:27:48 +08:00
|
|
|
{
|
2021-12-24 21:31:27 +08:00
|
|
|
SUBCASE("Int8")
|
2021-12-06 06:27:48 +08:00
|
|
|
{
|
|
|
|
testPacketStreamOperators(sf::Int8(0));
|
|
|
|
testPacketStreamOperators(sf::Int8(1));
|
|
|
|
testPacketStreamOperators(std::numeric_limits<sf::Int8>::min());
|
|
|
|
testPacketStreamOperators(std::numeric_limits<sf::Int8>::max());
|
|
|
|
}
|
|
|
|
|
2021-12-24 21:31:27 +08:00
|
|
|
SUBCASE("Int16")
|
2021-12-06 06:27:48 +08:00
|
|
|
{
|
|
|
|
testPacketStreamOperators(sf::Int16(0));
|
|
|
|
testPacketStreamOperators(sf::Int16(1));
|
|
|
|
testPacketStreamOperators(std::numeric_limits<sf::Int16>::min());
|
|
|
|
testPacketStreamOperators(std::numeric_limits<sf::Int16>::max());
|
|
|
|
}
|
|
|
|
|
2021-12-24 21:31:27 +08:00
|
|
|
SUBCASE("Int32")
|
2021-12-06 06:27:48 +08:00
|
|
|
{
|
|
|
|
testPacketStreamOperators(sf::Int32(0));
|
|
|
|
testPacketStreamOperators(sf::Int32(1));
|
|
|
|
testPacketStreamOperators(std::numeric_limits<sf::Int32>::min());
|
|
|
|
testPacketStreamOperators(std::numeric_limits<sf::Int32>::max());
|
|
|
|
}
|
|
|
|
|
2021-12-24 21:31:27 +08:00
|
|
|
SUBCASE("Int64")
|
2021-12-06 06:27:48 +08:00
|
|
|
{
|
|
|
|
testPacketStreamOperators(sf::Int64(0));
|
|
|
|
testPacketStreamOperators(sf::Int64(1));
|
|
|
|
testPacketStreamOperators(std::numeric_limits<sf::Int64>::min());
|
|
|
|
testPacketStreamOperators(std::numeric_limits<sf::Int64>::max());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|