From 6845ba892dc1ff3f949aecd8479feae2bb0ced08 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 27 Sep 2018 07:15:53 +0300 Subject: [PATCH] Add test that uses boost::exception_ptr --- test/Jamfile.v2 | 1 + test/throw_exception_test3.cpp | 71 ++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 test/throw_exception_test3.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index bfb1aa4..f635925 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -15,6 +15,7 @@ run throw_exception_no_both_test.cpp ; compile-fail throw_exception_fail.cpp ; run throw_exception_test2.cpp ; +run throw_exception_test3.cpp ; lib lib1_throw : lib1_throw.cpp : LIB1_SOURCE=1 shared:LIB1_DYN_LINK=1 : : shared:LIB1_DYN_LINK=1 ; lib lib2_throw : lib2_throw.cpp : LIB2_SOURCE=1 shared:LIB2_DYN_LINK=1 : : shared:LIB2_DYN_LINK=1 ; diff --git a/test/throw_exception_test3.cpp b/test/throw_exception_test3.cpp new file mode 100644 index 0000000..7f20420 --- /dev/null +++ b/test/throw_exception_test3.cpp @@ -0,0 +1,71 @@ +// Copyright 2018 Peter Dimov +// +// 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 +#include +#include + +class my_exception: public std::exception +{ +}; + +class my_exception2: public std::exception, public boost::exception +{ +}; + +int main() +{ + try + { + boost::throw_exception( my_exception() ); + } + catch( ... ) + { + boost::exception_ptr p = boost::current_exception(); + + BOOST_TEST_THROWS( boost::rethrow_exception( p ), my_exception ); + BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception ); + } + + try + { + boost::throw_exception( my_exception2() ); + } + catch( ... ) + { + boost::exception_ptr p = boost::current_exception(); + + BOOST_TEST_THROWS( boost::rethrow_exception( p ), my_exception2 ); + BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception ); + } + + try + { + BOOST_THROW_EXCEPTION( my_exception() ); + } + catch( ... ) + { + boost::exception_ptr p = boost::current_exception(); + + BOOST_TEST_THROWS( boost::rethrow_exception( p ), my_exception ); + BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception ); + } + + try + { + BOOST_THROW_EXCEPTION( my_exception2() ); + } + catch( ... ) + { + boost::exception_ptr p = boost::current_exception(); + + BOOST_TEST_THROWS( boost::rethrow_exception( p ), my_exception2 ); + BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception ); + } + + return boost::report_errors(); +}