69 lines
2.6 KiB
C++
69 lines
2.6 KiB
C++
//-----------------------------------------------------------------------------
|
|
// ___ __ _ _
|
|
// / _ \__ _ _ __ ___ ___ / /(_)_ __ | | __
|
|
// / /_)/ _` | '__/ __|/ _ \/ / | | '_ \| |/ /
|
|
// / ___/ (_| | | \__ \ __/ /__| | | | | <
|
|
// \/ \__,_|_| |___/\___\____/_|_| |_|_|\_\ .
|
|
//
|
|
//-----------------------------------------------------------------------------
|
|
// Author: Kurt Sassenrath
|
|
// Module: msgpack
|
|
//
|
|
// Unpacker tests for bytes.
|
|
//
|
|
// Copyright (c) 2023 Kurt Sassenrath.
|
|
//
|
|
// License TBD.
|
|
//-----------------------------------------------------------------------------
|
|
#include "test_unpacker.h"
|
|
|
|
using namespace boost::ut;
|
|
|
|
suite unpack_byte_types = [] {
|
|
// TODO: Make non-const version?
|
|
"unpacker::unpack<std::span<std::byte const>>"_test = [] {
|
|
constexpr auto payload =
|
|
test::make_bytes(0xc4, 0x05, 0x01, 0x02, 0x03, 0x04, 0x05);
|
|
constexpr auto expected =
|
|
test::make_bytes(0x01, 0x02, 0x03, 0x04, 0x05);
|
|
{
|
|
msgpack::unpacker unpacker(payload);
|
|
auto actual = unpacker.unpack<std::span<std::byte const>>();
|
|
expect(std::ranges::equal(*actual, expected));
|
|
}
|
|
{
|
|
// Test extent
|
|
msgpack::unpacker unpacker(payload);
|
|
auto actual = unpacker.unpack<std::span<std::byte const, 5>>();
|
|
expect(std::ranges::equal(*actual, expected));
|
|
}
|
|
{
|
|
msgpack::unpacker unpacker(payload);
|
|
auto actual = unpacker.unpack<std::span<std::byte const, 4>>();
|
|
expect(actual == tl::make_unexpected(msgpack::error::wrong_length));
|
|
auto actual2 = unpacker.unpack<std::span<std::byte const>>();
|
|
expect(std::ranges::equal(*actual2, expected));
|
|
}
|
|
};
|
|
|
|
// TODO: Make non-const version?
|
|
"unpacker::unpack<std::array<std::byte, N>>"_test = [] {
|
|
constexpr auto payload =
|
|
test::make_bytes(0xc4, 0x05, 0x01, 0x02, 0x03, 0x04, 0x06);
|
|
constexpr auto expected =
|
|
test::make_bytes(0x01, 0x02, 0x03, 0x04, 0x06);
|
|
{
|
|
msgpack::unpacker unpacker(payload);
|
|
auto actual = unpacker.unpack<std::array<std::byte, 5>>();
|
|
expect(std::ranges::equal(*actual, expected));
|
|
}
|
|
{
|
|
msgpack::unpacker unpacker(payload);
|
|
auto actual = unpacker.unpack<std::array<std::byte, 4>>();
|
|
expect(actual == tl::make_unexpected(msgpack::error::wrong_length));
|
|
auto actual2 = unpacker.unpack<std::span<std::byte const, 5>>();
|
|
expect(std::ranges::equal(*actual2, expected));
|
|
}
|
|
};
|
|
};
|