]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/contract/test/constructor/throwing_old.cpp
2 // Copyright (C) 2008-2018 Lorenzo Caminiti
3 // Distributed under the Boost Software License, Version 1.0 (see accompanying
4 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
5 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
7 // Test throw form constructor .old() (in middle branch of inheritance tree).
9 #include "../detail/oteststream.hpp"
10 #include <boost/contract/constructor.hpp>
11 #include <boost/contract/base_types.hpp>
12 #include <boost/contract/check.hpp>
13 #include <boost/detail/lightweight_test.hpp>
16 boost::contract::test::detail::oteststream out
;
19 #define BASES private boost::contract::constructor_precondition<c>
22 typedef BOOST_CONTRACT_BASE_TYPES(BASES
) base_types
;
25 static void static_invariant() { out
<< "c::static_inv" << std::endl
; }
26 void invariant() const { out
<< "c::inv" << std::endl
; }
29 boost::contract::constructor_precondition
<c
>([] {
30 out
<< "c::ctor::pre" << std::endl
;
33 boost::contract::check c
= boost::contract::constructor(this)
34 .old([] { out
<< "c::ctor::old" << std::endl
; })
35 .postcondition([] { out
<< "c::ctor::post" << std::endl
; })
36 .except([] { out
<< "c::ctor::except" << std::endl
; })
38 out
<< "c::ctor::body" << std::endl
;
39 // Do not throw (from inheritance root).
43 struct b_err
{}; // Global decl so visible in MSVC10 lambdas.
46 #define BASES private boost::contract::constructor_precondition<b>, public c
49 typedef BOOST_CONTRACT_BASE_TYPES(BASES
) base_types
;
52 static void static_invariant() { out
<< "b::static_inv" << std::endl
; }
53 void invariant() const { out
<< "b::inv" << std::endl
; }
56 boost::contract::constructor_precondition
<b
>([] {
57 out
<< "b::ctor::pre" << std::endl
;
60 boost::contract::check c
= boost::contract::constructor(this)
62 out
<< "b::ctor::old" << std::endl
;
63 throw b_err(); // Test this throws (from mid branch).
65 .postcondition([] { out
<< "b::ctor::post" << std::endl
; })
66 .except([] { out
<< "b::ctor::except" << std::endl
; })
68 out
<< "b::ctor::body" << std::endl
;
73 #define BASES private boost::contract::constructor_precondition<a>, public b
76 typedef BOOST_CONTRACT_BASE_TYPES(BASES
) base_types
;
79 static void static_invariant() { out
<< "a::static_inv" << std::endl
; }
80 void invariant() const { out
<< "a::inv" << std::endl
; }
83 boost::contract::constructor_precondition
<a
>([] {
84 out
<< "a::ctor::pre" << std::endl
;
87 boost::contract::check c
= boost::contract::constructor(this)
88 .old([] { out
<< "a::ctor::old" << std::endl
; })
89 .postcondition([] { out
<< "a::ctor::post" << std::endl
; })
90 .except([] { out
<< "a::ctor::except" << std::endl
; })
92 out
<< "a::ctor::body" << std::endl
;
93 // Do not throw (from inheritance leaf).
98 std::ostringstream ok
;
100 boost::contract::set_old_failure([] (boost::contract::from
) { throw; });
105 #ifndef BOOST_CONTRACT_NO_OLDS
107 } catch(b_err
const&) {
110 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
111 << "a::ctor::pre" << std::endl
112 << "b::ctor::pre" << std::endl
113 << "c::ctor::pre" << std::endl
116 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
117 << "c::static_inv" << std::endl
119 #ifndef BOOST_CONTRACT_NO_OLDS
120 << "c::ctor::old" << std::endl
122 << "c::ctor::body" << std::endl
123 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
124 << "c::static_inv" << std::endl
125 << "c::inv" << std::endl
127 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
128 << "c::ctor::post" << std::endl
131 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
132 << "b::static_inv" << std::endl
134 #ifndef BOOST_CONTRACT_NO_OLDS
135 << "b::ctor::old" << std::endl
// Test this threw.
137 << "b::ctor::body" << std::endl
138 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
139 << "b::static_inv" << std::endl
140 << "b::inv" << std::endl
143 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
144 << "a::static_inv" << std::endl
146 << "a::ctor::body" << std::endl
147 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
148 << "a::static_inv" << std::endl
149 << "a::inv" << std::endl
153 BOOST_TEST(out
.eq(ok
.str()));
154 } catch(...) { BOOST_TEST(false); }
156 return boost::report_errors();