finish serialize
This commit is contained in:
51
test/blitz/protocol/command/CommandSerializer_test.cpp
Normal file
51
test/blitz/protocol/command/CommandSerializer_test.cpp
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user