Merging from trunk: new function diagnostic_information_what, and mutable error info access.

[SVN r56477]
This commit is contained in:
Emil Dotchevski
2009-09-29 20:38:11 +00:00
parent d32fff4fb2
commit 6434a2031c
32 changed files with 9991 additions and 9480 deletions

View File

@ -14,38 +14,30 @@ boost_test_compile_fail(to_string_fail)
#exception
boost_test_run(1-throw_exception_test)
boost_test_run(2-throw_exception_no_exceptions_test)
boost_test_run(3-throw_exception_no_integration_test)
boost_test_run(4-throw_exception_no_both_test)
boost_test_run(cloning_test)
boost_test_run(copy_exception_test)
boost_test_run(unknown_exception_test)
boost_test_run(exception_test)
#boost_test_run(boost_error_info_test)
boost_test_run(enable_error_info_test enable_error_info_test.cpp helper1.cpp)
boost_test_run(throw_exception_test throw_exception_test.cpp helper2.cpp)
boost_test_run(errno_test)
boost_test_run(error_info_test)
boost_test_run(diagnostic_information_test)
boost_test_run(refcount_ptr_test)
boost_test_run(current_exception_cast_test)
message(STATUS "!!!> run no_exceptions_test.cpp : : : <exception-handling>off ;")
boost_test_compile_fail(exception_fail)
boost_test_compile_fail(throw_exception_fail)
# Compile headers tests
set (compile_tests
exception_ptr_hpp_test
diagnostic_information_hpp_test
error_info_hpp_test
exception_ptr_hpp_test
exception_hpp_test
get_error_info_hpp_test
info_hpp_test
info_tuple_hpp_test
to_string_hpp_test
to_string_stub_hpp_test
current_exception_cast_hpp_test
)
#-- Create a Compile test for each source

View File

@ -38,6 +38,7 @@ run no_exceptions_test.cpp : : : <exception-handling>off ;
run errinfos_test.cpp ;
compile-fail exception_fail.cpp ;
compile-fail throw_exception_fail.cpp ;
compile-fail error_info_const_fail.cpp ;
#headers

View File

@ -43,6 +43,29 @@ error2:
{
};
struct
error3:
std::exception
{
char const *
what() const throw()
{
return "error3";
}
};
struct
error4:
std::exception,
boost::exception
{
char const *
what() const throw()
{
return diagnostic_information_what(*this);
}
};
void
test1( std::string const & di1, std::string const & di2 )
{
@ -75,6 +98,33 @@ test2( std::string const & di1, std::string const & di2 )
BOOST_TEST(di2.find("bad value")!=std::string::npos);
}
void
test3( std::string const & di )
{
#ifndef BOOST_NO_RTTI
BOOST_TEST(di.find("type:")!=std::string::npos);
#endif
BOOST_TEST(di.find("error3")!=std::string::npos);
}
void
test4( std::string const & di1, std::string const & di2 )
{
BOOST_TEST( di1!=di2 );
#ifndef BOOST_NO_RTTI
BOOST_TEST(di1.find("type:")!=std::string::npos);
#endif
BOOST_TEST(di1.find("test_tag1")!=std::string::npos);
BOOST_TEST(di1.find("test_tag2")!=std::string::npos);
BOOST_TEST(di1.find("fourty-two")!=std::string::npos);
#ifndef BOOST_NO_RTTI
BOOST_TEST(di2.find("type:")!=std::string::npos);
#endif
BOOST_TEST(di2.find("test_tag1")!=std::string::npos);
BOOST_TEST(di2.find("test_tag2")!=std::string::npos);
BOOST_TEST(di2.find("bad value")!=std::string::npos);
}
int
main()
{
@ -131,9 +181,58 @@ main()
error2 & x )
{
std::string di1 = current_exception_diagnostic_information();
BOOST_TEST(di1==boost::diagnostic_information_what(x));
x << tagged_int1(2) << tagged_int2(2);
std::string di2 = current_exception_diagnostic_information();
BOOST_TEST(di2==boost::diagnostic_information_what(x));
test2(di1,di2);
}
try
{
error3 x;
std::string di=diagnostic_information(x);
test3(di);
throw x;
}
catch(
... )
{
std::string di=current_exception_diagnostic_information();
test3(di);
}
try
{
error4 x; x << tagged_int1(42) << tagged_int2(42);
throw x;
}
catch(
error4 & x )
{
std::string di1=boost::diagnostic_information(x);
std::string wh1=x.what();
BOOST_TEST(wh1==di1);
x << tagged_int1(2) << tagged_int2(2);
std::string di2 = diagnostic_information(x);
std::string wh2=x.what();
BOOST_TEST(wh2==di2);
test4(di1,di2);
}
try
{
error4 x; x << tagged_int1(42) << tagged_int2(42);
throw x;
}
catch(
error4 & x )
{
std::string di1=boost::current_exception_diagnostic_information();
std::string wh1=x.what();
BOOST_TEST(wh1==di1);
x << tagged_int1(2) << tagged_int2(2);
std::string di2 = current_exception_diagnostic_information();
std::string wh2=x.what();
BOOST_TEST(wh2==di2);
test4(di1,di2);
}
return boost::report_errors();
}

View File

@ -30,15 +30,19 @@ main()
using namespace boost;
try
{
BOOST_THROW_EXCEPTION(
test_exception() <<
test_exception e;
e <<
errinfo_api_function("failed_api_function") <<
errinfo_at_line(42) <<
errinfo_errno(errno) <<
errinfo_file_handle(weak_ptr<FILE>()) <<
errinfo_file_name("filename.txt") <<
errinfo_file_open_mode("rb") <<
errinfo_type_info_name(typeid(int).name()) );
errinfo_file_open_mode("rb");
#ifdef BOOST_NO_TYPEID
BOOST_THROW_EXCEPTION(e);
#else
BOOST_THROW_EXCEPTION(e<<errinfo_type_info_name(typeid(int).name()));
#endif
BOOST_TEST(false);
}
catch(
@ -50,7 +54,9 @@ main()
BOOST_TEST(get_error_info<errinfo_file_handle>(e) && get_error_info<errinfo_file_handle>(e)->expired());
BOOST_TEST(get_error_info<errinfo_file_name>(e) && *get_error_info<errinfo_file_name>(e)=="filename.txt");
BOOST_TEST(get_error_info<errinfo_file_open_mode>(e) && *get_error_info<errinfo_file_open_mode>(e)=="rb");
#ifndef BOOST_NO_TYPEID
BOOST_TEST(get_error_info<errinfo_type_info_name>(e) && *get_error_info<errinfo_type_info_name>(e)==typeid(int).name());
#endif
}
catch(
... )

View File

@ -0,0 +1,14 @@
//Copyright (c) 2006-2009 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>
typedef boost::error_info<struct foo_,int> foo;
void
test( boost::exception const * e )
{
++*boost::get_error_info<foo>(*e);
}

View File

@ -83,6 +83,23 @@ basic_test()
}
catch(
test_exception & x )
{
++*boost::get_error_info<test_1>(x);
++*boost::get_error_info<test_2>(x);
++*boost::get_error_info<test_3>(x);
BOOST_TEST(*boost::get_error_info<test_1>(x)==2);
BOOST_TEST(*boost::get_error_info<test_2>(x)==3u);
BOOST_TEST(*boost::get_error_info<test_3>(x)==4.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 const & x )
{
BOOST_TEST(*boost::get_error_info<test_1>(x)==1);
BOOST_TEST(*boost::get_error_info<test_2>(x)==2u);
@ -317,6 +334,28 @@ test_lifetime()
BOOST_TEST(!count);
}
bool
is_const( int const * )
{
return true;
}
bool
is_const( int * )
{
return false;
}
void
test_const()
{
test_exception e;
boost::exception const & c(e);
boost::exception & m(e);
BOOST_TEST(is_const(boost::get_error_info<test_1>(c)));
BOOST_TEST(!is_const(boost::get_error_info<test_1>(m)));
}
int
main()
{
@ -327,5 +366,6 @@ main()
test_catch_add_info();
test_add_tuple();
test_lifetime();
test_const();
return boost::report_errors();
}