From a18a3f5b2538daeea6e4f1dc6168643b86bea8ec Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 31 Aug 2025 20:15:04 +0000 Subject: [PATCH] Add comprehensive BouncerComponent serialization tests - Add 4 tests covering BouncerComponent serialization behavior - Test pet enabled/disabled states and bouncer activation combinations - Validate conditional serialization logic (only writes bouncer state when pet enabled) - Test initial update vs regular update behavior consistency - All tests pass, ensuring pet bouncer mechanics network correctly Co-authored-by: aronwk-aaron <26027722+aronwk-aaron@users.noreply.github.com> --- .../BouncerComponentTests.cpp | 116 ++++++++++++++++++ .../dComponentsTests/CMakeLists.txt | 1 + 2 files changed, 117 insertions(+) create mode 100644 tests/dGameTests/dComponentsTests/BouncerComponentTests.cpp diff --git a/tests/dGameTests/dComponentsTests/BouncerComponentTests.cpp b/tests/dGameTests/dComponentsTests/BouncerComponentTests.cpp new file mode 100644 index 00000000..bbaf22c3 --- /dev/null +++ b/tests/dGameTests/dComponentsTests/BouncerComponentTests.cpp @@ -0,0 +1,116 @@ +#include "GameDependencies.h" +#include + +#include "BitStream.h" +#include "BouncerComponent.h" +#include "Entity.h" +#include "eReplicaComponentType.h" + +class BouncerTest : public GameDependenciesTest { +protected: + Entity* baseEntity; + BouncerComponent* bouncerComponent; + CBITSTREAM + uint32_t flags = 0; + void SetUp() override { + SetUpDependencies(); + baseEntity = new Entity(15, GameDependenciesTest::info); + // BouncerComponent constructor doesn't require parameters + bouncerComponent = baseEntity->AddComponent(); + } + + void TearDown() override { + delete baseEntity; + TearDownDependencies(); + } +}; + +/** + * Test serialization of a BouncerComponent with pet enabled false + */ +TEST_F(BouncerTest, BouncerComponentSerializePetDisabledTest) { + bitStream.Reset(); + + // Default state should have pet disabled + bouncerComponent->SetPetEnabled(false); + + // Now we test a serialization for correctness. + bouncerComponent->Serialize(bitStream, false); + + // Read back the serialized data + bool petEnabled; + bitStream.Read(petEnabled); + EXPECT_EQ(petEnabled, false); + + // When pet is disabled, there should be no additional data + EXPECT_EQ(bitStream.GetNumberOfUnreadBits(), 0); +} + +/** + * Test serialization of a BouncerComponent with pet enabled true + */ +TEST_F(BouncerTest, BouncerComponentSerializePetEnabledTest) { + bitStream.Reset(); + + // Enable pet and set bouncer state + bouncerComponent->SetPetEnabled(true); + bouncerComponent->SetPetBouncerEnabled(true); + + // Now we test a serialization for correctness. + bouncerComponent->Serialize(bitStream, false); + + // Read back the serialized data + bool petEnabled; + bitStream.Read(petEnabled); + EXPECT_EQ(petEnabled, true); + + bool petBouncerEnabled; + bitStream.Read(petBouncerEnabled); + EXPECT_EQ(petBouncerEnabled, true); +} + +/** + * Test serialization of a BouncerComponent with pet enabled but bouncer disabled + */ +TEST_F(BouncerTest, BouncerComponentSerializePetEnabledBouncerDisabledTest) { + bitStream.Reset(); + + // Enable pet but disable bouncer + bouncerComponent->SetPetEnabled(true); + bouncerComponent->SetPetBouncerEnabled(false); + + // Now we test a serialization for correctness. + bouncerComponent->Serialize(bitStream, false); + + // Read back the serialized data + bool petEnabled; + bitStream.Read(petEnabled); + EXPECT_EQ(petEnabled, true); + + bool petBouncerEnabled; + bitStream.Read(petBouncerEnabled); + EXPECT_EQ(petBouncerEnabled, false); +} + +/** + * Test serialization during initial update + */ +TEST_F(BouncerTest, BouncerComponentSerializeInitialUpdateTest) { + bitStream.Reset(); + + // Enable pet and set bouncer state + bouncerComponent->SetPetEnabled(true); + bouncerComponent->SetPetBouncerEnabled(true); + + // Now we test a serialization for correctness with initial update. + bouncerComponent->Serialize(bitStream, true); + + // Read back the serialized data - behavior should be same as regular update + bool petEnabled; + bitStream.Read(petEnabled); + EXPECT_EQ(petEnabled, true); + + bool petBouncerEnabled; + bitStream.Read(petBouncerEnabled); + EXPECT_EQ(petBouncerEnabled, true); +} \ No newline at end of file diff --git a/tests/dGameTests/dComponentsTests/CMakeLists.txt b/tests/dGameTests/dComponentsTests/CMakeLists.txt index 8d4cb71c..f2f94cbb 100644 --- a/tests/dGameTests/dComponentsTests/CMakeLists.txt +++ b/tests/dGameTests/dComponentsTests/CMakeLists.txt @@ -1,5 +1,6 @@ set(DCOMPONENTS_TESTS "ActivityComponentTests.cpp" + "BouncerComponentTests.cpp" "DestroyableComponentTests.cpp" "HavokVehiclePhysicsComponentTests.cpp" "ModelComponentTests.cpp"