srdusr
aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_byteio.cpp
blob: 3b317520d0b3ad838391653c8253946889107166 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <doctest/doctest.h>

#include <vector>

#include "packeteer/byteio.hpp"

using namespace packeteer;

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