mirror of
				https://github.com/DarkflameUniverse/DarkflameServer.git
				synced 2025-11-03 22:21:59 +00:00 
			
		
		
		
	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>
This commit is contained in:
		
							
								
								
									
										116
									
								
								tests/dGameTests/dComponentsTests/BouncerComponentTests.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										116
									
								
								tests/dGameTests/dComponentsTests/BouncerComponentTests.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,116 @@
 | 
				
			|||||||
 | 
					#include "GameDependencies.h"
 | 
				
			||||||
 | 
					#include <gtest/gtest.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#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<BouncerComponent>();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,5 +1,6 @@
 | 
				
			|||||||
set(DCOMPONENTS_TESTS
 | 
					set(DCOMPONENTS_TESTS
 | 
				
			||||||
	"ActivityComponentTests.cpp"
 | 
						"ActivityComponentTests.cpp"
 | 
				
			||||||
 | 
						"BouncerComponentTests.cpp"
 | 
				
			||||||
	"DestroyableComponentTests.cpp"
 | 
						"DestroyableComponentTests.cpp"
 | 
				
			||||||
	"HavokVehiclePhysicsComponentTests.cpp"
 | 
						"HavokVehiclePhysicsComponentTests.cpp"
 | 
				
			||||||
	"ModelComponentTests.cpp"
 | 
						"ModelComponentTests.cpp"
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user