/////////////////////////////////////////////////////////////// // 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_ #define BOOST_TEST_MAIN #include // Boost.Test #include #include #include #include #include #include #include #include #include #include #include template void test() { boost::timer tim; boost::random::mt19937 gen; boost::random::uniform_01 d; while(true) { T val = d(gen); try{ { std::stringstream ss(std::ios_base::in | std::ios_base::out | std::ios_base::binary); boost::archive::text_oarchive oa(ss); oa << static_cast(val); boost::archive::text_iarchive ia(ss); 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::binary_oarchive ba(ss); ba << static_cast(val); boost::archive::binary_iarchive ib(ss); T val2; ib >> val2; BOOST_CHECK_EQUAL(val, val2); } { std::stringstream ss(std::ios_base::in | std::ios_base::out | std::ios_base::binary); val = -val; boost::archive::text_oarchive oa2(ss); oa2 << static_cast(val); boost::archive::text_iarchive ia2(ss); T val2; ia2 >> val2; BOOST_CHECK_EQUAL(val, val2); } { std::stringstream ss(std::ios_base::in | std::ios_base::out | std::ios_base::binary); boost::archive::binary_oarchive ba2(ss); ba2 << static_cast(val); boost::archive::binary_iarchive ib2(ss); T val2; ib2 >> val2; BOOST_CHECK_EQUAL(val, val2); } } catch(const boost::exception& e) { std::cout << "Caught boost::exception with:\n"; std::cout << diagnostic_information(e); BOOST_ERROR("Unexpected exception"); break; } catch(const std::exception& e) { std::cout << "Caught std::exception with:\n"; std::cout << e.what() << std::endl; BOOST_ERROR("Unexpected exception"); break; } // // Check to see if test is taking too long. // Tests run on the compiler farm time out after 300 seconds, // so don't get too close to that: // if(tim.elapsed() > 150) { std::cout << "Timeout reached, aborting tests now....\n"; break; } } } #if !defined(TEST_FLOAT) && !defined(TEST_DOUBLE) && !defined(TEST_LONG_DOUBLE) # error "No test type specified!!" #endif BOOST_AUTO_TEST_CASE( test_main ) { #ifdef TEST_FLOAT test(); #endif #ifdef TEST_DOUBLE test(); #endif #ifdef TEST_LONG_DOUBLE test(); #endif }