finish serialize

This commit is contained in:
2024-10-18 15:36:00 +02:00
parent 69d96b40ec
commit 871caf9056
9 changed files with 337 additions and 20 deletions

View File

@@ -0,0 +1,17 @@
#include <td/protocol/command/CommandFactory.h>
#include <td/misc/Test.h>
static int Test() {
for (std::size_t i = 0; i < static_cast<int>(td::protocol::CommandType::COMMAND_COUNT); i++) {
td::protocol::CommandType commandType = td::protocol::CommandType(i);
if (td::protocol::CommandFactory::CreateReadOnlyCommand(commandType)->GetType() != commandType)
return TD_TEST_FAILED;
}
return TD_TEST_SUCCESSFUL;
}
int main() {
return Test();
}

View File

@@ -0,0 +1,51 @@
#include <td/protocol/command/CommandSerializer.h>
#include <td/misc/Test.h>
#include <td/protocol/command/CommandFactory.h>
namespace tp = td::protocol;
template <typename Command_T, typename Command_Data_T = typename Command_T::CommandDataType>
static int TestCommand() {
Command_T command;
td::DataBuffer buffer = tp::CommandSerializer::Serialize(command);
auto abstractCommand = tp::CommandSerializer::Deserialize(buffer);
td_test_assert(abstractCommand);
Command_T* command2 = dynamic_cast<Command_T*>(abstractCommand.get());
td_test_assert(command2);
td_test_assert(command.GetType() == command2->GetType());
return std::memcmp(&command.m_Data, &command2->m_Data, sizeof(Command_Data_T));
}
#define DeclareCommand(Command, ...) TestCommand<tp::commands::Command>();
static int TestAllCommands() {
DeclareAllCommand()
return TD_TEST_SUCCESSFUL;
}
static int TestNewTeam() {
tp::commands::TeamChange tc;
tc.m_Data.m_Player = 69;
tc.m_Data.m_NewTeam = td::Team::Red;
td::DataBuffer db = tp::CommandSerializer::Serialize(tc);
auto packet = tp::CommandSerializer::Deserialize(db);
tp::commands::TeamChange* tc2 = dynamic_cast<tp::commands::TeamChange*>(packet.get());
return TD_TEST_SUCCESSFUL;
}
int main() {
TestNewTeam();
return TestAllCommands();
}