mirror of
https://github.com/boostorg/exception.git
synced 2025-07-23 00:57:14 +02:00
Boost Exception major refactoring: works with or without RTTI, vastly improved boost::throw_exception integration.
[SVN r48905]
This commit is contained in:
29
test/1-throw_exception_test.cpp
Normal file
29
test/1-throw_exception_test.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
//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/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();
|
||||
}
|
30
test/2-throw_exception_no_exceptions_test.cpp
Normal file
30
test/2-throw_exception_no_exceptions_test.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
//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)
|
||||
|
||||
#define BOOST_NO_EXCEPTIONS
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
class my_exception: public std::exception { };
|
||||
|
||||
bool called=false;
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
void
|
||||
throw_exception( std::exception const & )
|
||||
{
|
||||
called=true;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
boost::throw_exception(my_exception());
|
||||
BOOST_TEST(called);
|
||||
return boost::report_errors();
|
||||
}
|
30
test/3-throw_exception_no_integration_test.cpp
Normal file
30
test/3-throw_exception_no_integration_test.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
//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)
|
||||
|
||||
#define BOOST_EXCEPTION_DISABLE
|
||||
#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();
|
||||
}
|
31
test/4-throw_exception_no_both_test.cpp
Normal file
31
test/4-throw_exception_no_both_test.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
//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)
|
||||
|
||||
#define BOOST_NO_EXCEPTIONS
|
||||
#define BOOST_EXCEPTION_DISABLE
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
class my_exception: public std::exception { };
|
||||
|
||||
bool called=false;
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
void
|
||||
throw_exception( std::exception const & )
|
||||
{
|
||||
called=true;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
boost::throw_exception(my_exception());
|
||||
BOOST_TEST(called);
|
||||
return boost::report_errors();
|
||||
}
|
@ -19,16 +19,20 @@ compile-fail to_string_fail.cpp ;
|
||||
|
||||
#exception
|
||||
|
||||
run 1-throw_exception_test.cpp ;
|
||||
run 2-throw_exception_no_exceptions_test.cpp ;
|
||||
run 3-throw_exception_no_integration_test.cpp ;
|
||||
run 4-throw_exception_no_both_test.cpp ;
|
||||
run cloning_test.cpp ;
|
||||
run copy_exception_test.cpp ;
|
||||
run unknown_exception_test.cpp ;
|
||||
run exception_test.cpp ;
|
||||
run boost_error_info_test.cpp ;
|
||||
run enable_error_info_test.cpp helper1.cpp ;
|
||||
run throw_exception_test.cpp helper2.cpp ;
|
||||
run errno_test.cpp ;
|
||||
run error_info_test.cpp ;
|
||||
run diagnostic_information_test.cpp ;
|
||||
run refcount_ptr_test.cpp ;
|
||||
compile-fail exception_fail.cpp ;
|
||||
compile-fail throw_exception_fail.cpp ;
|
||||
|
||||
@ -36,10 +40,9 @@ compile-fail throw_exception_fail.cpp ;
|
||||
|
||||
compile exception_ptr_hpp_test.cpp ;
|
||||
compile diagnostic_information_hpp_test.cpp ;
|
||||
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 ;
|
||||
|
@ -1,40 +0,0 @@
|
||||
//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/info.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace
|
||||
test
|
||||
{
|
||||
class my_exception: public boost::exception { };
|
||||
|
||||
typedef boost::error_info<struct tag_my_info,int> my_info;
|
||||
|
||||
void
|
||||
test_boost_error_info()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw my_exception() << BOOST_ERROR_INFO << my_info(1);
|
||||
}
|
||||
catch(
|
||||
my_exception & x )
|
||||
{
|
||||
BOOST_TEST(1==*boost::get_error_info<my_info>(x));
|
||||
BOOST_TEST(boost::get_error_info<boost::throw_function>(x));
|
||||
BOOST_TEST(boost::get_error_info<boost::throw_file>(x));
|
||||
BOOST_TEST(boost::get_error_info<boost::throw_line>(x));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
test::test_boost_error_info();
|
||||
return boost::report_errors();
|
||||
}
|
@ -4,32 +4,267 @@
|
||||
//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>
|
||||
#include <string>
|
||||
|
||||
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
|
||||
test_exception:
|
||||
derives_nothing
|
||||
{
|
||||
int & count;
|
||||
|
||||
explicit
|
||||
derives_nothing( int & count ):
|
||||
count(count)
|
||||
{
|
||||
++count;
|
||||
}
|
||||
|
||||
derives_nothing( derives_nothing const & x ):
|
||||
count(x.count)
|
||||
{
|
||||
++count;
|
||||
}
|
||||
|
||||
~derives_nothing()
|
||||
{
|
||||
--count;
|
||||
}
|
||||
};
|
||||
|
||||
struct
|
||||
derives_std_exception:
|
||||
std::exception
|
||||
{
|
||||
};
|
||||
|
||||
int
|
||||
main()
|
||||
struct
|
||||
derives_std_boost_exception:
|
||||
std::exception,
|
||||
boost::exception
|
||||
{
|
||||
};
|
||||
|
||||
struct
|
||||
derives_boost_exception:
|
||||
boost::exception
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
void
|
||||
test_std_exception()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw boost::enable_current_exception(test_exception());
|
||||
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(
|
||||
test_exception & )
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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("what")==x.what());
|
||||
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("what")==x.what());
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
{
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
}
|
||||
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(
|
||||
@ -38,5 +273,194 @@ main()
|
||||
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(
|
||||
boost::unknown_exception & )
|
||||
{
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
{
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
}
|
||||
|
||||
test_std_exception_what<std::invalid_argument>();
|
||||
test_std_exception_what<std::out_of_range>();
|
||||
test_std_exception_what<std::logic_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>();
|
||||
|
||||
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(
|
||||
boost::unknown_exception & x )
|
||||
{
|
||||
BOOST_TEST(boost::get_error_info<my_info>(x));
|
||||
if( boost::shared_ptr<int const> p=boost::get_error_info<my_info>(x) )
|
||||
BOOST_TEST(*p==42);
|
||||
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( boost::shared_ptr<int const> p=boost::get_error_info<my_info>(x) )
|
||||
BOOST_TEST(*p==42);
|
||||
}
|
||||
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(
|
||||
boost::unknown_exception & x )
|
||||
{
|
||||
BOOST_TEST(boost::get_error_info<my_info>(x));
|
||||
if( boost::shared_ptr<int const> p=boost::get_error_info<my_info>(x) )
|
||||
BOOST_TEST(*p==42);
|
||||
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( boost::shared_ptr<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>();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -4,3 +4,4 @@
|
||||
//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>
|
||||
|
@ -7,11 +7,12 @@
|
||||
#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:
|
||||
public std::exception
|
||||
public std::exception,
|
||||
public boost::exception
|
||||
{
|
||||
char const *
|
||||
what() const throw()
|
||||
@ -22,53 +23,55 @@ error1:
|
||||
|
||||
struct
|
||||
error2:
|
||||
public std::exception,
|
||||
public boost::exception
|
||||
{
|
||||
char const *
|
||||
what() const throw()
|
||||
{
|
||||
return "error2";
|
||||
}
|
||||
};
|
||||
|
||||
struct
|
||||
error3:
|
||||
public boost::exception
|
||||
{
|
||||
};
|
||||
|
||||
std::string
|
||||
get_diagnostic_information( std::exception const & x )
|
||||
{
|
||||
return boost::diagnostic_information(x);
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
using namespace boost;
|
||||
try
|
||||
{
|
||||
error1 x;
|
||||
error1 x; x << tag_int(42);
|
||||
BOOST_TEST(x.what()==std::string("error1"));
|
||||
std::string di=get_diagnostic_information(x);
|
||||
throw x;
|
||||
}
|
||||
catch(
|
||||
boost::exception & x )
|
||||
{
|
||||
std::string di=boost::diagnostic_information(x);
|
||||
#ifndef BOOST_NO_RTTI
|
||||
BOOST_TEST(di.find("type:")!=std::string::npos);
|
||||
BOOST_TEST(di.find("error1")!=std::string::npos);
|
||||
#endif
|
||||
BOOST_TEST(di.find("test_tag")!=std::string::npos);
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
{
|
||||
error2 x; x << tag_int(42);
|
||||
BOOST_TEST(x.what()==std::string("error2"));
|
||||
std::string di=get_diagnostic_information(x);
|
||||
BOOST_TEST(di.find("type:")!=std::string::npos);
|
||||
BOOST_TEST(di.find("error2")!=std::string::npos);
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
try
|
||||
{
|
||||
error3 x;
|
||||
error2 x;
|
||||
x << tag_int(1);
|
||||
std::string w1 = x.diagnostic_information();
|
||||
throw x;
|
||||
}
|
||||
catch(
|
||||
boost::exception & x )
|
||||
{
|
||||
std::string w1 = diagnostic_information(x);
|
||||
x << tag_int(2);
|
||||
std::string w2 = x.diagnostic_information();
|
||||
std::string w2 = diagnostic_information(x);
|
||||
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();
|
||||
}
|
||||
|
@ -1,6 +0,0 @@
|
||||
//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/enable_error_info.hpp>
|
@ -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>
|
||||
@ -44,7 +45,26 @@ main()
|
||||
catch(
|
||||
std::exception & x )
|
||||
{
|
||||
BOOST_TEST( 42==*boost::get_error_info<test_int>(x) );
|
||||
#ifdef BOOST_NO_RTTI
|
||||
try
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch(
|
||||
boost::exception & x )
|
||||
{
|
||||
#endif
|
||||
BOOST_TEST( boost::get_error_info<test_int>(x) );
|
||||
if( boost::shared_ptr<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(
|
||||
|
@ -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>
|
||||
|
@ -4,3 +4,4 @@
|
||||
//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>
|
||||
|
@ -3,18 +3,44 @@
|
||||
//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>
|
||||
|
||||
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:
|
||||
@ -38,12 +64,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 +92,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 +141,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 +160,9 @@ test_empty()
|
||||
catch(
|
||||
test_exception & x )
|
||||
{
|
||||
BOOST_TEST( dynamic_cast<boost::exception *>(&x) );
|
||||
#ifndef BOOST_NO_RTTI
|
||||
BOOST_TEST( dynamic_cast<boost::exception const *>(&x)!=0 );
|
||||
#endif
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
@ -245,6 +283,29 @@ test_add_tuple()
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
test_lifetime()
|
||||
{
|
||||
int count=0;
|
||||
try
|
||||
{
|
||||
throw test_exception() << test_7(user_data(count));
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
catch(
|
||||
boost::exception & x )
|
||||
{
|
||||
BOOST_TEST(count==1);
|
||||
BOOST_TEST( boost::get_error_info<test_7>(x) );
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
{
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
BOOST_TEST(!count);
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
@ -254,5 +315,6 @@ main()
|
||||
test_basic_throw_catch();
|
||||
test_catch_add_info();
|
||||
test_add_tuple();
|
||||
test_lifetime();
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -4,3 +4,4 @@
|
||||
//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/exception.hpp>
|
||||
#include <boost/exception.hpp>
|
||||
|
@ -4,3 +4,4 @@
|
||||
//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>
|
||||
|
@ -3,4 +3,5 @@
|
||||
//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/enable_current_exception.hpp>
|
||||
#include <boost/exception/get_error_info.hpp>
|
||||
#include <boost/exception/get_error_info.hpp>
|
@ -3,7 +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/enable_error_info.hpp>
|
||||
#include <boost/exception/exception.hpp>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
|
@ -4,3 +4,4 @@
|
||||
//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>
|
||||
|
@ -4,3 +4,4 @@
|
||||
//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>
|
||||
|
103
test/refcount_ptr_test.cpp
Normal file
103
test/refcount_ptr_test.cpp
Normal file
@ -0,0 +1,103 @@
|
||||
//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/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_;
|
||||
}
|
||||
|
||||
void
|
||||
release()
|
||||
{
|
||||
if( !--count_ )
|
||||
delete this;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
@ -4,12 +4,73 @@
|
||||
//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>
|
||||
|
||||
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_TEST(false);
|
||||
}
|
||||
catch(
|
||||
boost::exception & x )
|
||||
{
|
||||
boost::shared_ptr<char const * const> file=boost::get_error_info<boost::throw_function>(x);
|
||||
boost::shared_ptr<char const * const> function=boost::get_error_info<boost::throw_file>(x);
|
||||
boost::shared_ptr<int const> line=boost::get_error_info<boost::throw_line>(x);
|
||||
BOOST_TEST( file && *file );
|
||||
BOOST_TEST( function && *function );
|
||||
BOOST_TEST( line && *line==32 );
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
{
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
try
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(exception2() << test_data(42));
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
catch(
|
||||
boost::exception & x )
|
||||
{
|
||||
boost::shared_ptr<char const * const> file=boost::get_error_info<boost::throw_function>(x);
|
||||
boost::shared_ptr<char const * const> function=boost::get_error_info<boost::throw_file>(x);
|
||||
boost::shared_ptr<int const> line=boost::get_error_info<boost::throw_line>(x);
|
||||
boost::shared_ptr<int const> data=boost::get_error_info<test_data>(x);
|
||||
BOOST_TEST( file && *file );
|
||||
BOOST_TEST( function && *function );
|
||||
BOOST_TEST( line && *line==52 );
|
||||
BOOST_TEST( data && *data==42 );
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
{
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
throw_fwd( void (*thrower)(int) )
|
||||
{
|
||||
@ -46,9 +107,26 @@ tester()
|
||||
catch(
|
||||
T & y )
|
||||
{
|
||||
BOOST_TEST(boost::get_error_info<test_data>(y));
|
||||
if( boost::shared_ptr<int const> d=boost::get_error_info<test_data>(y) )
|
||||
BOOST_TEST(*d==42);
|
||||
#ifdef BOOST_NO_RTTI
|
||||
try
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch(
|
||||
boost::exception & y )
|
||||
{
|
||||
#endif
|
||||
BOOST_TEST(boost::get_error_info<test_data>(y));
|
||||
if( boost::shared_ptr<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(
|
||||
@ -62,6 +140,7 @@ tester()
|
||||
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>();
|
||||
|
@ -4,3 +4,4 @@
|
||||
//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>
|
||||
|
@ -4,3 +4,4 @@
|
||||
//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>
|
||||
|
@ -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>
|
||||
|
||||
|
Reference in New Issue
Block a user