This commit is contained in:
David Markowitz 2023-07-15 23:35:58 -07:00
parent 0779f33c2e
commit f76d28584e
6 changed files with 140 additions and 135 deletions

View File

@ -43,7 +43,7 @@ public:
void ConstructEntity(Entity* entity, const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS, bool skipChecks = false);
void DestructEntity(Entity* entity, const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS);
void SerializeEntity(Entity* entity);
virtual void SerializeEntity(Entity* entity);
void ConstructAllEntities(const SystemAddress& sysAddr);
void DestructAllEntities(const SystemAddress& sysAddr);

View File

@ -30,7 +30,7 @@ CharacterComponent::CharacterComponent(Entity* parent, Character* character) : C
m_DirtySocialInfo = false;
m_PvpEnabled = false;
m_GMLevel = character->GetGMLevel();
m_GMLevel = character != nullptr ? character->GetGMLevel() : eGameMasterLevel::CIVILIAN;
m_EditorEnabled = false;
m_EditorLevel = m_GMLevel;

View File

@ -7,6 +7,7 @@
#include "EntityManager.h"
#include "GameMessages.h"
#include "eReplicaComponentType.h"
#include "PropertySelectQueryProperty.h"
/**
* Represents the launch pad that's used to select and browse properties

View File

@ -15,7 +15,7 @@ file(COPY ${GAMEMESSAGE_TESTBITSTREAMS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
# Add the executable. Remember to add all tests above this!
add_executable(dGameTests ${DGAMETEST_SOURCES})
target_link_libraries(dGameTests ${COMMON_LIBRARIES} GTest::gtest_main dGame dZoneManager dPhysics Detour Recast tinyxml2 dWorldServer dChatFilter dNavigation)
target_link_libraries(dGameTests ${COMMON_LIBRARIES} GTest::gtest_main GTest::gmock dGame dZoneManager dPhysics Detour Recast tinyxml2 dWorldServer dChatFilter dNavigation)
# Discover the tests
gtest_discover_tests(dGameTests)

View File

@ -101,153 +101,150 @@ protected:
srand(time(NULL));
SetUpDependencies();
testedEntity = new Entity(5, info);
// We allocate through malloc because we cannot call the constructors of some of thse methods.
baseCombatAIComponent = (BaseCombatAIComponent*)malloc(sizeof(BaseCombatAIComponent));
Game::logger->Log("EntityTests", "starting");
bouncerComponent = new BouncerComponent(testedEntity);
Game::logger->Log("EntityTests", "BouncerComponent");
buffComponent = new BuffComponent(testedEntity);
Game::logger->Log("EntityTests", "BuffComponent");
buildBorderComponent = new BuildBorderComponent(testedEntity);
Game::logger->Log("EntityTests", "BuildBorderComponent");
characterComponent = new CharacterComponent(testedEntity, nullptr);
Game::logger->Log("EntityTests", "CharacterComponent");
controllablePhysicsComponent = new ControllablePhysicsComponent(testedEntity);
Game::logger->Log("EntityTests", "ControllablePhysicsComponent");
destroyableComponent = new DestroyableComponent(testedEntity);
Game::logger->Log("EntityTests", "DestroyableComponent");
inventoryComponent = new InventoryComponent(testedEntity);
Game::logger->Log("EntityTests", "InventoryComponent");
levelProgressionComponent = new LevelProgressionComponent(testedEntity);
Game::logger->Log("EntityTests", "LevelProgressionComponent");
lUPExhibitComponent = new LUPExhibitComponent(testedEntity);
Game::logger->Log("EntityTests", "LUPExhibitComponent");
missionComponent = new MissionComponent(testedEntity);
Game::logger->Log("EntityTests", "MissionComponent");
missionOfferComponent = new MissionOfferComponent(testedEntity, 2345);
Game::logger->Log("EntityTests", "MissionOfferComponent");
modelComponent = new ModelComponent(testedEntity);
Game::logger->Log("EntityTests", "ModelComponent");
moduleAssemblyComponent = new ModuleAssemblyComponent(testedEntity);
Game::logger->Log("EntityTests", "ModuleAssemblyComponent");
movementAIComponent = new MovementAIComponent(testedEntity, MovementAIInfo());
Game::logger->Log("EntityTests", "MovementAIComponent");
movingPlatformComponent = new MovingPlatformComponent(testedEntity, "");
Game::logger->Log("EntityTests", "MovingPlatformComponent");
petComponent = new PetComponent(testedEntity, 1234);
Game::logger->Log("EntityTests", "PetComponent");
phantomPhysicsComponent = new PhantomPhysicsComponent(testedEntity);
Game::logger->Log("EntityTests", "PhantomPhysicsComponent");
playerForcedMovementComponent = new PlayerForcedMovementComponent(testedEntity);
Game::logger->Log("EntityTests", "PlayerForcedMovementComponent");
possessableComponent = new PossessableComponent(testedEntity, 124);
Game::logger->Log("EntityTests", "PossessableComponent");
possessorComponent = new PossessorComponent(testedEntity);
Game::logger->Log("EntityTests", "PossessorComponent");
propertyComponent = new PropertyComponent(testedEntity);
Game::logger->Log("EntityTests", "PropertyComponent");
propertyEntranceComponent = new PropertyEntranceComponent(38, testedEntity);
Game::logger->Log("EntityTests", "PropertyEntranceComponent");
propertyManagementComponent = new PropertyManagementComponent(testedEntity);
Game::logger->Log("EntityTests", "PropertyManagementComponent");
propertyVendorComponent = new PropertyVendorComponent(testedEntity);
Game::logger->Log("EntityTests", "PropertyVendorComponent");
proximityMonitorComponent = new ProximityMonitorComponent(testedEntity);
Game::logger->Log("EntityTests", "ProximityMonitorComponent");
racingControlComponent = new RacingControlComponent(testedEntity);
Game::logger->Log("EntityTests", "RacingControlComponent");
railActivatorComponent = new RailActivatorComponent(testedEntity, 4231);
Game::logger->Log("EntityTests", "RailActivatorComponent");
rebuildComponent = new RebuildComponent(testedEntity);
Game::logger->Log("EntityTests", "RebuildComponent");
renderComponent = new RenderComponent(testedEntity);
Game::logger->Log("EntityTests", "RenderComponent");
rigidbodyPhantomPhysicsComponent = new RigidbodyPhantomPhysicsComponent(testedEntity);
Game::logger->Log("EntityTests", "RigidbodyPhantomPhysicsComponent");
rocketLaunchLupComponent = new RocketLaunchLupComponent(testedEntity);
Game::logger->Log("EntityTests", "RocketLaunchLupComponent");
rocketLaunchpadControlComponent = new RocketLaunchpadControlComponent(testedEntity, 5);
Game::logger->Log("EntityTests", "RocketLaunchpadControlComponent");
scriptedActivityComponent = new ScriptedActivityComponent(testedEntity, 4);
Game::logger->Log("EntityTests", "ScriptedActivityComponent");
shootingGalleryComponent = new ShootingGalleryComponent(testedEntity);
Game::logger->Log("EntityTests", "ShootingGalleryComponent");
simplePhysicsComponent = new SimplePhysicsComponent(3, testedEntity);
Game::logger->Log("EntityTests", "SimplePhysicsComponent");
skillComponent = new SkillComponent(testedEntity);
Game::logger->Log("EntityTests", "SkillComponent");
soundTriggerComponent = new SoundTriggerComponent(testedEntity);
Game::logger->Log("EntityTests", "SoundTriggerComponent");
switchComponent = new SwitchComponent(testedEntity);
Game::logger->Log("EntityTests", "SwitchComponent");
triggerComponent = new TriggerComponent(testedEntity, "");
Game::logger->Log("EntityTests", "TriggerComponent");
vehiclePhysicsComponent = new VehiclePhysicsComponent(testedEntity);
Game::logger->Log("EntityTests", "VehiclePhysicsComponent");
vendorComponent = new VendorComponent(testedEntity);
Game::logger->Log("EntityTests", "VendorComponent");
baseCombatAIComponent->SetState(AiState::dead);
combatAiComponentTarget = rand();
baseCombatAIComponent->SetTarget(combatAiComponentTarget);
testedEntity->AddComponent(BaseCombatAIComponent::ComponentType, baseCombatAIComponent);
bouncerComponent = (BouncerComponent*)malloc(sizeof(BouncerComponent));
// bouncerComponent->SetPetEnabled(true);
testedEntity->AddComponent(BouncerComponent::ComponentType, bouncerComponent);
buffComponent = (BuffComponent*)malloc(sizeof(BuffComponent));
testedEntity->AddComponent(BuffComponent::ComponentType, buffComponent);
buildBorderComponent = (BuildBorderComponent*)malloc(sizeof(BuildBorderComponent));
testedEntity->AddComponent(BuildBorderComponent::ComponentType, buildBorderComponent);
characterComponent = (CharacterComponent*)malloc(sizeof(CharacterComponent));
testedEntity->AddComponent(CharacterComponent::ComponentType, characterComponent);
controllablePhysicsComponent = (ControllablePhysicsComponent*)malloc(sizeof(ControllablePhysicsComponent));
testedEntity->AddComponent(ControllablePhysicsComponent::ComponentType, controllablePhysicsComponent);
destroyableComponent = (DestroyableComponent*)malloc(sizeof(DestroyableComponent));
testedEntity->AddComponent(DestroyableComponent::ComponentType, destroyableComponent);
inventoryComponent = (InventoryComponent*)malloc(sizeof(InventoryComponent));
testedEntity->AddComponent(InventoryComponent::ComponentType, inventoryComponent);
levelProgressionComponent = (LevelProgressionComponent*)malloc(sizeof(LevelProgressionComponent));
testedEntity->AddComponent(LevelProgressionComponent::ComponentType, levelProgressionComponent);
lUPExhibitComponent = (LUPExhibitComponent*)malloc(sizeof(LUPExhibitComponent));
testedEntity->AddComponent(LUPExhibitComponent::ComponentType, lUPExhibitComponent);
missionComponent = (MissionComponent*)malloc(sizeof(MissionComponent));
testedEntity->AddComponent(MissionComponent::ComponentType, missionComponent);
missionOfferComponent = (MissionOfferComponent*)malloc(sizeof(MissionOfferComponent));
testedEntity->AddComponent(MissionOfferComponent::ComponentType, missionOfferComponent);
modelComponent = (ModelComponent*)malloc(sizeof(ModelComponent));
testedEntity->AddComponent(ModelComponent::ComponentType, modelComponent);
moduleAssemblyComponent = (ModuleAssemblyComponent*)malloc(sizeof(ModuleAssemblyComponent));
testedEntity->AddComponent(ModuleAssemblyComponent::ComponentType, moduleAssemblyComponent);
movementAIComponent = (MovementAIComponent*)malloc(sizeof(MovementAIComponent));
testedEntity->AddComponent(MovementAIComponent::ComponentType, movementAIComponent);
movingPlatformComponent = (MovingPlatformComponent*)malloc(sizeof(MovingPlatformComponent));
testedEntity->AddComponent(MovingPlatformComponent::ComponentType, movingPlatformComponent);
petComponent = (PetComponent*)malloc(sizeof(PetComponent));
testedEntity->AddComponent(PetComponent::ComponentType, petComponent);
phantomPhysicsComponent = (PhantomPhysicsComponent*)malloc(sizeof(PhantomPhysicsComponent));
testedEntity->AddComponent(PhantomPhysicsComponent::ComponentType, phantomPhysicsComponent);
playerForcedMovementComponent = (PlayerForcedMovementComponent*)malloc(sizeof(PlayerForcedMovementComponent));
testedEntity->AddComponent(PlayerForcedMovementComponent::ComponentType, playerForcedMovementComponent);
possessableComponent = (PossessableComponent*)malloc(sizeof(PossessableComponent));
testedEntity->AddComponent(PossessableComponent::ComponentType, possessableComponent);
possessorComponent = (PossessorComponent*)malloc(sizeof(PossessorComponent));
testedEntity->AddComponent(PossessorComponent::ComponentType, possessorComponent);
propertyComponent = (PropertyComponent*)malloc(sizeof(PropertyComponent));
testedEntity->AddComponent(PropertyComponent::ComponentType, propertyComponent);
propertyEntranceComponent = (PropertyEntranceComponent*)malloc(sizeof(PropertyEntranceComponent));
testedEntity->AddComponent(PropertyEntranceComponent::ComponentType, propertyEntranceComponent);
propertyManagementComponent = (PropertyManagementComponent*)malloc(sizeof(PropertyManagementComponent));
testedEntity->AddComponent(PropertyManagementComponent::ComponentType, propertyManagementComponent);
propertyVendorComponent = (PropertyVendorComponent*)malloc(sizeof(PropertyVendorComponent));
testedEntity->AddComponent(PropertyVendorComponent::ComponentType, propertyVendorComponent);
proximityMonitorComponent = (ProximityMonitorComponent*)malloc(sizeof(ProximityMonitorComponent));
testedEntity->AddComponent(ProximityMonitorComponent::ComponentType, proximityMonitorComponent);
racingControlComponent = (RacingControlComponent*)malloc(sizeof(RacingControlComponent));
testedEntity->AddComponent(RacingControlComponent::ComponentType, racingControlComponent);
railActivatorComponent = (RailActivatorComponent*)malloc(sizeof(RailActivatorComponent));
testedEntity->AddComponent(RailActivatorComponent::ComponentType, railActivatorComponent);
rebuildComponent = (RebuildComponent*)malloc(sizeof(RebuildComponent));
testedEntity->AddComponent(RebuildComponent::ComponentType, rebuildComponent);
renderComponent = (RenderComponent*)malloc(sizeof(RenderComponent));
testedEntity->AddComponent(RenderComponent::ComponentType, renderComponent);
rigidbodyPhantomPhysicsComponent = (RigidbodyPhantomPhysicsComponent*)malloc(sizeof(RigidbodyPhantomPhysicsComponent));
testedEntity->AddComponent(RigidbodyPhantomPhysicsComponent::ComponentType, rigidbodyPhantomPhysicsComponent);
rocketLaunchLupComponent = (RocketLaunchLupComponent*)malloc(sizeof(RocketLaunchLupComponent));
testedEntity->AddComponent(RocketLaunchLupComponent::ComponentType, rocketLaunchLupComponent);
rocketLaunchpadControlComponent = (RocketLaunchpadControlComponent*)malloc(sizeof(RocketLaunchpadControlComponent));
testedEntity->AddComponent(RocketLaunchpadControlComponent::ComponentType, rocketLaunchpadControlComponent);
scriptedActivityComponent = (ScriptedActivityComponent*)malloc(sizeof(ScriptedActivityComponent));
testedEntity->AddComponent(ScriptedActivityComponent::ComponentType, scriptedActivityComponent);
shootingGalleryComponent = (ShootingGalleryComponent*)malloc(sizeof(ShootingGalleryComponent));
testedEntity->AddComponent(ShootingGalleryComponent::ComponentType, shootingGalleryComponent);
simplePhysicsComponent = (SimplePhysicsComponent*)malloc(sizeof(SimplePhysicsComponent));
testedEntity->AddComponent(SimplePhysicsComponent::ComponentType, simplePhysicsComponent);
skillComponent = (SkillComponent*)malloc(sizeof(SkillComponent));
testedEntity->AddComponent(SkillComponent::ComponentType, skillComponent);
soundTriggerComponent = (SoundTriggerComponent*)malloc(sizeof(SoundTriggerComponent));
testedEntity->AddComponent(SoundTriggerComponent::ComponentType, soundTriggerComponent);
switchComponent = (SwitchComponent*)malloc(sizeof(SwitchComponent));
testedEntity->AddComponent(SwitchComponent::ComponentType, switchComponent);
triggerComponent = (TriggerComponent*)malloc(sizeof(TriggerComponent));
testedEntity->AddComponent(TriggerComponent::ComponentType, triggerComponent);
vehiclePhysicsComponent = (VehiclePhysicsComponent*)malloc(sizeof(VehiclePhysicsComponent));
testedEntity->AddComponent(VehiclePhysicsComponent::ComponentType, vehiclePhysicsComponent);
vendorComponent = (VendorComponent*)malloc(sizeof(VendorComponent));
testedEntity->AddComponent(VendorComponent::ComponentType, vendorComponent);
bouncerComponent->SetPetEnabled(true);
}
void TearDown() override {
TearDownDependencies();
free(baseCombatAIComponent);
free(bouncerComponent);
free(buffComponent);
free(buildBorderComponent);
free(characterComponent);
free(controllablePhysicsComponent);
free(destroyableComponent);
free(inventoryComponent);
free(levelProgressionComponent);
free(lUPExhibitComponent);
free(missionComponent);
free(missionOfferComponent);
free(modelComponent);
free(moduleAssemblyComponent);
free(movementAIComponent);
free(movingPlatformComponent);
free(petComponent);
free(phantomPhysicsComponent);
free(playerForcedMovementComponent);
free(possessableComponent);
free(possessorComponent);
free(propertyComponent);
free(propertyEntranceComponent);
free(propertyManagementComponent);
free(propertyVendorComponent);
free(proximityMonitorComponent);
free(racingControlComponent);
free(railActivatorComponent);
free(rebuildComponent);
free(renderComponent);
free(rigidbodyPhantomPhysicsComponent);
free(rocketLaunchLupComponent);
free(rocketLaunchpadControlComponent);
free(scriptedActivityComponent);
free(shootingGalleryComponent);
free(simplePhysicsComponent);
free(skillComponent);
free(soundTriggerComponent);
free(switchComponent);
free(triggerComponent);
free(vehiclePhysicsComponent);
free(vendorComponent);
delete baseCombatAIComponent;
delete bouncerComponent;
delete buffComponent;
delete buildBorderComponent;
delete characterComponent;
delete controllablePhysicsComponent;
delete destroyableComponent;
delete inventoryComponent;
delete levelProgressionComponent;
delete lUPExhibitComponent;
delete missionComponent;
delete missionOfferComponent;
delete modelComponent;
delete moduleAssemblyComponent;
delete movementAIComponent;
delete movingPlatformComponent;
delete petComponent;
delete phantomPhysicsComponent;
delete playerForcedMovementComponent;
delete possessableComponent;
delete possessorComponent;
delete propertyComponent;
delete propertyEntranceComponent;
delete propertyManagementComponent;
delete propertyVendorComponent;
delete proximityMonitorComponent;
delete racingControlComponent;
delete railActivatorComponent;
delete rebuildComponent;
delete renderComponent;
delete rigidbodyPhantomPhysicsComponent;
delete rocketLaunchLupComponent;
delete rocketLaunchpadControlComponent;
delete scriptedActivityComponent;
delete shootingGalleryComponent;
delete simplePhysicsComponent;
delete skillComponent;
delete soundTriggerComponent;
delete switchComponent;
delete triggerComponent;
delete vehiclePhysicsComponent;
delete vendorComponent;
operator delete(testedEntity);
}
};
TEST_F(EntityTests, EntityConstructionTest) {
CBITSTREAM;
// testedEntity->WriteComponents(&bitStream, eReplicaPacketType::CONSTRUCTION);
testedEntity->WriteComponents(&bitStream, eReplicaPacketType::CONSTRUCTION);
}
TEST_F(EntityTests, EntitySerializationTest) {
CBITSTREAM;
// testedEntity->WriteComponents(&bitStream, eReplicaPacketType::SERIALIZATION);
testedEntity->WriteComponents(&bitStream, eReplicaPacketType::SERIALIZATION);
}

View File

@ -7,6 +7,8 @@
#include "EntityInfo.h"
#include "EntityManager.h"
#include "dConfig.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
class dZoneManager;
@ -21,6 +23,11 @@ public:
void Send(RakNet::BitStream* bitStream, const SystemAddress& sysAddr, bool broadcast) override { sentBitStream = bitStream; };
};
class EntityManagerMock : public EntityManager {
public:
void SerializeEntity(Entity* entity) override {};
};
class GameDependenciesTest : public ::testing::Test {
protected:
void SetUpDependencies() {
@ -32,7 +39,7 @@ protected:
Game::logger = new dLogger("./testing.log", true, true);
Game::server = new dServerMock();
Game::config = new dConfig("worldconfig.ini");
Game::entityManager = new EntityManager();
Game::entityManager = new EntityManagerMock();
}
void TearDownDependencies() {