DarkflameServer/tests/dGameTests/dComponentsTests/PetComponentTests.cpp

137 lines
4.6 KiB
C++
Raw Normal View History

2023-12-15 05:43:08 +00:00
#include "GameDependencies.h"
#include <gtest/gtest.h>
#include "BitStream.h"
#include "PetComponent.h"
#include "Entity.h"
#include "eReplicaComponentType.h"
#include "ePetAbilityType.h"
#include "eStateChangeType.h"
class PetTest : public GameDependenciesTest {
protected:
Entity* baseEntity;
PetComponent* petComponent;
CBITSTREAM
2023-12-15 11:34:38 +00:00
2023-12-15 05:43:08 +00:00
void SetUp() override {
SetUpDependencies();
// Set up entity and pet component
2023-12-15 11:34:38 +00:00
baseEntity = new Entity(15, GameDependenciesTest::info);
2023-12-15 05:43:08 +00:00
petComponent = baseEntity->AddComponent<PetComponent>(1);
// Initialize some values to be not default
2023-12-15 05:43:08 +00:00
}
void TearDown() override {
delete baseEntity;
TearDownDependencies();
}
};
TEST_F(PetTest, PlacementNewAddComponentTest) {
2024-03-06 05:37:42 +00:00
using enum PetFlag;
// Test adding component
2023-12-15 05:43:08 +00:00
ASSERT_NE(petComponent, nullptr);
2023-12-15 11:34:38 +00:00
baseEntity->AddComponent<PetComponent>(1);
2023-12-15 05:43:08 +00:00
ASSERT_NE(baseEntity->GetComponent<PetComponent>(), nullptr);
// Test getting initial status
2023-12-15 05:43:08 +00:00
ASSERT_EQ(petComponent->GetParent()->GetObjectID(), 15);
ASSERT_TRUE(petComponent->HasFlag(NONE));
2023-12-15 11:34:38 +00:00
ASSERT_EQ(petComponent->GetPetAiState(), PetAiState::spawn);
2023-12-15 05:43:08 +00:00
ASSERT_EQ(petComponent->GetAbility(), ePetAbilityType::Invalid);
}
/**
2023-12-15 11:34:38 +00:00
* Test bitset pet flags
*/
2023-12-15 05:43:08 +00:00
TEST_F(PetTest, PetComponentFlagTest) {
2024-03-06 05:37:42 +00:00
using enum PetFlag;
// Test setting and reading single flags, exclusively
petComponent->SetOnlyFlag(NONE);
ASSERT_TRUE(petComponent->HasOnlyFlag(NONE));
petComponent->SetOnlyFlag(TAMEABLE);
ASSERT_TRUE(petComponent->HasOnlyFlag(TAMEABLE));
ASSERT_FALSE(petComponent->HasOnlyFlag(SPAWNING));
// Test setting and reading multiple flags, exclusively
petComponent->SetOnlyFlag(NOT_WAITING, SPAWNING);
ASSERT_FALSE(petComponent->HasFlag(TAMEABLE));
ASSERT_TRUE(petComponent->HasFlag(NOT_WAITING));
ASSERT_TRUE(petComponent->HasFlag(SPAWNING));
ASSERT_TRUE(petComponent->HasFlag(NOT_WAITING, SPAWNING));
ASSERT_FALSE(petComponent->HasOnlyFlag(NOT_WAITING));
ASSERT_FALSE(petComponent->HasOnlyFlag(SPAWNING));
ASSERT_TRUE(petComponent->HasOnlyFlag(NOT_WAITING, SPAWNING));
// Test flags are being properly reset for next batch of tests
petComponent->SetOnlyFlag(NONE);
ASSERT_TRUE(petComponent->HasFlag(NONE));
ASSERT_TRUE(petComponent->HasOnlyFlag(NONE));
ASSERT_FALSE(petComponent->HasFlag(NOT_WAITING));
ASSERT_FALSE(petComponent->HasFlag(NOT_WAITING, SPAWNING, TAMEABLE));
// Test setting and reading single flags, non-exclusively
2023-12-15 11:34:38 +00:00
petComponent->SetFlag(NOT_WAITING);
ASSERT_TRUE(petComponent->HasFlag(NOT_WAITING));
ASSERT_FALSE(petComponent->HasFlag(SPAWNING));
// Test setting and reading multiple flags, non-exclusively
2023-12-15 11:34:38 +00:00
petComponent->SetFlag(TAMEABLE, BEING_TAMED);
ASSERT_TRUE(petComponent->HasFlag(TAMEABLE, BEING_TAMED));
ASSERT_TRUE(petComponent->HasFlag(NOT_WAITING));
ASSERT_FALSE(petComponent->HasFlag(NOT_WAITING, SPAWNING));
ASSERT_TRUE(petComponent->HasFlag(NOT_WAITING, TAMEABLE, BEING_TAMED));
ASSERT_FALSE(petComponent->HasFlag(SPAWNING));
ASSERT_FALSE(petComponent->HasFlag(SPAWNING, NOT_WAITING, TAMEABLE, BEING_TAMED));
// Test unsetting and reading multiple flags, non-exclusively
2023-12-15 11:34:38 +00:00
petComponent->UnsetFlag(NOT_WAITING, SPAWNING);
ASSERT_FALSE(petComponent->HasFlag(NOT_WAITING, SPAWNING));
ASSERT_FALSE(petComponent->HasFlag(NOT_WAITING));
ASSERT_TRUE(petComponent->HasFlag(TAMEABLE, BEING_TAMED));
ASSERT_FALSE(petComponent->HasFlag(NOT_WAITING, TAMEABLE, BEING_TAMED));
ASSERT_FALSE(petComponent->HasFlag(SPAWNING));
ASSERT_FALSE(petComponent->HasFlag(SPAWNING, NOT_WAITING, TAMEABLE, BEING_TAMED));
2023-12-15 05:43:08 +00:00
}
2024-04-01 02:49:59 +00:00
TEST_F(PetTest, PetAiState) {
const auto initialState = petComponent->GetPetAiState();
ASSERT_EQ(initialState, PetAiState::spawn);
petComponent->SetPetAiState(PetAiState::follow);
ASSERT_EQ(PetAiState::follow, petComponent->GetPetAiState());
petComponent->SetPetAiState(PetAiState::idle);
ASSERT_EQ(PetAiState::idle, petComponent->GetPetAiState());
petComponent->SetPetAiState(PetAiState::interact);
ASSERT_EQ(PetAiState::interact, petComponent->GetPetAiState());
petComponent->SetPetAiState(PetAiState::despawn);
ASSERT_EQ(PetAiState::despawn, petComponent->GetPetAiState());
}
// Test the pet use logic
TEST_F(PetTest, PetUse) {
ASSERT_FALSE(petComponent->IsReadyToInteract());
petComponent->SetIsReadyToInteract(true);
ASSERT_TRUE(petComponent->IsReadyToInteract());
// Test bouncer logic
ASSERT_FALSE(petComponent->IsHandlingInteraction());
petComponent->SetAbility(ePetAbilityType::JumpOnObject);
ASSERT_EQ(petComponent->GetAbility(), ePetAbilityType::JumpOnObject);
petComponent->SetInteractType(PetInteractType::bouncer);
petComponent->OnUse(baseEntity);
// need to add a destroyable component to the test entity and test the imagination drain
}