test dServer stuff

This commit is contained in:
David Markowitz 2024-06-09 11:02:45 -07:00
parent 8685d0dbdc
commit b28cd58634
3 changed files with 28 additions and 12 deletions

View File

@ -86,7 +86,7 @@ private:
void SetupForMasterConnection();
bool ConnectToMaster();
private:
protected:
Logger* mLogger = nullptr;
dConfig* mConfig = nullptr;
RakPeerInterface* mPeer = nullptr;

View File

@ -21,6 +21,7 @@ public:
~dServerMock() {};
RakNet::BitStream* GetMostRecentBitStream() { return sentBitStream; };
void Send(RakNet::BitStream& bitStream, const SystemAddress& sysAddr, bool broadcast) override { sentBitStream = &bitStream; };
void SetZoneId(unsigned int zoneId) { mZoneID = zoneId; }
};
class GameDependenciesTest : public ::testing::Test {

View File

@ -3,6 +3,7 @@
#include "Entity.h"
#include "tinyxml2.h"
#include "BuffComponent.h"
#include "CharacterComponent.h"
class SavingTest : public GameDependenciesTest {
protected:
@ -14,38 +15,52 @@ protected:
void SetUp() override {
SetUpDependencies();
Game::zoneManager->LoadZone(LWOZONEID(1800, 2, 0));
GameDependenciesTest::info.lot = 1;
static_cast<dServerMock*>(Game::server)->SetZoneId(1800);
entity = std::make_unique<Entity>(1, GameDependenciesTest::info);
character = std::make_unique<Character>(1, nullptr);
doc.LoadFile("./test_xml_data.xml");
entity->SetCharacter(character.get());
character->SetEntity(entity.get());
doc.Print(&printer);
character->_setXmlData(printer.CStr());
doc.Clear();
printer.ClearBuffer();
character->_doQuickXMLDataParse();
character->LoadXmlRespawnCheckpoints();
entity->AddComponent<BuffComponent>()->LoadFromXml(entity->GetCharacter()->GetXMLDoc());
entity->AddComponent<CharacterComponent>(character.get(), UNASSIGNED_SYSTEM_ADDRESS)->LoadFromXml(entity->GetCharacter()->GetXMLDoc());
}
void TearDown() override {
entity->SetCharacter(nullptr);
entity.reset();
character.reset();
TearDownDependencies();
}
};
TEST_F(SavingTest, EntityLevelTest) {
doc.Print(&printer);
// Print the original XML data
character->GetXMLDoc().Print(&printer);
std::string xmlDataOriginal(printer.CStr());
doc.Clear();
printer.ClearBuffer();
character->SaveXMLToDatabase();
doc.Print(&printer);
// Load the modified XML data
character->GetXMLDoc().Print(&printer);
std::string xmlDataModified(printer.CStr());
doc.Clear();
// std::ofstream oldXml("./test_xml_data_original.xml");
// std::ofstream newXml("./test_xml_data_new.xml");
// oldXml << xmlDataOriginal;
// newXml << xmlDataModified;
LOG("Component count: %i Same: %i", entity->GetComponents().size(), xmlDataOriginal == xmlDataModified);
printer.ClearBuffer();
std::ofstream oldXml("./test_xml_data_original.xml");
std::ofstream newXml("./test_xml_data_new.xml");
oldXml << xmlDataOriginal;
newXml << xmlDataModified;
ASSERT_EQ(xmlDataOriginal, xmlDataModified);
}