mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-11-06 15:42:06 +00:00
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:
66
tests/dGameTests/dComponentsTests/ScriptComponentTests.cpp
Normal file
66
tests/dGameTests/dComponentsTests/ScriptComponentTests.cpp
Normal 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());
|
||||
}
|
||||
Reference in New Issue
Block a user