Adding additional tests to cover issue #79

This commit is contained in:
Shane Grant
2014-06-06 15:24:24 -07:00
parent f067ba6905
commit ea007dafd8

View File

@@ -169,6 +169,41 @@ void load_minimal( Archive const &, Issue79Struct & val, std::int32_t const & xx
val.x = xx;
}
struct Issue79StructInternal
{
Issue79StructInternal() = default;
Issue79StructInternal( std::int32_t xx ) : x(xx) {}
std::int32_t x;
template <class Archive, cereal::traits::DisableIf<std::is_same<Archive, cereal::BinaryOutputArchive>::value ||
std::is_same<Archive, cereal::PortableBinaryOutputArchive>::value> = cereal::traits::sfinae>
std::string save_minimal( Archive const & ) const
{
return std::to_string( x );
}
template <class Archive, cereal::traits::DisableIf<std::is_same<Archive, cereal::BinaryInputArchive>::value ||
std::is_same<Archive, cereal::PortableBinaryInputArchive>::value> = cereal::traits::sfinae>
void load_minimal( Archive const &, std::string const & str )
{
x = std::stoi( str );
}
template <class Archive, cereal::traits::EnableIf<std::is_same<Archive, cereal::BinaryOutputArchive>::value ||
std::is_same<Archive, cereal::PortableBinaryOutputArchive>::value> = cereal::traits::sfinae>
std::int32_t save_minimal( Archive const & ) const
{
return x;
}
template <class Archive, cereal::traits::EnableIf<std::is_same<Archive, cereal::BinaryInputArchive>::value ||
std::is_same<Archive, cereal::PortableBinaryInputArchive>::value> = cereal::traits::sfinae>
void load_minimal( Archive const &, std::int32_t const & xx )
{
x = xx;
}
};
template <class IArchive, class OArchive>
void test_structs_minimal()
{
@@ -181,22 +216,26 @@ void test_structs_minimal()
random_value<std::uint32_t>(gen), random_value<uint8_t>(gen) % 2 ? true : false };
Issue79Struct o_struct2 = { random_value<std::int32_t>(gen) };
Issue79StructInternal o_struct3 = { random_value<std::int32_t>(gen) };
std::ostringstream os;
{
OArchive oar(os);
oar( o_struct );
oar( o_struct2 );
oar( o_struct3 );
}
decltype(o_struct) i_struct;
decltype(o_struct2) i_struct2;
decltype(o_struct3) i_struct3;
std::istringstream is(os.str());
{
IArchive iar(is);
iar( i_struct );
iar( i_struct2 );
iar( i_struct3 );
}
BOOST_CHECK(o_struct.mm.x == i_struct.mm.x);
@@ -206,6 +245,8 @@ void test_structs_minimal()
BOOST_CHECK(o_struct.nmmv.x == i_struct.nmmv.x);
BOOST_CHECK(o_struct2.x == i_struct2.x);
BOOST_CHECK(o_struct3.x == i_struct3.x);
}
}