]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/throw_exception/test/throw_from_library_test.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / throw_exception / test / throw_from_library_test.cpp
1 // Copyright 2018 Peter Dimov
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 //
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7
8 #include "lib1_throw.hpp"
9 #include "lib2_throw.hpp"
10 #include "lib3_throw.hpp"
11 #include <boost/exception/exception.hpp>
12 #include <boost/exception_ptr.hpp>
13 #include <boost/exception/get_error_info.hpp>
14 #include <boost/core/lightweight_test.hpp>
15
16 void test_catch_by_type()
17 {
18 BOOST_TEST_THROWS( lib1::f(), lib1::exception );
19 BOOST_TEST_THROWS( lib2::f(), lib2::exception );
20 BOOST_TEST_THROWS( lib3::f(), lib3::exception );
21 }
22
23 void test_catch_by_exception()
24 {
25 BOOST_TEST_THROWS( lib2::f(), boost::exception );
26 BOOST_TEST_THROWS( lib3::f(), boost::exception );
27 }
28
29 void test_exception_ptr()
30 {
31 try
32 {
33 lib2::f();
34 }
35 catch( ... )
36 {
37 boost::exception_ptr p = boost::current_exception();
38
39 BOOST_TEST_THROWS( boost::rethrow_exception( p ), lib2::exception );
40 BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception );
41 }
42
43 try
44 {
45 lib3::f();
46 }
47 catch( ... )
48 {
49 boost::exception_ptr p = boost::current_exception();
50
51 BOOST_TEST_THROWS( boost::rethrow_exception( p ), lib3::exception );
52 BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception );
53 }
54 }
55
56 void test_throw_line()
57 {
58 try
59 {
60 lib3::f();
61 }
62 catch( boost::exception const & x )
63 {
64 int const * line = boost::get_error_info<boost::throw_line>( x );
65
66 BOOST_TEST( line != 0 );
67 BOOST_TEST_EQ( *line, 13 );
68 }
69 }
70
71 int main()
72 {
73 test_catch_by_type();
74 test_catch_by_exception();
75 test_exception_ptr();
76 test_throw_line();
77
78 return boost::report_errors();
79 }