add tests
This commit is contained in:
15
test/blitz/protocol/packet/PacketFactory_test.cpp
Normal file
15
test/blitz/protocol/packet/PacketFactory_test.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <td/protocol/packet/PacketFactory.h>
|
||||
|
||||
static int Test() {
|
||||
for (std::size_t i = 0; i < static_cast<int>(td::protocol::PacketType::PACKET_COUNT); i++) {
|
||||
td::protocol::PacketType packetType = td::protocol::PacketType(i);
|
||||
|
||||
if (td::protocol::PacketFactory::CreateReadOnlyPacket(packetType)->GetType() != packetType)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
return Test();
|
||||
}
|
||||
31
test/blitz/protocol/packet/PacketSerializer_test.cpp
Normal file
31
test/blitz/protocol/packet/PacketSerializer_test.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <td/protocol/packet/PacketSerializer.h>
|
||||
|
||||
#include <td/misc/Test.h>
|
||||
#include <td/protocol/packet/PacketFactory.h>
|
||||
|
||||
namespace tp = td::protocol;
|
||||
|
||||
static int TestAllPackets() {
|
||||
for (std::size_t i = 0; i < static_cast<std::size_t>(tp::PacketType::PACKET_COUNT); i++) {
|
||||
const auto& packet = tp::PacketFactory::CreateReadOnlyPacket(tp::PacketType(i));
|
||||
|
||||
td::DataBuffer buffer = tp::PacketSerializer::Serialize(*packet.get());
|
||||
|
||||
tp::PacketPtr packet2 = tp::PacketSerializer::Deserialize(buffer);
|
||||
|
||||
td_test_assert(packet2 != nullptr);
|
||||
|
||||
td_test_assert(packet2->GetType() == packet->GetType());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void Test() {
|
||||
tp::packets::ChatMessage packet({"caca"});
|
||||
td::DataBuffer buffer = tp::PacketSerializer::Serialize(packet);
|
||||
}
|
||||
|
||||
int main() {
|
||||
Test();
|
||||
return TestAllPackets();
|
||||
}
|
||||
Reference in New Issue
Block a user