diff --git a/test/Network/Packet.cpp b/test/Network/Packet.cpp index 19bd0fb1..8c607c06 100644 --- a/test/Network/Packet.cpp +++ b/test/Network/Packet.cpp @@ -2,20 +2,62 @@ #include +#include #include -#define CHECK_PACKET_STREAM_OPERATORS(expected) \ - do \ - { \ - sf::Packet packet; \ - packet << expected; \ - decltype(expected) received; \ - packet >> received; \ - CHECK(expected == received); \ +#define CHECK_PACKET_STREAM_OPERATORS(expected) \ + do \ + { \ + sf::Packet packet; \ + packet << expected; \ + CHECK(packet.getReadPosition() == 0); \ + CHECK(packet.getData() != nullptr); \ + CHECK(packet.getDataSize() == sizeof(expected)); \ + CHECK(!packet.endOfPacket()); \ + CHECK(static_cast(packet)); \ + \ + decltype(expected) received; \ + packet >> received; \ + CHECK(packet.getReadPosition() == sizeof(expected)); \ + CHECK(packet.getData() != nullptr); \ + CHECK(packet.getDataSize() == sizeof(expected)); \ + CHECK(packet.endOfPacket()); \ + CHECK(static_cast(packet)); \ + CHECK(expected == received); \ } while (false) TEST_CASE("sf::Packet class - [network]") { + SUBCASE("Default constructor") + { + const sf::Packet packet; + CHECK(packet.getReadPosition() == 0); + CHECK(packet.getData() == nullptr); + CHECK(packet.getDataSize() == 0); + CHECK(packet.endOfPacket()); + CHECK(static_cast(packet)); + } + + SUBCASE("Append and clear") + { + constexpr std::array data = {1, 2, 3, 4, 5, 6}; + + sf::Packet packet; + packet.append(data.data(), data.size()); + CHECK(packet.getReadPosition() == 0); + CHECK(packet.getData() != nullptr); + CHECK(packet.getDataSize() == data.size()); + CHECK(!packet.endOfPacket()); + CHECK(static_cast(packet)); + + packet.clear(); + CHECK(packet.getReadPosition() == 0); + CHECK(packet.getData() == nullptr); + CHECK(packet.getDataSize() == 0); + CHECK(packet.endOfPacket()); + CHECK(static_cast(packet)); + } + SUBCASE("Stream operators") { SUBCASE("std::int8_t")