improve tests
This commit is contained in:
@@ -18,10 +18,10 @@ namespace test {
|
||||
#define TD_TEST_SUCCESSFUL 0
|
||||
|
||||
/**
|
||||
* \def BLITZ_TEST_FAILED
|
||||
* \def TD_TEST_FAILED
|
||||
* \brief Used in tests to indicate that a test failed
|
||||
*/
|
||||
#define BLITZ_TEST_FAILED 1
|
||||
#define TD_TEST_FAILED 1
|
||||
|
||||
#ifndef __FUNCTION_NAME__
|
||||
#ifdef _WIN32
|
||||
@@ -40,7 +40,7 @@ namespace test {
|
||||
#define td_test_assert(...) \
|
||||
if (!static_cast<bool>(__VA_ARGS__)) { \
|
||||
td::test::LogAssert(#__VA_ARGS__, __FILE__, __LINE__, __FUNCTION_NAME__); \
|
||||
std::exit(BLITZ_TEST_FAILED); \
|
||||
std::exit(TD_TEST_FAILED); \
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
#include <td/protocol/packet/PacketFactory.h>
|
||||
|
||||
#include <td/misc/Test.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 TD_TEST_FAILED;
|
||||
}
|
||||
return 0;
|
||||
return TD_TEST_SUCCESSFUL;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
@@ -5,27 +5,32 @@
|
||||
|
||||
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));
|
||||
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.get());
|
||||
td::DataBuffer buffer = tp::PacketSerializer::Serialize(packet);
|
||||
|
||||
tp::PacketPtr packet2 = tp::PacketSerializer::Deserialize(buffer);
|
||||
auto abstractPacket = tp::PacketSerializer::Deserialize(buffer);
|
||||
|
||||
td_test_assert(packet2 != nullptr);
|
||||
td_test_assert(abstractPacket);
|
||||
|
||||
td_test_assert(packet2->GetType() == packet->GetType());
|
||||
}
|
||||
return 0;
|
||||
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));
|
||||
}
|
||||
|
||||
static void Test() {
|
||||
tp::packets::ChatMessage packet({"caca"});
|
||||
td::DataBuffer buffer = tp::PacketSerializer::Serialize(packet);
|
||||
#define DeclarePacket(Packet, ...) TestPacket<tp::packets::Packet>();
|
||||
|
||||
static int TestAllPackets() {
|
||||
DeclareAllPacket()
|
||||
|
||||
return TD_TEST_SUCCESSFUL;
|
||||
}
|
||||
|
||||
int main() {
|
||||
Test();
|
||||
return TestAllPackets();
|
||||
}
|
||||
Reference in New Issue
Block a user