Add additional component serialization tests for QuickBuildComponent, VendorComponent, and RenderComponent with comprehensive coverage

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:18:26 +00:00
parent de49b53366
commit 125c98570d
6 changed files with 491 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
#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, ScriptComponentSerializeConsistencyTest) {
// Test that multiple initial serializations are consistent
RakNet::BitStream firstSerialization;
RakNet::BitStream secondSerialization;
scriptComponent->Serialize(firstSerialization, true);
scriptComponent->Serialize(secondSerialization, true);
ASSERT_EQ(firstSerialization.GetNumberOfBitsUsed(), secondSerialization.GetNumberOfBitsUsed());
ASSERT_EQ(firstSerialization.GetNumberOfBitsUsed(), 1);
}
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());
}