early-access version 3088

This commit is contained in:
pineappleEA
2022-11-05 15:35:56 +01:00
parent 4e4fc25ce3
commit b601909c6d
35519 changed files with 5996896 additions and 860 deletions

View File

@@ -0,0 +1,35 @@
//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/config.hpp>
#if defined( BOOST_NO_EXCEPTIONS )
# error This program requires exception handling.
#endif
#include <boost/throw_exception.hpp>
#include <boost/detail/lightweight_test.hpp>
class my_exception: public std::exception { };
int
main()
{
try
{
boost::throw_exception(my_exception());
BOOST_ERROR("boost::throw_exception failed to throw.");
}
catch(
my_exception & )
{
}
catch(
... )
{
BOOST_ERROR("boost::throw_exception malfunction.");
}
return boost::report_errors();
}

View File

@@ -0,0 +1,32 @@
//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/config.hpp>
#if !defined( BOOST_NO_EXCEPTIONS )
# error This program requires exception handling disabled.
#endif
#include <boost/throw_exception.hpp>
#include <stdlib.h>
class my_exception: public std::exception { };
namespace
boost
{
void
throw_exception( std::exception const & )
{
exit(0);
}
}
int
main()
{
boost::throw_exception(my_exception());
return 1;
}

View File

@@ -0,0 +1,37 @@
//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)
#define BOOST_EXCEPTION_DISABLE
#include <boost/config.hpp>
#if defined( BOOST_NO_EXCEPTIONS )
# error This program requires exception handling.
#endif
#include <boost/throw_exception.hpp>
#include <boost/detail/lightweight_test.hpp>
class my_exception: public std::exception { };
int
main()
{
try
{
boost::throw_exception(my_exception());
BOOST_ERROR("boost::throw_exception failed to throw.");
}
catch(
my_exception & )
{
}
catch(
... )
{
BOOST_ERROR("boost::throw_exception malfunction.");
}
return boost::report_errors();
}

View File

@@ -0,0 +1,34 @@
//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)
#define BOOST_EXCEPTION_DISABLE
#include <boost/config.hpp>
#if !defined( BOOST_NO_EXCEPTIONS )
# error This program requires exception handling disabled.
#endif
#include <boost/throw_exception.hpp>
#include <stdlib.h>
class my_exception: public std::exception { };
namespace
boost
{
void
throw_exception( std::exception const & )
{
exit(0);
}
}
int
main()
{
boost::throw_exception(my_exception());
return 1;
}

View File

@@ -0,0 +1,71 @@
# Boost Exception Library test Jamfile
#
# Copyright (c) 2006-2013 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)
import testing ;
#to_string
run is_output_streamable_test.cpp ;
run has_to_string_test.cpp ;
run to_string_test.cpp ;
run to_string_stub_test.cpp ;
compile-fail to_string_fail.cpp ;
#exception
run 1-throw_exception_test.cpp : : : <exception-handling>on ;
run 2-throw_exception_no_exceptions_test.cpp : : : <exception-handling>off ;
run 3-throw_exception_no_integration_test.cpp : : : <exception-handling>on ;
run 4-throw_exception_no_both_test.cpp : : : <exception-handling>off ;
run cloning_test.cpp : : : <exception-handling>on ;
run copy_exception_test.cpp ../../thread/src/tss_null.cpp /boost//thread : : : <threading>multi <exception-handling>on ;
run copy_exception_no_exceptions_test.cpp : : : <exception-handling>off <rtti>on ;
run unknown_exception_test.cpp : : : <exception-handling>on ;
run exception_test.cpp : : : <exception-handling>on ;
run enable_error_info_test.cpp helper1.cpp : : : <exception-handling>on ;
run throw_exception_test.cpp helper2.cpp : : : <exception-handling>on ;
run errno_test.cpp : : : <exception-handling>on ;
run error_info_basic_test.cpp : : : <exception-handling>on ;
run error_info_lv_test.cpp : : : <exception-handling>on ;
run error_info_lv_const_test.cpp : : : <exception-handling>on ;
run error_info_rv_test.cpp : : : <exception-handling>on ;
run error_info_rv_const_test.cpp : : : <exception-handling>on ;
run diagnostic_information_test.cpp : : : <exception-handling>on ;
run refcount_ptr_test.cpp ;
run current_exception_cast_test.cpp : : : <exception-handling>on ;
run no_exceptions_test.cpp : : : <exception-handling>off ;
run errinfos_test.cpp : : : <exception-handling>on ;
run exception_ptr_test.cpp/<define>BOOST_ENABLE_NON_INTRUSIVE_EXCEPTION_PTR ../../thread/src/tss_null.cpp /boost/exception /boost//thread : : : <threading>multi <exception-handling>on : non_intrusive_exception_ptr_test ;
run exception_ptr_test.cpp ../../thread/src/tss_null.cpp /boost//thread : : : <threading>multi <exception-handling>on ;
lib visibility_test_lib : visibility_test_lib.cpp : <visibility>hidden <exception-handling>on ;
run visibility_test.cpp visibility_test_lib/<link>shared : : : <visibility>hidden <exception-handling>on ;
compile-fail exception_fail.cpp ;
compile-fail throw_exception_fail.cpp ;
compile-fail error_info_const_fail.cpp ;
#headers
compile exception_ptr_hpp_test.cpp ;
compile diagnostic_information_hpp_test.cpp ;
compile error_info_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 ;
compile to_string_stub_hpp_test.cpp ;
compile all_hpp_test.cpp ;
compile current_exception_cast_hpp_test.cpp ;
compile errinfo_api_function_hpp_test.cpp ;
compile errinfo_at_line_hpp_test.cpp ;
compile errinfo_errno_hpp_test.cpp ;
compile errinfo_file_handle_hpp_test.cpp ;
compile errinfo_file_name_hpp_test.cpp ;
compile errinfo_file_open_mode_hpp_test.cpp ;
compile errinfo_nested_exception_hpp_test.cpp ;
compile errinfo_type_info_name_hpp_test.cpp ;

View File

@@ -0,0 +1,7 @@
//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/all.hpp>
#include <boost/exception/all.hpp>

View File

@@ -0,0 +1,607 @@
//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/config.hpp>
#if defined( BOOST_NO_EXCEPTIONS )
# error This program requires exception handling.
#endif
#include <boost/exception_ptr.hpp>
#include <boost/exception/get_error_info.hpp>
#include <boost/exception/errinfo_nested_exception.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/detail/workaround.hpp>
#include <string>
#include <ios>
typedef boost::error_info<struct my_tag,int> my_info;
template <class T>
struct
may_throw_on_copy
{
may_throw_on_copy():
throw_(false)
{
}
may_throw_on_copy( may_throw_on_copy const & x ):
throw_(x.throw_)
{
if( throw_ )
throw T();
}
bool throw_;
};
struct
derives_nothing
{
int & count;
explicit
derives_nothing( int & c ):
count(c)
{
++count;
}
derives_nothing( derives_nothing const & x ):
count(x.count)
{
++count;
}
~derives_nothing()
{
--count;
}
};
struct
derives_std_exception:
std::exception
{
};
struct
derives_std_boost_exception:
std::exception,
boost::exception
{
char const * const wh_;
derives_std_boost_exception( char const * wh="derives_std_boost_exception" ):
wh_(wh)
{
}
char const * what() const BOOST_NOEXCEPT_OR_NOTHROW
{
return wh_;
}
};
struct
derives_boost_exception:
boost::exception
{
};
template <class T>
void
test_std_exception()
{
try
{
throw T();
}
catch(
... )
{
boost::exception_ptr p = boost::current_exception();
BOOST_TEST(!(p==boost::exception_ptr()));
BOOST_TEST(p!=boost::exception_ptr());
BOOST_TEST(p);
try
{
rethrow_exception(p);
BOOST_TEST(false);
}
catch(
T & )
{
boost::exception_ptr p = boost::current_exception();
BOOST_TEST(!(p==boost::exception_ptr()));
BOOST_TEST(p!=boost::exception_ptr());
BOOST_TEST(p);
try
{
rethrow_exception(p);
BOOST_TEST(false);
}
catch(
T & )
{
}
catch(
... )
{
BOOST_TEST(false);
}
}
catch(
... )
{
BOOST_TEST(false);
}
try
{
rethrow_exception(p);
BOOST_TEST(false);
}
catch(
boost::exception & x )
{
#ifndef BOOST_NO_RTTI
std::type_info const * const * t=boost::get_error_info<boost::original_exception_type>(x);
BOOST_TEST(t!=0 && *t!=0 && **t==typeid(T));
std::string s=diagnostic_information(x);
BOOST_TEST(!s.empty());
#endif
}
catch(
T & )
{
}
catch(
... )
{
BOOST_TEST(false);
}
}
}
template <class T>
void
test_std_exception_what()
{
try
{
throw T("what");
}
catch(
... )
{
boost::exception_ptr p = boost::current_exception();
BOOST_TEST(!(p==boost::exception_ptr()));
BOOST_TEST(p!=boost::exception_ptr());
BOOST_TEST(p);
try
{
rethrow_exception(p);
BOOST_TEST(false);
}
catch(
T & x )
{
BOOST_TEST(std::string(x.what()).find("what")!=std::string::npos);
boost::exception_ptr p = boost::current_exception();
BOOST_TEST(!(p==boost::exception_ptr()));
BOOST_TEST(p!=boost::exception_ptr());
BOOST_TEST(p);
try
{
rethrow_exception(p);
BOOST_TEST(false);
}
catch(
T & x )
{
BOOST_TEST(std::string(x.what()).find("what")!=std::string::npos);
}
catch(
... )
{
BOOST_TEST(false);
}
}
catch(
... )
{
BOOST_TEST(false);
}
try
{
rethrow_exception(p);
BOOST_TEST(false);
}
catch(
boost::exception & x )
{
#ifndef BOOST_NO_RTTI
std::type_info const * const * t=boost::get_error_info<boost::original_exception_type>(x);
BOOST_TEST(t!=0 && *t!=0 && **t==typeid(T));
#endif
}
catch(
T & )
{
}
catch(
... )
{
BOOST_TEST(false);
}
}
}
template <class Throw,class Catch>
void
test_throw_on_copy()
{
try
{
try
{
throw boost::enable_current_exception(may_throw_on_copy<Throw>());
}
catch(
may_throw_on_copy<Throw> & x )
{
x.throw_=true;
throw;
}
catch(
... )
{
BOOST_TEST(false);
}
}
catch(
... )
{
boost::exception_ptr p = boost::current_exception();
BOOST_TEST(!(p==boost::exception_ptr()));
BOOST_TEST(p!=boost::exception_ptr());
BOOST_TEST(p);
try
{
rethrow_exception(p);
BOOST_TEST(false);
}
catch(
Catch & )
{
boost::exception_ptr p = boost::current_exception();
BOOST_TEST(!(p==boost::exception_ptr()));
BOOST_TEST(p!=boost::exception_ptr());
BOOST_TEST(p);
try
{
boost::rethrow_exception(p);
BOOST_TEST(false);
}
catch(
Catch & )
{
}
catch(
... )
{
BOOST_TEST(false);
}
}
catch(
... )
{
BOOST_TEST(false);
}
}
}
int
main()
{
BOOST_TEST( boost::exception_ptr()==boost::exception_ptr() );
BOOST_TEST( !(boost::exception_ptr()!=boost::exception_ptr()) );
BOOST_TEST( !boost::exception_ptr() );
int count=0;
try
{
throw boost::enable_current_exception(derives_nothing(count));
}
catch(
... )
{
boost::exception_ptr p = boost::current_exception();
BOOST_TEST(!(p==boost::exception_ptr()));
BOOST_TEST(p!=boost::exception_ptr());
BOOST_TEST(p);
try
{
rethrow_exception(p);
BOOST_TEST(false);
}
catch(
derives_nothing & )
{
}
catch(
... )
{
BOOST_TEST(false);
}
}
BOOST_TEST(count==0);
try
{
throw boost::enable_current_exception(derives_std_exception());
}
catch(
... )
{
boost::exception_ptr p = boost::current_exception();
BOOST_TEST(!(p==boost::exception_ptr()));
BOOST_TEST(p!=boost::exception_ptr());
BOOST_TEST(p);
try
{
rethrow_exception(p);
BOOST_TEST(false);
}
catch(
derives_std_exception & )
{
boost::exception_ptr p = boost::current_exception();
BOOST_TEST(!(p==boost::exception_ptr()));
BOOST_TEST(p!=boost::exception_ptr());
BOOST_TEST(p);
try
{
rethrow_exception(p);
BOOST_TEST(false);
}
catch(
derives_std_exception & )
{
}
catch(
... )
{
BOOST_TEST(false);
}
}
catch(
... )
{
BOOST_TEST(false);
}
}
try
{
throw derives_std_exception();
}
catch(
... )
{
boost::exception_ptr p = boost::current_exception();
BOOST_TEST(!(p==boost::exception_ptr()));
BOOST_TEST(p!=boost::exception_ptr());
BOOST_TEST(p);
try
{
rethrow_exception(p);
BOOST_TEST(false);
}
catch(
derives_std_exception & )
{
//Yay! Non-intrusive cloning supported!
}
catch(
boost::unknown_exception & e )
{
#ifndef BOOST_NO_RTTI
std::type_info const * const * t=boost::get_error_info<boost::original_exception_type>(e);
BOOST_TEST(t!=0 && *t!=0 && **t==typeid(derives_std_exception));
#endif
}
catch(
... )
{
BOOST_TEST(false);
}
}
test_std_exception_what<std::domain_error>();
test_std_exception_what<std::invalid_argument>();
test_std_exception_what<std::length_error>();
test_std_exception_what<std::out_of_range>();
test_std_exception_what<std::logic_error>();
test_std_exception_what<std::range_error>();
test_std_exception_what<std::overflow_error>();
test_std_exception_what<std::underflow_error>();
#if !defined(_GLIBCXX_USE_CXX11_ABI) || !_GLIBCXX_USE_CXX11_ABI
test_std_exception_what<std::ios_base::failure>();
#endif
test_std_exception_what<std::runtime_error>();
test_std_exception<std::bad_alloc>();
#ifndef BOOST_NO_TYPEID
test_std_exception<std::bad_cast>();
test_std_exception<std::bad_typeid>();
#endif
test_std_exception<std::bad_exception>();
test_std_exception<std::exception>();
try
{
throw derives_std_boost_exception() << my_info(42);
}
catch(
... )
{
boost::exception_ptr p = boost::current_exception();
BOOST_TEST(!(p==boost::exception_ptr()));
BOOST_TEST(p!=boost::exception_ptr());
BOOST_TEST(p);
try
{
rethrow_exception(p);
BOOST_TEST(false);
}
catch(
derives_std_boost_exception & x )
{
//Yay! Non-intrusive cloning supported!
BOOST_TEST(boost::get_error_info<my_info>(x));
if( int const * p=boost::get_error_info<my_info>(x) )
BOOST_TEST(*p==42);
}
catch(
boost::unknown_exception & x )
{
BOOST_TEST(boost::get_error_info<my_info>(x));
if( int const * p=boost::get_error_info<my_info>(x) )
BOOST_TEST(*p==42);
#ifndef BOOST_NO_RTTI
{
std::type_info const * const * t=boost::get_error_info<boost::original_exception_type>(x);
BOOST_TEST(t && *t && **t==typeid(derives_std_boost_exception));
}
#endif
boost::exception_ptr p = boost::current_exception();
BOOST_TEST(!(p==boost::exception_ptr()));
BOOST_TEST(p!=boost::exception_ptr());
BOOST_TEST(p);
try
{
rethrow_exception(p);
BOOST_TEST(false);
}
catch(
boost::unknown_exception & x )
{
BOOST_TEST(boost::get_error_info<my_info>(x));
if( int const * p=boost::get_error_info<my_info>(x) )
BOOST_TEST(*p==42);
#ifndef BOOST_NO_RTTI
std::type_info const * const * t=boost::get_error_info<boost::original_exception_type>(x);
BOOST_TEST(t && *t && **t==typeid(derives_std_boost_exception));
#endif
}
catch(
... )
{
BOOST_TEST(false);
}
}
catch(
... )
{
BOOST_TEST(false);
}
}
try
{
throw derives_boost_exception() << my_info(42);
}
catch(
... )
{
boost::exception_ptr p = boost::current_exception();
BOOST_TEST(!(p==boost::exception_ptr()));
BOOST_TEST(p!=boost::exception_ptr());
BOOST_TEST(p);
try
{
rethrow_exception(p);
BOOST_TEST(false);
}
catch(
derives_boost_exception & x )
{
//Yay! Non-intrusive cloning supported!
BOOST_TEST(boost::get_error_info<my_info>(x));
if( int const * p=boost::get_error_info<my_info>(x) )
BOOST_TEST(*p==42);
}
catch(
boost::unknown_exception & x )
{
BOOST_TEST(boost::get_error_info<my_info>(x));
if( int const * p=boost::get_error_info<my_info>(x) )
BOOST_TEST(*p==42);
#ifndef BOOST_NO_RTTI
{
std::type_info const * const * t=boost::get_error_info<boost::original_exception_type>(x);
BOOST_TEST(t && *t && **t==typeid(derives_boost_exception));
}
#endif
boost::exception_ptr p = boost::current_exception();
BOOST_TEST(!(p==boost::exception_ptr()));
BOOST_TEST(p!=boost::exception_ptr());
BOOST_TEST(p);
try
{
rethrow_exception(p);
BOOST_TEST(false);
}
catch(
boost::unknown_exception & x )
{
BOOST_TEST(boost::get_error_info<my_info>(x));
if( int const * p=boost::get_error_info<my_info>(x) )
BOOST_TEST(*p==42);
}
catch(
... )
{
BOOST_TEST(false);
}
}
catch(
... )
{
BOOST_TEST(false);
}
}
test_throw_on_copy<std::bad_alloc,std::bad_alloc>();
test_throw_on_copy<int,std::bad_exception>();
try
{
throw boost::enable_current_exception(derives_std_boost_exception("what1"));
}
catch(
... )
{
boost::exception_ptr p=boost::current_exception();
{
std::string s=diagnostic_information(p);
BOOST_TEST(s.find("what1")!=s.npos);
}
try
{
throw boost::enable_current_exception(derives_std_boost_exception("what2") << boost::errinfo_nested_exception(p) );
}
catch(
... )
{
std::string s=boost::current_exception_diagnostic_information();
BOOST_TEST(s.find("what1")!=s.npos);
BOOST_TEST(s.find("what2")!=s.npos);
}
}
BOOST_TEST(!diagnostic_information(boost::exception_ptr()).empty());
return boost::report_errors();
}

View File

@@ -0,0 +1,93 @@
//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)
#define BOOST_NORETURN
#include <boost/config.hpp>
#if !defined( BOOST_NO_EXCEPTIONS )
# error This program requires exception handling disabled.
#endif
#include <boost/exception_ptr.hpp>
#include <boost/exception/get_error_info.hpp>
#include <boost/detail/lightweight_test.hpp>
typedef boost::error_info<struct tag_answer,int> answer;
int exc_count;
struct
err:
virtual boost::exception,
virtual std::exception
{
err()
{
++exc_count;
}
err( err const & )
{
++exc_count;
}
virtual
~err() BOOST_NOEXCEPT_OR_NOTHROW
{
--exc_count;
}
private:
err & operator=( err const & );
};
namespace
{
bool throw_exception_called;
}
// It is not valid to return to the caller but we do for testing purposes.
namespace
boost
{
void
throw_exception( std::exception const & e )
{
throw_exception_called = true;
BOOST_TEST(dynamic_cast<err const *>(&e)!=0);
int const * ans=boost::get_error_info<answer>(e);
BOOST_TEST(ans && *ans==42);
}
struct source_location;
void
throw_exception( std::exception const & e, boost::source_location const & )
{
throw_exception_called = true;
BOOST_TEST(dynamic_cast<err const *>(&e)!=0);
int const * ans=boost::get_error_info<answer>(e);
BOOST_TEST(ans && *ans==42);
}
}
void
simple_test()
{
boost::exception_ptr p = boost::copy_exception(err() << answer(42));
throw_exception_called = false;
boost::exception_detail::rethrow_exception_(p);
BOOST_TEST(throw_exception_called);
}
int
main()
{
BOOST_TEST(++exc_count==1);
simple_test();
BOOST_TEST(!--exc_count);
return boost::report_errors();
}

View File

@@ -0,0 +1,155 @@
//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/config.hpp>
#if defined( BOOST_NO_EXCEPTIONS )
# error This program requires exception handling.
#endif
#include <boost/exception_ptr.hpp>
#include <boost/exception/get_error_info.hpp>
#include <boost/thread.hpp>
#include <boost/detail/atomic_count.hpp>
#include <boost/detail/lightweight_test.hpp>
typedef boost::error_info<struct tag_answer,int> answer;
int const thread_count = 100;
boost::detail::atomic_count exc_count(0);
struct
err:
virtual boost::exception,
virtual std::exception
{
err()
{
++exc_count;
}
err( err const & )
{
++exc_count;
}
virtual
~err() BOOST_NOEXCEPT_OR_NOTHROW
{
--exc_count;
}
private:
err & operator=( err const & );
};
class
future
{
public:
future():
ready_(false)
{
}
void
set_exception( boost::exception_ptr const & e )
{
boost::unique_lock<boost::mutex> lck(mux_);
exc_ = e;
ready_ = true;
cond_.notify_all();
}
void
get_exception() const
{
boost::unique_lock<boost::mutex> lck(mux_);
while( !ready_ )
cond_.wait(lck);
rethrow_exception(exc_);
}
private:
bool ready_;
boost::exception_ptr exc_;
mutable boost::mutex mux_;
mutable boost::condition_variable cond_;
};
void
producer( future & f )
{
f.set_exception(boost::copy_exception(err() << answer(42)));
}
void
consumer()
{
future f;
boost::thread thr(boost::bind(&producer, boost::ref(f)));
try
{
f.get_exception();
}
catch(
err & e )
{
int const * ans=boost::get_error_info<answer>(e);
BOOST_TEST(ans && *ans==42);
}
thr.join();
}
void
consume()
{
for( int i=0; i!=thread_count; ++i )
consumer();
}
void
thread_test()
{
boost::thread_group grp;
for( int i=0; i!=thread_count; ++i )
grp.create_thread(&consume);
grp.join_all();
}
void
simple_test()
{
boost::exception_ptr p = boost::copy_exception(err() << answer(42));
try
{
rethrow_exception(p);
BOOST_TEST(false);
}
catch(
err & )
{
}
catch(
... )
{
BOOST_TEST(false);
}
}
int
main()
{
BOOST_TEST(++exc_count==1);
simple_test();
thread_test();
BOOST_TEST(!--exc_count);
return boost::report_errors();
}

View File

@@ -0,0 +1,7 @@
//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/current_exception_cast.hpp>
#include <boost/exception/current_exception_cast.hpp>

View File

@@ -0,0 +1,53 @@
//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/config.hpp>
#if defined( BOOST_NO_EXCEPTIONS )
# error This program requires exception handling.
#endif
#include <boost/exception/current_exception_cast.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <exception>
class
my_exception:
public std::exception
{
};
class
polymorphic
{
virtual
~polymorphic()
{
}
};
int
main()
{
try
{
throw my_exception();
}
catch(
std::exception & e )
{
try
{
throw;
}
catch(
...)
{
BOOST_TEST(boost::current_exception_cast<std::exception>()==&e);
BOOST_TEST(!boost::current_exception_cast<polymorphic>());
}
}
return boost::report_errors();
}

View File

@@ -0,0 +1,7 @@
//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/diagnostic_information.hpp>
#include <boost/exception/diagnostic_information.hpp>

View File

@@ -0,0 +1,252 @@
//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/config.hpp>
#if defined( BOOST_NO_EXCEPTIONS )
# error This program requires exception handling.
#endif
#include <boost/exception/diagnostic_information.hpp>
#include <boost/exception/info.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/detail/workaround.hpp>
#if BOOST_WORKAROUND(BOOST_CODEGEARC, BOOST_TESTED_AT(0x610))
struct test_tag1 {};
struct test_tag2 {};
#endif
typedef boost::error_info<struct test_tag1,int> tagged_int1;
typedef boost::error_info<struct test_tag2,int> tagged_int2;
std::string
to_string( tagged_int2 const & x )
{
return '[' +boost::error_info_name(x) + "] = " + (x.value()==42 ? "fourty-two" : "bad value");
}
struct
error1:
std::exception,
boost::exception
{
char const *
what() const BOOST_NOEXCEPT_OR_NOTHROW
{
return "error1";
}
};
struct
error2:
boost::exception
{
};
struct
error3:
std::exception
{
char const *
what() const BOOST_NOEXCEPT_OR_NOTHROW
{
return "error3";
}
};
struct
error4:
std::exception,
boost::exception
{
char const *
what() const BOOST_NOEXCEPT_OR_NOTHROW
{
return diagnostic_information_what(*this);
}
};
void
test1( std::string const & di1, std::string const & di2 )
{
BOOST_TEST( di1!=di2 );
#ifndef BOOST_NO_RTTI
BOOST_TEST(di1.find("type:")!=std::string::npos);
BOOST_TEST(di1.find("error1")!=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);
BOOST_TEST(di2.find("error1")!=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);
}
void
test2( std::string const & di1, std::string const & di2 )
{
BOOST_TEST( di1!=di2 );
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);
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);
}
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()
{
using namespace boost;
try
{
error1 x; x << tagged_int1(42) << tagged_int2(42);
BOOST_TEST(x.what()==std::string("error1"));
throw x;
}
catch(
error1 & x )
{
std::string di1=boost::diagnostic_information(x);
x << tagged_int1(2) << tagged_int2(2);
std::string di2 = diagnostic_information(x);
test1(di1,di2);
}
try
{
error1 x; x << tagged_int1(42) << tagged_int2(42);
BOOST_TEST(x.what()==std::string("error1"));
throw x;
}
catch(
error1 & x )
{
std::string di1=boost::current_exception_diagnostic_information();
x << tagged_int1(2) << tagged_int2(2);
std::string di2 = current_exception_diagnostic_information();
test1(di1,di2);
}
try
{
error2 x;
x << tagged_int1(42) << tagged_int2(42);
throw x;
}
catch(
error2 & x )
{
std::string di1 = diagnostic_information(x);
x << tagged_int1(2) << tagged_int2(2);
std::string di2 = diagnostic_information(x);
test2(di1,di2);
}
try
{
error2 x;
x << tagged_int1(42) << tagged_int2(42);
throw x;
}
catch(
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
{
throw error4();
}
catch(
error4 & x )
{
std::string di1=boost::diagnostic_information(x);
std::string wh1=x.what();
BOOST_TEST(wh1==di1);
}
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

@@ -0,0 +1,82 @@
//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/config.hpp>
#if defined( BOOST_NO_EXCEPTIONS )
# error This program requires exception handling.
#endif
#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>
namespace
{
typedef boost::error_info<struct tag_test_int,int> test_int;
void
throw_wrapper()
{
try
{
boost::exception_test::throw_length_error();
}
catch(
boost::exception & x )
{
x << test_int(42);
throw;
}
catch(
... )
{
BOOST_TEST(false);
}
}
}
int
main()
{
try
{
throw_wrapper();
BOOST_TEST(false);
}
catch(
std::exception & x )
{
#ifdef BOOST_NO_RTTI
try
{
throw;
}
catch(
boost::exception & x )
{
#endif
BOOST_TEST( boost::get_error_info<test_int>(x) );
if( int const * p=boost::get_error_info<test_int>(x) )
BOOST_TEST( 42==*p );
#ifdef BOOST_NO_RTTI
}
catch(
... )
{
BOOST_TEST(false);
}
#endif
BOOST_TEST( std::string(x.what())==std::string("exception test length error") );
}
catch(
... )
{
BOOST_TEST(false);
}
return boost::report_errors();
}

View File

@@ -0,0 +1,7 @@
//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/errinfo_api_function.hpp>
#include <boost/exception/errinfo_api_function.hpp>

View File

@@ -0,0 +1,7 @@
//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/errinfo_at_line.hpp>
#include <boost/exception/errinfo_at_line.hpp>

View File

@@ -0,0 +1,7 @@
//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/errinfo_errno.hpp>
#include <boost/exception/errinfo_errno.hpp>

View File

@@ -0,0 +1,7 @@
//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/errinfo_file_handle.hpp>
#include <boost/exception/errinfo_file_handle.hpp>

View File

@@ -0,0 +1,7 @@
//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/errinfo_file_name.hpp>
#include <boost/exception/errinfo_file_name.hpp>

View File

@@ -0,0 +1,7 @@
//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/errinfo_file_open_mode.hpp>
#include <boost/exception/errinfo_file_open_mode.hpp>

View File

@@ -0,0 +1,7 @@
//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/errinfo_file_name.hpp>
#include <boost/exception/errinfo_file_name.hpp>

View File

@@ -0,0 +1,7 @@
//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/errinfo_type_info_name.hpp>
#include <boost/exception/errinfo_type_info_name.hpp>

View File

@@ -0,0 +1,73 @@
//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/config.hpp>
#if defined( BOOST_NO_EXCEPTIONS )
# error This program requires exception handling.
#endif
#include <boost/exception/errinfo_api_function.hpp>
#include <boost/exception/errinfo_at_line.hpp>
#include <boost/exception/errinfo_errno.hpp>
#include <boost/exception/errinfo_file_handle.hpp>
#include <boost/exception/errinfo_file_name.hpp>
#include <boost/exception/errinfo_file_open_mode.hpp>
#include <boost/exception/errinfo_type_info_name.hpp>
#include <boost/exception/info.hpp>
#include <boost/exception/get_error_info.hpp>
#include <boost/throw_exception.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <exception>
struct
test_exception:
virtual boost::exception,
virtual std::exception
{
};
int
main()
{
using namespace boost;
try
{
test_exception e;
e <<
errinfo_api_function("failed_api_function") <<
errinfo_at_line(42) <<
errinfo_errno(0) <<
errinfo_file_handle(weak_ptr<FILE>()) <<
errinfo_file_name("filename.txt") <<
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_ERROR("BOOST_THROW_EXCEPTION failed to throw.");
}
catch(
boost::exception & e )
{
BOOST_TEST(get_error_info<errinfo_api_function>(e) && *get_error_info<errinfo_api_function>(e)==std::string("failed_api_function"));
BOOST_TEST(get_error_info<errinfo_at_line>(e) && *get_error_info<errinfo_at_line>(e)==42);
BOOST_TEST(get_error_info<errinfo_errno>(e) && *get_error_info<errinfo_errno>(e)==0);
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(
... )
{
BOOST_TEST(false);
}
return boost::report_errors();
}

View File

@@ -0,0 +1,40 @@
//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/config.hpp>
#if defined( BOOST_NO_EXCEPTIONS )
# error This program requires exception handling.
#endif
#include <boost/exception/get_error_info.hpp>
#include <boost/exception/info.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/detail/workaround.hpp>
#include <errno.h>
typedef boost::error_info<struct tag_errno,int> info_errno;
class
my_exception:
public boost::exception
{
};
int
main()
{
try
{
errno=1;
throw my_exception() << info_errno(errno);
}
catch(
my_exception & x )
{
BOOST_TEST(1==*boost::get_error_info<info_errno>(x));
}
return boost::report_errors();
}

View File

@@ -0,0 +1,35 @@
//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/config.hpp>
#if defined( BOOST_NO_EXCEPTIONS )
# error This program requires exception handling.
#endif
#include <boost/exception/error_info.hpp>
#include <boost/exception/exception.hpp>
#include <boost/exception/info.hpp>
#include <boost/exception/get_error_info.hpp>
#include <boost/core/lightweight_test.hpp>
#include <string>
#include <string.h>
struct my_exception: virtual boost::exception {};
typedef boost::error_info<struct error_info_string_, std::string> error_info_string;
int
main()
{
try
{
throw my_exception() << error_info_string("doh");
}
catch( my_exception & e )
{
BOOST_TEST(boost::get_error_info<error_info_string>(e) && !strcmp(boost::get_error_info<error_info_string>(e)->c_str(),"doh"));
}
return boost::report_errors();
}

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

@@ -0,0 +1,7 @@
//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/error_info.hpp>
#include <boost/exception/error_info.hpp>

View File

@@ -0,0 +1,13 @@
//Copyright (c) 2006-2015 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/info.hpp>
template <class E,class I>
E const &
add_info( E const & e, I const & i )
{
return e << i;
}
#include "error_info_test.hpp"

View File

@@ -0,0 +1,13 @@
//Copyright (c) 2006-2015 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/info.hpp>
template <class E,class I>
E const &
add_info( E const & e, I i )
{
return e << i;
}
#include "error_info_test.hpp"

View File

@@ -0,0 +1,28 @@
//Copyright (c) 2006-2015 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/info.hpp>
#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
int
main()
{
return 0;
}
#else
template <class I>
I const
rv_const( I i )
{
return i;
}
template <class E,class I>
E const &
add_info( E const & e, I i )
{
return e << rv_const(i);
}
#include "error_info_test.hpp"
#endif

View File

@@ -0,0 +1,22 @@
//Copyright (c) 2006-2015 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/info.hpp>
#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
int
main()
{
return 0;
}
#else
template <class E,class I>
E const &
add_info( E const & e, I i )
{
return e << std::move(i);
}
#include "error_info_test.hpp"
#endif

View File

@@ -0,0 +1,410 @@
//Copyright (c) 2006-2015 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/config.hpp>
#if defined( BOOST_NO_EXCEPTIONS )
# error This program requires exception handling.
#endif
#include <boost/exception/get_error_info.hpp>
#include <boost/exception/info_tuple.hpp>
#include <boost/exception_ptr.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/detail/workaround.hpp>
struct throws_on_copy;
struct non_printable { };
struct
user_data
{
int & count;
explicit
user_data( int & count ):
count(count)
{
++count;
}
user_data( user_data const & x ):
count(x.count)
{
++count;
}
~user_data()
{
--count;
}
};
typedef boost::error_info<struct tag_test_1,int> test_1;
typedef boost::error_info<struct tag_test_2,unsigned int> test_2;
typedef boost::error_info<struct tag_test_3,float> test_3;
typedef boost::error_info<struct tag_test_4,throws_on_copy> test_4;
typedef boost::error_info<struct tag_test_5,std::string> test_5;
typedef boost::error_info<struct tag_test_6,non_printable> test_6;
typedef boost::error_info<struct tag_user_data,user_data> test_7;
struct
test_exception:
boost::exception
{
};
struct
throws_on_copy
{
throws_on_copy()
{
}
throws_on_copy( throws_on_copy const & )
{
throw test_exception();
}
};
void
basic_test()
{
try
{
test_exception x;
add_info(add_info(add_info(x,test_1(1)),test_2(2u)),test_3(3.14159f));
throw x;
}
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;
add_info(add_info(add_info(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);
BOOST_TEST(*boost::get_error_info<test_3>(x)==3.14159f);
BOOST_TEST(!boost::get_error_info<test_4>(x));
}
}
void
exception_safety_test()
{
test_exception x;
try
{
add_info(x,test_4(throws_on_copy()));
BOOST_TEST(false);
}
catch(
test_exception & )
{
BOOST_TEST(!boost::get_error_info<test_4>(x));
}
}
void
throw_empty()
{
throw test_exception();
}
void
throw_test_1( char const * value )
{
throw add_info(test_exception(),test_5(std::string(value)));
}
void
throw_test_2()
{
throw add_info(test_exception(),test_6(non_printable()));
}
void
throw_catch_add_file_name( char const * name )
{
try
{
throw_empty();
BOOST_TEST(false);
}
catch(
boost::exception & x )
{
add_info(x,test_5(std::string(name)));
throw;
}
}
void
test_empty()
{
try
{
throw_empty();
BOOST_TEST(false);
}
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(
... )
{
BOOST_TEST(false);
}
try
{
throw_empty();
BOOST_TEST(false);
}
catch(
test_exception & x )
{
#ifndef BOOST_NO_RTTI
BOOST_TEST( dynamic_cast<boost::exception const *>(&x)!=0 );
#endif
}
catch(
... )
{
BOOST_TEST(false);
}
}
void
test_basic_throw_catch()
{
try
{
throw_test_1("test");
BOOST_ASSERT(false);
}
catch(
boost::exception & x )
{
BOOST_TEST(*boost::get_error_info<test_5>(x)==std::string("test"));
}
catch(
... )
{
BOOST_TEST(false);
}
try
{
throw_test_2();
BOOST_ASSERT(false);
}
catch(
boost::exception & x )
{
BOOST_TEST(boost::get_error_info<test_6>(x));
}
catch(
... )
{
BOOST_TEST(false);
}
}
void
test_catch_add_info()
{
try
{
throw_catch_add_file_name("test");
BOOST_TEST(false);
}
catch(
boost::exception & x )
{
BOOST_TEST(*boost::get_error_info<test_5>(x)==std::string("test"));
}
catch(
... )
{
BOOST_TEST(false);
}
}
void
test_add_tuple()
{
typedef boost::tuple<> tuple_test_;
typedef boost::tuple<test_1> tuple_test_1;
typedef boost::tuple<test_1,test_2> tuple_test_12;
typedef boost::tuple<test_1,test_2,test_3> tuple_test_123;
typedef boost::tuple<test_1,test_2,test_3,test_5> tuple_test_1235;
try
{
throw add_info(test_exception(),tuple_test_());
}
catch(
test_exception & )
{
}
catch(
... )
{
BOOST_TEST(false);
}
try
{
throw add_info(test_exception(),tuple_test_1(42));
}
catch(
test_exception & x )
{
BOOST_TEST( *boost::get_error_info<test_1>(x)==42 );
}
catch(
... )
{
BOOST_TEST(false);
}
try
{
throw add_info(test_exception(),tuple_test_12(42,42u));
}
catch(
test_exception & x )
{
BOOST_TEST( *boost::get_error_info<test_1>(x)==42 );
BOOST_TEST( *boost::get_error_info<test_2>(x)==42u );
}
catch(
... )
{
BOOST_TEST(false);
}
try
{
throw add_info(test_exception(),tuple_test_123(42,42u,42.0f));
}
catch(
test_exception & x )
{
BOOST_TEST( *boost::get_error_info<test_1>(x)==42 );
BOOST_TEST( *boost::get_error_info<test_2>(x)==42u );
BOOST_TEST( *boost::get_error_info<test_3>(x)==42.0f );
}
catch(
... )
{
BOOST_TEST(false);
}
try
{
throw add_info(test_exception(),tuple_test_1235(42,42u,42.0f,std::string("42")));
}
catch(
test_exception & x )
{
BOOST_TEST( *boost::get_error_info<test_1>(x)==42 );
BOOST_TEST( *boost::get_error_info<test_2>(x)==42u );
BOOST_TEST( *boost::get_error_info<test_3>(x)==42.0f );
BOOST_TEST( *boost::get_error_info<test_5>(x)=="42" );
}
catch(
... )
{
BOOST_TEST(false);
}
}
void
test_lifetime1()
{
int count=0;
try
{
throw add_info(test_exception(),test_7(user_data(count)));
}
catch(
boost::exception & x )
{
BOOST_TEST(count==1);
BOOST_TEST( boost::get_error_info<test_7>(x) );
}
catch(
... )
{
BOOST_TEST(false);
}
BOOST_TEST(!count);
}
void
test_lifetime2()
{
int count=0;
{
boost::exception_ptr ep;
test_exception e; add_info(e,test_7(user_data(count)));
ep=boost::copy_exception(e);
BOOST_TEST(count>0);
}
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()
{
basic_test();
exception_safety_test();
test_empty();
test_basic_throw_catch();
test_catch_add_info();
test_add_tuple();
test_lifetime1();
test_lifetime2();
test_const();
return boost::report_errors();
}

View File

@@ -0,0 +1,12 @@
//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/exception.hpp>
void
tester( boost::exception & x )
{
throw x; //must not compile.
}

View File

@@ -0,0 +1,7 @@
//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_ptr.hpp>
#include <boost/exception_ptr.hpp>

View File

@@ -0,0 +1,184 @@
//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/config.hpp>
#if defined( BOOST_NO_EXCEPTIONS )
# error This program requires exception handling.
#endif
#include <boost/exception_ptr.hpp>
#include <boost/exception/info.hpp>
#include <boost/exception/get_error_info.hpp>
#include <boost/exception/diagnostic_information.hpp>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/thread.hpp>
#include <boost/detail/atomic_count.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <iostream>
class thread_handle;
boost::shared_ptr<thread_handle> create_thread( boost::function<void()> const & f );
void join( thread_handle & t );
class
thread_handle
{
thread_handle( thread_handle const & );
thread_handle & operator=( thread_handle const & );
boost::exception_ptr err_;
boost::thread t_;
static
void
thread_wrapper( boost::function<void()> const & f, boost::exception_ptr & ep )
{
BOOST_ASSERT(!ep);
try
{
f();
}
catch(...)
{
ep = boost::current_exception();
}
}
explicit
thread_handle( boost::function<void()> const & f ):
t_(boost::bind(thread_wrapper,f,boost::ref(err_)))
{
}
friend boost::shared_ptr<thread_handle> create_thread( boost::function<void()> const & f );
friend void join( thread_handle & t );
};
boost::shared_ptr<thread_handle>
create_thread( boost::function<void()> const & f )
{
boost::shared_ptr<thread_handle> t( new thread_handle(f) );
return t;
}
void
join( thread_handle & t )
{
t.t_.join();
assert(t.err_);
rethrow_exception(t.err_);
}
boost::detail::atomic_count exc_count(0);
struct
exc:
virtual boost::exception,
virtual std::exception
{
exc()
{
++exc_count;
}
exc( exc const & e ):
boost::exception(e),
std::exception(e)
{
++exc_count;
}
virtual
~exc() BOOST_NOEXCEPT_OR_NOTHROW
{
--exc_count;
}
private:
exc & operator=( exc const & );
};
typedef boost::error_info<struct answer_,int> answer;
void
thread_func()
{
BOOST_THROW_EXCEPTION(exc() << answer(42));
}
void
check( boost::shared_ptr<thread_handle> const & t )
{
try
{
join(*t);
BOOST_TEST(false);
}
catch(
exc & e )
{
int const * a = boost::get_error_info<answer>(e);
BOOST_TEST(a && *a==42);
}
}
void
test_deep_copy()
{
int const * p1=0;
boost::exception_ptr p;
try
{
BOOST_THROW_EXCEPTION(exc() << answer(42));
BOOST_ERROR("BOOST_THROW_EXCEPTION didn't throw");
}
catch(
exc & e )
{
p1=boost::get_error_info<answer>(e);
p=boost::current_exception();
}
BOOST_TEST(p1!=0);
BOOST_TEST(p);
try
{
boost::rethrow_exception(p);
BOOST_ERROR("rethrow_exception didn't throw");
}
catch(
exc & e )
{
int const * p2=boost::get_error_info<answer>(e);
BOOST_TEST(p2!=0 && *p2==42);
BOOST_TEST(p2!=p1);
}
}
int
main()
{
test_deep_copy();
BOOST_TEST(++exc_count==1);
try
{
std::vector< boost::shared_ptr<thread_handle> > threads;
std::generate_n(std::inserter(threads,threads.end()),1,boost::bind(create_thread,thread_func));
std::for_each(threads.begin(),threads.end(),check);
return boost::report_errors();
}
catch(
... )
{
std::cerr <<
"Caught unexpected exception.\n"
"Output from current_exception_diagnostic_information:\n" <<
boost::current_exception_diagnostic_information() << std::endl;
return 42;
}
BOOST_TEST(!--exc_count);
}

View File

@@ -0,0 +1,41 @@
//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/config.hpp>
#if defined( BOOST_NO_EXCEPTIONS )
# error This program requires exception handling.
#endif
#include <boost/exception/exception.hpp>
#include <boost/detail/lightweight_test.hpp>
class
test_exception:
public boost::exception
{
};
void
test_throw()
{
throw test_exception();
}
int
main()
{
try
{
test_throw();
BOOST_TEST(false);
}
catch(
test_exception & )
{
BOOST_TEST(true);
}
return boost::report_errors();
}

View File

@@ -0,0 +1,7 @@
//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>
#include <boost/exception/get_error_info.hpp>

View File

@@ -0,0 +1,57 @@
//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/to_string.hpp>
#include <boost/detail/lightweight_test.hpp>
namespace
n1
{
struct
c1
{
};
}
namespace
n2
{
struct
c2
{
};
std::string
to_string( c2 const & )
{
return "c2";
}
}
namespace
n3
{
struct
c3
{
};
std::ostream &
operator<<( std::ostream & s, c3 const & )
{
return s << "c3";
}
}
int
main()
{
using namespace boost;
BOOST_TEST( !has_to_string<n1::c1>::value );
BOOST_TEST( has_to_string<n2::c2>::value );
BOOST_TEST( has_to_string<n3::c3>::value );
BOOST_TEST( has_to_string<int>::value );
return boost::report_errors();
}

View File

@@ -0,0 +1,28 @@
//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/config.hpp>
#if defined( BOOST_NO_EXCEPTIONS )
# error This program requires exception handling.
#endif
#include <boost/exception/exception.hpp>
#include <stdexcept>
#include <string>
namespace
boost
{
namespace
exception_test
{
void
throw_length_error()
{
throw enable_error_info( std::length_error("exception test length error") );
}
}
}

View File

@@ -0,0 +1,19 @@
//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)
#ifndef BOOST_EXCEPTION_4AEB7924CA2E11DC888A8C9355D89593
#define BOOST_EXCEPTION_4AEB7924CA2E11DC888A8C9355D89593
namespace
boost
{
namespace
exception_test
{
void throw_length_error();
}
}
#endif

View File

@@ -0,0 +1,78 @@
//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/config.hpp>
#if defined( BOOST_NO_EXCEPTIONS )
# error This program requires exception handling.
#endif
#include "helper2.hpp"
#include <boost/throw_exception.hpp>
namespace
boost
{
namespace
exception_test
{
inline
derives_boost_exception::
derives_boost_exception( int x ):
x_(x)
{
}
derives_boost_exception::
~derives_boost_exception() BOOST_NOEXCEPT_OR_NOTHROW
{
}
inline
derives_boost_exception_virtually::
derives_boost_exception_virtually( int x ):
x_(x)
{
}
derives_boost_exception_virtually::
~derives_boost_exception_virtually() BOOST_NOEXCEPT_OR_NOTHROW
{
}
inline
derives_std_exception::
derives_std_exception( int x ):
x_(x)
{
}
derives_std_exception::
~derives_std_exception() BOOST_NOEXCEPT_OR_NOTHROW
{
}
template <>
void
throw_test_exception<derives_boost_exception>( int x )
{
boost::throw_exception( derives_boost_exception(x) );
}
template <>
void
throw_test_exception<derives_boost_exception_virtually>( int x )
{
boost::throw_exception( derives_boost_exception_virtually(x) );
}
template <>
void
throw_test_exception<derives_std_exception>( int x )
{
boost::throw_exception( derives_std_exception(x) );
}
}
}

View File

@@ -0,0 +1,61 @@
//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)
#ifndef BOOST_EXCEPTION_BC765EB4CA2A11DCBDC5828355D89593
#define BOOST_EXCEPTION_BC765EB4CA2A11DCBDC5828355D89593
#include <boost/exception/exception.hpp>
#include <exception>
namespace
boost
{
namespace
exception_test
{
struct
derives_boost_exception:
public boost::exception,
public std::exception
{
explicit derives_boost_exception( int x );
virtual ~derives_boost_exception() BOOST_NOEXCEPT_OR_NOTHROW;
int x_;
};
struct
derives_boost_exception_virtually:
public virtual boost::exception,
public std::exception
{
explicit derives_boost_exception_virtually( int x );
virtual ~derives_boost_exception_virtually() BOOST_NOEXCEPT_OR_NOTHROW;
int x_;
};
struct
derives_std_exception:
public std::exception
{
explicit derives_std_exception( int x );
virtual ~derives_std_exception() BOOST_NOEXCEPT_OR_NOTHROW;
int x_;
};
template <class>
void throw_test_exception( int );
template <>
void throw_test_exception<derives_boost_exception>( int );
template <>
void throw_test_exception<derives_boost_exception_virtually>( int );
template <>
void throw_test_exception<derives_std_exception>( int );
}
}
#endif

View File

@@ -0,0 +1,7 @@
//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/info.hpp>
#include <boost/exception/info.hpp>

View File

@@ -0,0 +1,7 @@
//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/info_tuple.hpp>
#include <boost/exception/info_tuple.hpp>

View File

@@ -0,0 +1,49 @@
//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/detail/is_output_streamable.hpp>
namespace
n1
{
class
c1
{
};
}
namespace
n2
{
class
c2
{
};
std::ostream &
operator<<( std::ostream & s, c2 const & )
{
s << "c2";
return s;
}
}
template <bool Test>
struct test;
template <>
struct
test<true>
{
};
int
main()
{
test<!boost::is_output_streamable<n1::c1>::value>();
test<boost::is_output_streamable<n2::c2>::value>();
test<boost::is_output_streamable<int>::value>();
return 0;
}

View File

@@ -0,0 +1,61 @@
//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/config.hpp>
#if !defined( BOOST_NO_EXCEPTIONS )
# error This program requires exception handling disabled.
#endif
#include <boost/throw_exception.hpp>
#include <boost/exception/info.hpp>
#include <boost/exception/diagnostic_information.hpp>
#include <boost/core/lightweight_test.hpp>
#include <stdlib.h>
struct
my_exception:
boost::exception,
std::exception
{
char const *
what() const BOOST_NOEXCEPT_OR_NOTHROW
{
return "my_exception";
}
};
typedef boost::error_info<struct my_tag,int> my_int;
bool called=false;
namespace
boost
{
void
throw_exception( std::exception const & x )
{
called=true;
std::string s=boost::diagnostic_information(x);
std::cout << s;
#ifndef BOOST_NO_RTTI
BOOST_TEST(s.find("my_tag")!=std::string::npos);
#endif
exit(boost::report_errors());
}
void
throw_exception(std::exception const & x, boost::source_location const &)
{
throw_exception(x);
}
}
int
main()
{
BOOST_THROW_EXCEPTION( my_exception() << my_int(42) );
BOOST_TEST(called);
return boost::report_errors();
}

View File

@@ -0,0 +1,108 @@
//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/exception.hpp>
#include <boost/detail/lightweight_test.hpp>
struct
test_type
{
test_type( int & count ):
count_(count)
{
BOOST_TEST(count_==42);
count_=0;
}
~test_type()
{
BOOST_TEST(!count_);
count_=42;
}
void
add_ref()
{
++count_;
}
bool
release()
{
if( --count_ )
return false;
else
{
delete this;
return true;
}
}
private:
test_type( test_type const & );
test_type & operator=( test_type const & );
int & count_;
};
int
main()
{
using boost::exception_detail::refcount_ptr;
{
refcount_ptr<test_type> x;
BOOST_TEST(!x.get());
}
{
int count=42;
test_type * a=new test_type(count);
BOOST_TEST(!count);
{
refcount_ptr<test_type> p;
BOOST_TEST(0==count);
p.adopt(a);
BOOST_TEST(p.get()==a);
BOOST_TEST(1==count);
{
refcount_ptr<test_type> q;
q.adopt(p.get());
BOOST_TEST(q.get()==a);
BOOST_TEST(2==count);
{
refcount_ptr<test_type> t(p);
BOOST_TEST(t.get()==a);
BOOST_TEST(3==count);
{
refcount_ptr<test_type> n;
n=t;
BOOST_TEST(n.get()==a);
BOOST_TEST(4==count);
int cb=42;
test_type * b=new test_type(cb);
BOOST_TEST(0==cb);
n.adopt(b);
BOOST_TEST(1==cb);
BOOST_TEST(n.get()==b);
BOOST_TEST(3==count);
n.adopt(0);
BOOST_TEST(42==cb);
}
BOOST_TEST(t.get()==a);
BOOST_TEST(3==count);
}
BOOST_TEST(q.get()==a);
BOOST_TEST(2==count);
}
BOOST_TEST(p.get()==a);
BOOST_TEST(1==count);
}
BOOST_TEST(42==count);
}
return boost::report_errors();
}

View File

@@ -0,0 +1,18 @@
//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/throw_exception.hpp>
struct
my_exception
{
};
void
tester()
{
//Must not compile, throw_exception requires exception types to derive std::exception.
boost::throw_exception(my_exception());
}

View File

@@ -0,0 +1,154 @@
//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/config.hpp>
#if defined( BOOST_NO_EXCEPTIONS )
# error This program requires exception handling.
#endif
#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>
typedef boost::error_info<struct tag_test_int,int> test_data;
struct
exception1:
std::exception
{
};
struct
exception2:
std::exception,
boost::exception
{
};
void
boost_throw_exception_test()
{
try
{
BOOST_THROW_EXCEPTION(exception1());
BOOST_ERROR("BOOST_THROW_EXCEPTION failed to throw.");
}
catch(
boost::exception & x )
{
char const * const * function=boost::get_error_info<boost::throw_function>(x);
char const * const * file=boost::get_error_info<boost::throw_file>(x);
int const * line=boost::get_error_info<boost::throw_line>(x);
BOOST_TEST( file && *file );
BOOST_TEST( function && *function );
BOOST_TEST( line && *line==38 );
}
catch(
... )
{
BOOST_TEST(false);
}
try
{
BOOST_THROW_EXCEPTION(exception2() << test_data(42));
BOOST_ERROR("BOOST_THROW_EXCEPTION failed to throw.");
}
catch(
boost::exception & x )
{
char const * const * function=boost::get_error_info<boost::throw_function>(x);
char const * const * file=boost::get_error_info<boost::throw_file>(x);
int const * line=boost::get_error_info<boost::throw_line>(x);
int const * data=boost::get_error_info<test_data>(x);
BOOST_TEST( file && *file );
BOOST_TEST( function && *function );
BOOST_TEST( line && *line==58 );
BOOST_TEST( data && *data==42 );
}
catch(
... )
{
BOOST_TEST(false);
}
}
void
throw_fwd( void (*thrower)(int) )
{
try
{
thrower(42);
}
catch(
boost::exception & x )
{
x << test_data(42);
throw;
}
}
template <class T>
void
tester()
{
try
{
throw_fwd( &boost::exception_test::throw_test_exception<T> );
BOOST_ASSERT(false);
}
catch(
... )
{
boost::exception_ptr p = boost::current_exception();
try
{
rethrow_exception(p);
BOOST_TEST(false);
}
catch(
T & y )
{
#ifdef BOOST_NO_RTTI
try
{
throw;
}
catch(
boost::exception & y )
{
#endif
BOOST_TEST(boost::get_error_info<test_data>(y));
if( int const * d=boost::get_error_info<test_data>(y) )
BOOST_TEST(*d==42);
#ifdef BOOST_NO_RTTI
}
catch(
... )
{
BOOST_TEST(false);
}
#endif
BOOST_TEST(y.x_==42);
}
catch(
... )
{
BOOST_TEST(false);
}
}
}
int
main()
{
boost_throw_exception_test();
tester<boost::exception_test::derives_boost_exception>();
tester<boost::exception_test::derives_boost_exception_virtually>();
tester<boost::exception_test::derives_std_exception>();
return boost::report_errors();
}

View File

@@ -0,0 +1,23 @@
//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/to_string.hpp>
namespace
n1
{
struct
c1
{
};
}
int
tester()
{
using namespace boost;
(void) to_string(n1::c1());
return 1;
}

View File

@@ -0,0 +1,7 @@
//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/to_string.hpp>
#include <boost/exception/to_string.hpp>

View File

@@ -0,0 +1,7 @@
//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/to_string_stub.hpp>
#include <boost/exception/to_string_stub.hpp>

View File

@@ -0,0 +1,98 @@
//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/to_string_stub.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <iostream>
namespace
n1
{
class
c1
{
};
std::string
to_string( c1 const & )
{
return "c1";
}
}
namespace
n2
{
class
c2
{
};
std::ostream &
operator<<( std::ostream & s, c2 const & )
{
s << "c2";
return s;
}
}
namespace
n3
{
class
c3
{
};
std::ostream &
operator<<( std::ostream & s, c3 const & )
{
s << "bad";
return s;
}
std::string
to_string( c3 const & )
{
return "c3";
}
}
namespace
boost
{
class
to_string_tester
{
};
}
template <class T>
struct
my_stub
{
std::string
operator()( T const & )
{
return "stub";
}
};
int
main()
{
using namespace boost;
BOOST_TEST( to_string(42)=="42" );
BOOST_TEST( to_string(n1::c1())=="c1" );
BOOST_TEST( to_string(n2::c2())=="c2" );
BOOST_TEST( to_string(n3::c3())=="c3" );
BOOST_TEST( to_string_stub(42)=="42" );
BOOST_TEST( to_string_stub(n1::c1())=="c1" );
BOOST_TEST( to_string_stub(n2::c2())=="c2" );
BOOST_TEST( to_string_stub(n3::c3())=="c3" );
BOOST_TEST( to_string_stub(to_string_tester(),my_stub<to_string_tester>())=="stub" );
BOOST_TEST( !to_string_stub(to_string_tester()).empty() );
return boost::report_errors();
}

View File

@@ -0,0 +1,56 @@
//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/to_string.hpp>
#include <boost/detail/lightweight_test.hpp>
namespace
n1
{
struct
c1
{
};
}
namespace
n2
{
struct
c2
{
};
std::string
to_string( c2 const & )
{
return "c2";
}
}
namespace
n3
{
struct
c3
{
};
std::ostream &
operator<<( std::ostream & s, c3 const & )
{
return s << "c3";
}
}
int
main()
{
using namespace boost;
BOOST_TEST( "c2"==to_string(n2::c2()) );
BOOST_TEST( "c3"==to_string(n3::c3()) );
BOOST_TEST( "42"==to_string(42) );
return boost::report_errors();
}

View File

@@ -0,0 +1,277 @@
//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/config.hpp>
#if defined( BOOST_NO_EXCEPTIONS )
# error This program requires exception handling.
#endif
#include <boost/exception_ptr.hpp>
#include <boost/exception/get_error_info.hpp>
#include <boost/exception/info.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/detail/workaround.hpp>
#if BOOST_WORKAROUND(BOOST_CODEGEARC, BOOST_TESTED_AT(0x610))
struct tag_test {};
#endif
typedef boost::error_info<struct tag_test,int> test;
struct
test_boost_exception:
boost::exception
{
};
void
throw_boost_exception()
{
throw test_boost_exception() << test(42);
}
void
throw_unknown_exception()
{
struct
test_exception:
std::exception
{
};
throw test_exception();
}
struct
user_defined_exception
{
user_defined_exception(int d):data(d){}
int data;
};
void
throw_user_defined_exception()
{
throw user_defined_exception(42);
}
void
throw_builtin_exception()
{
throw 42;
}
int
main()
{
try
{
throw_boost_exception();
}
catch(
... )
{
boost::exception_ptr ep=boost::current_exception();
try
{
rethrow_exception(ep);
}
catch(
boost::unknown_exception & x )
{
if( int const * d=boost::get_error_info<test>(x) )
BOOST_TEST( 42==*d );
else
BOOST_TEST(false);
}
catch(
boost::exception & x )
{
//Yay! Non-intrusive cloning supported!
if( int const * d=boost::get_error_info<test>(x) )
BOOST_TEST( 42==*d );
else
BOOST_TEST(false);
}
catch(
... )
{
BOOST_TEST(false);
}
try
{
rethrow_exception(ep);
}
catch(
boost::exception & x )
{
if( int const * d=boost::get_error_info<test>(x) )
BOOST_TEST( 42==*d );
else
BOOST_TEST(false);
}
catch(
... )
{
BOOST_TEST(false);
}
}
try
{
throw_unknown_exception();
}
catch(
... )
{
boost::exception_ptr ep=boost::current_exception();
try
{
rethrow_exception(ep);
}
catch(
boost::unknown_exception & )
{
}
catch(
std::exception & )
{
//Yay! Non-intrusive cloning supported!
}
catch(
... )
{
BOOST_TEST(false);
}
try
{
rethrow_exception(ep);
}
catch(
boost::exception & )
{
}
catch(
std::exception & )
{
//Yay! Non-intrusive cloning supported!
}
catch(
... )
{
BOOST_TEST(false);
}
}
try
{
throw_user_defined_exception();
}
catch(
... )
{
boost::exception_ptr ep=boost::current_exception();
try
{
rethrow_exception(ep);
}
#ifndef BOOST_NO_CXX11_HDR_EXCEPTION
catch(
user_defined_exception & x)
{
//Yay! std::current_exception to the rescue!
BOOST_TEST( 42==x.data );
}
#else
catch(
boost::unknown_exception & )
{
//Boo! user defined exception was transported as a boost::unknown_exception
}
#endif
catch(
... )
{
BOOST_TEST(false);
}
try
{
rethrow_exception(ep);
}
#ifndef BOOST_NO_CXX11_HDR_EXCEPTION
catch(
user_defined_exception & x)
{
//Yay! std::current_exception to the rescue!
BOOST_TEST( 42==x.data );
}
#else
catch(
boost::unknown_exception & )
{
//Boo! user defined exception was transported as a boost::unknown_exception
}
#endif
catch(
... )
{
BOOST_TEST(false);
}
}
try
{
throw_builtin_exception();
}
catch(
... )
{
boost::exception_ptr ep=boost::current_exception();
try
{
rethrow_exception(ep);
}
#ifndef BOOST_NO_CXX11_HDR_EXCEPTION
catch(
int & x)
{
//Yay! std::current_exception to the rescue!
BOOST_TEST( 42==x );
}
#else
catch(
boost::unknown_exception & )
{
//Boo! builtin exception was transported as a boost::unknown_exception
}
#endif
catch(
... )
{
BOOST_TEST(false);
}
try
{
rethrow_exception(ep);
}
#ifndef BOOST_NO_CXX11_HDR_EXCEPTION
catch(
int & x)
{
//Yay! std::current_exception to the rescue!
BOOST_TEST( 42==x );
}
#else
catch(
boost::unknown_exception & )
{
//Boo! builtin exception was transported as a boost::unknown_exception
}
#endif
catch(
... )
{
BOOST_TEST(false);
}
}
return boost::report_errors();
}

View File

@@ -0,0 +1,32 @@
//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/config.hpp>
#if defined( BOOST_NO_EXCEPTIONS )
# error This program requires exception handling.
#endif
#include "visibility_test_lib.hpp"
#include <boost/exception/get_error_info.hpp>
#include <boost/detail/lightweight_test.hpp>
void BOOST_SYMBOL_IMPORT hidden_throw();
int
main()
{
try
{
hidden_throw();
BOOST_TEST(false);
}
catch(
my_exception & e )
{
BOOST_TEST(boost::get_error_info<my_info>(e) && *boost::get_error_info<my_info>(e)==42);
}
return boost::report_errors();
}

View File

@@ -0,0 +1,9 @@
#include "visibility_test_lib.hpp"
#include <boost/throw_exception.hpp>
void
BOOST_SYMBOL_EXPORT
hidden_throw()
{
BOOST_THROW_EXCEPTION(my_exception() << my_info(42));
}

View File

@@ -0,0 +1,15 @@
#ifndef HIDDEN_HPP_INCLUDED
#define HIDDEN_HPP_INCLUDED
//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/info.hpp>
typedef boost::error_info<struct my_info_, int> my_info;
struct BOOST_SYMBOL_VISIBLE my_exception: virtual std::exception, virtual boost::exception { };
#endif