Files
Blitz2/test/blitz/protocol/PacketSerializer_test.cpp
2024-07-18 20:45:55 +02:00

31 lines
856 B
C++

#include <blitz/protocol/PacketSerializer.h>
#include <blitz/protocol/PacketFactory.h>
#include <blitz/utils/Test.h>
namespace bp = blitz::protocol;
static int TestAllPackets() {
for (std::size_t i = 0; i < static_cast<std::size_t>(bp::PacketType::PACKET_COUNT); i++) {
const auto& packet = bp::PacketFactory::CreateReadOnlyPacket(bp::PacketType(i));
Nz::ByteArray buffer = bp::PacketSerializer::Serialize(*packet.get());
bp::PacketPtr packet2 = bp::PacketSerializer::Deserialize(buffer);
blitz_test_assert(packet2 != nullptr);
blitz_test_assert(packet2->GetType() == packet->GetType());
}
return 0;
}
static void Test() {
bp::packets::ChatMessage packet({"caca"});
Nz::ByteArray buffer = bp::PacketSerializer::Serialize(packet);
}
int main() {
Test();
return TestAllPackets();
}