]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/contract/test/constructor/ifdef_macro.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 contract compilation on/off (using macro interface).
9 #include "../detail/oteststream.hpp"
10 #include "../detail/unprotected_commas.hpp"
11 #include <boost/contract/core/config.hpp>
12 #include <boost/contract/constructor.hpp> // Outside #if below for ctor pre.
13 #include <boost/contract_macro.hpp>
14 #include <boost/detail/lightweight_test.hpp>
17 boost::contract::test::detail::oteststream out
;
20 private boost::contract::constructor_precondition
<b
> // OK, always in code.
22 BOOST_CONTRACT_STATIC_INVARIANT({
23 boost::contract::test::detail::unprotected_commas
<void, void, void>::
25 out
<< "b::static_inv" << std::endl
;
28 BOOST_CONTRACT_INVARIANT({
29 boost::contract::test::detail::unprotected_commas
<void, void, void>::
31 out
<< "b::inv" << std::endl
;
35 BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION(b
)([] {
36 boost::contract::test::detail::unprotected_commas
<void, void, void>
38 out
<< "b::ctor::pre" << std::endl
;
41 BOOST_CONTRACT_OLD_PTR(
42 boost::contract::test::detail::unprotected_commas
<int, void,
46 (boost::contract::test::detail::unprotected_commas
<void, void,
49 BOOST_CONTRACT_CONSTRUCTOR(this)
50 BOOST_CONTRACT_OLD([] {
51 boost::contract::test::detail::unprotected_commas
<
52 void, void, void>::call();
53 out
<< "b::f::old" << std::endl
;
55 BOOST_CONTRACT_POSTCONDITION([] {
56 boost::contract::test::detail::unprotected_commas
<
57 void, void, void>::call();
58 out
<< "b::ctor::post" << std::endl
;
61 out
<< "b::ctor::body" << std::endl
;
66 private boost::contract::constructor_precondition
<a
>, // OK, always in code.
69 BOOST_CONTRACT_STATIC_INVARIANT({
70 boost::contract::test::detail::unprotected_commas
<void, void, void>::
72 out
<< "a::static_inv" << std::endl
;
75 BOOST_CONTRACT_INVARIANT({
76 boost::contract::test::detail::unprotected_commas
<void, void, void>::
78 out
<< "a::inv" << std::endl
;
82 BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION(a
)([] {
83 boost::contract::test::detail::unprotected_commas
<void, void, void>
85 out
<< "a::ctor::pre" << std::endl
; }
89 BOOST_CONTRACT_OLD_PTR(
90 boost::contract::test::detail::unprotected_commas
<int, void,
94 (boost::contract::test::detail::unprotected_commas
<void, void,
97 BOOST_CONTRACT_CONSTRUCTOR(boost::contract::test::detail::
98 unprotected_commas
<void, void, void>::same(this))
99 BOOST_CONTRACT_OLD([] {
100 boost::contract::test::detail::unprotected_commas
<
101 void, void, void>::call();
102 out
<< "a::f::old" << std::endl
;
104 BOOST_CONTRACT_POSTCONDITION([] {
105 boost::contract::test::detail::unprotected_commas
<
106 void, void, void>::call();
107 out
<< "a::ctor::post" << std::endl
;
110 out
<< "a::ctor::body" << std::endl
;
115 std::ostringstream ok
;
119 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
120 << "a::ctor::pre" << std::endl
121 << "b::ctor::pre" << std::endl
124 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
125 << "b::static_inv" << std::endl
127 #ifndef BOOST_CONTRACT_NO_OLDS
128 << "b::f::old" << std::endl
130 << "b::ctor::body" << std::endl
131 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
132 << "b::static_inv" << std::endl
133 << "b::inv" << std::endl
135 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
136 << "b::ctor::post" << std::endl
139 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
140 << "a::static_inv" << std::endl
142 #ifndef BOOST_CONTRACT_NO_OLDS
143 << "a::f::old" << std::endl
145 << "a::ctor::body" << std::endl
146 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
147 << "a::static_inv" << std::endl
148 << "a::inv" << std::endl
150 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
151 << "a::ctor::post" << std::endl
154 BOOST_TEST(out
.eq(ok
.str()));
155 return boost::report_errors();