From 9b99dd5f60bfa33c3ba232d207c41db34d2d1583 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 27 Sep 2018 08:26:29 +0300 Subject: [PATCH] Add tests for throw_line --- test/Jamfile.v2 | 1 + test/throw_exception_test4.cpp | 47 ++++++++++++++++++++++++++++++++ test/throw_from_library_test.cpp | 17 ++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 test/throw_exception_test4.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index f635925..e28308d 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -16,6 +16,7 @@ compile-fail throw_exception_fail.cpp ; run throw_exception_test2.cpp ; run throw_exception_test3.cpp ; +run throw_exception_test4.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_test4.cpp b/test/throw_exception_test4.cpp new file mode 100644 index 0000000..5b8e303 --- /dev/null +++ b/test/throw_exception_test4.cpp @@ -0,0 +1,47 @@ +// 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 const & x ) + { + int const * line = boost::get_error_info( x ); + + BOOST_TEST( line != 0 ); + BOOST_TEST_EQ( *line, 24 ); + } + + try + { + BOOST_THROW_EXCEPTION( my_exception2() ); + } + catch( boost::exception const & x ) + { + int const * line = boost::get_error_info( x ); + + BOOST_TEST( line != 0 ); + BOOST_TEST_EQ( *line, 36 ); + } + + return boost::report_errors(); +} diff --git a/test/throw_from_library_test.cpp b/test/throw_from_library_test.cpp index 3adfa0c..22a89da 100644 --- a/test/throw_from_library_test.cpp +++ b/test/throw_from_library_test.cpp @@ -10,6 +10,7 @@ #include "lib3_throw.hpp" #include #include +#include #include void test_catch_by_type() @@ -52,11 +53,27 @@ void test_exception_ptr() } } +void test_throw_line() +{ + try + { + lib3::f(); + } + catch( boost::exception const & x ) + { + int const * line = boost::get_error_info( x ); + + BOOST_TEST( line != 0 ); + BOOST_TEST_EQ( *line, 13 ); + } +} + int main() { test_catch_by_type(); test_catch_by_exception(); test_exception_ptr(); + test_throw_line(); return boost::report_errors(); }