]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/contract/test/constructor/decl_pre_all.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 all derived and base classes with preconditions.
9 #undef BOOST_CONTRACT_TEST_NO_A_PRE
10 #undef 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_after() {
19 std::ostringstream ok
; ok
20 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
21 << "c::static_inv" << std::endl
23 #ifndef BOOST_CONTRACT_NO_OLDS
24 << "c::ctor::old" << std::endl
26 << "c::ctor::body" << std::endl
27 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
28 << "c::static_inv" << std::endl
29 << "c::inv" << std::endl
31 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
32 << "c::ctor::post" << std::endl
35 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
36 << "b::static_inv" << std::endl
38 #ifndef BOOST_CONTRACT_NO_OLDS
39 << "b::ctor::old" << std::endl
41 << "b::ctor::body" << std::endl
42 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
43 << "b::static_inv" << std::endl
44 << "b::inv" << std::endl
46 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
47 << "b::ctor::post" << std::endl
50 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
51 << "a::static_inv" << std::endl
53 #ifndef BOOST_CONTRACT_NO_OLDS
54 << "a::ctor::old" << std::endl
56 << "a::ctor::body" << std::endl
57 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
58 << "a::static_inv" << std::endl
59 << "a::inv" << std::endl
61 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
62 << "a::ctor::post" << std::endl
68 struct err
{}; // Global decl so visible in MSVC10 lambdas.
71 std::ostringstream ok
;
79 ok
.str(""); ok
// Test nothing failed.
80 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
81 << "a::ctor::pre" << std::endl
82 << "b::ctor::pre" << std::endl
83 << "c::ctor::pre" << std::endl
87 BOOST_TEST(out
.eq(ok
.str()));
90 boost::contract::set_precondition_failure(
91 [] (boost::contract::from
) { throw err(); });
99 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
101 } catch(err
const&) {
104 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
105 << "a::ctor::pre" << std::endl
// Test this failed.
110 BOOST_TEST(out
.eq(ok
.str()));
111 } catch(...) { BOOST_TEST(false); }
119 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
121 } catch(err
const&) {
124 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
125 << "a::ctor::pre" << std::endl
126 << "b::ctor::pre" << std::endl
// Test this failed.
131 BOOST_TEST(out
.eq(ok
.str()));
132 } catch(...) { BOOST_TEST(false); }
140 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
142 } catch(err
const&) {
145 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
146 << "a::ctor::pre" << std::endl
147 << "b::ctor::pre" << std::endl
148 << "c::ctor::pre" << std::endl
// Test this failed.
153 BOOST_TEST(out
.eq(ok
.str()));
154 } catch(...) { BOOST_TEST(false); }
162 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
164 } catch(err
const&) {
167 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
168 << "a::ctor::pre" << std::endl
// Test this failed (as all did).
173 BOOST_TEST(out
.eq(ok
.str()));
174 } catch(...) { BOOST_TEST(false); }
176 return boost::report_errors();