diff options
Diffstat (limited to 'tests/test_byteio.cpp')
| -rw-r--r-- | tests/test_byteio.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/test_byteio.cpp b/tests/test_byteio.cpp new file mode 100644 index 0000000..81fa741 --- /dev/null +++ b/tests/test_byteio.cpp @@ -0,0 +1,23 @@ +#include <doctest/doctest.h> + +#include <vector> + +#include "wireframe/byteio.hpp" + +using namespace wireframe; + +TEST_CASE("read_be16 reads a big-endian 16-bit value") { + std::vector<unsigned char> bytes = {0x12, 0x34}; + CHECK(read_be16(bytes, 0) == 0x1234); +} + +TEST_CASE("read_be32 reads a big-endian 32-bit value") { + std::vector<unsigned char> bytes = {0xDE, 0xAD, 0xBE, 0xEF}; + CHECK(read_be32(bytes, 0) == 0xDEADBEEFu); +} + +TEST_CASE("read_be16/read_be32 read from a nonzero offset") { + std::vector<unsigned char> bytes = {0x00, 0x00, 0x12, 0x34, 0x56, 0x78}; + CHECK(read_be16(bytes, 2) == 0x1234); + CHECK(read_be32(bytes, 2) == 0x12345678u); +} |