Add tests for throw_line

This commit is contained in:
Peter Dimov
2018-09-27 08:26:29 +03:00
parent a732dfad3c
commit 9b99dd5f60
3 changed files with 65 additions and 0 deletions

View File

@ -16,6 +16,7 @@ compile-fail throw_exception_fail.cpp ;
run throw_exception_test2.cpp ; run throw_exception_test2.cpp ;
run throw_exception_test3.cpp ; run throw_exception_test3.cpp ;
run throw_exception_test4.cpp ;
lib lib1_throw : lib1_throw.cpp : <define>LIB1_SOURCE=1 <link>shared:<define>LIB1_DYN_LINK=1 : : <link>shared:<define>LIB1_DYN_LINK=1 ; lib lib1_throw : lib1_throw.cpp : <define>LIB1_SOURCE=1 <link>shared:<define>LIB1_DYN_LINK=1 : : <link>shared:<define>LIB1_DYN_LINK=1 ;
lib lib2_throw : lib2_throw.cpp : <define>LIB2_SOURCE=1 <link>shared:<define>LIB2_DYN_LINK=1 : : <link>shared:<define>LIB2_DYN_LINK=1 ; lib lib2_throw : lib2_throw.cpp : <define>LIB2_SOURCE=1 <link>shared:<define>LIB2_DYN_LINK=1 : : <link>shared:<define>LIB2_DYN_LINK=1 ;

View File

@ -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 <boost/throw_exception.hpp>
#include <boost/exception/get_error_info.hpp>
#include <boost/detail/lightweight_test.hpp>
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<boost::throw_line>( 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<boost::throw_line>( x );
BOOST_TEST( line != 0 );
BOOST_TEST_EQ( *line, 36 );
}
return boost::report_errors();
}

View File

@ -10,6 +10,7 @@
#include "lib3_throw.hpp" #include "lib3_throw.hpp"
#include <boost/exception/exception.hpp> #include <boost/exception/exception.hpp>
#include <boost/exception_ptr.hpp> #include <boost/exception_ptr.hpp>
#include <boost/exception/get_error_info.hpp>
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
void test_catch_by_type() 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<boost::throw_line>( x );
BOOST_TEST( line != 0 );
BOOST_TEST_EQ( *line, 13 );
}
}
int main() int main()
{ {
test_catch_by_type(); test_catch_by_type();
test_catch_by_exception(); test_catch_by_exception();
test_exception_ptr(); test_exception_ptr();
test_throw_line();
return boost::report_errors(); return boost::report_errors();
} }