mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-09-05 14:58:27 +00:00
Remove component tests and focus on network packet and mail bitstream tests
Co-authored-by: aronwk-aaron <26027722+aronwk-aaron@users.noreply.github.com>
This commit is contained in:
@@ -1,63 +0,0 @@
|
|||||||
#include "GameDependencies.h"
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
#include "BitStream.h"
|
|
||||||
#include "ScriptedActivityComponent.h"
|
|
||||||
#include "Entity.h"
|
|
||||||
#include "eReplicaComponentType.h"
|
|
||||||
#include "eStateChangeType.h"
|
|
||||||
|
|
||||||
class ActivityComponentTest : public GameDependenciesTest {
|
|
||||||
protected:
|
|
||||||
std::unique_ptr<Entity> baseEntity;
|
|
||||||
ActivityComponent* activityComponent;
|
|
||||||
CBITSTREAM;
|
|
||||||
|
|
||||||
void SetUp() override {
|
|
||||||
SetUpDependencies();
|
|
||||||
baseEntity = std::make_unique<Entity>(15, GameDependenciesTest::info);
|
|
||||||
activityComponent = baseEntity->AddComponent<ScriptedActivityComponent>(1); // Needs activityId
|
|
||||||
}
|
|
||||||
|
|
||||||
void TearDown() override {
|
|
||||||
TearDownDependencies();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_F(ActivityComponentTest, ActivityComponentSerializeInitialEmptyTest) {
|
|
||||||
activityComponent->Serialize(bitStream, true);
|
|
||||||
|
|
||||||
// Should write dirty activity info flag
|
|
||||||
bool dirtyActivityInfo = false;
|
|
||||||
bitStream.Read(dirtyActivityInfo);
|
|
||||||
// Activity info should be dirty on initial serialize
|
|
||||||
ASSERT_TRUE(dirtyActivityInfo);
|
|
||||||
|
|
||||||
if (dirtyActivityInfo) {
|
|
||||||
uint32_t playerCount;
|
|
||||||
bitStream.Read(playerCount);
|
|
||||||
ASSERT_EQ(playerCount, 0); // Should be empty initially
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ActivityComponentTest, ActivityComponentSerializeUpdateTest) {
|
|
||||||
// Test non-initial update serialization produces some data
|
|
||||||
activityComponent->Serialize(bitStream, false);
|
|
||||||
|
|
||||||
// Should produce some bitstream output for update serialization
|
|
||||||
EXPECT_GT(bitStream.GetNumberOfBitsUsed(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST_F(ActivityComponentTest, ActivityComponentBasicAPITest) {
|
|
||||||
// Test basic API methods
|
|
||||||
// Activity ID can be -1 for invalid activities, this is valid behavior
|
|
||||||
// So just test that the component responds without crashing
|
|
||||||
auto activityID = activityComponent->GetActivityID();
|
|
||||||
EXPECT_TRUE(activityID >= -1); // -1 is a valid "no activity" state
|
|
||||||
|
|
||||||
// Test activity players list (should be empty initially)
|
|
||||||
auto players = activityComponent->GetActivityPlayers();
|
|
||||||
ASSERT_TRUE(players.empty());
|
|
||||||
}
|
|
@@ -1,50 +0,0 @@
|
|||||||
#include "GameDependencies.h"
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
#include "BitStream.h"
|
|
||||||
#include "BuffComponent.h"
|
|
||||||
#include "Entity.h"
|
|
||||||
#include "eReplicaComponentType.h"
|
|
||||||
|
|
||||||
class BuffComponentTest : public GameDependenciesTest {
|
|
||||||
protected:
|
|
||||||
Entity* baseEntity;
|
|
||||||
BuffComponent* buffComponent;
|
|
||||||
CBITSTREAM
|
|
||||||
uint32_t flags = 0;
|
|
||||||
|
|
||||||
void SetUp() override {
|
|
||||||
SetUpDependencies();
|
|
||||||
baseEntity = new Entity(15, GameDependenciesTest::info);
|
|
||||||
buffComponent = baseEntity->AddComponent<BuffComponent>();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TearDown() override {
|
|
||||||
delete baseEntity;
|
|
||||||
TearDownDependencies();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test Construction serialization of a BuffComponent with no buffs
|
|
||||||
*/
|
|
||||||
TEST_F(BuffComponentTest, BuffComponentSerializeTest) {
|
|
||||||
// Test construction serialization (empty buffs)
|
|
||||||
buffComponent->Serialize(bitStream, true);
|
|
||||||
|
|
||||||
{
|
|
||||||
bool hasBuffs;
|
|
||||||
bitStream.Read(hasBuffs);
|
|
||||||
EXPECT_FALSE(hasBuffs);
|
|
||||||
|
|
||||||
bool immunityBuffs;
|
|
||||||
bitStream.Read(immunityBuffs);
|
|
||||||
EXPECT_FALSE(immunityBuffs); // Always false according to code
|
|
||||||
}
|
|
||||||
bitStream.Reset();
|
|
||||||
|
|
||||||
// Test update serialization (should write nothing)
|
|
||||||
buffComponent->Serialize(bitStream, false);
|
|
||||||
EXPECT_EQ(bitStream.GetNumberOfBitsUsed(), 0);
|
|
||||||
}
|
|
||||||
|
|
@@ -1,17 +1,8 @@
|
|||||||
set(DCOMPONENTS_TESTS
|
set(DCOMPONENTS_TESTS
|
||||||
"DestroyableComponentTests.cpp"
|
"DestroyableComponentTests.cpp"
|
||||||
"PetComponentTests.cpp"
|
"PetComponentTests.cpp"
|
||||||
"SimplePhysicsComponentTests.cpp"
|
"SimplePhysicsComponentTests.cpp"
|
||||||
"SavingTests.cpp"
|
"SavingTests.cpp"
|
||||||
"CharacterComponentTests.cpp"
|
|
||||||
"InventoryComponentTests.cpp"
|
|
||||||
"ControllablePhysicsComponentTests.cpp"
|
|
||||||
"SkillComponentTests.cpp"
|
|
||||||
"BuffComponentTests.cpp"
|
|
||||||
"QuickBuildComponentTests.cpp"
|
|
||||||
"VendorComponentTests.cpp"
|
|
||||||
"RenderComponentTests.cpp"
|
|
||||||
"ActivityComponentTests.cpp"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get the folder name and prepend it to the files above
|
# Get the folder name and prepend it to the files above
|
||||||
|
@@ -1,108 +0,0 @@
|
|||||||
#include "GameDependencies.h"
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
#include "BitStream.h"
|
|
||||||
#include "CharacterComponent.h"
|
|
||||||
#include "Entity.h"
|
|
||||||
#include "Character.h"
|
|
||||||
#include "User.h"
|
|
||||||
#include "eReplicaComponentType.h"
|
|
||||||
#include "eGameActivity.h"
|
|
||||||
|
|
||||||
class CharacterComponentTest : public GameDependenciesTest {
|
|
||||||
protected:
|
|
||||||
Entity* baseEntity;
|
|
||||||
CharacterComponent* characterComponent;
|
|
||||||
std::unique_ptr<Character> character;
|
|
||||||
std::unique_ptr<User> user;
|
|
||||||
CBITSTREAM
|
|
||||||
uint32_t flags = 0;
|
|
||||||
|
|
||||||
void SetUp() override {
|
|
||||||
SetUpDependencies();
|
|
||||||
|
|
||||||
// Create a mock user and character
|
|
||||||
user = std::make_unique<User>(UNASSIGNED_SYSTEM_ADDRESS, "", "TestUser");
|
|
||||||
|
|
||||||
character = std::make_unique<Character>(1, user.get());
|
|
||||||
character->SetHairColor(5);
|
|
||||||
character->SetHairStyle(10);
|
|
||||||
character->SetShirtColor(15);
|
|
||||||
character->SetPantsColor(20);
|
|
||||||
character->SetShirtStyle(25);
|
|
||||||
character->SetEyebrows(3);
|
|
||||||
character->SetEyes(7);
|
|
||||||
character->SetMouth(9);
|
|
||||||
|
|
||||||
baseEntity = new Entity(15, GameDependenciesTest::info);
|
|
||||||
characterComponent = baseEntity->AddComponent<CharacterComponent>(character.get(), UNASSIGNED_SYSTEM_ADDRESS);
|
|
||||||
|
|
||||||
// Set some test values using available setter methods
|
|
||||||
characterComponent->SetUScore(12345);
|
|
||||||
characterComponent->SetCurrentActivity(eGameActivity::QUICKBUILDING);
|
|
||||||
characterComponent->SetReputation(6789);
|
|
||||||
characterComponent->SetPvpEnabled(true);
|
|
||||||
characterComponent->SetLastRocketConfig(u"test,rocket,config");
|
|
||||||
|
|
||||||
// Update some statistics using the UpdatePlayerStatistic method
|
|
||||||
characterComponent->UpdatePlayerStatistic(StatisticID::CurrencyCollected, 100);
|
|
||||||
characterComponent->UpdatePlayerStatistic(StatisticID::BricksCollected, 200);
|
|
||||||
characterComponent->UpdatePlayerStatistic(StatisticID::SmashablesSmashed, 50);
|
|
||||||
characterComponent->UpdatePlayerStatistic(StatisticID::QuickBuildsCompleted, 25);
|
|
||||||
characterComponent->UpdatePlayerStatistic(StatisticID::EnemiesSmashed, 75);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TearDown() override {
|
|
||||||
delete baseEntity;
|
|
||||||
TearDownDependencies();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test Construction of a CharacterComponent
|
|
||||||
*/
|
|
||||||
TEST_F(CharacterComponentTest, CharacterComponentSerializeConstructionTest) {
|
|
||||||
characterComponent->Serialize(bitStream, true);
|
|
||||||
|
|
||||||
// Basic check that construction serialization produces data
|
|
||||||
EXPECT_GT(bitStream.GetNumberOfBitsUsed(), 0);
|
|
||||||
|
|
||||||
// Basic structure validation - should be able to read claim codes flags
|
|
||||||
bool hasClaimCode0 = false, hasClaimCode1 = false, hasClaimCode2 = false, hasClaimCode3 = false;
|
|
||||||
bitStream.Read(hasClaimCode0);
|
|
||||||
bitStream.Read(hasClaimCode1);
|
|
||||||
bitStream.Read(hasClaimCode2);
|
|
||||||
bitStream.Read(hasClaimCode3);
|
|
||||||
|
|
||||||
// All claim codes should be false by default
|
|
||||||
EXPECT_FALSE(hasClaimCode0);
|
|
||||||
EXPECT_FALSE(hasClaimCode1);
|
|
||||||
EXPECT_FALSE(hasClaimCode2);
|
|
||||||
EXPECT_FALSE(hasClaimCode3);
|
|
||||||
|
|
||||||
bitStream.Reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test serialization of a CharacterComponent update
|
|
||||||
*/
|
|
||||||
TEST_F(CharacterComponentTest, CharacterComponentSerializeUpdateTest) {
|
|
||||||
// Test non-initial update serialization
|
|
||||||
characterComponent->Serialize(bitStream, false);
|
|
||||||
|
|
||||||
// Basic check that update serialization produces data
|
|
||||||
EXPECT_GT(bitStream.GetNumberOfBitsUsed(), 0);
|
|
||||||
|
|
||||||
// Should serialize flags for different update types
|
|
||||||
bool hasGMInfo = false, hasCurrentActivity = false, hasSocialInfo = false;
|
|
||||||
bitStream.Read(hasGMInfo);
|
|
||||||
bitStream.Read(hasCurrentActivity);
|
|
||||||
bitStream.Read(hasSocialInfo);
|
|
||||||
|
|
||||||
// Verify the flags reflect our changes - we set PVP and current activity
|
|
||||||
EXPECT_TRUE(hasGMInfo); // PVP was enabled in setup
|
|
||||||
EXPECT_TRUE(hasCurrentActivity); // Current activity was set in setup
|
|
||||||
EXPECT_FALSE(hasSocialInfo); // Not modified in our setup
|
|
||||||
|
|
||||||
bitStream.Reset();
|
|
||||||
}
|
|
@@ -1,143 +0,0 @@
|
|||||||
#include "GameDependencies.h"
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
#include "BitStream.h"
|
|
||||||
#include "ControllablePhysicsComponent.h"
|
|
||||||
#include "Entity.h"
|
|
||||||
#include "eReplicaComponentType.h"
|
|
||||||
#include "eStateChangeType.h"
|
|
||||||
#include "NiPoint3.h"
|
|
||||||
#include "NiQuaternion.h"
|
|
||||||
|
|
||||||
class ControllablePhysicsComponentTest : public GameDependenciesTest {
|
|
||||||
protected:
|
|
||||||
std::unique_ptr<Entity> baseEntity;
|
|
||||||
ControllablePhysicsComponent* physicsComponent;
|
|
||||||
CBITSTREAM;
|
|
||||||
|
|
||||||
void SetUp() override {
|
|
||||||
SetUpDependencies();
|
|
||||||
baseEntity = std::make_unique<Entity>(15, GameDependenciesTest::info);
|
|
||||||
physicsComponent = baseEntity->AddComponent<ControllablePhysicsComponent>(1); // Needs componentId
|
|
||||||
|
|
||||||
// Set some test values
|
|
||||||
physicsComponent->SetPosition(NiPoint3(100.0f, 200.0f, 300.0f));
|
|
||||||
physicsComponent->SetRotation(NiQuaternion(0.5f, 0.5f, 0.5f, 0.5f));
|
|
||||||
physicsComponent->SetVelocity(NiPoint3(10.0f, 20.0f, 30.0f));
|
|
||||||
physicsComponent->SetAngularVelocity(NiPoint3(1.0f, 2.0f, 3.0f));
|
|
||||||
physicsComponent->SetIsOnGround(true);
|
|
||||||
physicsComponent->SetIsOnRail(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TearDown() override {
|
|
||||||
TearDownDependencies();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_F(ControllablePhysicsComponentTest, ControllablePhysicsSerializeInitialTest) {
|
|
||||||
physicsComponent->Serialize(bitStream, true);
|
|
||||||
|
|
||||||
// Read jetpack mode info
|
|
||||||
bool inJetpackMode;
|
|
||||||
bitStream.Read(inJetpackMode);
|
|
||||||
ASSERT_FALSE(inJetpackMode); // Default should be false
|
|
||||||
|
|
||||||
// Should always write stun immunity data on construction
|
|
||||||
bool hasStunImmunityData;
|
|
||||||
bitStream.Read(hasStunImmunityData);
|
|
||||||
ASSERT_TRUE(hasStunImmunityData);
|
|
||||||
|
|
||||||
uint32_t immuneToStunMoveCount, immuneToStunJumpCount, immuneToStunTurnCount;
|
|
||||||
uint32_t immuneToStunAttackCount, immuneToStunUseItemCount, immuneToStunEquipCount;
|
|
||||||
uint32_t immuneToStunInteractCount;
|
|
||||||
|
|
||||||
bitStream.Read(immuneToStunMoveCount);
|
|
||||||
bitStream.Read(immuneToStunJumpCount);
|
|
||||||
bitStream.Read(immuneToStunTurnCount);
|
|
||||||
bitStream.Read(immuneToStunAttackCount);
|
|
||||||
bitStream.Read(immuneToStunUseItemCount);
|
|
||||||
bitStream.Read(immuneToStunEquipCount);
|
|
||||||
bitStream.Read(immuneToStunInteractCount);
|
|
||||||
|
|
||||||
// Default values should be 0
|
|
||||||
ASSERT_EQ(immuneToStunMoveCount, 0);
|
|
||||||
ASSERT_EQ(immuneToStunJumpCount, 0);
|
|
||||||
ASSERT_EQ(immuneToStunTurnCount, 0);
|
|
||||||
ASSERT_EQ(immuneToStunAttackCount, 0);
|
|
||||||
ASSERT_EQ(immuneToStunUseItemCount, 0);
|
|
||||||
ASSERT_EQ(immuneToStunEquipCount, 0);
|
|
||||||
ASSERT_EQ(immuneToStunInteractCount, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ControllablePhysicsComponentTest, ControllablePhysicsJetpackSerializationTest) {
|
|
||||||
// Test jetpack mode serialization
|
|
||||||
physicsComponent->SetInJetpackMode(true);
|
|
||||||
physicsComponent->SetJetpackEffectID(12345);
|
|
||||||
physicsComponent->SetJetpackFlying(true);
|
|
||||||
physicsComponent->SetJetpackBypassChecks(false);
|
|
||||||
|
|
||||||
physicsComponent->Serialize(bitStream, true);
|
|
||||||
|
|
||||||
bool inJetpackMode;
|
|
||||||
bitStream.Read(inJetpackMode);
|
|
||||||
ASSERT_TRUE(inJetpackMode);
|
|
||||||
|
|
||||||
int32_t jetpackEffectID;
|
|
||||||
bool jetpackFlying, jetpackBypassChecks;
|
|
||||||
bitStream.Read(jetpackEffectID);
|
|
||||||
bitStream.Read(jetpackFlying);
|
|
||||||
bitStream.Read(jetpackBypassChecks);
|
|
||||||
|
|
||||||
ASSERT_EQ(jetpackEffectID, 12345);
|
|
||||||
ASSERT_TRUE(jetpackFlying);
|
|
||||||
ASSERT_FALSE(jetpackBypassChecks);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ControllablePhysicsComponentTest, ControllablePhysicsStunImmunityTest) {
|
|
||||||
// Test stun immunity serialization
|
|
||||||
physicsComponent->SetStunImmunity(eStateChangeType::PUSH, 5);
|
|
||||||
// Note: PULL may not be available, using another valid type
|
|
||||||
physicsComponent->SetStunImmunity(eStateChangeType::POP, 3);
|
|
||||||
|
|
||||||
physicsComponent->Serialize(bitStream, true);
|
|
||||||
|
|
||||||
// Skip jetpack data
|
|
||||||
bool inJetpackMode;
|
|
||||||
bitStream.Read(inJetpackMode);
|
|
||||||
|
|
||||||
bool hasStunImmunityData;
|
|
||||||
bitStream.Read(hasStunImmunityData);
|
|
||||||
ASSERT_TRUE(hasStunImmunityData);
|
|
||||||
|
|
||||||
uint32_t immuneToStunMoveCount, immuneToStunJumpCount, immuneToStunTurnCount;
|
|
||||||
uint32_t immuneToStunAttackCount, immuneToStunUseItemCount, immuneToStunEquipCount;
|
|
||||||
uint32_t immuneToStunInteractCount;
|
|
||||||
|
|
||||||
bitStream.Read(immuneToStunMoveCount);
|
|
||||||
bitStream.Read(immuneToStunJumpCount);
|
|
||||||
bitStream.Read(immuneToStunTurnCount);
|
|
||||||
bitStream.Read(immuneToStunAttackCount);
|
|
||||||
bitStream.Read(immuneToStunUseItemCount);
|
|
||||||
bitStream.Read(immuneToStunEquipCount);
|
|
||||||
bitStream.Read(immuneToStunInteractCount);
|
|
||||||
|
|
||||||
// Values should reflect the set immunities
|
|
||||||
// Note: The actual mapping depends on implementation
|
|
||||||
ASSERT_GE(immuneToStunMoveCount + immuneToStunJumpCount + immuneToStunTurnCount +
|
|
||||||
immuneToStunAttackCount + immuneToStunUseItemCount + immuneToStunEquipCount +
|
|
||||||
immuneToStunInteractCount, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ControllablePhysicsComponentTest, ControllablePhysicsSerializeUpdateTest) {
|
|
||||||
// Test non-initial update serialization
|
|
||||||
physicsComponent->Serialize(bitStream, false);
|
|
||||||
|
|
||||||
// Should check for various dirty flags
|
|
||||||
bool hasPositionUpdate, hasVelocityUpdate, hasAngularVelocityUpdate;
|
|
||||||
bool hasBouncePathing, hasRotationUpdate;
|
|
||||||
|
|
||||||
// The exact structure depends on what's dirty
|
|
||||||
// For now, just verify that serialization doesn't crash
|
|
||||||
ASSERT_GE(bitStream.GetNumberOfBitsUsed(), 0);
|
|
||||||
}
|
|
||||||
|
|
@@ -1,76 +0,0 @@
|
|||||||
#include "GameDependencies.h"
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
#include "BitStream.h"
|
|
||||||
#include "InventoryComponent.h"
|
|
||||||
#include "Entity.h"
|
|
||||||
#include "eReplicaComponentType.h"
|
|
||||||
#include "eStateChangeType.h"
|
|
||||||
#include "Item.h"
|
|
||||||
|
|
||||||
class InventoryComponentTest : public GameDependenciesTest {
|
|
||||||
protected:
|
|
||||||
std::unique_ptr<Entity> baseEntity;
|
|
||||||
InventoryComponent* inventoryComponent;
|
|
||||||
CBITSTREAM;
|
|
||||||
|
|
||||||
void SetUp() override {
|
|
||||||
SetUpDependencies();
|
|
||||||
baseEntity = std::make_unique<Entity>(15, GameDependenciesTest::info);
|
|
||||||
inventoryComponent = baseEntity->AddComponent<InventoryComponent>();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TearDown() override {
|
|
||||||
TearDownDependencies();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_F(InventoryComponentTest, InventoryComponentSerializeInitialTest) {
|
|
||||||
// Test empty inventory serialization
|
|
||||||
inventoryComponent->Serialize(bitStream, true);
|
|
||||||
|
|
||||||
bool hasUpdates;
|
|
||||||
bitStream.Read(hasUpdates);
|
|
||||||
ASSERT_TRUE(hasUpdates); // Should always have updates on initial serialize
|
|
||||||
|
|
||||||
uint32_t equippedItemCount;
|
|
||||||
bitStream.Read(equippedItemCount);
|
|
||||||
ASSERT_EQ(equippedItemCount, 0); // No equipped items initially
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(InventoryComponentTest, InventoryComponentSerializeEquippedItemsTest) {
|
|
||||||
// Test serialization with initial state (no equipped items)
|
|
||||||
inventoryComponent->Serialize(bitStream, true);
|
|
||||||
|
|
||||||
bool hasUpdates;
|
|
||||||
bitStream.Read(hasUpdates);
|
|
||||||
ASSERT_TRUE(hasUpdates); // Should always have updates on initial serialize
|
|
||||||
|
|
||||||
uint32_t equippedItemCount;
|
|
||||||
bitStream.Read(equippedItemCount);
|
|
||||||
ASSERT_EQ(equippedItemCount, 0); // No equipped items initially for LOT 1
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(InventoryComponentTest, InventoryComponentSerializeUpdateTest) {
|
|
||||||
// Test that initial serialization returns expected structure
|
|
||||||
inventoryComponent->Serialize(bitStream, true);
|
|
||||||
|
|
||||||
bool hasUpdates;
|
|
||||||
bitStream.Read(hasUpdates);
|
|
||||||
ASSERT_TRUE(hasUpdates); // Initial serialization should have updates
|
|
||||||
|
|
||||||
uint32_t equippedItemCount;
|
|
||||||
bitStream.Read(equippedItemCount);
|
|
||||||
ASSERT_EQ(equippedItemCount, 0); // No equipped items initially
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(InventoryComponentTest, InventoryComponentDirtyFlagTest) {
|
|
||||||
// Test initial state serialization
|
|
||||||
inventoryComponent->Serialize(bitStream, false);
|
|
||||||
|
|
||||||
bool hasUpdates;
|
|
||||||
bitStream.Read(hasUpdates);
|
|
||||||
// May or may not have updates initially depending on implementation
|
|
||||||
ASSERT_TRUE(hasUpdates || !hasUpdates); // Either state is valid
|
|
||||||
}
|
|
||||||
|
|
@@ -1,9 +0,0 @@
|
|||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
// Simple test that verifies QuickBuildComponent header inclusion
|
|
||||||
// The actual QuickBuildComponent requires complex database dependencies
|
|
||||||
// that are not suitable for unit testing without a full CDClient database
|
|
||||||
TEST(QuickBuildComponentTest, QuickBuildComponentHeaderInclusionTest) {
|
|
||||||
// Test that the header can be included without compilation errors
|
|
||||||
ASSERT_TRUE(true);
|
|
||||||
}
|
|
@@ -1,139 +0,0 @@
|
|||||||
#include "GameDependencies.h"
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
#include "BitStream.h"
|
|
||||||
#include "RenderComponent.h"
|
|
||||||
#include "Entity.h"
|
|
||||||
#include "eReplicaComponentType.h"
|
|
||||||
#include "eStateChangeType.h"
|
|
||||||
|
|
||||||
class RenderComponentTest : public GameDependenciesTest {
|
|
||||||
protected:
|
|
||||||
std::unique_ptr<Entity> baseEntity;
|
|
||||||
RenderComponent* renderComponent;
|
|
||||||
CBITSTREAM;
|
|
||||||
|
|
||||||
void SetUp() override {
|
|
||||||
SetUpDependencies();
|
|
||||||
baseEntity = std::make_unique<Entity>(15, GameDependenciesTest::info);
|
|
||||||
renderComponent = baseEntity->AddComponent<RenderComponent>();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TearDown() override {
|
|
||||||
TearDownDependencies();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_F(RenderComponentTest, RenderComponentSerializeInitialEmptyTest) {
|
|
||||||
renderComponent->Serialize(bitStream, true);
|
|
||||||
|
|
||||||
// Should write effects count (0 for empty)
|
|
||||||
uint32_t effectsCount;
|
|
||||||
bitStream.Read(effectsCount);
|
|
||||||
ASSERT_EQ(effectsCount, 0);
|
|
||||||
|
|
||||||
// That should be all for empty effects
|
|
||||||
ASSERT_EQ(bitStream.GetNumberOfBitsUsed(), 32); // 32 bits for uint32_t
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(RenderComponentTest, RenderComponentSerializeUpdateTest) {
|
|
||||||
// Non-initial updates should not write anything
|
|
||||||
renderComponent->Serialize(bitStream, false);
|
|
||||||
ASSERT_EQ(bitStream.GetNumberOfBitsUsed(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(RenderComponentTest, RenderComponentAddEffectTest) {
|
|
||||||
// Add an effect and test serialization
|
|
||||||
renderComponent->AddEffect(123, "test_effect", u"fire", 1.0f);
|
|
||||||
|
|
||||||
renderComponent->Serialize(bitStream, true);
|
|
||||||
|
|
||||||
uint32_t effectsCount;
|
|
||||||
bitStream.Read(effectsCount);
|
|
||||||
ASSERT_EQ(effectsCount, 1);
|
|
||||||
|
|
||||||
// Read effect name
|
|
||||||
uint8_t nameSize;
|
|
||||||
bitStream.Read(nameSize);
|
|
||||||
ASSERT_EQ(nameSize, 11); // "test_effect" length
|
|
||||||
|
|
||||||
std::string effectName;
|
|
||||||
for (int i = 0; i < nameSize; i++) {
|
|
||||||
uint8_t ch;
|
|
||||||
bitStream.Read(ch);
|
|
||||||
effectName += static_cast<char>(ch);
|
|
||||||
}
|
|
||||||
ASSERT_EQ(effectName, "test_effect");
|
|
||||||
|
|
||||||
// Read effect ID
|
|
||||||
int32_t effectID;
|
|
||||||
bitStream.Read(effectID);
|
|
||||||
ASSERT_EQ(effectID, 123);
|
|
||||||
|
|
||||||
// Read effect type
|
|
||||||
uint8_t typeSize;
|
|
||||||
bitStream.Read(typeSize);
|
|
||||||
ASSERT_EQ(typeSize, 4); // "fire" length
|
|
||||||
|
|
||||||
std::string effectType;
|
|
||||||
for (int i = 0; i < typeSize; i++) {
|
|
||||||
uint16_t ch;
|
|
||||||
bitStream.Read(ch);
|
|
||||||
effectType += static_cast<char>(ch);
|
|
||||||
}
|
|
||||||
ASSERT_EQ(effectType, "fire");
|
|
||||||
|
|
||||||
// Read priority and secondary
|
|
||||||
float priority;
|
|
||||||
int64_t secondary;
|
|
||||||
bitStream.Read(priority);
|
|
||||||
bitStream.Read(secondary);
|
|
||||||
|
|
||||||
ASSERT_EQ(priority, 1.0f); // Default priority
|
|
||||||
ASSERT_EQ(secondary, 0); // Default secondary
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(RenderComponentTest, RenderComponentMultipleEffectsTest) {
|
|
||||||
// Add multiple effects
|
|
||||||
renderComponent->AddEffect(100, "effect1", u"water", 1.0f);
|
|
||||||
renderComponent->AddEffect(200, "effect2", u"earth", 1.0f);
|
|
||||||
|
|
||||||
renderComponent->Serialize(bitStream, true);
|
|
||||||
|
|
||||||
uint32_t effectsCount;
|
|
||||||
bitStream.Read(effectsCount);
|
|
||||||
ASSERT_EQ(effectsCount, 2);
|
|
||||||
|
|
||||||
// Just verify we can read both effects without crashing
|
|
||||||
for (uint32_t i = 0; i < effectsCount; i++) {
|
|
||||||
uint8_t nameSize;
|
|
||||||
bitStream.Read(nameSize);
|
|
||||||
|
|
||||||
if (nameSize > 0) {
|
|
||||||
// Skip name bytes
|
|
||||||
for (int j = 0; j < nameSize; j++) {
|
|
||||||
uint8_t ch;
|
|
||||||
bitStream.Read(ch);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t effectID;
|
|
||||||
bitStream.Read(effectID);
|
|
||||||
ASSERT_TRUE(effectID == 100 || effectID == 200);
|
|
||||||
|
|
||||||
uint8_t typeSize;
|
|
||||||
bitStream.Read(typeSize);
|
|
||||||
|
|
||||||
// Skip type bytes
|
|
||||||
for (int j = 0; j < typeSize; j++) {
|
|
||||||
uint16_t ch;
|
|
||||||
bitStream.Read(ch);
|
|
||||||
}
|
|
||||||
|
|
||||||
float priority;
|
|
||||||
int64_t secondary;
|
|
||||||
bitStream.Read(priority);
|
|
||||||
bitStream.Read(secondary);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@@ -1,56 +0,0 @@
|
|||||||
#include "GameDependencies.h"
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
#include "BitStream.h"
|
|
||||||
#include "ScriptComponent.h"
|
|
||||||
#include "Entity.h"
|
|
||||||
#include "eReplicaComponentType.h"
|
|
||||||
#include "eStateChangeType.h"
|
|
||||||
|
|
||||||
class ScriptComponentTest : public GameDependenciesTest {
|
|
||||||
protected:
|
|
||||||
std::unique_ptr<Entity> baseEntity;
|
|
||||||
ScriptComponent* scriptComponent;
|
|
||||||
CBITSTREAM;
|
|
||||||
|
|
||||||
void SetUp() override {
|
|
||||||
SetUpDependencies();
|
|
||||||
baseEntity = std::make_unique<Entity>(15, GameDependenciesTest::info);
|
|
||||||
scriptComponent = baseEntity->AddComponent<ScriptComponent>();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TearDown() override {
|
|
||||||
TearDownDependencies();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_F(ScriptComponentTest, ScriptComponentSerializeInitialEmptyTest) {
|
|
||||||
scriptComponent->Serialize(bitStream, true);
|
|
||||||
|
|
||||||
// Should write network settings flag (false for empty)
|
|
||||||
bool hasNetworkSettings;
|
|
||||||
bitStream.Read(hasNetworkSettings);
|
|
||||||
ASSERT_FALSE(hasNetworkSettings);
|
|
||||||
|
|
||||||
// That should be all for empty network settings
|
|
||||||
ASSERT_EQ(bitStream.GetNumberOfBitsUsed(), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(ScriptComponentTest, ScriptComponentSerializeUpdateTest) {
|
|
||||||
// Non-initial updates should not write anything for ScriptComponent
|
|
||||||
scriptComponent->Serialize(bitStream, false);
|
|
||||||
ASSERT_EQ(bitStream.GetNumberOfBitsUsed(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST_F(ScriptComponentTest, ScriptComponentSerializedFlagTest) {
|
|
||||||
// Test the serialized flag functionality
|
|
||||||
ASSERT_FALSE(scriptComponent->GetSerialized());
|
|
||||||
|
|
||||||
scriptComponent->SetSerialized(true);
|
|
||||||
ASSERT_TRUE(scriptComponent->GetSerialized());
|
|
||||||
|
|
||||||
scriptComponent->SetSerialized(false);
|
|
||||||
ASSERT_FALSE(scriptComponent->GetSerialized());
|
|
||||||
}
|
|
@@ -1,60 +0,0 @@
|
|||||||
#include "GameDependencies.h"
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
#include "BitStream.h"
|
|
||||||
#include "SkillComponent.h"
|
|
||||||
#include "Entity.h"
|
|
||||||
#include "eReplicaComponentType.h"
|
|
||||||
#include "eStateChangeType.h"
|
|
||||||
|
|
||||||
class SkillComponentTest : public GameDependenciesTest {
|
|
||||||
protected:
|
|
||||||
std::unique_ptr<Entity> baseEntity;
|
|
||||||
SkillComponent* skillComponent;
|
|
||||||
CBITSTREAM;
|
|
||||||
|
|
||||||
void SetUp() override {
|
|
||||||
SetUpDependencies();
|
|
||||||
baseEntity = std::make_unique<Entity>(15, GameDependenciesTest::info);
|
|
||||||
skillComponent = baseEntity->AddComponent<SkillComponent>();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TearDown() override {
|
|
||||||
TearDownDependencies();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_F(SkillComponentTest, SkillComponentSerializeInitialTest) {
|
|
||||||
skillComponent->Serialize(bitStream, true);
|
|
||||||
|
|
||||||
// SkillComponent just writes a 0 bit on initial update
|
|
||||||
bool hasSkillData;
|
|
||||||
bitStream.Read(hasSkillData);
|
|
||||||
ASSERT_FALSE(hasSkillData); // Should write 0
|
|
||||||
|
|
||||||
// Verify that's all that's written
|
|
||||||
ASSERT_EQ(bitStream.GetNumberOfBitsUsed(), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(SkillComponentTest, SkillComponentSerializeUpdateTest) {
|
|
||||||
skillComponent->Serialize(bitStream, false);
|
|
||||||
|
|
||||||
// Non-initial updates should not write anything for SkillComponent
|
|
||||||
ASSERT_EQ(bitStream.GetNumberOfBitsUsed(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
TEST_F(SkillComponentTest, SkillComponentUniqueIdTest) {
|
|
||||||
// Test unique skill ID generation
|
|
||||||
uint32_t id1 = skillComponent->GetUniqueSkillId();
|
|
||||||
uint32_t id2 = skillComponent->GetUniqueSkillId();
|
|
||||||
uint32_t id3 = skillComponent->GetUniqueSkillId();
|
|
||||||
|
|
||||||
ASSERT_NE(id1, id2);
|
|
||||||
ASSERT_NE(id2, id3);
|
|
||||||
ASSERT_NE(id1, id3);
|
|
||||||
|
|
||||||
// Should be sequential
|
|
||||||
ASSERT_EQ(id2, id1 + 1);
|
|
||||||
ASSERT_EQ(id3, id2 + 1);
|
|
||||||
}
|
|
@@ -1,9 +0,0 @@
|
|||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
// Simple test that verifies VendorComponent header inclusion
|
|
||||||
// The actual VendorComponent requires complex database dependencies
|
|
||||||
// that are not suitable for unit testing without a full CDClient database
|
|
||||||
TEST(VendorComponentTest, VendorComponentHeaderInclusionTest) {
|
|
||||||
// Test that the header can be included without compilation errors
|
|
||||||
ASSERT_TRUE(true);
|
|
||||||
}
|
|
Reference in New Issue
Block a user