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