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 ConstructEntity(Entity* entity, const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS, bool skipChecks = false);
void DestructEntity(Entity* entity, const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS); 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 ConstructAllEntities(const SystemAddress& sysAddr);
void DestructAllEntities(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_DirtySocialInfo = false;
m_PvpEnabled = false; m_PvpEnabled = false;
m_GMLevel = character->GetGMLevel(); m_GMLevel = character != nullptr ? character->GetGMLevel() : eGameMasterLevel::CIVILIAN;
m_EditorEnabled = false; m_EditorEnabled = false;
m_EditorLevel = m_GMLevel; m_EditorLevel = m_GMLevel;

View File

@ -7,6 +7,7 @@
#include "EntityManager.h" #include "EntityManager.h"
#include "GameMessages.h" #include "GameMessages.h"
#include "eReplicaComponentType.h" #include "eReplicaComponentType.h"
#include "PropertySelectQueryProperty.h"
/** /**
* Represents the launch pad that's used to select and browse properties * 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 the executable. Remember to add all tests above this!
add_executable(dGameTests ${DGAMETEST_SOURCES}) 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 # Discover the tests
gtest_discover_tests(dGameTests) gtest_discover_tests(dGameTests)

View File

@ -101,153 +101,150 @@ protected:
srand(time(NULL)); srand(time(NULL));
SetUpDependencies(); SetUpDependencies();
testedEntity = new Entity(5, info); testedEntity = new Entity(5, info);
// We allocate through malloc because we cannot call the constructors of some of thse methods. Game::logger->Log("EntityTests", "starting");
baseCombatAIComponent = (BaseCombatAIComponent*)malloc(sizeof(BaseCombatAIComponent)); 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); baseCombatAIComponent->SetState(AiState::dead);
combatAiComponentTarget = rand(); combatAiComponentTarget = rand();
baseCombatAIComponent->SetTarget(combatAiComponentTarget); baseCombatAIComponent->SetTarget(combatAiComponentTarget);
testedEntity->AddComponent(BaseCombatAIComponent::ComponentType, baseCombatAIComponent);
bouncerComponent = (BouncerComponent*)malloc(sizeof(BouncerComponent)); bouncerComponent->SetPetEnabled(true);
// 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);
} }
void TearDown() override { void TearDown() override {
TearDownDependencies(); TearDownDependencies();
free(baseCombatAIComponent); delete baseCombatAIComponent;
free(bouncerComponent); delete bouncerComponent;
free(buffComponent); delete buffComponent;
free(buildBorderComponent); delete buildBorderComponent;
free(characterComponent); delete characterComponent;
free(controllablePhysicsComponent); delete controllablePhysicsComponent;
free(destroyableComponent); delete destroyableComponent;
free(inventoryComponent); delete inventoryComponent;
free(levelProgressionComponent); delete levelProgressionComponent;
free(lUPExhibitComponent); delete lUPExhibitComponent;
free(missionComponent); delete missionComponent;
free(missionOfferComponent); delete missionOfferComponent;
free(modelComponent); delete modelComponent;
free(moduleAssemblyComponent); delete moduleAssemblyComponent;
free(movementAIComponent); delete movementAIComponent;
free(movingPlatformComponent); delete movingPlatformComponent;
free(petComponent); delete petComponent;
free(phantomPhysicsComponent); delete phantomPhysicsComponent;
free(playerForcedMovementComponent); delete playerForcedMovementComponent;
free(possessableComponent); delete possessableComponent;
free(possessorComponent); delete possessorComponent;
free(propertyComponent); delete propertyComponent;
free(propertyEntranceComponent); delete propertyEntranceComponent;
free(propertyManagementComponent); delete propertyManagementComponent;
free(propertyVendorComponent); delete propertyVendorComponent;
free(proximityMonitorComponent); delete proximityMonitorComponent;
free(racingControlComponent); delete racingControlComponent;
free(railActivatorComponent); delete railActivatorComponent;
free(rebuildComponent); delete rebuildComponent;
free(renderComponent); delete renderComponent;
free(rigidbodyPhantomPhysicsComponent); delete rigidbodyPhantomPhysicsComponent;
free(rocketLaunchLupComponent); delete rocketLaunchLupComponent;
free(rocketLaunchpadControlComponent); delete rocketLaunchpadControlComponent;
free(scriptedActivityComponent); delete scriptedActivityComponent;
free(shootingGalleryComponent); delete shootingGalleryComponent;
free(simplePhysicsComponent); delete simplePhysicsComponent;
free(skillComponent); delete skillComponent;
free(soundTriggerComponent); delete soundTriggerComponent;
free(switchComponent); delete switchComponent;
free(triggerComponent); delete triggerComponent;
free(vehiclePhysicsComponent); delete vehiclePhysicsComponent;
free(vendorComponent); delete vendorComponent;
operator delete(testedEntity); operator delete(testedEntity);
} }
}; };
TEST_F(EntityTests, EntityConstructionTest) { TEST_F(EntityTests, EntityConstructionTest) {
CBITSTREAM; CBITSTREAM;
// testedEntity->WriteComponents(&bitStream, eReplicaPacketType::CONSTRUCTION); testedEntity->WriteComponents(&bitStream, eReplicaPacketType::CONSTRUCTION);
} }
TEST_F(EntityTests, EntitySerializationTest) { TEST_F(EntityTests, EntitySerializationTest) {
CBITSTREAM; CBITSTREAM;
// testedEntity->WriteComponents(&bitStream, eReplicaPacketType::SERIALIZATION); testedEntity->WriteComponents(&bitStream, eReplicaPacketType::SERIALIZATION);
} }

View File

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