///////////////////////////////////////////////////////////////
// Copyright 2013 John Maddock. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
-// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_
+// LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
+#include <boost/archive/xml_iarchive.hpp>
+#include <boost/archive/xml_oarchive.hpp>
#include <boost/exception/all.hpp>
-
#ifndef BOOST_MP_TEST_FLOAT_SERIAL_HPP
#define BOOST_MP_TEST_FLOAT_SERIAL_HPP
T generate_random(unsigned /*bits_wanted*/)
{
typedef typename T::backend_type::exponent_type e_type;
- static boost::random::mt19937 gen;
- T val = gen();
- T prev_val = -1;
- while(val != prev_val)
+ static boost::random::mt19937 gen;
+ T val = gen();
+ T prev_val = -1;
+ while (val != prev_val)
{
val *= (gen.max)();
prev_val = val;
{
boost::timer tim;
- while(true)
+ while (true)
{
- T val = generate_random<T>(boost::math::tools::digits<T>());
- int test_id = 0;
+ T val = generate_random<T>(boost::math::tools::digits<T>());
+ int test_id = 0;
std::string stream_contents;
#ifndef BOOST_NO_EXCEPTIONS
- try{
+ try
+ {
#endif
test_id = 0;
{
- std::stringstream ss(std::ios_base::in | std::ios_base::out | std::ios_base::binary);
+ std::stringstream ss(std::ios_base::in | std::ios_base::out | std::ios_base::binary);
boost::archive::text_oarchive oa(ss);
oa << static_cast<const T&>(val);
stream_contents = ss.str();
boost::archive::text_iarchive ia(ss);
- T val2;
+ T val2;
ia >> val2;
BOOST_CHECK_EQUAL(val, val2);
}
+ {
+ std::stringstream ss(std::ios_base::in | std::ios_base::out | std::ios_base::binary);
+ {
+ boost::archive::xml_oarchive oa(ss);
+ oa << boost::serialization::make_nvp("value", static_cast<const T&>(val));
+ stream_contents = ss.str();
+ }
+ boost::archive::xml_iarchive ia(ss);
+ T val2;
+ ia >> boost::serialization::make_nvp("value", val2);
+ BOOST_CHECK_EQUAL(val, val2);
+ }
{
std::stringstream ss(std::ios_base::in | std::ios_base::out | std::ios_base::binary);
++test_id;
ba << static_cast<const T&>(val);
stream_contents = ss.str();
boost::archive::binary_iarchive ib(ss);
- T val2;
+ T val2;
ib >> val2;
BOOST_CHECK_EQUAL(val, val2);
}
oa2 << static_cast<const T&>(val);
stream_contents = ss.str();
boost::archive::text_iarchive ia2(ss);
- T val2;
+ T val2;
ia2 >> val2;
BOOST_CHECK_EQUAL(val, val2);
}
+ {
+ std::stringstream ss(std::ios_base::in | std::ios_base::out | std::ios_base::binary);
+ ++test_id;
+ {
+ boost::archive::xml_oarchive oa2(ss);
+ oa2 << boost::serialization::make_nvp("value", static_cast<const T&>(val));
+ stream_contents = ss.str();
+ }
+ boost::archive::xml_iarchive ia2(ss);
+ T val2;
+ ia2 >> boost::serialization::make_nvp("value", val2);
+ BOOST_CHECK_EQUAL(val, val2);
+ }
{
std::stringstream ss(std::ios_base::in | std::ios_base::out | std::ios_base::binary);
++test_id;
ba2 << static_cast<const T&>(val);
stream_contents = ss.str();
boost::archive::binary_iarchive ib2(ss);
- T val2;
+ T val2;
ib2 >> val2;
BOOST_CHECK_EQUAL(val, val2);
}
#ifndef BOOST_NO_EXCEPTIONS
}
- catch(const boost::exception& e)
+ catch (const boost::exception& e)
{
std::cout << "Caught boost::exception with:\n";
std::cout << diagnostic_information(e);
std::cout << "Failed test ID = " << test_id << std::endl;
- std::cout << "Stream contents were: \n" << stream_contents << std::endl;
+ std::cout << "Stream contents were: \n"
+ << stream_contents << std::endl;
++boost::detail::test_errors();
break;
}
- catch(const std::exception& e)
+ catch (const std::exception& e)
{
std::cout << "Caught std::exception with:\n";
std::cout << e.what() << std::endl;
std::cout << "Failed test ID = " << test_id << std::endl;
- std::cout << "Stream contents were: \n" << stream_contents << std::endl;
+ std::cout << "Stream contents were: \n"
+ << stream_contents << std::endl;
++boost::detail::test_errors();
break;
}
// so don't get too close to that:
//
#ifndef CI_SUPPRESS_KNOWN_ISSUES
- if(tim.elapsed() > 150)
+ if (tim.elapsed() > 150)
#else
- if(tim.elapsed() > 25)
+ if (tim.elapsed() > 25)
#endif
{
std::cout << "Timeout reached, aborting tests now....\n";