Add DonationVendorComponent, ItemComponent, LevelProgressionComponent, MiniGameControlComponent tests and enhance PetComponent tests

Co-authored-by: aronwk-aaron <26027722+aronwk-aaron@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-08-31 22:37:18 +00:00
parent c29f0d151e
commit f4a9cd21be
6 changed files with 622 additions and 1 deletions

View File

@@ -41,3 +41,184 @@ TEST_F(PetTest, PlacementNewAddComponentTest) {
ASSERT_EQ(petComponent->GetParent()->GetObjectID(), 15);
ASSERT_EQ(petComponent->GetAbility(), ePetAbilityType::Invalid);
}
// Test untamed pet serialization (initial update)
TEST_F(PetTest, UntamedPetInitialSerialization) {
petComponent->Serialize(bitStream, true);
// Read the serialized data manually
bool alwaysDirty;
uint32_t status;
ePetAbilityType ability;
bool interacting;
bool tamed;
bool tamedForInitial;
bitStream.Read(alwaysDirty);
EXPECT_TRUE(alwaysDirty); // Always true
bitStream.Read(status);
EXPECT_EQ(status, 0); // Default status should be 0
bitStream.Read(ability);
EXPECT_EQ(ability, ePetAbilityType::Invalid); // Should be Invalid for untamed pets
bitStream.Read(interacting);
EXPECT_FALSE(interacting); // No interaction by default
bitStream.Read(tamed);
EXPECT_FALSE(tamed); // Pet is not tamed by default
// For initial update, should write tamed flag again
bitStream.Read(tamedForInitial);
EXPECT_FALSE(tamedForInitial); // Should match tamed flag
bitStream.Reset();
}
// Test tamed pet serialization (initial update)
TEST_F(PetTest, TamedPetInitialSerialization) {
// Set up a tamed pet
LWOOBJID ownerID = 12345;
petComponent->Activate(ownerID, false, false);
petComponent->SetPetNameForModeration("TestPet");
petComponent->SetOwnerName("TestOwner");
petComponent->Serialize(bitStream, true);
// Read the serialized data manually
bool alwaysDirty;
uint32_t status;
ePetAbilityType ability;
bool interacting;
bool tamed;
LWOOBJID owner;
bool tamedForInitial;
uint32_t moderationStatus;
uint8_t nameLength;
std::vector<uint16_t> nameData;
uint8_t ownerNameLength;
std::vector<uint16_t> ownerNameData;
bitStream.Read(alwaysDirty);
EXPECT_TRUE(alwaysDirty); // Always true
bitStream.Read(status);
bitStream.Read(ability);
EXPECT_NE(ability, ePetAbilityType::Invalid); // Should have a valid ability when tamed
bitStream.Read(interacting);
EXPECT_FALSE(interacting); // No interaction by default
bitStream.Read(tamed);
EXPECT_TRUE(tamed); // Pet should be tamed
if (tamed) {
bitStream.Read(owner);
EXPECT_EQ(owner, ownerID);
}
// For initial update with tamed pet
bitStream.Read(tamedForInitial);
EXPECT_TRUE(tamedForInitial);
if (tamedForInitial) {
bitStream.Read(moderationStatus);
EXPECT_EQ(moderationStatus, 0); // Default moderation status
bitStream.Read(nameLength);
EXPECT_GT(nameLength, 0); // Should have a name
nameData.resize(nameLength);
for (uint8_t i = 0; i < nameLength; i++) {
bitStream.Read(nameData[i]);
}
bitStream.Read(ownerNameLength);
EXPECT_GT(ownerNameLength, 0); // Should have an owner name
ownerNameData.resize(ownerNameLength);
for (uint8_t i = 0; i < ownerNameLength; i++) {
bitStream.Read(ownerNameData[i]);
}
}
bitStream.Reset();
}
// Test tamed pet regular update serialization
TEST_F(PetTest, TamedPetRegularSerialization) {
// Set up a tamed pet
LWOOBJID ownerID = 12345;
petComponent->Activate(ownerID, false, false);
petComponent->Serialize(bitStream, false);
// Read the serialized data manually
bool alwaysDirty;
uint32_t status;
ePetAbilityType ability;
bool interacting;
bool tamed;
LWOOBJID owner;
bitStream.Read(alwaysDirty);
EXPECT_TRUE(alwaysDirty); // Always true
bitStream.Read(status);
bitStream.Read(ability);
EXPECT_NE(ability, ePetAbilityType::Invalid); // Should have a valid ability when tamed
bitStream.Read(interacting);
EXPECT_FALSE(interacting); // No interaction by default
bitStream.Read(tamed);
EXPECT_TRUE(tamed); // Pet should be tamed
if (tamed) {
bitStream.Read(owner);
EXPECT_EQ(owner, ownerID);
}
// Regular update should not include initial update data
EXPECT_EQ(bitStream.GetNumberOfUnreadBits(), 0);
bitStream.Reset();
}
// Test pet with interaction serialization
TEST_F(PetTest, PetWithInteractionSerialization) {
// Set up a pet with interaction
LWOOBJID interactionID = 67890;
petComponent->SetInteraction(interactionID);
petComponent->Serialize(bitStream, false);
// Read the serialized data manually
bool alwaysDirty;
uint32_t status;
ePetAbilityType ability;
bool interacting;
LWOOBJID interaction;
bool tamed;
bitStream.Read(alwaysDirty);
EXPECT_TRUE(alwaysDirty); // Always true
bitStream.Read(status);
bitStream.Read(ability);
EXPECT_EQ(ability, ePetAbilityType::Invalid); // Should be Invalid for untamed pets
bitStream.Read(interacting);
EXPECT_TRUE(interacting); // Should be true
if (interacting) {
bitStream.Read(interaction);
EXPECT_EQ(interaction, interactionID);
}
bitStream.Read(tamed);
EXPECT_FALSE(tamed); // Pet is not tamed by default
bitStream.Reset();
}