#define BOOST_TEST_MODULE BitSet #include #include #include #include #include #include #include #include #include #include namespace MyGrate { class BitSet; } namespace boost::numeric { class bad_numeric_cast; } struct timespec; BOOST_AUTO_TEST_CASE(verify) { BOOST_CHECK_NO_THROW(MyGrate::verify(true, "no throw")); BOOST_CHECK_THROW(MyGrate::verify(false, "throw re"), std::runtime_error); BOOST_CHECK_THROW(MyGrate::verify(false, "throw le"), std::logic_error); } using Ints = std::tuple; using Floats = std::tuple; using Times = std::tuple; using Str = std::tuple; using Others = std::tuple; using TinyInts = std::tuple; using SmallInts = std::tuple; BOOST_AUTO_TEST_CASE_TEMPLATE(DbValueConvIntToInts, I, Ints) { MyGrate::DbValue v {123}; I out {v}; BOOST_CHECK_EQUAL(123, out); } BOOST_AUTO_TEST_CASE_TEMPLATE(DbValueConvIntToTinyInts, I, TinyInts) { MyGrate::DbValue v {1234}; BOOST_CHECK_THROW([[maybe_unused]] I out {v}, boost::bad_numeric_cast); } BOOST_AUTO_TEST_CASE_TEMPLATE(DbValueConvIntToSmallInts, I, SmallInts) { MyGrate::DbValue v {123400}; BOOST_CHECK_THROW([[maybe_unused]] I out {v}, boost::bad_numeric_cast); } BOOST_AUTO_TEST_CASE_TEMPLATE(DbValueConvIntToFloats, F, Floats) { MyGrate::DbValue v {123400}; BOOST_CHECK_THROW([[maybe_unused]] F out {v}, std::logic_error); } BOOST_AUTO_TEST_CASE(DbValueConvIntToStringView) { MyGrate::DbValue v {123}; BOOST_CHECK_THROW([[maybe_unused]] std::string_view out {v}, std::bad_variant_access); } BOOST_AUTO_TEST_CASE(DbValueConvStrViewToStringView) { using namespace std::literals; MyGrate::DbValue v {"str"}; BOOST_CHECK_EQUAL((std::string_view)v, "str"sv); BOOST_CHECK_EQUAL((std::string)v, "str"s); } static_assert(MyGrate::detail::HasToString); static_assert(!MyGrate::detail::HasToString); BOOST_AUTO_TEST_CASE_TEMPLATE(DbValueConvIntToString, I, Ints) { using namespace std::literals; MyGrate::DbValue v {I {123}}; BOOST_CHECK_EQUAL((std::string)v, "123"s); } BOOST_AUTO_TEST_CASE_TEMPLATE(DbValueConvFloatToString, F, Floats) { using namespace std::literals; MyGrate::DbValue v {F {123}}; BOOST_CHECK_EQUAL((std::string)v, "123.000000"s); }