]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/contract/test/destructor/decl_post_ends.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 only derived and grandparent classes (ends) with postconditions.
9 #undef BOOST_CONTRACT_TEST_NO_A_POST
10 #define BOOST_CONTRACT_TEST_NO_B_POST
11 #undef BOOST_CONTRACT_TEST_NO_C_POST
14 #include <boost/detail/lightweight_test.hpp>
19 std::ostringstream ok
; ok
20 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
21 << "a::static_inv" << std::endl
22 << "a::inv" << std::endl
24 #ifndef BOOST_CONTRACT_NO_OLDS
25 << "a::dtor::old" << std::endl
27 << "a::dtor::body" << std::endl
28 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
29 << "a::static_inv" << std::endl
31 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
32 << "a::dtor::post" << std::endl
// This can fail.
38 std::string
ok_b(bool threw
= false) {
39 std::ostringstream ok
; ok
40 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
41 << "b::static_inv" << std::endl
42 << "b::inv" << std::endl
44 #ifndef BOOST_CONTRACT_NO_OLDS
45 << "b::dtor::old" << std::endl
47 << "b::dtor::body" << std::endl
48 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
49 << "b::static_inv" << std::endl
50 << (threw
? "b::inv\n" : "")
56 std::string
ok_c(bool threw
= false) {
57 std::ostringstream ok
; ok
58 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
59 << "c::static_inv" << std::endl
60 << "c::inv" << std::endl
62 #ifndef BOOST_CONTRACT_NO_OLDS
63 << "c::dtor::old" << std::endl
65 << "c::dtor::body" << std::endl
66 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
67 << "c::static_inv" << std::endl
68 << (threw
? "c::inv\n" : "")
70 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
71 << (!threw
? "c::dtor::post\n" : "") // This can fail.
77 struct err
{}; // Global decl so visible in MSVC10 lambdas.
80 std::ostringstream ok
;
89 ok
.str(""); ok
// Test nothing failed.
94 BOOST_TEST(out
.eq(ok
.str()));
96 boost::contract::set_postcondition_failure([&ok
] (boost::contract::from
) {
97 BOOST_TEST(out
.eq(ok
.str())); // Must check before dtor throws...
98 throw err(); // ... for testing (as dtors should never throw anyways).
101 #ifdef BOOST_CONTRACT_NO_POSTCONDITIONS
102 #define BOOST_CONTRACT_TEST_post 0
104 #define BOOST_CONTRACT_TEST_post 1
114 << ok_a() // Test a::dtor::post failed.
118 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
120 } catch(err
const&) {
122 ok
// ... then exec other dtors and check inv on throw (as dtor threw).
123 << ok_b(BOOST_CONTRACT_TEST_post
)
124 << ok_c(BOOST_CONTRACT_TEST_post
)
126 BOOST_TEST(out
.eq(ok
.str()));
127 } catch(...) { BOOST_TEST(false); }
139 << ok_b() // Test no b::dtor::post so no failure here.
142 BOOST_TEST(out
.eq(ok
.str()));
143 } catch(...) { BOOST_TEST(false); }
154 << ok_c() // Test c::dtor::post failed.
158 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
160 } catch(err
const&) {
162 // ... then exec other dtors and check inv on throw (as dtor threw).
163 BOOST_TEST(out
.eq(ok
.str()));
164 } catch(...) { BOOST_TEST(false); }
173 << ok_a() // Test a::dtor::post failed.
177 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
179 } catch(err
const&) {
181 ok
// ... then exec other dtors and check inv on throw (as dtor threw).
182 << ok_b(BOOST_CONTRACT_TEST_post
)
183 << ok_c(BOOST_CONTRACT_TEST_post
)
185 BOOST_TEST(out
.eq(ok
.str()));
186 } catch(...) { BOOST_TEST(false); }
188 #undef BOOST_CONTRACT_TEST_post
189 return boost::report_errors();