Compare commits

...

5 Commits

Author SHA1 Message Date
David Markowitz
f76d28584e bleh 2023-07-15 23:35:58 -07:00
David Markowitz
0779f33c2e Merge branch 'main' into AddEntitySerializeTests 2023-07-15 14:30:37 -07:00
EmosewaMC
2b1edfa7e5 Add Construction and serialize test
Update EntityTests.cpp
2023-07-14 17:41:28 -07:00
EmosewaMC
972db85dbf Update EntityTests.cpp 2023-07-14 17:39:58 -07:00
EmosewaMC
7321382fe2 Add Construction and serialize test 2023-07-11 11:32:50 -07:00
7 changed files with 266 additions and 5 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

@@ -1,4 +1,5 @@
set(DGAME_DCOMPONENTS_SOURCES "BaseCombatAIComponent.cpp"
set(DGAME_DCOMPONENTS_SOURCES
"BaseCombatAIComponent.cpp"
"BouncerComponent.cpp"
"BuffComponent.cpp"
"BuildBorderComponent.cpp"

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

@@ -1,5 +1,7 @@
set(DGAMETEST_SOURCES
"EntityTests.cpp"
"GameDependencies.cpp"
"EntityTests.cpp"
)
add_subdirectory(dComponentsTests)
@@ -13,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

@@ -0,0 +1,250 @@
#include "GameDependencies.h"
#include <gtest/gtest.h>
#include "BaseCombatAIComponent.h"
#include "BouncerComponent.h"
#include "BuffComponent.h"
#include "BuildBorderComponent.h"
#include "CharacterComponent.h"
#include "Component.h"
#include "ControllablePhysicsComponent.h"
#include "DestroyableComponent.h"
#include "InventoryComponent.h"
#include "LevelProgressionComponent.h"
#include "LUPExhibitComponent.h"
#include "MissionComponent.h"
#include "MissionOfferComponent.h"
#include "ModelComponent.h"
#include "ModuleAssemblyComponent.h"
#include "MovementAIComponent.h"
#include "MovingPlatformComponent.h"
#include "PetComponent.h"
#include "PhantomPhysicsComponent.h"
#include "PlayerForcedMovementComponent.h"
#include "PossessableComponent.h"
#include "PossessorComponent.h"
#include "PropertyComponent.h"
#include "PropertyEntranceComponent.h"
#include "PropertyManagementComponent.h"
#include "PropertyVendorComponent.h"
#include "ProximityMonitorComponent.h"
#include "RacingControlComponent.h"
#include "RailActivatorComponent.h"
#include "RebuildComponent.h"
#include "RenderComponent.h"
#include "RigidbodyPhantomPhysicsComponent.h"
#include "RocketLaunchLupComponent.h"
#include "RocketLaunchpadControlComponent.h"
#include "ScriptedActivityComponent.h"
#include "ShootingGalleryComponent.h"
#include "SimplePhysicsComponent.h"
#include "SkillComponent.h"
#include "SoundTriggerComponent.h"
#include "SwitchComponent.h"
#include "TriggerComponent.h"
#include "VehiclePhysicsComponent.h"
#include "VendorComponent.h"
#include "Entity.h"
#include "eReplicaPacketType.h"
class EntityTests : public GameDependenciesTest {
protected:
struct {
BaseCombatAIComponent* baseCombatAIComponent;
int32_t combatAiComponentTarget = 0;
};
BouncerComponent* bouncerComponent;
BuffComponent* buffComponent;
BuildBorderComponent* buildBorderComponent;
CharacterComponent* characterComponent;
ControllablePhysicsComponent* controllablePhysicsComponent;
DestroyableComponent* destroyableComponent;
InventoryComponent* inventoryComponent;
LevelProgressionComponent* levelProgressionComponent;
LUPExhibitComponent* lUPExhibitComponent;
MissionComponent* missionComponent;
MissionOfferComponent* missionOfferComponent;
ModelComponent* modelComponent;
ModuleAssemblyComponent* moduleAssemblyComponent;
MovementAIComponent* movementAIComponent;
MovingPlatformComponent* movingPlatformComponent;
PetComponent* petComponent;
PhantomPhysicsComponent* phantomPhysicsComponent;
PlayerForcedMovementComponent* playerForcedMovementComponent;
PossessableComponent* possessableComponent;
PossessorComponent* possessorComponent;
PropertyComponent* propertyComponent;
PropertyEntranceComponent* propertyEntranceComponent;
PropertyManagementComponent* propertyManagementComponent;
PropertyVendorComponent* propertyVendorComponent;
ProximityMonitorComponent* proximityMonitorComponent;
RacingControlComponent* racingControlComponent;
RailActivatorComponent* railActivatorComponent;
RebuildComponent* rebuildComponent;
RenderComponent* renderComponent;
RigidbodyPhantomPhysicsComponent* rigidbodyPhantomPhysicsComponent;
RocketLaunchLupComponent* rocketLaunchLupComponent;
RocketLaunchpadControlComponent* rocketLaunchpadControlComponent;
ScriptedActivityComponent* scriptedActivityComponent;
ShootingGalleryComponent* shootingGalleryComponent;
SimplePhysicsComponent* simplePhysicsComponent;
SkillComponent* skillComponent;
SoundTriggerComponent* soundTriggerComponent;
SwitchComponent* switchComponent;
TriggerComponent* triggerComponent;
VehiclePhysicsComponent* vehiclePhysicsComponent;
VendorComponent* vendorComponent;
Entity* testedEntity;
void SetUp() override {
srand(time(NULL));
SetUpDependencies();
testedEntity = new Entity(5, info);
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);
bouncerComponent->SetPetEnabled(true);
}
void TearDown() override {
TearDownDependencies();
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);
}
TEST_F(EntityTests, EntitySerializationTest) {
CBITSTREAM;
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() {