//----------------------------------------------------------------------------- // ___ __ _ _ // / _ \__ _ _ __ ___ ___ / /(_)_ __ | | __ // / /_)/ _` | '__/ __|/ _ \/ / | | '_ \| |/ / // / ___/ (_| | | \__ \ __/ /__| | | | | < // \/ \__,_|_| |___/\___\____/_|_| |_|_|\_\ . // //----------------------------------------------------------------------------- // Author: Kurt Sassenrath // Module: msgpack // // Unpacker tests, common code. // // Copyright (c) 2023 Kurt Sassenrath. // // License TBD. //----------------------------------------------------------------------------- #ifndef tests_msgpack_unpacker_25b118dd14e2b1b4 #define tests_msgpack_unpacker_25b118dd14e2b1b4 #include "parselink/msgpack/core/unpacker.h" #include "test_utils.h" // Helper template to check that a type is either equal to itself, or verify // that it won't unpack correctly. template constexpr bool unpack_type_check(msgpack::unpacker unpacker) noexcept { auto wrong_type = tl::make_unexpected(msgpack::error::wrong_type); auto compatible_type = std::same_as || (std::is_unsigned_v && std::is_unsigned_v) || (std::is_signed_v && std::is_signed_v); auto result = compatible_type || unpacker.unpack() == wrong_type; if (!result) { fmt::print("Unpack_type_check failed: {}\n", std::source_location::current().function_name()); } return result; } // Validate the wrong types do not unpack correctly, or fail. template constexpr bool try_unpacking_types(msgpack::unpacker unpacker) noexcept { return ((unpack_type_check(unpacker)) && ...); } #define SUPPORTED_TYPES \ msgpack::nil, msgpack::invalid, bool, std::uint8_t, std::uint16_t, \ std::uint32_t, std::uint64_t, std::int8_t, std::int16_t, \ std::int32_t, std::int64_t, std::string_view template constexpr bool type_check_unpacker(msgpack::unpacker unpacker) noexcept { return try_unpacking_types(unpacker); } #endif // tests_msgpack_unpacker_25b118dd14e2b1b4