mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-09-05 14:58:27 +00:00
Add CollectibleComponent and LUPExhibitComponent serialization tests
Co-authored-by: aronwk-aaron <26027722+aronwk-aaron@users.noreply.github.com>
This commit is contained in:
@@ -2,8 +2,10 @@ set(DCOMPONENTS_TESTS
|
||||
"ActivityComponentTests.cpp"
|
||||
"BaseCombatAIComponentTests.cpp"
|
||||
"BouncerComponentTests.cpp"
|
||||
"CollectibleComponentTests.cpp"
|
||||
"DestroyableComponentTests.cpp"
|
||||
"HavokVehiclePhysicsComponentTests.cpp"
|
||||
"LUPExhibitComponentTests.cpp"
|
||||
"ModelComponentTests.cpp"
|
||||
"MovingPlatformComponentTests.cpp"
|
||||
"PetComponentTests.cpp"
|
||||
|
106
tests/dGameTests/dComponentsTests/CollectibleComponentTests.cpp
Normal file
106
tests/dGameTests/dComponentsTests/CollectibleComponentTests.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
#include "GameDependencies.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "BitStream.h"
|
||||
#include "CollectibleComponent.h"
|
||||
#include "Entity.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
class CollectibleTest : public GameDependenciesTest {
|
||||
protected:
|
||||
Entity* baseEntity;
|
||||
CollectibleComponent* collectibleComponent;
|
||||
CBITSTREAM
|
||||
uint32_t flags = 0;
|
||||
void SetUp() override {
|
||||
SetUpDependencies();
|
||||
baseEntity = new Entity(15, GameDependenciesTest::info);
|
||||
collectibleComponent = baseEntity->AddComponent<CollectibleComponent>(123); // Test with collectibleId = 123
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
delete baseEntity;
|
||||
TearDownDependencies();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Test basic CollectibleComponent serialization
|
||||
*/
|
||||
TEST_F(CollectibleTest, CollectibleComponentSerializeBasicTest) {
|
||||
bitStream.Reset();
|
||||
|
||||
// Serialize the collectible component
|
||||
collectibleComponent->Serialize(bitStream, true);
|
||||
|
||||
// Read back the serialized data
|
||||
int16_t collectibleId;
|
||||
bitStream.Read(collectibleId);
|
||||
EXPECT_EQ(collectibleId, 123); // Should match the ID we set
|
||||
|
||||
// Verify getter
|
||||
EXPECT_EQ(collectibleComponent->GetCollectibleId(), 123);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test CollectibleComponent serialization with construction flag true
|
||||
*/
|
||||
TEST_F(CollectibleTest, CollectibleComponentSerializeConstructionTest) {
|
||||
bitStream.Reset();
|
||||
|
||||
// Serialize with construction = true
|
||||
collectibleComponent->Serialize(bitStream, true);
|
||||
|
||||
// Read back the serialized data
|
||||
int16_t collectibleId;
|
||||
bitStream.Read(collectibleId);
|
||||
EXPECT_EQ(collectibleId, 123);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test CollectibleComponent serialization with construction flag false
|
||||
*/
|
||||
TEST_F(CollectibleTest, CollectibleComponentSerializeRegularUpdateTest) {
|
||||
bitStream.Reset();
|
||||
|
||||
// Serialize with construction = false
|
||||
collectibleComponent->Serialize(bitStream, false);
|
||||
|
||||
// Read back the serialized data
|
||||
int16_t collectibleId;
|
||||
bitStream.Read(collectibleId);
|
||||
EXPECT_EQ(collectibleId, 123); // Should still serialize the same way
|
||||
}
|
||||
|
||||
/**
|
||||
* Test CollectibleComponent with different collectible IDs
|
||||
*/
|
||||
TEST_F(CollectibleTest, CollectibleComponentDifferentIDsTest) {
|
||||
// Create another entity with a different collectible ID
|
||||
Entity* anotherEntity = new Entity(16, GameDependenciesTest::info);
|
||||
CollectibleComponent* anotherCollectible = anotherEntity->AddComponent<CollectibleComponent>(456);
|
||||
|
||||
bitStream.Reset();
|
||||
|
||||
// Serialize the first collectible
|
||||
collectibleComponent->Serialize(bitStream, true);
|
||||
|
||||
int16_t firstId;
|
||||
bitStream.Read(firstId);
|
||||
EXPECT_EQ(firstId, 123);
|
||||
|
||||
bitStream.Reset();
|
||||
|
||||
// Serialize the second collectible
|
||||
anotherCollectible->Serialize(bitStream, true);
|
||||
|
||||
int16_t secondId;
|
||||
bitStream.Read(secondId);
|
||||
EXPECT_EQ(secondId, 456);
|
||||
|
||||
// Verify getters
|
||||
EXPECT_EQ(collectibleComponent->GetCollectibleId(), 123);
|
||||
EXPECT_EQ(anotherCollectible->GetCollectibleId(), 456);
|
||||
|
||||
delete anotherEntity;
|
||||
}
|
120
tests/dGameTests/dComponentsTests/LUPExhibitComponentTests.cpp
Normal file
120
tests/dGameTests/dComponentsTests/LUPExhibitComponentTests.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
#include "GameDependencies.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "BitStream.h"
|
||||
#include "LUPExhibitComponent.h"
|
||||
#include "Entity.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
class LUPExhibitTest : public GameDependenciesTest {
|
||||
protected:
|
||||
Entity* baseEntity;
|
||||
LUPExhibitComponent* lupExhibitComponent;
|
||||
CBITSTREAM
|
||||
uint32_t flags = 0;
|
||||
void SetUp() override {
|
||||
SetUpDependencies();
|
||||
baseEntity = new Entity(15, GameDependenciesTest::info);
|
||||
lupExhibitComponent = baseEntity->AddComponent<LUPExhibitComponent>();
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
delete baseEntity;
|
||||
TearDownDependencies();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Test LUPExhibitComponent initial serialization
|
||||
*/
|
||||
TEST_F(LUPExhibitTest, LUPExhibitComponentSerializeInitialUpdateTest) {
|
||||
bitStream.Reset();
|
||||
|
||||
// Component should be dirty by default
|
||||
lupExhibitComponent->Serialize(bitStream, true);
|
||||
|
||||
// Read back the serialized data
|
||||
bool isDirty;
|
||||
bitStream.Read(isDirty);
|
||||
EXPECT_EQ(isDirty, true); // Should be dirty by default
|
||||
|
||||
LOT exhibitLOT;
|
||||
bitStream.Read(exhibitLOT);
|
||||
EXPECT_EQ(exhibitLOT, 11121); // First exhibit in the array
|
||||
}
|
||||
|
||||
/**
|
||||
* Test LUPExhibitComponent regular update when not dirty
|
||||
*/
|
||||
TEST_F(LUPExhibitTest, LUPExhibitComponentSerializeNotDirtyTest) {
|
||||
bitStream.Reset();
|
||||
|
||||
// First serialize to clear dirty flag
|
||||
lupExhibitComponent->Serialize(bitStream, false); // This clears the dirty flag
|
||||
bitStream.Reset();
|
||||
|
||||
// Now serialize again - should not be dirty
|
||||
lupExhibitComponent->Serialize(bitStream, false);
|
||||
|
||||
bool isDirty;
|
||||
bitStream.Read(isDirty);
|
||||
EXPECT_EQ(isDirty, false); // Should not be dirty after previous serialization
|
||||
}
|
||||
|
||||
/**
|
||||
* Test LUPExhibitComponent cycling through exhibits
|
||||
*/
|
||||
TEST_F(LUPExhibitTest, LUPExhibitComponentNextExhibitTest) {
|
||||
bitStream.Reset();
|
||||
|
||||
// Get first exhibit
|
||||
lupExhibitComponent->Serialize(bitStream, true);
|
||||
|
||||
bool isDirty;
|
||||
bitStream.Read(isDirty);
|
||||
EXPECT_EQ(isDirty, true);
|
||||
|
||||
LOT firstExhibit;
|
||||
bitStream.Read(firstExhibit);
|
||||
EXPECT_EQ(firstExhibit, 11121); // First exhibit
|
||||
|
||||
bitStream.Reset();
|
||||
|
||||
// Move to next exhibit
|
||||
lupExhibitComponent->NextLUPExhibit();
|
||||
lupExhibitComponent->Serialize(bitStream, false);
|
||||
|
||||
bitStream.Read(isDirty);
|
||||
EXPECT_EQ(isDirty, true); // Should be dirty after NextLUPExhibit
|
||||
|
||||
LOT secondExhibit;
|
||||
bitStream.Read(secondExhibit);
|
||||
EXPECT_EQ(secondExhibit, 11295); // Second exhibit
|
||||
}
|
||||
|
||||
/**
|
||||
* Test LUPExhibitComponent cycling through all exhibits and wrapping around
|
||||
*/
|
||||
TEST_F(LUPExhibitTest, LUPExhibitComponentCycleAllExhibitsTest) {
|
||||
bitStream.Reset();
|
||||
|
||||
// Expected exhibit sequence: 11121, 11295, 11423, 11979, then back to 11121
|
||||
std::array<LOT, 5> expectedLOTs = { 11121, 11295, 11423, 11979, 11121 };
|
||||
|
||||
for (size_t i = 0; i < expectedLOTs.size(); ++i) {
|
||||
if (i > 0) {
|
||||
lupExhibitComponent->NextLUPExhibit();
|
||||
}
|
||||
|
||||
bitStream.Reset();
|
||||
lupExhibitComponent->Serialize(bitStream, false);
|
||||
|
||||
bool isDirty;
|
||||
bitStream.Read(isDirty);
|
||||
EXPECT_EQ(isDirty, true);
|
||||
|
||||
LOT exhibitLOT;
|
||||
bitStream.Read(exhibitLOT);
|
||||
EXPECT_EQ(exhibitLOT, expectedLOTs[i]) << "Exhibit " << i << " should be " << expectedLOTs[i];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user