Add initial comprehensive component serialization tests for CharacterComponent, InventoryComponent, ControllablePhysicsComponent, SkillComponent, and BuffComponent

Co-authored-by: aronwk-aaron <26027722+aronwk-aaron@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-08-31 06:11:52 +00:00
parent 5a17e6cf23
commit de49b53366
6 changed files with 709 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
#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, SkillComponentSerializeConsistencyTest) {
// Test multiple initial serializations are consistent
RakNet::BitStream firstSerialization;
RakNet::BitStream secondSerialization;
skillComponent->Serialize(firstSerialization, true);
skillComponent->Serialize(secondSerialization, true);
ASSERT_EQ(firstSerialization.GetNumberOfBitsUsed(), secondSerialization.GetNumberOfBitsUsed());
ASSERT_EQ(firstSerialization.GetNumberOfBitsUsed(), 1);
bool hasSkillData1, hasSkillData2;
firstSerialization.Read(hasSkillData1);
secondSerialization.Read(hasSkillData2);
ASSERT_EQ(hasSkillData1, hasSkillData2);
ASSERT_FALSE(hasSkillData1);
}
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);
}