Boost Exception now works with BOOST_NO_RTTI and/or BOOST_NO_TYPEID.

[SVN r48429]
This commit is contained in:
Emil Dotchevski
2008-08-28 23:49:55 +00:00
parent 14765312e2
commit 850b7d9618
20 changed files with 369 additions and 148 deletions

View File

@ -40,6 +40,7 @@ compile enable_current_exception_hpp_test.cpp ;
compile enable_error_info_hpp_test.cpp ;
compile error_info_hpp_test.cpp ;
compile exception_hpp_test.cpp ;
compile get_error_info_hpp_test.cpp ;
compile info_hpp_test.cpp ;
compile info_tuple_hpp_test.cpp ;
compile to_string_hpp_test.cpp ;

View File

@ -3,6 +3,7 @@
//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_0.txt)
#include <boost/exception/get_error_info.hpp>
#include <boost/exception/info.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <stdexcept>

View File

@ -7,7 +7,7 @@
#include <boost/exception/info.hpp>
#include <boost/detail/lightweight_test.hpp>
typedef boost::error_info<struct tag,int> tag_int;
typedef boost::error_info<struct test_tag,int> tag_int;
struct
error1:
@ -48,27 +48,65 @@ int
main()
{
using namespace boost;
try
{
error1 x;
BOOST_TEST(x.what()==std::string("error1"));
throw x;
}
catch(
std::exception & x )
{
std::string di=get_diagnostic_information(x);
BOOST_TEST(di.find("type:")!=std::string::npos);
BOOST_TEST(di.find("error1")!=std::string::npos);
}
catch(
... )
{
BOOST_TEST(false);
}
try
{
error2 x; x << tag_int(42);
BOOST_TEST(x.what()==std::string("error2"));
throw x;
}
catch(
std::exception & x )
{
std::string di=get_diagnostic_information(x);
BOOST_TEST(di.find("type:")!=std::string::npos);
#ifndef BOOST_NO_RTTI
BOOST_TEST(di.find("error2")!=std::string::npos);
#endif
BOOST_TEST(di.find("test_tag")!=std::string::npos);
}
catch(
... )
{
BOOST_TEST(false);
}
try
{
error3 x;
x << tag_int(1);
throw x;
}
catch(
boost::exception & x )
{
std::string w1 = x.diagnostic_information();
x << tag_int(2);
std::string w2 = x.diagnostic_information();
BOOST_TEST( w1!=w2 );
BOOST_TEST(w1.find("test_tag")!=std::string::npos);
BOOST_TEST(w2.find("test_tag")!=std::string::npos);
}
catch(
... )
{
BOOST_TEST(false);
}
return boost::report_errors();
}

View File

@ -4,6 +4,7 @@
//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include "helper1.hpp"
#include <boost/exception/get_error_info.hpp>
#include <boost/exception/info.hpp>
#include <boost/exception/diagnostic_information.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@ -3,6 +3,7 @@
//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_0.txt)
#include <boost/exception/get_error_info.hpp>
#include <boost/exception/info.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <errno.h>

View File

@ -3,6 +3,7 @@
//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_0.txt)
#include <boost/exception/get_error_info.hpp>
#include <boost/exception/info_tuple.hpp>
#include <boost/detail/lightweight_test.hpp>
@ -38,12 +39,20 @@ throws_on_copy
void
basic_test()
{
test_exception x;
x << test_1(1) << test_2(2u) << test_3(3.14159f);
BOOST_TEST(*boost::get_error_info<test_1>(x)==1);
BOOST_TEST(*boost::get_error_info<test_2>(x)==2u);
BOOST_TEST(*boost::get_error_info<test_3>(x)==3.14159f);
BOOST_TEST(!boost::get_error_info<test_4>(x));
try
{
test_exception x;
x << test_1(1) << test_2(2u) << test_3(3.14159f);
throw x;
}
catch(
test_exception & x )
{
BOOST_TEST(*boost::get_error_info<test_1>(x)==1);
BOOST_TEST(*boost::get_error_info<test_2>(x)==2u);
BOOST_TEST(*boost::get_error_info<test_3>(x)==3.14159f);
BOOST_TEST(!boost::get_error_info<test_4>(x));
}
}
void
@ -58,8 +67,8 @@ exception_safety_test()
catch(
test_exception & )
{
BOOST_TEST(!boost::get_error_info<test_4>(x));
}
BOOST_TEST(!boost::get_error_info<test_4>(x));
}
void
@ -107,7 +116,9 @@ test_empty()
catch(
boost::exception & x )
{
#ifndef BOOST_NO_RTTI
BOOST_TEST( dynamic_cast<test_exception *>(&x) );
#endif
BOOST_TEST( !boost::get_error_info<test_1>(x) );
}
catch(
@ -124,7 +135,7 @@ test_empty()
catch(
test_exception & x )
{
BOOST_TEST( dynamic_cast<boost::exception *>(&x) );
BOOST_TEST( boost::exception_detail::get_boost_exception(&x) );
}
catch(
... )

View File

@ -0,0 +1,6 @@
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
//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_0.txt)
#include <boost/exception/get_error_info.hpp>

View File

@ -4,6 +4,7 @@
//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include "helper2.hpp"
#include <boost/exception/get_error_info.hpp>
#include <boost/exception/info.hpp>
#include <boost/exception_ptr.hpp>
#include <boost/detail/lightweight_test.hpp>

View File

@ -4,6 +4,7 @@
//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <boost/exception_ptr.hpp>
#include <boost/exception/get_error_info.hpp>
#include <boost/exception/info.hpp>
#include <boost/detail/lightweight_test.hpp>