64 lines
1.9 KiB
C++
64 lines
1.9 KiB
C++
//-----------------------------------------------------------------------------
|
|
// ___ __ _ _
|
|
// / _ \__ _ _ __ ___ ___ / /(_)_ __ | | __
|
|
// / /_)/ _` | '__/ __|/ _ \/ / | | '_ \| |/ /
|
|
// / ___/ (_| | | \__ \ __/ /__| | | | | <
|
|
// \/ \__,_|_| |___/\___\____/_|_| |_|_|\_\ .
|
|
//
|
|
//-----------------------------------------------------------------------------
|
|
// Author: Kurt Sassenrath
|
|
// Module: msgpack
|
|
//
|
|
// Packer tests, ranges (for types that serialize to array / map formats)
|
|
//
|
|
// Copyright (c) 2023 Kurt Sassenrath.
|
|
//
|
|
// License TBD.
|
|
//-----------------------------------------------------------------------------
|
|
|
|
#include "test_packer.h"
|
|
|
|
#include <fmt/ranges.h>
|
|
|
|
using namespace boost::ut;
|
|
|
|
namespace {
|
|
constexpr bool expect_equal(auto const& expected, auto const& actual) {
|
|
if (!std::ranges::equal(expected, actual)) {
|
|
fmt::print("\n\tExpected: ");
|
|
for (auto x : expected) {
|
|
fmt::print("{:02x} ", x);
|
|
}
|
|
fmt::print("\n\t Actual: ");
|
|
for (auto x : actual) {
|
|
fmt::print("{:02x} ", x);
|
|
}
|
|
fmt::print("\n");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
} // namespace
|
|
|
|
suite pack_ranges = [] {
|
|
"packer::pack<std::array/std::span<int>>"_test = [] {
|
|
constexpr auto data_array = std::to_array<int>({5, 10, 15, 20});
|
|
constexpr auto expected = test::make_bytes(0x94, 0x05, 0xa, 0xf, 0x14);
|
|
|
|
{
|
|
std::array<std::byte, std::size(expected)> payload;
|
|
msgpack::packer packer(payload);
|
|
expect(!!packer.pack(data_array));
|
|
expect(expect_equal(std::span(expected), payload));
|
|
}
|
|
|
|
{
|
|
std::span data_span{data_array};
|
|
std::array<std::byte, std::size(expected)> payload;
|
|
msgpack::packer packer(payload);
|
|
expect(!!packer.pack(data_span));
|
|
expect(expect_equal(expected, payload));
|
|
}
|
|
};
|
|
};
|