//----------------------------------------------------------------------------- // ___ __ _ _ // / _ \__ _ _ __ ___ ___ / /(_)_ __ | | __ // / /_)/ _` | '__/ __|/ _ \/ / | | '_ \| |/ / // / ___/ (_| | | \__ \ __/ /__| | | | | < // \/ \__,_|_| |___/\___\____/_|_| |_|_|\_\ . // //----------------------------------------------------------------------------- // Author: Kurt Sassenrath // Module: msgpack // // Packer tests, unsigned ints. // // Copyright (c) 2023 Kurt Sassenrath. // // License TBD. //----------------------------------------------------------------------------- #include "test_packer.h" #include using namespace boost::ut; namespace { template auto check_unsigned() { return rc::check([](T value) { std::array payload; msgpack::packer packer(payload); if (!packer.pack(value)) return false; if (value < 128) { // positive_fixint return packer.tell() == 1 && payload[0] == static_cast(value); } else if (within(value)) { return payload[0] == msgpack::format::uint8::marker && verify_packed(packer, value); } else if (within(value)) { return payload[0] == msgpack::format::uint16::marker && verify_packed(packer, value); } else if (within(value)) { return payload[0] == msgpack::format::uint32::marker && verify_packed(packer, value); } else { return payload[0] == msgpack::format::uint64::marker && verify_packed(packer, value); } }); } } // anonymous namespace suite packer_unsigned_ints = [] { "packer::pack"_test = [] { expect(check_unsigned()); }; "packer::pack"_test = [] { expect(check_unsigned()); }; "packer::pack"_test = [] { expect(check_unsigned()); }; "packer::pack"_test = [] { expect(check_unsigned()); }; };