From c58f418c2f40d67ebf2e709781059504068a686d Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 30 Nov 2019 20:22:32 +0200 Subject: [PATCH] Add test with error_info --- test/Jamfile.v2 | 1 + test/throw_exception_test5.cpp | 66 ++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 test/throw_exception_test5.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index bd2df4c..26cd203 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -17,6 +17,7 @@ compile-fail throw_exception_fail.cpp ; run throw_exception_test2.cpp ; run throw_exception_test3.cpp ; run throw_exception_test4.cpp ; +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 ; diff --git a/test/throw_exception_test5.cpp b/test/throw_exception_test5.cpp new file mode 100644 index 0000000..a4a8c43 --- /dev/null +++ b/test/throw_exception_test5.cpp @@ -0,0 +1,66 @@ +// Copyright 2018, 2019 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 +#include +#include + +typedef boost::error_info error_code; +typedef boost::error_info error_string; + +class my_exception: public std::exception, public boost::exception +{ +}; + +int main() +{ + try + { + boost::throw_exception( my_exception() << error_code( 123 ) << error_string( "error%%string" ) ); + } + catch( boost::exception const & x ) + { + { + int const * code = boost::get_error_info( x ); + + BOOST_TEST( code != 0 ); + BOOST_TEST_EQ( *code, 123 ); + } + + { + std::string const * str = boost::get_error_info( x ); + + BOOST_TEST( str != 0 ); + BOOST_TEST_EQ( *str, "error%%string" ); + } + } + + try + { + BOOST_THROW_EXCEPTION( my_exception() << error_code( 123 ) << error_string( "error%%string" ) ); + } + catch( boost::exception const & x ) + { + { + int const * code = boost::get_error_info( x ); + + BOOST_TEST( code != 0 ); + BOOST_TEST_EQ( *code, 123 ); + } + + { + std::string const * str = boost::get_error_info( x ); + + BOOST_TEST( str != 0 ); + BOOST_TEST_EQ( *str, "error%%string" ); + } + } + + return boost::report_errors(); +}