]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/contract/test/public_function/decl_pre_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 preconditions.
9 #undef BOOST_CONTRACT_TEST_NO_A_PRE
10 #define BOOST_CONTRACT_TEST_NO_B_PRE
11 #undef BOOST_CONTRACT_TEST_NO_C_PRE
14 #include <boost/detail/lightweight_test.hpp>
18 std::string
ok_begin() {
19 std::ostringstream ok
; ok
<< "" // Suppress a warning.
20 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
21 << "c::static_inv" << std::endl
22 << "c::inv" << std::endl
23 << "b::static_inv" << std::endl
24 << "b::inv" << std::endl
25 << "a::static_inv" << std::endl
26 << "a::inv" << std::endl
32 std::string
ok_end() {
33 std::ostringstream ok
; ok
34 #ifndef BOOST_CONTRACT_NO_OLDS
35 << "c::f::old" << std::endl
36 << "b::f::old" << std::endl
37 << "a::f::old" << std::endl
39 << "a::f::body" << std::endl
40 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
41 << "c::static_inv" << std::endl
42 << "c::inv" << std::endl
43 << "b::static_inv" << std::endl
44 << "b::inv" << std::endl
45 << "a::static_inv" << std::endl
46 << "a::inv" << std::endl
48 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
49 << "c::f::old" << std::endl
// Old only if post (or except) run.
50 << "c::f::post" << std::endl
51 << "b::f::old" << std::endl
52 << "b::f::post" << std::endl
53 << "a::f::post" << std::endl
59 struct err
{}; // Global decl so visible in MSVC10 lambdas.
62 std::ostringstream ok
;
71 ok
.str(""); ok
// Test nothing failed.
73 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
74 << "c::f::pre" << std::endl
// Test only c pre checked.
78 BOOST_TEST(out
.eq(ok
.str()));
87 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
88 << "c::f::pre" << std::endl
89 // Test b's pre not checked.
90 << "a::f::pre" << std::endl
94 BOOST_TEST(out
.eq(ok
.str()));
103 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
104 << "c::f::pre" << std::endl
// Test only c pre checked.
108 BOOST_TEST(out
.eq(ok
.str()));
110 boost::contract::set_precondition_failure(
111 [] (boost::contract::from
) { throw err(); });
119 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
121 } catch(err
const&) {
125 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
126 << "c::f::pre" << std::endl
127 << "a::f::pre" << std::endl
// Only ends pre checked and failed.
132 BOOST_TEST(out
.eq(ok
.str()));
133 } catch(...) { BOOST_TEST(false); }
141 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
143 } catch(err
const&) {
147 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
148 << "c::f::pre" << std::endl
149 << "a::f::pre" << std::endl
// Only ends pre checked and failed.
154 BOOST_TEST(out
.eq(ok
.str()));
155 } catch(...) { BOOST_TEST(false); }
157 return boost::report_errors();