Skip to content

Commit 6225cb2

Browse files
committed
Add BufferReader tests
1 parent fa74d12 commit 6225cb2

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

native/V2StyxLib/modules/l5/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ if(BUILD_MODULE_L5)
1313

1414
add_executable(module_l5_tests
1515
test/test_BufferWriterImpl.cpp
16+
test/test_BufferReaderImpl.cpp
1617
)
1718
target_include_directories(module_l5_tests PRIVATE ./include/)
1819
target_link_libraries(module_l5_tests PRIVATE Catch2::Catch2WithMain module_l5)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <catch2/catch_test_macros.hpp>
2+
#include "serialization/BufferReaderImpl.h"
3+
4+
TEST_CASE("readUTFString", "[BufferReaderImpl]") {
5+
uint8_t testData[] = {0x05, 0x00, 'A', 'B', 'C', 'D', 'E', 'F', 'G'};
6+
BufferReaderImpl impl(testData, sizeof(testData));
7+
REQUIRE("ABCDE" == impl.readUTFString());
8+
}
9+
10+
TEST_CASE("readUInt8", "[BufferReaderImpl]") {
11+
uint8_t testData[] = {0x05, 0x06};
12+
BufferReaderImpl impl(testData, sizeof(testData));
13+
REQUIRE(0x05 == impl.readUInt8());
14+
REQUIRE(0x06 == impl.readUInt8());
15+
}
16+
17+
TEST_CASE("readUInt16", "[BufferReaderImpl]") {
18+
uint8_t testData[] = {0x05, 0x06, 0x07, 0x08};
19+
BufferReaderImpl impl(testData, sizeof(testData));
20+
REQUIRE(0x0605 == impl.readUInt16());
21+
REQUIRE(0x0807 == impl.readUInt16());
22+
}
23+
24+
TEST_CASE("readUInt32", "[BufferReaderImpl]") {
25+
uint8_t testData[] = {0x05, 0x06, 0x07, 0x08, 0x10, 0x11, 0x12, 0x13};
26+
BufferReaderImpl impl(testData, sizeof(testData));
27+
REQUIRE(0x08070605 == impl.readUInt32());
28+
REQUIRE(0x13121110 == impl.readUInt32());
29+
}
30+
31+
TEST_CASE("readUInt64", "[BufferReaderImpl]") {
32+
uint8_t testData[] = {0x05, 0x06, 0x07, 0x08, 0x10, 0x11, 0x12, 0x13,
33+
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27};
34+
BufferReaderImpl impl(testData, sizeof(testData));
35+
REQUIRE(0x1312111008070605L == impl.readUInt64());
36+
REQUIRE(0x2726252423222120L == impl.readUInt64());
37+
}

0 commit comments

Comments
 (0)