]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/stacktrace/test/test_noop.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / stacktrace / test / test_noop.cpp
1 // Copyright Antony Polukhin, 2016-2017.
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6
7
8 #include <boost/stacktrace.hpp>
9 #include <boost/core/lightweight_test.hpp>
10 #include <stdexcept>
11
12 #include <boost/functional/hash.hpp>
13
14 using boost::stacktrace::stacktrace;
15 using boost::stacktrace::frame;
16
17 #ifdef BOOST_STACKTRACE_DYN_LINK
18 # define BOOST_ST_API BOOST_SYMBOL_IMPORT
19 #else
20 # define BOOST_ST_API
21 #endif
22
23 typedef std::pair<stacktrace, stacktrace> (*foo1_t)(int i);
24 BOOST_ST_API std::pair<stacktrace, stacktrace> foo2(int i, foo1_t foo1);
25 BOOST_ST_API stacktrace return_from_nested_namespaces();
26
27
28 BOOST_NOINLINE std::pair<stacktrace, stacktrace> foo1(int i) {
29 if (i) {
30 return foo2(i - 1, foo1);
31 }
32
33 std::pair<stacktrace, stacktrace> ret;
34 try {
35 throw std::logic_error("test");
36 } catch (const std::logic_error& /*e*/) {
37 ret.second = stacktrace();
38 return ret;
39 }
40 }
41
42 void test_deeply_nested_namespaces() {
43 BOOST_TEST(return_from_nested_namespaces().size() == 0);
44 BOOST_TEST(return_from_nested_namespaces().empty());
45 BOOST_TEST(!return_from_nested_namespaces());
46 }
47
48 void test_nested() {
49 std::pair<stacktrace, stacktrace> res = foo2(15, foo1);
50
51 BOOST_TEST(!res.first);
52 BOOST_TEST(res.first.empty());
53 BOOST_TEST(res.first.size() == 0);
54
55 BOOST_TEST(res.second <= res.first);
56 BOOST_TEST(res.second >= res.first);
57 BOOST_TEST(res.second == res.first);
58 BOOST_TEST(res.second == res.first);
59 BOOST_TEST(!(res.second > res.first));
60 }
61
62 void test_empty_frame() {
63 boost::stacktrace::frame empty_frame;
64 BOOST_TEST(!empty_frame);
65 BOOST_TEST(empty_frame.source_file() == "");
66 BOOST_TEST(empty_frame.name() == "");
67 BOOST_TEST(empty_frame.source_line() == 0);
68
69 boost::stacktrace::frame f(0);
70 BOOST_TEST(f.name() == "");
71 BOOST_TEST(f.source_file() == "");
72 BOOST_TEST(f.source_line() == 0);
73 }
74
75 int main() {
76 test_deeply_nested_namespaces();
77 test_nested();
78 test_empty_frame();
79
80 return boost::report_errors();
81 }