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:
David Markowitz
2023-05-08 04:31:10 -07:00
committed by GitHub
parent 64a947e338
commit 7aad6e4bc2
7 changed files with 63 additions and 51 deletions

View File

@@ -1,5 +1,6 @@
set(DCOMMONTEST_SOURCES
"AMFDeserializeTests.cpp"
"HeaderSkipTest.cpp"
"TestLDFFormat.cpp"
"TestNiPoint3.cpp"
"TestEncoding.cpp"

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