mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-09-05 06:48:37 +00:00
Remove mail extended tests and add proper Mail.h tests to dGameTests
Co-authored-by: aronwk-aaron <26027722+aronwk-aaron@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
set(DGAMETEST_SOURCES
|
||||
"GameDependencies.cpp"
|
||||
"MailTests.cpp"
|
||||
)
|
||||
|
||||
add_subdirectory(dComponentsTests)
|
||||
|
302
tests/dGameTests/MailTests.cpp
Normal file
302
tests/dGameTests/MailTests.cpp
Normal file
@@ -0,0 +1,302 @@
|
||||
#include "GameDependencies.h"
|
||||
#include "Mail.h"
|
||||
#include "MailInfo.h"
|
||||
#include "BitStream.h"
|
||||
#include "Entity.h"
|
||||
#include "User.h"
|
||||
#include "Character.h"
|
||||
#include "dCommonVars.h"
|
||||
|
||||
class MailTests : public GameDependenciesTest {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
SetUpDependencies();
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
TearDownDependencies();
|
||||
}
|
||||
};
|
||||
|
||||
// Test SendRequest packet with MailInfo serialization
|
||||
TEST_F(MailTests, SendRequestMailInfoSerialization) {
|
||||
Mail::SendRequest sendRequest;
|
||||
|
||||
// Set up test mail info
|
||||
sendRequest.mailInfo.senderUsername = "TestSender";
|
||||
sendRequest.mailInfo.recipient = "TestRecipient";
|
||||
sendRequest.mailInfo.subject = "Test Subject";
|
||||
sendRequest.mailInfo.body = "Test mail body content";
|
||||
sendRequest.mailInfo.id = 12345;
|
||||
sendRequest.mailInfo.senderId = 678;
|
||||
sendRequest.mailInfo.receiverId = 901;
|
||||
sendRequest.mailInfo.timeSent = 1640995200;
|
||||
sendRequest.mailInfo.wasRead = false;
|
||||
sendRequest.mailInfo.languageCode = 1033;
|
||||
sendRequest.mailInfo.itemID = 555;
|
||||
sendRequest.mailInfo.itemCount = 10;
|
||||
sendRequest.mailInfo.itemLOT = 1234;
|
||||
sendRequest.mailInfo.itemSubkey = 999;
|
||||
|
||||
// Test that the mail info serializes to a non-empty bitstream
|
||||
RakNet::BitStream mailInfoStream;
|
||||
sendRequest.mailInfo.Serialize(mailInfoStream);
|
||||
|
||||
// Verify the stream contains data
|
||||
ASSERT_GT(mailInfoStream.GetNumberOfBytesUsed(), 0);
|
||||
|
||||
// Verify first field (id) is correct
|
||||
mailInfoStream.ResetReadPointer();
|
||||
uint64_t readId;
|
||||
ASSERT_TRUE(mailInfoStream.Read(readId));
|
||||
ASSERT_EQ(readId, 12345);
|
||||
}
|
||||
|
||||
// Test SendResponse packet serialization
|
||||
TEST_F(MailTests, SendResponseSerialization) {
|
||||
Mail::SendResponse sendResponse;
|
||||
sendResponse.status = Mail::eSendResponse::Success;
|
||||
|
||||
RakNet::BitStream outStream;
|
||||
sendResponse.Serialize(outStream);
|
||||
|
||||
// Verify the stream contains data
|
||||
ASSERT_GT(outStream.GetNumberOfBytesUsed(), 0);
|
||||
|
||||
// Verify message ID and status are written
|
||||
outStream.ResetReadPointer();
|
||||
uint32_t messageID;
|
||||
uint32_t status;
|
||||
ASSERT_TRUE(outStream.Read(messageID));
|
||||
ASSERT_TRUE(outStream.Read(status));
|
||||
ASSERT_EQ(messageID, static_cast<uint32_t>(Mail::eMessageID::SendResponse));
|
||||
ASSERT_EQ(status, static_cast<uint32_t>(Mail::eSendResponse::Success));
|
||||
}
|
||||
|
||||
// Test NotificationResponse packet serialization
|
||||
TEST_F(MailTests, NotificationResponseSerialization) {
|
||||
Mail::NotificationResponse notificationResponse;
|
||||
notificationResponse.status = Mail::eNotificationResponse::NewMail;
|
||||
notificationResponse.auctionID = 12345;
|
||||
notificationResponse.mailCount = 3;
|
||||
|
||||
RakNet::BitStream outStream;
|
||||
notificationResponse.Serialize(outStream);
|
||||
|
||||
// Verify the stream contains data
|
||||
ASSERT_GT(outStream.GetNumberOfBytesUsed(), 0);
|
||||
|
||||
// Verify message ID and fields are written in the correct order
|
||||
// Order: messageID, status, unused, unused, auctionID, unused, mailCount, packing
|
||||
outStream.ResetReadPointer();
|
||||
uint32_t messageID;
|
||||
uint32_t status;
|
||||
uint64_t unused1, unused2, auctionID, unused3;
|
||||
uint32_t mailCount, packing;
|
||||
ASSERT_TRUE(outStream.Read(messageID));
|
||||
ASSERT_TRUE(outStream.Read(status));
|
||||
ASSERT_TRUE(outStream.Read(unused1));
|
||||
ASSERT_TRUE(outStream.Read(unused2));
|
||||
ASSERT_TRUE(outStream.Read(auctionID));
|
||||
ASSERT_TRUE(outStream.Read(unused3));
|
||||
ASSERT_TRUE(outStream.Read(mailCount));
|
||||
ASSERT_TRUE(outStream.Read(packing));
|
||||
ASSERT_EQ(messageID, static_cast<uint32_t>(Mail::eMessageID::NotificationResponse));
|
||||
ASSERT_EQ(status, static_cast<uint32_t>(Mail::eNotificationResponse::NewMail));
|
||||
ASSERT_EQ(auctionID, 12345);
|
||||
ASSERT_EQ(mailCount, 3);
|
||||
}
|
||||
|
||||
// Test DataResponse packet serialization
|
||||
TEST_F(MailTests, DataResponseSerialization) {
|
||||
Mail::DataResponse dataResponse;
|
||||
dataResponse.throttled = 0;
|
||||
|
||||
// Add some mail info
|
||||
MailInfo mail1, mail2;
|
||||
mail1.senderUsername = "Sender1";
|
||||
mail1.recipient = "Recipient1";
|
||||
mail1.subject = "Subject1";
|
||||
mail1.body = "Body1";
|
||||
mail1.id = 1;
|
||||
mail1.senderId = 100;
|
||||
mail1.receiverId = 200;
|
||||
mail1.timeSent = 1640995200;
|
||||
mail1.wasRead = false;
|
||||
mail1.languageCode = 1033;
|
||||
mail1.itemID = LWOOBJID_EMPTY;
|
||||
mail1.itemCount = 0;
|
||||
mail1.itemLOT = LOT_NULL;
|
||||
mail1.itemSubkey = LWOOBJID_EMPTY;
|
||||
|
||||
mail2.senderUsername = "Sender2";
|
||||
mail2.recipient = "Recipient2";
|
||||
mail2.subject = "Subject2";
|
||||
mail2.body = "Body2";
|
||||
mail2.id = 2;
|
||||
mail2.senderId = 300;
|
||||
mail2.receiverId = 400;
|
||||
mail2.timeSent = 1640995300;
|
||||
mail2.wasRead = true;
|
||||
mail2.languageCode = 1033;
|
||||
mail2.itemID = 555;
|
||||
mail2.itemCount = 10;
|
||||
mail2.itemLOT = 1234;
|
||||
mail2.itemSubkey = 999;
|
||||
|
||||
dataResponse.playerMail.push_back(mail1);
|
||||
dataResponse.playerMail.push_back(mail2);
|
||||
|
||||
RakNet::BitStream outStream;
|
||||
dataResponse.Serialize(outStream);
|
||||
|
||||
// Verify the stream contains data
|
||||
ASSERT_GT(outStream.GetNumberOfBytesUsed(), 0);
|
||||
|
||||
// Verify message ID, throttled, and mail count are written
|
||||
outStream.ResetReadPointer();
|
||||
uint32_t messageID;
|
||||
uint32_t throttled;
|
||||
uint16_t mailCount;
|
||||
ASSERT_TRUE(outStream.Read(messageID));
|
||||
ASSERT_TRUE(outStream.Read(throttled));
|
||||
ASSERT_TRUE(outStream.Read(mailCount));
|
||||
ASSERT_EQ(messageID, static_cast<uint32_t>(Mail::eMessageID::DataResponse));
|
||||
ASSERT_EQ(throttled, 0);
|
||||
ASSERT_EQ(mailCount, 2);
|
||||
}
|
||||
|
||||
// Test AttachmentCollectRequest packet deserialization
|
||||
TEST_F(MailTests, AttachmentCollectRequestDeserialize) {
|
||||
// This test verifies the deserialization reads data in the correct order
|
||||
RakNet::BitStream inStream;
|
||||
uint32_t unknown = 123; // Unknown field that comes first
|
||||
uint64_t mailID = 12345;
|
||||
uint64_t playerID = 67890;
|
||||
|
||||
// The Deserialize method reads: unknown, mailID, playerID
|
||||
inStream.Write(unknown);
|
||||
inStream.Write(mailID);
|
||||
inStream.Write(playerID);
|
||||
|
||||
inStream.ResetReadPointer();
|
||||
Mail::AttachmentCollectRequest request;
|
||||
ASSERT_TRUE(request.Deserialize(inStream));
|
||||
|
||||
ASSERT_EQ(request.mailID, mailID);
|
||||
ASSERT_EQ(request.playerID, playerID);
|
||||
}
|
||||
|
||||
// Test AttachmentCollectResponse packet serialization
|
||||
TEST_F(MailTests, AttachmentCollectResponseSerialization) {
|
||||
Mail::AttachmentCollectResponse response;
|
||||
response.status = Mail::eAttachmentCollectResponse::Success;
|
||||
response.mailID = 54321;
|
||||
|
||||
RakNet::BitStream outStream;
|
||||
response.Serialize(outStream);
|
||||
|
||||
// Verify the stream contains data
|
||||
ASSERT_GT(outStream.GetNumberOfBytesUsed(), 0);
|
||||
|
||||
// Verify message ID, status, and mail ID are written
|
||||
outStream.ResetReadPointer();
|
||||
uint32_t messageID;
|
||||
uint32_t status;
|
||||
uint64_t mailID;
|
||||
ASSERT_TRUE(outStream.Read(messageID));
|
||||
ASSERT_TRUE(outStream.Read(status));
|
||||
ASSERT_TRUE(outStream.Read(mailID));
|
||||
ASSERT_EQ(messageID, static_cast<uint32_t>(Mail::eMessageID::AttachmentCollectResponse));
|
||||
ASSERT_EQ(status, static_cast<uint32_t>(Mail::eAttachmentCollectResponse::Success));
|
||||
ASSERT_EQ(mailID, 54321);
|
||||
}
|
||||
|
||||
// Test DeleteRequest packet deserialization
|
||||
TEST_F(MailTests, DeleteRequestDeserialize) {
|
||||
// This test verifies the deserialization reads data in the correct order
|
||||
RakNet::BitStream inStream;
|
||||
int32_t unknown = 456; // Unknown field that comes first
|
||||
uint64_t mailID = 98765;
|
||||
uint64_t playerID = 11111;
|
||||
|
||||
// The Deserialize method reads: unknown, mailID, playerID
|
||||
inStream.Write(unknown);
|
||||
inStream.Write(mailID);
|
||||
inStream.Write(playerID);
|
||||
|
||||
inStream.ResetReadPointer();
|
||||
Mail::DeleteRequest request;
|
||||
ASSERT_TRUE(request.Deserialize(inStream));
|
||||
|
||||
ASSERT_EQ(request.mailID, mailID);
|
||||
ASSERT_EQ(request.playerID, playerID);
|
||||
}
|
||||
|
||||
// Test DeleteResponse packet serialization
|
||||
TEST_F(MailTests, DeleteResponseSerialization) {
|
||||
Mail::DeleteResponse response;
|
||||
response.status = Mail::eDeleteResponse::Success;
|
||||
response.mailID = 13579;
|
||||
|
||||
RakNet::BitStream outStream;
|
||||
response.Serialize(outStream);
|
||||
|
||||
// Verify the stream contains data
|
||||
ASSERT_GT(outStream.GetNumberOfBytesUsed(), 0);
|
||||
|
||||
// Verify message ID, status, and mail ID are written
|
||||
outStream.ResetReadPointer();
|
||||
uint32_t messageID;
|
||||
uint32_t status;
|
||||
uint64_t mailID;
|
||||
ASSERT_TRUE(outStream.Read(messageID));
|
||||
ASSERT_TRUE(outStream.Read(status));
|
||||
ASSERT_TRUE(outStream.Read(mailID));
|
||||
ASSERT_EQ(messageID, static_cast<uint32_t>(Mail::eMessageID::DeleteResponse));
|
||||
ASSERT_EQ(status, static_cast<uint32_t>(Mail::eDeleteResponse::Success));
|
||||
ASSERT_EQ(mailID, 13579);
|
||||
}
|
||||
|
||||
// Test ReadRequest packet deserialization
|
||||
TEST_F(MailTests, ReadRequestDeserialize) {
|
||||
// This test verifies the deserialization reads data in the correct order
|
||||
RakNet::BitStream inStream;
|
||||
int32_t unknown = 789; // Unknown field that comes first
|
||||
uint64_t mailID = 24680;
|
||||
|
||||
// The Deserialize method reads: unknown, mailID
|
||||
inStream.Write(unknown);
|
||||
inStream.Write(mailID);
|
||||
|
||||
inStream.ResetReadPointer();
|
||||
Mail::ReadRequest request;
|
||||
ASSERT_TRUE(request.Deserialize(inStream));
|
||||
|
||||
ASSERT_EQ(request.mailID, mailID);
|
||||
}
|
||||
|
||||
// Test ReadResponse packet serialization
|
||||
TEST_F(MailTests, ReadResponseSerialization) {
|
||||
Mail::ReadResponse response;
|
||||
response.mailID = 97531;
|
||||
response.status = Mail::eReadResponse::Success;
|
||||
|
||||
RakNet::BitStream outStream;
|
||||
response.Serialize(outStream);
|
||||
|
||||
// Verify the stream contains data
|
||||
ASSERT_GT(outStream.GetNumberOfBytesUsed(), 0);
|
||||
|
||||
// Verify message ID, status, and mail ID are written in correct order
|
||||
outStream.ResetReadPointer();
|
||||
uint32_t messageID;
|
||||
uint32_t status;
|
||||
uint64_t mailID;
|
||||
ASSERT_TRUE(outStream.Read(messageID));
|
||||
ASSERT_TRUE(outStream.Read(status));
|
||||
ASSERT_TRUE(outStream.Read(mailID));
|
||||
ASSERT_EQ(messageID, static_cast<uint32_t>(Mail::eMessageID::ReadResponse));
|
||||
ASSERT_EQ(status, static_cast<uint32_t>(Mail::eReadResponse::Success));
|
||||
ASSERT_EQ(mailID, 97531);
|
||||
}
|
@@ -6,7 +6,6 @@ set(DNETTESTS_SOURCES
|
||||
"MasterPacketTests.cpp"
|
||||
"PacketEdgeCaseTests.cpp"
|
||||
"MailBitStreamTests.cpp"
|
||||
"MailExtendedTests.cpp"
|
||||
)
|
||||
|
||||
# Set our executable
|
||||
|
@@ -1,279 +0,0 @@
|
||||
#include "TestCommon.h"
|
||||
#include "MailInfo.h"
|
||||
#include "dCommonVars.h"
|
||||
#include "BitStream.h"
|
||||
#include "ServiceType.h"
|
||||
|
||||
// Simple test for Mail enum definitions and basic constants
|
||||
// since the full Mail.h requires dGame dependencies that are complex to mock
|
||||
|
||||
class MailEnumTests : public PacketTestsBase {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
PacketTestsBase::SetUp();
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
PacketTestsBase::TearDown();
|
||||
}
|
||||
};
|
||||
|
||||
// Test basic MailInfo extended serialization with various field combinations
|
||||
TEST_F(MailEnumTests, MailInfoExtendedFieldTesting) {
|
||||
MailInfo mailInfo;
|
||||
mailInfo.senderUsername = "ExtendedTestSender";
|
||||
mailInfo.recipient = "ExtendedTestRecipient";
|
||||
mailInfo.subject = "Extended Test Subject";
|
||||
mailInfo.body = "Extended test body message with more content";
|
||||
mailInfo.id = 999888777;
|
||||
mailInfo.senderId = 123456789;
|
||||
mailInfo.receiverId = 987654321;
|
||||
mailInfo.timeSent = 1640995200; // Unix timestamp for a known date
|
||||
mailInfo.wasRead = true;
|
||||
mailInfo.languageCode = 1033; // English
|
||||
mailInfo.itemID = 555444333;
|
||||
mailInfo.itemCount = 10;
|
||||
mailInfo.itemLOT = 8888;
|
||||
mailInfo.itemSubkey = 777666555;
|
||||
|
||||
RakNet::BitStream outStream;
|
||||
mailInfo.Serialize(outStream);
|
||||
|
||||
// Verify serialization produced data
|
||||
ASSERT_GT(outStream.GetNumberOfBytesUsed(), 0);
|
||||
|
||||
// Verify the first field (id) matches
|
||||
outStream.ResetReadPointer();
|
||||
uint64_t readId;
|
||||
outStream.Read(readId);
|
||||
ASSERT_EQ(readId, mailInfo.id);
|
||||
}
|
||||
|
||||
// Test MailInfo with boundary values for different data types
|
||||
TEST_F(MailEnumTests, MailInfoBoundaryValues) {
|
||||
MailInfo mailInfo;
|
||||
|
||||
// Test minimum values
|
||||
mailInfo.senderUsername = ""; // Empty string
|
||||
mailInfo.recipient = "";
|
||||
mailInfo.subject = "";
|
||||
mailInfo.body = "";
|
||||
mailInfo.id = 0; // Minimum uint64_t
|
||||
mailInfo.senderId = 0; // Minimum uint32_t
|
||||
mailInfo.receiverId = 0;
|
||||
mailInfo.timeSent = 0;
|
||||
mailInfo.wasRead = false;
|
||||
mailInfo.languageCode = 0; // Minimum uint16_t
|
||||
mailInfo.itemID = 0;
|
||||
mailInfo.itemCount = -32768; // Minimum int16_t
|
||||
mailInfo.itemLOT = 0;
|
||||
mailInfo.itemSubkey = 0;
|
||||
|
||||
RakNet::BitStream outStream;
|
||||
mailInfo.Serialize(outStream);
|
||||
|
||||
ASSERT_GT(outStream.GetNumberOfBytesUsed(), 0);
|
||||
|
||||
// Read back the ID to verify basic serialization worked
|
||||
outStream.ResetReadPointer();
|
||||
uint64_t readId;
|
||||
outStream.Read(readId);
|
||||
ASSERT_EQ(readId, 0);
|
||||
}
|
||||
|
||||
// Test MailInfo with maximum values for different data types
|
||||
TEST_F(MailEnumTests, MailInfoMaximumValues) {
|
||||
MailInfo mailInfo;
|
||||
|
||||
// Test maximum values
|
||||
mailInfo.senderUsername = std::string(1000, 'A'); // Very long string
|
||||
mailInfo.recipient = std::string(1000, 'B');
|
||||
mailInfo.subject = std::string(1000, 'C');
|
||||
mailInfo.body = std::string(1000, 'D');
|
||||
mailInfo.id = UINT64_MAX; // Maximum uint64_t
|
||||
mailInfo.senderId = UINT32_MAX; // Maximum uint32_t
|
||||
mailInfo.receiverId = UINT32_MAX;
|
||||
mailInfo.timeSent = UINT64_MAX;
|
||||
mailInfo.wasRead = true;
|
||||
mailInfo.languageCode = UINT16_MAX; // Maximum uint16_t
|
||||
mailInfo.itemID = UINT64_MAX;
|
||||
mailInfo.itemCount = 32767; // Maximum positive int16_t
|
||||
mailInfo.itemLOT = UINT32_MAX;
|
||||
mailInfo.itemSubkey = UINT64_MAX;
|
||||
|
||||
RakNet::BitStream outStream;
|
||||
mailInfo.Serialize(outStream);
|
||||
|
||||
ASSERT_GT(outStream.GetNumberOfBytesUsed(), 0);
|
||||
|
||||
// Read back the ID to verify basic serialization worked with max values
|
||||
outStream.ResetReadPointer();
|
||||
uint64_t readId;
|
||||
outStream.Read(readId);
|
||||
ASSERT_EQ(readId, UINT64_MAX);
|
||||
}
|
||||
|
||||
// Test MailInfo serialization with special Unicode characters in different fields
|
||||
TEST_F(MailEnumTests, MailInfoUnicodeInAllFields) {
|
||||
MailInfo mailInfo;
|
||||
|
||||
// Use Unicode in various string fields
|
||||
mailInfo.senderUsername = "测试用户"; // "Test User" in Chinese
|
||||
mailInfo.recipient = "пользователь"; // "User" in Russian
|
||||
mailInfo.subject = "🎮メールテスト🎮"; // Mixed emoji and Japanese
|
||||
mailInfo.body = "العربية ✅ 한국어 ✅ Français ✅"; // Multiple languages
|
||||
mailInfo.id = 12345;
|
||||
mailInfo.senderId = 67890;
|
||||
mailInfo.receiverId = 11111;
|
||||
mailInfo.timeSent = 1234567890;
|
||||
mailInfo.wasRead = false;
|
||||
mailInfo.languageCode = 1041; // Japanese
|
||||
mailInfo.itemID = LWOOBJID_EMPTY;
|
||||
mailInfo.itemCount = 0;
|
||||
mailInfo.itemLOT = LOT_NULL;
|
||||
mailInfo.itemSubkey = LWOOBJID_EMPTY;
|
||||
|
||||
RakNet::BitStream outStream;
|
||||
mailInfo.Serialize(outStream);
|
||||
|
||||
ASSERT_GT(outStream.GetNumberOfBytesUsed(), 0);
|
||||
|
||||
// Verify the serialization handled Unicode content
|
||||
outStream.ResetReadPointer();
|
||||
uint64_t readId;
|
||||
outStream.Read(readId);
|
||||
ASSERT_EQ(readId, 12345);
|
||||
}
|
||||
|
||||
// Test MailInfo with alternating boolean and special constant values
|
||||
TEST_F(MailEnumTests, MailInfoSpecialConstants) {
|
||||
MailInfo mailInfo;
|
||||
|
||||
mailInfo.senderUsername = "ConstantTester";
|
||||
mailInfo.recipient = "ConstantRecipient";
|
||||
mailInfo.subject = "Testing Constants";
|
||||
mailInfo.body = "This tests special constant values";
|
||||
mailInfo.id = 1;
|
||||
mailInfo.senderId = 2;
|
||||
mailInfo.receiverId = 3;
|
||||
mailInfo.timeSent = 4;
|
||||
mailInfo.wasRead = true; // Test true value
|
||||
mailInfo.languageCode = 5;
|
||||
mailInfo.itemID = LWOOBJID_EMPTY; // Special empty constant
|
||||
mailInfo.itemCount = 0;
|
||||
mailInfo.itemLOT = LOT_NULL; // Special null constant
|
||||
mailInfo.itemSubkey = LWOOBJID_EMPTY;
|
||||
|
||||
RakNet::BitStream outStream;
|
||||
mailInfo.Serialize(outStream);
|
||||
|
||||
ASSERT_GT(outStream.GetNumberOfBytesUsed(), 0);
|
||||
|
||||
outStream.ResetReadPointer();
|
||||
uint64_t readId;
|
||||
outStream.Read(readId);
|
||||
ASSERT_EQ(readId, 1);
|
||||
}
|
||||
|
||||
// Test MailInfo serialization stability with repeated calls
|
||||
TEST_F(MailEnumTests, MailInfoSerializationStability) {
|
||||
MailInfo mailInfo;
|
||||
mailInfo.senderUsername = "StabilityTest";
|
||||
mailInfo.recipient = "StabilityRecipient";
|
||||
mailInfo.subject = "Stability Subject";
|
||||
mailInfo.body = "Testing serialization stability across multiple calls";
|
||||
mailInfo.id = 98765;
|
||||
mailInfo.senderId = 43210;
|
||||
mailInfo.receiverId = 56789;
|
||||
mailInfo.timeSent = 1609459200; // Known timestamp
|
||||
mailInfo.wasRead = false;
|
||||
mailInfo.languageCode = 1033;
|
||||
mailInfo.itemID = 111222333;
|
||||
mailInfo.itemCount = 25;
|
||||
mailInfo.itemLOT = 4567;
|
||||
mailInfo.itemSubkey = 444555666;
|
||||
|
||||
// Serialize multiple times and verify consistency
|
||||
std::vector<RakNet::BitStream> streams(5);
|
||||
|
||||
for (auto& stream : streams) {
|
||||
mailInfo.Serialize(stream);
|
||||
}
|
||||
|
||||
// All streams should have the same size
|
||||
size_t expectedSize = streams[0].GetNumberOfBytesUsed();
|
||||
for (size_t i = 1; i < streams.size(); ++i) {
|
||||
ASSERT_EQ(streams[i].GetNumberOfBytesUsed(), expectedSize);
|
||||
}
|
||||
|
||||
// All streams should have the same content
|
||||
std::vector<uint8_t> referenceData(expectedSize);
|
||||
memcpy(referenceData.data(), streams[0].GetData(), expectedSize);
|
||||
|
||||
for (size_t i = 1; i < streams.size(); ++i) {
|
||||
std::vector<uint8_t> currentData(expectedSize);
|
||||
memcpy(currentData.data(), streams[i].GetData(), expectedSize);
|
||||
ASSERT_EQ(currentData, referenceData);
|
||||
}
|
||||
}
|
||||
|
||||
// Test MailInfo with negative item count edge cases
|
||||
TEST_F(MailEnumTests, MailInfoNegativeItemCount) {
|
||||
MailInfo mailInfo;
|
||||
mailInfo.senderUsername = "NegativeTest";
|
||||
mailInfo.recipient = "NegativeRecipient";
|
||||
mailInfo.subject = "Negative Count Test";
|
||||
mailInfo.body = "Testing negative item counts";
|
||||
mailInfo.id = 11111;
|
||||
mailInfo.senderId = 22222;
|
||||
mailInfo.receiverId = 33333;
|
||||
mailInfo.timeSent = 44444;
|
||||
mailInfo.wasRead = false;
|
||||
mailInfo.languageCode = 55555;
|
||||
mailInfo.itemID = 666666;
|
||||
mailInfo.itemCount = -1; // Negative count
|
||||
mailInfo.itemLOT = 777777;
|
||||
mailInfo.itemSubkey = 888888;
|
||||
|
||||
RakNet::BitStream outStream;
|
||||
mailInfo.Serialize(outStream);
|
||||
|
||||
ASSERT_GT(outStream.GetNumberOfBytesUsed(), 0);
|
||||
|
||||
outStream.ResetReadPointer();
|
||||
uint64_t readId;
|
||||
outStream.Read(readId);
|
||||
ASSERT_EQ(readId, 11111);
|
||||
}
|
||||
|
||||
// Test data type integrity with specific bit patterns
|
||||
TEST_F(MailEnumTests, MailInfoDataTypeIntegrity) {
|
||||
MailInfo mailInfo;
|
||||
|
||||
// Use bit patterns that might reveal endianness or packing issues
|
||||
mailInfo.senderUsername = "BitPatternTest";
|
||||
mailInfo.recipient = "BitPatternRecipient";
|
||||
mailInfo.subject = "Testing Bit Patterns";
|
||||
mailInfo.body = "This tests specific bit patterns in data types";
|
||||
mailInfo.id = 0x0123456789ABCDEF; // Known bit pattern
|
||||
mailInfo.senderId = 0x12345678; // Known 32-bit pattern
|
||||
mailInfo.receiverId = 0x87654321; // Reverse pattern
|
||||
mailInfo.timeSent = 0xFEDCBA9876543210; // Another known pattern
|
||||
mailInfo.wasRead = true;
|
||||
mailInfo.languageCode = 0xABCD; // Known 16-bit pattern
|
||||
mailInfo.itemID = 0x1111222233334444; // Repeated pattern
|
||||
mailInfo.itemCount = 0x7FFF; // Maximum positive int16_t
|
||||
mailInfo.itemLOT = 0xFFFFFFFF; // Maximum uint32_t
|
||||
mailInfo.itemSubkey = 0x5555666677778888; // Another pattern
|
||||
|
||||
RakNet::BitStream outStream;
|
||||
mailInfo.Serialize(outStream);
|
||||
|
||||
ASSERT_GT(outStream.GetNumberOfBytesUsed(), 0);
|
||||
|
||||
// Verify the specific bit pattern for ID was preserved
|
||||
outStream.ResetReadPointer();
|
||||
uint64_t readId;
|
||||
outStream.Read(readId);
|
||||
ASSERT_EQ(readId, 0x0123456789ABCDEF);
|
||||
}
|
Reference in New Issue
Block a user