mirror of
https://github.com/USCiLab/cereal.git
synced 2025-10-18 01:45:52 +02:00
modified unit tests to not use floats for map keys, complex now uses boost_check_close for double types
This commit is contained in:
@@ -337,11 +337,10 @@ namespace cereal
|
|||||||
size = (itsValueStack.rbegin() + 1)->value().Size();
|
size = (itsValueStack.rbegin() + 1)->value().Size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char const * itsNextName;
|
char const * itsNextName;
|
||||||
ReadStream itsReadStream; //!< Rapidjson write stream
|
ReadStream itsReadStream; //!< Rapidjson write stream
|
||||||
std::vector<Iterator> itsValueStack; //!< Stack of values
|
std::vector<Iterator> itsValueStack; //!< Stack of values
|
||||||
rapidjson::Document itsDocument; //!< Rapidjson document
|
rapidjson::Document itsDocument; //!< Rapidjson document
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -379,11 +378,13 @@ namespace cereal
|
|||||||
/*! SizeTags are strictly ignored for JSON */
|
/*! SizeTags are strictly ignored for JSON */
|
||||||
template <class T>
|
template <class T>
|
||||||
void prologue( JSONOutputArchive & ar, SizeTag<T> const & )
|
void prologue( JSONOutputArchive & ar, SizeTag<T> const & )
|
||||||
{ ar.makeArray(); }
|
{
|
||||||
|
ar.makeArray();
|
||||||
|
}
|
||||||
|
|
||||||
//! Prologue for SizeTags for JSON archives
|
//! Prologue for SizeTags for JSON archives
|
||||||
template <class T>
|
template <class T>
|
||||||
void prologue( JSONInputArchive & ar, SizeTag<T> const & )
|
void prologue( JSONInputArchive &, SizeTag<T> const & )
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
// ######################################################################
|
// ######################################################################
|
||||||
@@ -404,7 +405,7 @@ namespace cereal
|
|||||||
that may be given data by the type about to be archived */
|
that may be given data by the type about to be archived */
|
||||||
template <class T>
|
template <class T>
|
||||||
typename std::enable_if<!std::is_arithmetic<T>::value, void>::type
|
typename std::enable_if<!std::is_arithmetic<T>::value, void>::type
|
||||||
prologue( JSONOutputArchive & ar, T const & data )
|
prologue( JSONOutputArchive & ar, T const & )
|
||||||
{
|
{
|
||||||
ar.startNode();
|
ar.startNode();
|
||||||
}
|
}
|
||||||
@@ -412,7 +413,7 @@ namespace cereal
|
|||||||
//! Prologue for all other types for JSON archives
|
//! Prologue for all other types for JSON archives
|
||||||
template <class T>
|
template <class T>
|
||||||
typename std::enable_if<!std::is_arithmetic<T>::value, void>::type
|
typename std::enable_if<!std::is_arithmetic<T>::value, void>::type
|
||||||
prologue( JSONInputArchive & ar, T const & data )
|
prologue( JSONInputArchive & ar, T const & )
|
||||||
{
|
{
|
||||||
ar.startNode();
|
ar.startNode();
|
||||||
}
|
}
|
||||||
@@ -422,7 +423,7 @@ namespace cereal
|
|||||||
/*! Finishes the node created in the prologue */
|
/*! Finishes the node created in the prologue */
|
||||||
template <class T>
|
template <class T>
|
||||||
typename std::enable_if<!std::is_arithmetic<T>::value, void>::type
|
typename std::enable_if<!std::is_arithmetic<T>::value, void>::type
|
||||||
epilogue( JSONOutputArchive & ar, T const & data )
|
epilogue( JSONOutputArchive & ar, T const & )
|
||||||
{
|
{
|
||||||
ar.finishNode();
|
ar.finishNode();
|
||||||
}
|
}
|
||||||
@@ -430,7 +431,7 @@ namespace cereal
|
|||||||
//! Epilogue for all other types other for JSON archives
|
//! Epilogue for all other types other for JSON archives
|
||||||
template <class T>
|
template <class T>
|
||||||
typename std::enable_if<!std::is_arithmetic<T>::value, void>::type
|
typename std::enable_if<!std::is_arithmetic<T>::value, void>::type
|
||||||
epilogue( JSONInputArchive & ar, T const & data )
|
epilogue( JSONInputArchive & ar, T const & )
|
||||||
{
|
{
|
||||||
ar.finishNode();
|
ar.finishNode();
|
||||||
}
|
}
|
||||||
@@ -439,7 +440,7 @@ namespace cereal
|
|||||||
//! Prologue for arithmetic types for JSON archives
|
//! Prologue for arithmetic types for JSON archives
|
||||||
template <class T>
|
template <class T>
|
||||||
typename std::enable_if<std::is_arithmetic<T>::value, void>::type
|
typename std::enable_if<std::is_arithmetic<T>::value, void>::type
|
||||||
prologue( JSONOutputArchive & ar, T const & data )
|
prologue( JSONOutputArchive & ar, T const & )
|
||||||
{
|
{
|
||||||
ar.writeName();
|
ar.writeName();
|
||||||
}
|
}
|
||||||
@@ -447,47 +448,44 @@ namespace cereal
|
|||||||
//! Prologue for arithmetic types for JSON archives
|
//! Prologue for arithmetic types for JSON archives
|
||||||
template <class T>
|
template <class T>
|
||||||
typename std::enable_if<std::is_arithmetic<T>::value, void>::type
|
typename std::enable_if<std::is_arithmetic<T>::value, void>::type
|
||||||
prologue( JSONInputArchive & ar, T const & data )
|
prologue( JSONInputArchive &, T const & )
|
||||||
{
|
{ }
|
||||||
}
|
|
||||||
|
|
||||||
// ######################################################################
|
// ######################################################################
|
||||||
//! Epilogue for arithmetic types for JSON archives
|
//! Epilogue for arithmetic types for JSON archives
|
||||||
template <class T>
|
template <class T>
|
||||||
typename std::enable_if<std::is_arithmetic<T>::value, void>::type
|
typename std::enable_if<std::is_arithmetic<T>::value, void>::type
|
||||||
epilogue( JSONOutputArchive & ar, T const & data )
|
epilogue( JSONOutputArchive &, T const & )
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
//! Epilogue for arithmetic types for JSON archives
|
//! Epilogue for arithmetic types for JSON archives
|
||||||
template <class T>
|
template <class T>
|
||||||
typename std::enable_if<std::is_arithmetic<T>::value, void>::type
|
typename std::enable_if<std::is_arithmetic<T>::value, void>::type
|
||||||
epilogue( JSONInputArchive & ar, T const & data )
|
epilogue( JSONInputArchive &, T const & )
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
// ######################################################################
|
// ######################################################################
|
||||||
//! Prologue for strings for JSON archives
|
//! Prologue for strings for JSON archives
|
||||||
template<class CharT, class Traits, class Alloc> inline
|
template<class CharT, class Traits, class Alloc> inline
|
||||||
void prologue(JSONOutputArchive & ar, std::basic_string<CharT, Traits, Alloc> const & str)
|
void prologue(JSONOutputArchive & ar, std::basic_string<CharT, Traits, Alloc> const &)
|
||||||
{
|
{
|
||||||
ar.writeName();
|
ar.writeName();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Prologue for strings for JSON archives
|
//! Prologue for strings for JSON archives
|
||||||
template<class CharT, class Traits, class Alloc> inline
|
template<class CharT, class Traits, class Alloc> inline
|
||||||
void prologue(JSONInputArchive & ar, std::basic_string<CharT, Traits, Alloc> const & str)
|
void prologue(JSONInputArchive &, std::basic_string<CharT, Traits, Alloc> const &)
|
||||||
{
|
{ }
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ######################################################################
|
// ######################################################################
|
||||||
//! Epilogue for strings for JSON archives
|
//! Epilogue for strings for JSON archives
|
||||||
template<class CharT, class Traits, class Alloc> inline
|
template<class CharT, class Traits, class Alloc> inline
|
||||||
void epilogue(JSONOutputArchive & ar, std::basic_string<CharT, Traits, Alloc> const & str)
|
void epilogue(JSONOutputArchive &, std::basic_string<CharT, Traits, Alloc> const &)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
//! Epilogue for strings for JSON archives
|
//! Epilogue for strings for JSON archives
|
||||||
template<class CharT, class Traits, class Alloc> inline
|
template<class CharT, class Traits, class Alloc> inline
|
||||||
void epilogue(JSONInputArchive & ar, std::basic_string<CharT, Traits, Alloc> const & str)
|
void epilogue(JSONInputArchive &, std::basic_string<CharT, Traits, Alloc> const &)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
// ######################################################################
|
// ######################################################################
|
||||||
@@ -545,7 +543,6 @@ namespace cereal
|
|||||||
{
|
{
|
||||||
ar.loadSize( st.size );
|
ar.loadSize( st.size );
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace cereal
|
} // namespace cereal
|
||||||
|
|
||||||
// register archives for polymorphic support
|
// register archives for polymorphic support
|
||||||
|
|||||||
@@ -314,11 +314,13 @@ int main()
|
|||||||
int xxx[] = {-1, 95, 3};
|
int xxx[] = {-1, 95, 3};
|
||||||
archive( xxx );
|
archive( xxx );
|
||||||
|
|
||||||
cereal::XMLOutputArchive archive2(std::cout, 10, true);
|
cereal::XMLOutputArchive archive2(std::cout, 10);
|
||||||
archive2( xxx );
|
archive2( xxx );
|
||||||
|
|
||||||
std::vector<int> yyy = {1, 2, 3};
|
std::vector<int> yyy = {1, 2, 3};
|
||||||
archive2( yyy );
|
archive2( yyy );
|
||||||
|
|
||||||
|
archive2.saveBinaryValue( xxx, sizeof(int)*3 );
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1434,7 +1434,36 @@ BOOST_AUTO_TEST_CASE( json_stack )
|
|||||||
|
|
||||||
// ######################################################################
|
// ######################################################################
|
||||||
template <class IArchive, class OArchive>
|
template <class IArchive, class OArchive>
|
||||||
void test_string()
|
void test_string_basic()
|
||||||
|
{
|
||||||
|
std::random_device rd;
|
||||||
|
std::mt19937 gen(rd());
|
||||||
|
|
||||||
|
for(size_t i=0; i<100; ++i)
|
||||||
|
{
|
||||||
|
std::basic_string<char> o_string = random_basic_string<char>(gen);
|
||||||
|
|
||||||
|
std::ostringstream os;
|
||||||
|
{
|
||||||
|
OArchive oar(os);
|
||||||
|
oar(o_string);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::basic_string<char> i_string;
|
||||||
|
|
||||||
|
std::istringstream is(os.str());
|
||||||
|
{
|
||||||
|
IArchive iar(is);
|
||||||
|
|
||||||
|
iar(i_string);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL(i_string, o_string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class IArchive, class OArchive>
|
||||||
|
void test_string_all()
|
||||||
{
|
{
|
||||||
std::random_device rd;
|
std::random_device rd;
|
||||||
std::mt19937 gen(rd());
|
std::mt19937 gen(rd());
|
||||||
@@ -1479,14 +1508,18 @@ void test_string()
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( binary_string )
|
BOOST_AUTO_TEST_CASE( binary_string )
|
||||||
{
|
{
|
||||||
test_string<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
|
test_string_all<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: xml needs support for non standard strings
|
BOOST_AUTO_TEST_CASE( xml_string_basic )
|
||||||
//BOOST_AUTO_TEST_CASE( xml_string )
|
{
|
||||||
//{
|
test_string_basic<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
|
||||||
// test_string<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
|
}
|
||||||
//}
|
|
||||||
|
BOOST_AUTO_TEST_CASE( json_string_basic )
|
||||||
|
{
|
||||||
|
test_string_basic<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
|
||||||
|
}
|
||||||
|
|
||||||
// ######################################################################
|
// ######################################################################
|
||||||
template <class IArchive, class OArchive>
|
template <class IArchive, class OArchive>
|
||||||
@@ -1614,18 +1647,18 @@ void test_unordered_multimap()
|
|||||||
o_podunordered_multimap.insert({key, random_value<int>(gen)});
|
o_podunordered_multimap.insert({key, random_value<int>(gen)});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unordered_multimap<double, StructInternalSerialize> o_iserunordered_multimap;
|
std::unordered_multimap<int, StructInternalSerialize> o_iserunordered_multimap;
|
||||||
for(int j=0; j<100; ++j)
|
for(int j=0; j<100; ++j)
|
||||||
{
|
{
|
||||||
auto key = random_value<double>(gen);
|
auto key = random_value<int>(gen);
|
||||||
o_iserunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
|
o_iserunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
|
||||||
o_iserunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
|
o_iserunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unordered_multimap<float, StructInternalSplit> o_isplunordered_multimap;
|
std::unordered_multimap<int, StructInternalSplit> o_isplunordered_multimap;
|
||||||
for(int j=0; j<100; ++j)
|
for(int j=0; j<100; ++j)
|
||||||
{
|
{
|
||||||
auto key = random_value<float>(gen);
|
auto key = random_value<int>(gen);
|
||||||
o_isplunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
|
o_isplunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
|
||||||
o_isplunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
|
o_isplunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
|
||||||
}
|
}
|
||||||
@@ -1658,8 +1691,8 @@ void test_unordered_multimap()
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::unordered_multimap<std::string, int> i_podunordered_multimap;
|
std::unordered_multimap<std::string, int> i_podunordered_multimap;
|
||||||
std::unordered_multimap<double, StructInternalSerialize> i_iserunordered_multimap;
|
std::unordered_multimap<int, StructInternalSerialize> i_iserunordered_multimap;
|
||||||
std::unordered_multimap<float, StructInternalSplit> i_isplunordered_multimap;
|
std::unordered_multimap<int, StructInternalSplit> i_isplunordered_multimap;
|
||||||
std::unordered_multimap<uint32_t, StructExternalSerialize> i_eserunordered_multimap;
|
std::unordered_multimap<uint32_t, StructExternalSerialize> i_eserunordered_multimap;
|
||||||
std::unordered_multimap<int8_t, StructExternalSplit> i_esplunordered_multimap;
|
std::unordered_multimap<int8_t, StructExternalSplit> i_esplunordered_multimap;
|
||||||
|
|
||||||
@@ -2237,7 +2270,8 @@ void test_complex()
|
|||||||
}
|
}
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL( o_float, i_float );
|
BOOST_CHECK_EQUAL( o_float, i_float );
|
||||||
BOOST_CHECK_EQUAL( o_double, i_double );
|
BOOST_CHECK_CLOSE( o_double.real(), i_double.real(), 1e-5);
|
||||||
|
BOOST_CHECK_CLOSE( o_double.imag(), i_double.imag(), 1e-5);
|
||||||
BOOST_CHECK_CLOSE( o_ldouble.real(), i_ldouble.real(), 1e-5);
|
BOOST_CHECK_CLOSE( o_ldouble.real(), i_ldouble.real(), 1e-5);
|
||||||
BOOST_CHECK_CLOSE( o_ldouble.imag(), i_ldouble.imag(), 1e-5);
|
BOOST_CHECK_CLOSE( o_ldouble.imag(), i_ldouble.imag(), 1e-5);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user