]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/contract/test/constructor/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_PRECONDITIONS
21 << "a::ctor::pre" << std::endl
22 << "b::ctor::pre" << std::endl
23 << "c::ctor::pre" << std::endl
26 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
27 << "c::static_inv" << std::endl
29 #ifndef BOOST_CONTRACT_NO_OLDS
30 << "c::ctor::old" << std::endl
32 << "c::ctor::body" << std::endl
33 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
34 << "c::static_inv" << std::endl
35 << "c::inv" << std::endl
37 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
38 << "c::ctor::post" << std::endl
45 std::ostringstream ok
; ok
46 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
47 << "b::static_inv" << std::endl
49 #ifndef BOOST_CONTRACT_NO_OLDS
50 << "b::ctor::old" << std::endl
52 << "b::ctor::body" << std::endl
53 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
54 << "b::static_inv" << std::endl
55 << "b::inv" << std::endl
57 // No b::ctor::post here.
59 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
60 << "a::static_inv" << std::endl
62 #ifndef BOOST_CONTRACT_NO_OLDS
63 << "a::ctor::old" << std::endl
65 << "a::ctor::body" << std::endl
66 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
67 << "a::static_inv" << std::endl
68 << "a::inv" << std::endl
70 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
71 << "a::ctor::post" << std::endl
77 struct err
{}; // Global decl so visible in MSVC10 lambdas.
80 std::ostringstream ok
;
88 ok
.str(""); ok
// Test nothing failed.
92 BOOST_TEST(out
.eq(ok
.str()));
95 boost::contract::set_postcondition_failure(
96 [] (boost::contract::from
) { throw err(); });
104 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
106 } catch(err
const&) {
110 << ok_ba() // Test a::ctor::post failed.
112 BOOST_TEST(out
.eq(ok
.str()));
113 } catch(...) { BOOST_TEST(false); }
123 << ok_ba() // Test no b::ctor::post so no failure.
125 BOOST_TEST(out
.eq(ok
.str()));
134 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
136 } catch(err
const&) {
139 << ok_c() // Test c::ctor::post failed.
140 #ifdef BOOST_CONTRACT_NO_POSTCONDITIONS
144 BOOST_TEST(out
.eq(ok
.str()));
145 } catch(...) { BOOST_TEST(false); }
153 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
155 } catch(err
const&) {
158 << ok_c() // Test c::ctor::post failed (as all did).
159 #ifdef BOOST_CONTRACT_NO_POSTCONDITIONS
163 BOOST_TEST(out
.eq(ok
.str()));
164 } catch(...) { BOOST_TEST(false); }
166 return boost::report_errors();