Skip to content

Commit ea007da

Browse files
committed
Adding additional tests to cover issue #79
1 parent f067ba6 commit ea007da

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

unittests/structs_minimal.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,41 @@ void load_minimal( Archive const &, Issue79Struct & val, std::int32_t const & xx
169169
val.x = xx;
170170
}
171171

172+
struct Issue79StructInternal
173+
{
174+
Issue79StructInternal() = default;
175+
Issue79StructInternal( std::int32_t xx ) : x(xx) {}
176+
std::int32_t x;
177+
178+
template <class Archive, cereal::traits::DisableIf<std::is_same<Archive, cereal::BinaryOutputArchive>::value ||
179+
std::is_same<Archive, cereal::PortableBinaryOutputArchive>::value> = cereal::traits::sfinae>
180+
std::string save_minimal( Archive const & ) const
181+
{
182+
return std::to_string( x );
183+
}
184+
185+
template <class Archive, cereal::traits::DisableIf<std::is_same<Archive, cereal::BinaryInputArchive>::value ||
186+
std::is_same<Archive, cereal::PortableBinaryInputArchive>::value> = cereal::traits::sfinae>
187+
void load_minimal( Archive const &, std::string const & str )
188+
{
189+
x = std::stoi( str );
190+
}
191+
192+
template <class Archive, cereal::traits::EnableIf<std::is_same<Archive, cereal::BinaryOutputArchive>::value ||
193+
std::is_same<Archive, cereal::PortableBinaryOutputArchive>::value> = cereal::traits::sfinae>
194+
std::int32_t save_minimal( Archive const & ) const
195+
{
196+
return x;
197+
}
198+
199+
template <class Archive, cereal::traits::EnableIf<std::is_same<Archive, cereal::BinaryInputArchive>::value ||
200+
std::is_same<Archive, cereal::PortableBinaryInputArchive>::value> = cereal::traits::sfinae>
201+
void load_minimal( Archive const &, std::int32_t const & xx )
202+
{
203+
x = xx;
204+
}
205+
};
206+
172207
template <class IArchive, class OArchive>
173208
void test_structs_minimal()
174209
{
@@ -181,22 +216,26 @@ void test_structs_minimal()
181216
random_value<std::uint32_t>(gen), random_value<uint8_t>(gen) % 2 ? true : false };
182217

183218
Issue79Struct o_struct2 = { random_value<std::int32_t>(gen) };
219+
Issue79StructInternal o_struct3 = { random_value<std::int32_t>(gen) };
184220

185221
std::ostringstream os;
186222
{
187223
OArchive oar(os);
188224
oar( o_struct );
189225
oar( o_struct2 );
226+
oar( o_struct3 );
190227
}
191228

192229
decltype(o_struct) i_struct;
193230
decltype(o_struct2) i_struct2;
231+
decltype(o_struct3) i_struct3;
194232

195233
std::istringstream is(os.str());
196234
{
197235
IArchive iar(is);
198236
iar( i_struct );
199237
iar( i_struct2 );
238+
iar( i_struct3 );
200239
}
201240

202241
BOOST_CHECK(o_struct.mm.x == i_struct.mm.x);
@@ -206,6 +245,8 @@ void test_structs_minimal()
206245
BOOST_CHECK(o_struct.nmmv.x == i_struct.nmmv.x);
207246

208247
BOOST_CHECK(o_struct2.x == i_struct2.x);
248+
249+
BOOST_CHECK(o_struct3.x == i_struct3.x);
209250
}
210251
}
211252

0 commit comments

Comments
 (0)