|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r85619 - trunk/libs/multiprecision/test
From: john_at_[hidden]
Date: 2013-09-09 07:52:30
Author: johnmaddock
Date: 2013-09-09 07:52:30 EDT (Mon, 09 Sep 2013)
New Revision: 85619
URL: http://svn.boost.org/trac/boost/changeset/85619
Log:
Improve error handling in serialization tests.
Text files modified:
trunk/libs/multiprecision/test/test_adapt_serial.cpp | 83 ++++++++++++++++++++++-----------
trunk/libs/multiprecision/test/test_cpp_int_deserial.cpp | 96 ++++++++++++++++++++++++++++++++++-----
trunk/libs/multiprecision/test/test_cpp_int_serial.cpp | 82 ++++++++++++++++++++++-----------
trunk/libs/multiprecision/test/test_cpp_rat_serial.cpp | 83 ++++++++++++++++++++++-----------
trunk/libs/multiprecision/test/test_float_serial.hpp | 67 ++++++++++++++++-----------
5 files changed, 287 insertions(+), 124 deletions(-)
Modified: trunk/libs/multiprecision/test/test_adapt_serial.cpp
==============================================================================
--- trunk/libs/multiprecision/test/test_adapt_serial.cpp Mon Sep 9 00:06:52 2013 (r85618)
+++ trunk/libs/multiprecision/test/test_adapt_serial.cpp 2013-09-09 07:52:30 EDT (Mon, 09 Sep 2013) (r85619)
@@ -26,6 +26,7 @@
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
+#include <boost/exception/all.hpp>
template <class T>
T generate_random(unsigned bits_wanted)
@@ -65,20 +66,33 @@
void test_neg(const T& x, const boost::mpl::true_&)
{
T val = -x;
- std::stringstream ss;
- boost::archive::text_oarchive oa(ss);
- oa << static_cast<const T&>(val);
- boost::archive::text_iarchive ia(ss);
- T val2;
- ia >> val2;
- BOOST_CHECK_EQUAL(val, val2);
-
- ss.clear();
- boost::archive::binary_oarchive ob(ss);
- ob << static_cast<const T&>(val);
- boost::archive::binary_iarchive ib(ss);
- ib >> val2;
- BOOST_CHECK_EQUAL(val, val2);
+ try
+ {
+ std::stringstream ss;
+ boost::archive::text_oarchive oa(ss);
+ oa << static_cast<const T&>(val);
+ boost::archive::text_iarchive ia(ss);
+ T val2;
+ ia >> val2;
+ BOOST_CHECK_EQUAL(val, val2);
+
+ ss.clear();
+ boost::archive::binary_oarchive ob(ss);
+ ob << static_cast<const T&>(val);
+ boost::archive::binary_iarchive ib(ss);
+ ib >> val2;
+ BOOST_CHECK_EQUAL(val, val2);
+ }
+ catch(const boost::exception& e)
+ {
+ std::cout << "Caught boost::exception with:\n";
+ std::cout << diagnostic_information(e);
+ }
+ catch(const std::exception& e)
+ {
+ std::cout << "Caught std::exception with:\n";
+ std::cout << e.what() << std::endl;
+ }
}
template <class T>
void test_neg(const T& , const boost::mpl::false_&){}
@@ -95,20 +109,33 @@
while(true)
{
T val = generate_random<T>(d(gen));
- std::stringstream ss;
- boost::archive::text_oarchive oa(ss);
- oa << static_cast<const T&>(val);
- boost::archive::text_iarchive ia(ss);
- T val2;
- ia >> val2;
- BOOST_CHECK_EQUAL(val, val2);
-
- ss.clear();
- boost::archive::binary_oarchive ob(ss);
- ob << static_cast<const T&>(val);
- boost::archive::binary_iarchive ib(ss);
- ib >> val2;
- BOOST_CHECK_EQUAL(val, val2);
+ try
+ {
+ std::stringstream ss;
+ boost::archive::text_oarchive oa(ss);
+ oa << static_cast<const T&>(val);
+ boost::archive::text_iarchive ia(ss);
+ T val2;
+ ia >> val2;
+ BOOST_CHECK_EQUAL(val, val2);
+
+ ss.clear();
+ boost::archive::binary_oarchive ob(ss);
+ ob << static_cast<const T&>(val);
+ boost::archive::binary_iarchive ib(ss);
+ ib >> val2;
+ BOOST_CHECK_EQUAL(val, val2);
+ }
+ catch(const boost::exception& e)
+ {
+ std::cout << "Caught boost::exception with:\n";
+ std::cout << diagnostic_information(e);
+ }
+ catch(const std::exception& e)
+ {
+ std::cout << "Caught std::exception with:\n";
+ std::cout << e.what() << std::endl;
+ }
test_neg(val, boost::mpl::bool_<std::numeric_limits<T>::is_signed>());
//
Modified: trunk/libs/multiprecision/test/test_cpp_int_deserial.cpp
==============================================================================
--- trunk/libs/multiprecision/test/test_cpp_int_deserial.cpp Mon Sep 9 00:06:52 2013 (r85618)
+++ trunk/libs/multiprecision/test/test_cpp_int_deserial.cpp 2013-09-09 07:52:30 EDT (Mon, 09 Sep 2013) (r85619)
@@ -21,7 +21,7 @@
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
-
+#include <boost/exception/all.hpp>
template <class T>
void test64()
@@ -1032,6 +1032,9 @@
};
std::ifstream is("cpp_int64_serial64.txt");
+ std::cout << "Testing cpp_int64_serial64.txt with T=" << typeid(T).name() << std::endl;
+ is.peek();
+ BOOST_CHECK(is.good());
boost::archive::text_iarchive ia(is);
for(unsigned i = 0; i < sizeof(text_array) / sizeof(text_array[0]); ++i)
{
@@ -1041,6 +1044,9 @@
}
std::ifstream is2("cpp_int64_serial32.txt");
+ std::cout << "Testing cpp_int64_serial32.txt with T=" << typeid(T).name() << std::endl;
+ is2.peek();
+ BOOST_CHECK(is2.good());
boost::archive::text_iarchive ia2(is2);
for(unsigned i = 0; i < sizeof(text_array) / sizeof(text_array[0]); ++i)
{
@@ -2059,21 +2065,53 @@
};
std::ifstream is("cpp_int128_serial64.txt");
+ std::cout << "Testing cpp_int128_serial64.txt with T=" << typeid(T).name() << std::endl;
+ is.peek();
+ BOOST_CHECK(is.good());
boost::archive::text_iarchive ia(is);
for(unsigned i = 0; i < sizeof(text_array) / sizeof(text_array[0]); ++i)
{
- T val;
- ia >> val;
- BOOST_CHECK_EQUAL(val, T(text_array[i]));
+ try
+ {
+ T val;
+ ia >> val;
+ BOOST_CHECK_EQUAL(val, T(text_array[i]));
+ }
+ catch(const boost::exception& e)
+ {
+ std::cout << "Caught boost::exception with:\n";
+ std::cout << diagnostic_information(e);
+ }
+ catch(const std::exception& e)
+ {
+ std::cout << "Caught std::exception with:\n";
+ std::cout << e.what() << std::endl;
+ }
}
std::ifstream is2("cpp_int128_serial32.txt");
+ std::cout << "Testing cpp_int128_serial32.txt with T=" << typeid(T).name() << std::endl;
+ is2.peek();
+ BOOST_CHECK(is2.good());
boost::archive::text_iarchive ia2(is2);
for(unsigned i = 0; i < sizeof(text_array) / sizeof(text_array[0]); ++i)
{
- T val;
- ia2 >> val;
- BOOST_CHECK_EQUAL(val, T(text_array[i]));
+ try
+ {
+ T val;
+ ia2 >> val;
+ BOOST_CHECK_EQUAL(val, T(text_array[i]));
+ }
+ catch(const boost::exception& e)
+ {
+ std::cout << "Caught boost::exception with:\n";
+ std::cout << diagnostic_information(e);
+ }
+ catch(const std::exception& e)
+ {
+ std::cout << "Caught std::exception with:\n";
+ std::cout << e.what() << std::endl;
+ }
}
}
@@ -3086,21 +3124,53 @@
};
std::ifstream is("cpp_int1024_serial64.txt");
+ std::cout << "Testing cpp_int1024_serial64.txt with T=" << typeid(T).name() << std::endl;
+ is.peek();
+ BOOST_CHECK(is.good());
boost::archive::text_iarchive ia(is);
for(unsigned i = 0; i < sizeof(text_array) / sizeof(text_array[0]); ++i)
{
- T val;
- ia >> val;
- BOOST_CHECK_EQUAL(val, T(text_array[i]));
+ try
+ {
+ T val;
+ ia >> val;
+ BOOST_CHECK_EQUAL(val, T(text_array[i]));
+ }
+ catch(const boost::exception& e)
+ {
+ std::cout << "Caught boost::exception with:\n";
+ std::cout << diagnostic_information(e);
+ }
+ catch(const std::exception& e)
+ {
+ std::cout << "Caught std::exception with:\n";
+ std::cout << e.what() << std::endl;
+ }
}
std::ifstream is2("cpp_int1024_serial32.txt");
+ std::cout << "Testing cpp_int1024_serial32.txt with T=" << typeid(T).name() << std::endl;
+ is2.peek();
+ BOOST_CHECK(is2.good());
boost::archive::text_iarchive ia2(is2);
for(unsigned i = 0; i < sizeof(text_array) / sizeof(text_array[0]); ++i)
{
- T val;
- ia2 >> val;
- BOOST_CHECK_EQUAL(val, T(text_array[i]));
+ try
+ {
+ T val;
+ ia2 >> val;
+ BOOST_CHECK_EQUAL(val, T(text_array[i]));
+ }
+ catch(const boost::exception& e)
+ {
+ std::cout << "Caught boost::exception with:\n";
+ std::cout << diagnostic_information(e);
+ }
+ catch(const std::exception& e)
+ {
+ std::cout << "Caught std::exception with:\n";
+ std::cout << e.what() << std::endl;
+ }
}
}
Modified: trunk/libs/multiprecision/test/test_cpp_int_serial.cpp
==============================================================================
--- trunk/libs/multiprecision/test/test_cpp_int_serial.cpp Mon Sep 9 00:06:52 2013 (r85618)
+++ trunk/libs/multiprecision/test/test_cpp_int_serial.cpp 2013-09-09 07:52:30 EDT (Mon, 09 Sep 2013) (r85619)
@@ -24,6 +24,7 @@
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
+#include <boost/exception/all.hpp>
template <class T>
T generate_random(unsigned bits_wanted)
@@ -63,20 +64,32 @@
void test_neg(const T& x, const boost::mpl::true_&)
{
T val = -x;
- std::stringstream ss;
- boost::archive::text_oarchive oa(ss);
- oa << static_cast<const T&>(val);
- boost::archive::text_iarchive ia(ss);
- T val2;
- ia >> val2;
- BOOST_CHECK_EQUAL(val, val2);
-
- ss.clear();
- boost::archive::binary_oarchive ob(ss);
- ob << static_cast<const T&>(val);
- boost::archive::binary_iarchive ib(ss);
- ib >> val2;
- BOOST_CHECK_EQUAL(val, val2);
+ try{
+ std::stringstream ss;
+ boost::archive::text_oarchive oa(ss);
+ oa << static_cast<const T&>(val);
+ boost::archive::text_iarchive ia(ss);
+ T val2;
+ ia >> val2;
+ BOOST_CHECK_EQUAL(val, val2);
+
+ ss.clear();
+ boost::archive::binary_oarchive ob(ss);
+ ob << static_cast<const T&>(val);
+ boost::archive::binary_iarchive ib(ss);
+ ib >> val2;
+ BOOST_CHECK_EQUAL(val, val2);
+ }
+ catch(const boost::exception& e)
+ {
+ std::cout << "Caught boost::exception with:\n";
+ std::cout << diagnostic_information(e);
+ }
+ catch(const std::exception& e)
+ {
+ std::cout << "Caught std::exception with:\n";
+ std::cout << e.what() << std::endl;
+ }
}
template <class T>
void test_neg(const T& , const boost::mpl::false_&){}
@@ -93,20 +106,33 @@
while(true)
{
T val = generate_random<T>(d(gen));
- std::stringstream ss;
- boost::archive::text_oarchive oa(ss);
- oa << static_cast<const T&>(val);
- boost::archive::text_iarchive ia(ss);
- T val2;
- ia >> val2;
- BOOST_CHECK_EQUAL(val, val2);
-
- ss.clear();
- boost::archive::binary_oarchive ob(ss);
- ob << static_cast<const T&>(val);
- boost::archive::binary_iarchive ib(ss);
- ib >> val2;
- BOOST_CHECK_EQUAL(val, val2);
+ try
+ {
+ std::stringstream ss;
+ boost::archive::text_oarchive oa(ss);
+ oa << static_cast<const T&>(val);
+ boost::archive::text_iarchive ia(ss);
+ T val2;
+ ia >> val2;
+ BOOST_CHECK_EQUAL(val, val2);
+
+ ss.clear();
+ boost::archive::binary_oarchive ob(ss);
+ ob << static_cast<const T&>(val);
+ boost::archive::binary_iarchive ib(ss);
+ ib >> val2;
+ BOOST_CHECK_EQUAL(val, val2);
+ }
+ catch(const boost::exception& e)
+ {
+ std::cout << "Caught boost::exception with:\n";
+ std::cout << diagnostic_information(e);
+ }
+ catch(const std::exception& e)
+ {
+ std::cout << "Caught std::exception with:\n";
+ std::cout << e.what() << std::endl;
+ }
test_neg(val, boost::mpl::bool_<std::numeric_limits<T>::is_signed>());
//
Modified: trunk/libs/multiprecision/test/test_cpp_rat_serial.cpp
==============================================================================
--- trunk/libs/multiprecision/test/test_cpp_rat_serial.cpp Mon Sep 9 00:06:52 2013 (r85618)
+++ trunk/libs/multiprecision/test/test_cpp_rat_serial.cpp 2013-09-09 07:52:30 EDT (Mon, 09 Sep 2013) (r85619)
@@ -24,6 +24,7 @@
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
+#include <boost/exception/all.hpp>
template <class T>
T generate_random(unsigned bits_wanted)
@@ -65,20 +66,33 @@
void test_neg(const T& x, const boost::mpl::true_&)
{
T val = -x;
- std::stringstream ss;
- boost::archive::text_oarchive oa(ss);
- oa << static_cast<const T&>(val);
- boost::archive::text_iarchive ia(ss);
- T val2;
- ia >> val2;
- BOOST_CHECK_EQUAL(val, val2);
-
- ss.clear();
- boost::archive::binary_oarchive ob(ss);
- ob << static_cast<const T&>(val);
- boost::archive::binary_iarchive ib(ss);
- ib >> val2;
- BOOST_CHECK_EQUAL(val, val2);
+ try
+ {
+ std::stringstream ss;
+ boost::archive::text_oarchive oa(ss);
+ oa << static_cast<const T&>(val);
+ boost::archive::text_iarchive ia(ss);
+ T val2;
+ ia >> val2;
+ BOOST_CHECK_EQUAL(val, val2);
+
+ ss.clear();
+ boost::archive::binary_oarchive ob(ss);
+ ob << static_cast<const T&>(val);
+ boost::archive::binary_iarchive ib(ss);
+ ib >> val2;
+ BOOST_CHECK_EQUAL(val, val2);
+ }
+ catch(const boost::exception& e)
+ {
+ std::cout << "Caught boost::exception with:\n";
+ std::cout << diagnostic_information(e);
+ }
+ catch(const std::exception& e)
+ {
+ std::cout << "Caught std::exception with:\n";
+ std::cout << e.what() << std::endl;
+ }
}
template <class T>
void test_neg(const T& , const boost::mpl::false_&){}
@@ -95,20 +109,33 @@
while(true)
{
T val(generate_random<typename component_type<T>::type>(d(gen)), generate_random<typename component_type<T>::type>(d(gen)));
- std::stringstream ss;
- boost::archive::text_oarchive oa(ss);
- oa << static_cast<const T&>(val);
- boost::archive::text_iarchive ia(ss);
- T val2;
- ia >> val2;
- BOOST_CHECK_EQUAL(val, val2);
-
- ss.clear();
- boost::archive::binary_oarchive ob(ss);
- ob << static_cast<const T&>(val);
- boost::archive::binary_iarchive ib(ss);
- ib >> val2;
- BOOST_CHECK_EQUAL(val, val2);
+ try
+ {
+ std::stringstream ss;
+ boost::archive::text_oarchive oa(ss);
+ oa << static_cast<const T&>(val);
+ boost::archive::text_iarchive ia(ss);
+ T val2;
+ ia >> val2;
+ BOOST_CHECK_EQUAL(val, val2);
+
+ ss.clear();
+ boost::archive::binary_oarchive ob(ss);
+ ob << static_cast<const T&>(val);
+ boost::archive::binary_iarchive ib(ss);
+ ib >> val2;
+ BOOST_CHECK_EQUAL(val, val2);
+ }
+ catch(const boost::exception& e)
+ {
+ std::cout << "Caught boost::exception with:\n";
+ std::cout << diagnostic_information(e);
+ }
+ catch(const std::exception& e)
+ {
+ std::cout << "Caught std::exception with:\n";
+ std::cout << e.what() << std::endl;
+ }
test_neg(val, boost::mpl::bool_<std::numeric_limits<T>::is_signed>());
Modified: trunk/libs/multiprecision/test/test_float_serial.hpp
==============================================================================
--- trunk/libs/multiprecision/test/test_float_serial.hpp Mon Sep 9 00:06:52 2013 (r85618)
+++ trunk/libs/multiprecision/test/test_float_serial.hpp 2013-09-09 07:52:30 EDT (Mon, 09 Sep 2013) (r85619)
@@ -15,6 +15,7 @@
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
+#include <boost/exception/all.hpp>
#ifndef BOOST_MP_TEST_FLOAT_SERIAL_HPP
@@ -48,33 +49,45 @@
while(true)
{
T val = generate_random<T>(boost::math::tools::digits<T>());
- std::stringstream ss;
- boost::archive::text_oarchive oa(ss);
- oa << static_cast<const T&>(val);
- boost::archive::text_iarchive ia(ss);
- T val2;
- ia >> val2;
- BOOST_CHECK_EQUAL(val, val2);
- ss.clear();
- boost::archive::binary_oarchive ba(ss);
- ba << static_cast<const T&>(val);
- boost::archive::binary_iarchive ib(ss);
- ib >> val2;
- BOOST_CHECK_EQUAL(val, val2);
+ try{
+ std::stringstream ss;
+ boost::archive::text_oarchive oa(ss);
+ oa << static_cast<const T&>(val);
+ boost::archive::text_iarchive ia(ss);
+ T val2;
+ ia >> val2;
+ BOOST_CHECK_EQUAL(val, val2);
+ ss.clear();
+ boost::archive::binary_oarchive ba(ss);
+ ba << static_cast<const T&>(val);
+ boost::archive::binary_iarchive ib(ss);
+ ib >> val2;
+ BOOST_CHECK_EQUAL(val, val2);
- val = -val;
- ss.clear();
- boost::archive::text_oarchive oa2(ss);
- oa2 << static_cast<const T&>(val);
- boost::archive::text_iarchive ia2(ss);
- ia2 >> val2;
- BOOST_CHECK_EQUAL(val, val2);
- ss.clear();
- boost::archive::binary_oarchive ba2(ss);
- ba2 << static_cast<const T&>(val);
- boost::archive::binary_iarchive ib2(ss);
- ib2 >> val2;
- BOOST_CHECK_EQUAL(val, val2);
+ val = -val;
+ ss.clear();
+ boost::archive::text_oarchive oa2(ss);
+ oa2 << static_cast<const T&>(val);
+ boost::archive::text_iarchive ia2(ss);
+ ia2 >> val2;
+ BOOST_CHECK_EQUAL(val, val2);
+ ss.clear();
+ boost::archive::binary_oarchive ba2(ss);
+ ba2 << static_cast<const T&>(val);
+ boost::archive::binary_iarchive ib2(ss);
+ ib2 >> val2;
+ BOOST_CHECK_EQUAL(val, val2);
+ }
+ catch(const boost::exception& e)
+ {
+ std::cout << "Caught boost::exception with:\n";
+ std::cout << diagnostic_information(e);
+ }
+ catch(const std::exception& e)
+ {
+ std::cout << "Caught std::exception with:\n";
+ std::cout << e.what() << std::endl;
+ }
//
// Check to see if test is taking too long.
// Tests run on the compiler farm time out after 300 seconds,
@@ -88,4 +101,4 @@
}
}
-#endif
\ No newline at end of file
+#endif
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk