DarkflameServer/tests/dCommonTests/HeaderSkipTest.cpp
David Markowitz 7aad6e4bc2
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
2023-05-08 06:31:10 -05:00

38 lines
1.3 KiB
C++

#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);
}