From f1419ae6de3096b4311abcaaf8d8bae0f48342c1 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 26 Jan 2022 06:20:27 +0200 Subject: [PATCH] Update throw_from_library_test.cpp --- test/Jamfile.v2 | 6 ++++-- test/lib4_throw.cpp | 14 +++++++++++++ test/lib4_throw.hpp | 36 ++++++++++++++++++++++++++++++++ test/lib5_throw.cpp | 14 +++++++++++++ test/lib5_throw.hpp | 36 ++++++++++++++++++++++++++++++++ test/throw_from_library_test.cpp | 34 ++++++++++++++++++++++++++---- 6 files changed, 134 insertions(+), 6 deletions(-) create mode 100644 test/lib4_throw.cpp create mode 100644 test/lib4_throw.hpp create mode 100644 test/lib5_throw.cpp create mode 100644 test/lib5_throw.hpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 99f2963..b93cfbb 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -31,9 +31,11 @@ run throw_exception_test5.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 ; lib lib3_throw : lib3_throw.cpp : LIB3_SOURCE=1 shared:LIB3_DYN_LINK=1 : : shared:LIB3_DYN_LINK=1 ; +lib lib4_throw : lib4_throw.cpp : LIB4_SOURCE=1 shared:LIB4_DYN_LINK=1 : : shared:LIB4_DYN_LINK=1 ; +lib lib5_throw : lib5_throw.cpp : LIB5_SOURCE=1 shared:LIB5_DYN_LINK=1 : : shared:LIB5_DYN_LINK=1 ; -run throw_from_library_test.cpp lib1_throw lib2_throw lib3_throw : : : static : throw_from_library_static ; -run throw_from_library_test.cpp lib1_throw lib2_throw lib3_throw : : : shared : throw_from_library_shared ; +run throw_from_library_test.cpp lib1_throw lib2_throw lib3_throw lib4_throw lib5_throw : : : static : throw_from_library_static ; +run throw_from_library_test.cpp lib1_throw lib2_throw lib3_throw lib4_throw lib5_throw : : : shared : throw_from_library_shared ; run throw_exception_nx_test.cpp : : : off ; run throw_exception_nx_test2.cpp : : : off ; diff --git a/test/lib4_throw.cpp b/test/lib4_throw.cpp new file mode 100644 index 0000000..fa8dae7 --- /dev/null +++ b/test/lib4_throw.cpp @@ -0,0 +1,14 @@ +// 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 "lib4_throw.hpp" +#include + +void lib4::f() +{ + boost::throw_exception( lib4::exception() ); +} diff --git a/test/lib4_throw.hpp b/test/lib4_throw.hpp new file mode 100644 index 0000000..c55eb56 --- /dev/null +++ b/test/lib4_throw.hpp @@ -0,0 +1,36 @@ +#ifndef LIB4_THROW_HPP_INCLUDED +#define LIB4_THROW_HPP_INCLUDED + +// 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 + +#if defined(LIB4_DYN_LINK) +# if defined(LIB4_SOURCE) +# define LIB4_DECL BOOST_SYMBOL_EXPORT +# else +# define LIB4_DECL BOOST_SYMBOL_IMPORT +# endif +#else +# define LIB4_DECL +#endif + +namespace lib4 +{ + +struct BOOST_SYMBOL_VISIBLE exception: public std::exception, public boost::exception +{ +}; + +LIB4_DECL void f(); + +} // namespace lib4 + +#endif // #ifndef LIB4_THROW_HPP_INCLUDED diff --git a/test/lib5_throw.cpp b/test/lib5_throw.cpp new file mode 100644 index 0000000..cbe7bbf --- /dev/null +++ b/test/lib5_throw.cpp @@ -0,0 +1,14 @@ +// 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 "lib5_throw.hpp" +#include + +void lib5::f() +{ + BOOST_THROW_EXCEPTION( lib5::exception() ); +} diff --git a/test/lib5_throw.hpp b/test/lib5_throw.hpp new file mode 100644 index 0000000..69d65fe --- /dev/null +++ b/test/lib5_throw.hpp @@ -0,0 +1,36 @@ +#ifndef LIB5_THROW_HPP_INCLUDED +#define LIB5_THROW_HPP_INCLUDED + +// 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 + +#if defined(LIB5_DYN_LINK) +# if defined(LIB5_SOURCE) +# define LIB5_DECL BOOST_SYMBOL_EXPORT +# else +# define LIB5_DECL BOOST_SYMBOL_IMPORT +# endif +#else +# define LIB5_DECL +#endif + +namespace lib5 +{ + +struct BOOST_SYMBOL_VISIBLE exception: public std::exception, public boost::exception +{ +}; + +LIB5_DECL void f(); + +} // namespace lib5 + +#endif // #ifndef LIB5_THROW_HPP_INCLUDED diff --git a/test/throw_from_library_test.cpp b/test/throw_from_library_test.cpp index af2a673..489d1a6 100644 --- a/test/throw_from_library_test.cpp +++ b/test/throw_from_library_test.cpp @@ -20,6 +20,8 @@ #include "lib1_throw.hpp" #include "lib2_throw.hpp" #include "lib3_throw.hpp" +#include "lib4_throw.hpp" +#include "lib5_throw.hpp" #include #include #include @@ -30,12 +32,14 @@ void test_catch_by_type() BOOST_TEST_THROWS( lib1::f(), lib1::exception ); BOOST_TEST_THROWS( lib2::f(), lib2::exception ); BOOST_TEST_THROWS( lib3::f(), lib3::exception ); + BOOST_TEST_THROWS( lib4::f(), lib4::exception ); + BOOST_TEST_THROWS( lib5::f(), lib5::exception ); } void test_catch_by_exception() { - BOOST_TEST_THROWS( lib2::f(), boost::exception ); - BOOST_TEST_THROWS( lib3::f(), boost::exception ); + BOOST_TEST_THROWS( lib4::f(), boost::exception ); + BOOST_TEST_THROWS( lib5::f(), boost::exception ); } void test_exception_ptr() @@ -49,7 +53,6 @@ void test_exception_ptr() boost::exception_ptr p = boost::current_exception(); BOOST_TEST_THROWS( boost::rethrow_exception( p ), lib2::exception ); - BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception ); } try @@ -61,6 +64,29 @@ void test_exception_ptr() boost::exception_ptr p = boost::current_exception(); BOOST_TEST_THROWS( boost::rethrow_exception( p ), lib3::exception ); + } + + try + { + lib4::f(); + } + catch( ... ) + { + boost::exception_ptr p = boost::current_exception(); + + BOOST_TEST_THROWS( boost::rethrow_exception( p ), lib4::exception ); + BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception ); + } + + try + { + lib5::f(); + } + catch( ... ) + { + boost::exception_ptr p = boost::current_exception(); + + BOOST_TEST_THROWS( boost::rethrow_exception( p ), lib5::exception ); BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception ); } } @@ -69,7 +95,7 @@ void test_throw_line() { try { - lib3::f(); + lib5::f(); } catch( boost::exception const & x ) {