2 #ifndef BOOST_CONTRACT_TEST_CONSTRUCTOR_DECL_HPP_
3 #define BOOST_CONTRACT_TEST_CONSTRUCTOR_DECL_HPP_
5 // Copyright (C) 2008-2018 Lorenzo Caminiti
6 // Distributed under the Boost Software License, Version 1.0 (see accompanying
7 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
8 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
10 // Test with and without pre, post, and inv declarations.
12 #include "../detail/oteststream.hpp"
13 #include <boost/contract/constructor.hpp>
14 #include <boost/contract/base_types.hpp>
15 #include <boost/contract/check.hpp>
16 #include <boost/contract/assert.hpp>
18 boost::contract::test::detail::oteststream out;
20 bool c_pre = true, c_post = true;
21 bool c_entering_static_inv = true, c_entry_static_inv = true,
22 c_exit_static_inv = true;
23 bool c_exit_inv = true; // Only exit non-static inv for ctors.
25 #ifndef BOOST_CONTRACT_TEST_NO_C_PRE
26 : private boost::contract::constructor_precondition<c>
29 #ifndef BOOST_CONTRACT_TEST_NO_C_STATIC_INV
30 static void static_invariant() {
31 out << "c::static_inv" << std::endl;
32 if(c_entering_static_inv) BOOST_CONTRACT_ASSERT(c_entry_static_inv);
33 else BOOST_CONTRACT_ASSERT(c_exit_static_inv);
34 c_entering_static_inv = false;
37 #ifndef BOOST_CONTRACT_TEST_NO_C_INV
38 void invariant() const {
39 out << "c::inv" << std::endl;
40 BOOST_CONTRACT_ASSERT(c_exit_inv);
45 #ifndef BOOST_CONTRACT_TEST_NO_C_PRE
46 : boost::contract::constructor_precondition<c>([] {
47 out << "c::ctor::pre" << std::endl;
48 BOOST_CONTRACT_ASSERT(c_pre);
52 boost::contract::check c = boost::contract::constructor(this)
53 .old([] { out << "c::ctor::old" << std::endl; })
54 #ifndef BOOST_CONTRACT_TEST_NO_C_POST
56 out << "c::ctor::post" << std::endl;
57 BOOST_CONTRACT_ASSERT(c_post);
61 out << "c::ctor::body" << std::endl;
65 bool b_pre = true, b_post = true;
66 bool b_entering_static_inv = true, b_entry_static_inv = true,
67 b_exit_static_inv = true;
68 bool b_exit_inv = true; // Only exit non-static inv for ctors.
70 #ifndef BOOST_CONTRACT_TEST_NO_B_PRE
72 private boost::contract::constructor_precondition<b>, public c
74 #define BASES public c
78 typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types;
81 #ifndef BOOST_CONTRACT_TEST_NO_B_STATIC_INV
82 static void static_invariant() {
83 out << "b::static_inv" << std::endl;
84 if(b_entering_static_inv) BOOST_CONTRACT_ASSERT(b_entry_static_inv);
85 else BOOST_CONTRACT_ASSERT(b_exit_static_inv);
86 b_entering_static_inv = false;
89 #ifndef BOOST_CONTRACT_TEST_NO_B_INV
90 void invariant() const {
91 out << "b::inv" << std::endl;
92 BOOST_CONTRACT_ASSERT(b_exit_inv);
97 #ifndef BOOST_CONTRACT_TEST_NO_B_PRE
98 : boost::contract::constructor_precondition<b>([] {
99 out << "b::ctor::pre" << std::endl;
100 BOOST_CONTRACT_ASSERT(b_pre);
104 boost::contract::check c = boost::contract::constructor(this)
105 .old([] { out << "b::ctor::old" << std::endl; })
106 #ifndef BOOST_CONTRACT_TEST_NO_B_POST
108 out << "b::ctor::post" << std::endl;
109 BOOST_CONTRACT_ASSERT(b_post);
113 out << "b::ctor::body" << std::endl;
117 bool a_pre = true, a_post = true;
118 bool a_entering_static_inv = true, a_entry_static_inv = true,
119 a_exit_static_inv = true;
120 bool a_exit_inv = true; // Only exit non-static inv for ctors.
122 #ifndef BOOST_CONTRACT_TEST_NO_A_PRE
124 private boost::contract::constructor_precondition<a>, public b
126 #define BASES public b
130 typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types;
133 #ifndef BOOST_CONTRACT_TEST_NO_A_STATIC_INV
134 static void static_invariant() {
135 out << "a::static_inv" << std::endl;
136 if(a_entering_static_inv) BOOST_CONTRACT_ASSERT(a_entry_static_inv);
137 else BOOST_CONTRACT_ASSERT(a_exit_static_inv);
138 a_entering_static_inv = false;
141 #ifndef BOOST_CONTRACT_TEST_NO_A_INV
142 void invariant() const {
143 out << "a::inv" << std::endl;
144 BOOST_CONTRACT_ASSERT(a_exit_inv);
149 #ifndef BOOST_CONTRACT_TEST_NO_A_PRE
150 : boost::contract::constructor_precondition<a>([] {
151 out << "a::ctor::pre" << std::endl;
152 BOOST_CONTRACT_ASSERT(a_pre);
156 boost::contract::check c = boost::contract::constructor(this)
157 .old([] { out << "a::ctor::old" << std::endl; })
158 #ifndef BOOST_CONTRACT_TEST_NO_A_POST
160 out << "a::ctor::post" << std::endl;
161 BOOST_CONTRACT_ASSERT(a_post);
165 out << "a::ctor::body" << std::endl;
169 #endif // #include guard