mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-04 09:44:10 +00:00
Make header skips more obvious (#1074)
* Make header skips more obvious seeing inStream.Read(LWOOBJID) is much less clear than a macro which very clearly skips the header. * Formatting pass
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
set(DCOMMONTEST_SOURCES
|
||||
"AMFDeserializeTests.cpp"
|
||||
"HeaderSkipTest.cpp"
|
||||
"TestLDFFormat.cpp"
|
||||
"TestNiPoint3.cpp"
|
||||
"TestEncoding.cpp"
|
||||
|
37
tests/dCommonTests/HeaderSkipTest.cpp
Normal file
37
tests/dCommonTests/HeaderSkipTest.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "dCommonDependencies.h"
|
||||
#include "dCommonVars.h"
|
||||
#include "BitStream.h"
|
||||
|
||||
#define PacketUniquePtr std::unique_ptr<Packet>
|
||||
|
||||
TEST(dCommonTests, HeaderSkipExcessTest) {
|
||||
PacketUniquePtr packet = std::make_unique<Packet>();
|
||||
unsigned char headerAndData[] = { 0x53, 0x02, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00 }; // positive
|
||||
packet->data = headerAndData;
|
||||
packet->length = sizeof(headerAndData);
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
ASSERT_EQ(inStream.GetNumberOfUnreadBits(), 64);
|
||||
ASSERT_EQ(inStream.GetNumberOfBitsAllocated(), 128);
|
||||
}
|
||||
|
||||
TEST(dCommonTests, HeaderSkipExactDataTest) {
|
||||
PacketUniquePtr packet = std::make_unique<Packet>();
|
||||
unsigned char header[] = { 0x53, 0x02, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00 }; // positive
|
||||
packet->data = header;
|
||||
packet->length = sizeof(header);
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
ASSERT_EQ(inStream.GetNumberOfUnreadBits(), 0);
|
||||
ASSERT_EQ(inStream.GetNumberOfBitsAllocated(), 64);
|
||||
}
|
||||
|
||||
TEST(dCommonTests, HeaderSkipNotEnoughDataTest) {
|
||||
PacketUniquePtr packet = std::make_unique<Packet>();
|
||||
unsigned char notEnoughData[] = { 0x53, 0x02, 0x00, 0x07, 0x00, 0x00 }; // negative
|
||||
packet->data = notEnoughData;
|
||||
packet->length = sizeof(notEnoughData);
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
ASSERT_EQ(inStream.GetNumberOfUnreadBits(), 0);
|
||||
ASSERT_EQ(inStream.GetNumberOfBitsAllocated(), 48);
|
||||
}
|
Reference in New Issue
Block a user