64 lines
2.2 KiB
C++
64 lines
2.2 KiB
C++
//-----------------------------------------------------------------------------
|
|
// ___ __ _ _
|
|
// / _ \__ _ _ __ ___ ___ / /(_)_ __ | | __
|
|
// / /_)/ _` | '__/ __|/ _ \/ / | | '_ \| |/ /
|
|
// / ___/ (_| | | \__ \ __/ /__| | | | | <
|
|
// \/ \__,_|_| |___/\___\____/_|_| |_|_|\_\ .
|
|
//
|
|
//-----------------------------------------------------------------------------
|
|
// Author: Kurt Sassenrath
|
|
// Module: msgpack
|
|
//
|
|
// Packer tests, byte types
|
|
//
|
|
// Copyright (c) 2023 Kurt Sassenrath.
|
|
//
|
|
// License TBD.
|
|
//-----------------------------------------------------------------------------
|
|
|
|
#include "test_packer.h"
|
|
|
|
using namespace boost::ut;
|
|
|
|
suite pack_bytes = [] {
|
|
#if 0
|
|
// Byte ranges -> Binary
|
|
"packer::pack<std::span<std::byte>>"_test = [] {
|
|
expect(test_deduced<std::span<std::byte const>>());
|
|
};
|
|
#endif
|
|
"packer::pack<std::array<std::byte, N>>"_test = [] {
|
|
{
|
|
constexpr auto data = test::make_bytes(0x01, 0x02, 0x03, 0x04);
|
|
constexpr auto expected =
|
|
test::make_bytes(0xc4, 0x04, 0x01, 0x02, 0x03, 0x04);
|
|
std::array<std::byte, std::size(expected)> payload;
|
|
|
|
msgpack::packer packer(payload);
|
|
expect(!!packer.pack(data));
|
|
expect(std::ranges::equal(payload, expected));
|
|
}
|
|
{
|
|
constexpr std::array<std::byte, 256> data{};
|
|
constexpr std::array<std::byte, 259> expected{
|
|
std::byte(0xc5), std::byte(0x01), std::byte(0x00)};
|
|
std::array<std::byte, std::size(expected)> payload;
|
|
|
|
msgpack::packer packer(payload);
|
|
expect(!!packer.pack(data));
|
|
expect(std::ranges::equal(payload, expected));
|
|
}
|
|
{
|
|
constexpr std::array<std::byte, 65536> data{};
|
|
constexpr std::array<std::byte, std::size(data) + 5> expected{
|
|
std::byte(0xc6), std::byte(0x00), std::byte(0x01),
|
|
std::byte(0x00), std::byte(0x00)};
|
|
std::array<std::byte, std::size(expected)> payload;
|
|
|
|
msgpack::packer packer(payload);
|
|
expect(!!packer.pack(data));
|
|
expect(std::ranges::equal(payload, expected));
|
|
}
|
|
};
|
|
};
|