36 lines
882 B
C++
36 lines
882 B
C++
#include <td/protocol/packet/PacketSerializer.h>
|
|
|
|
#include <td/misc/Test.h>
|
|
#include <td/protocol/packet/PacketFactory.h>
|
|
|
|
namespace tp = td::protocol;
|
|
|
|
template <typename Packet_T, typename Packet_Data_T = typename Packet_T::PacketDataType>
|
|
static int TestPacket() {
|
|
Packet_T packet;
|
|
|
|
td::DataBuffer buffer = tp::PacketSerializer::Serialize(packet);
|
|
|
|
auto abstractPacket = tp::PacketSerializer::Deserialize(buffer);
|
|
|
|
td_test_assert(abstractPacket);
|
|
|
|
Packet_T* packet2 = dynamic_cast<Packet_T*>(abstractPacket.get());
|
|
|
|
td_test_assert(packet2);
|
|
td_test_assert(packet.GetType() == packet2->GetType());
|
|
|
|
return std::memcmp(&packet.m_Data, &packet2->m_Data, sizeof(Packet_Data_T));
|
|
}
|
|
|
|
#define DeclarePacket(Packet, ...) TestPacket<tp::packets::Packet>();
|
|
|
|
static int TestAllPackets() {
|
|
DeclareAllPacket()
|
|
|
|
return TD_TEST_SUCCESSFUL;
|
|
}
|
|
|
|
int main() {
|
|
return TestAllPackets();
|
|
} |