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/core/virtual.hpp>
13 #include <boost/contract_macro.hpp>
14 #include <boost/detail/lightweight_test.hpp>
17 boost::contract::test::detail::oteststream out;
20 BOOST_CONTRACT_STATIC_INVARIANT({
21 boost::contract::test::detail::unprotected_commas<void, void, void>::
23 out << "b::static_inv" << std::endl;
26 BOOST_CONTRACT_INVARIANT({
27 boost::contract::test::detail::unprotected_commas<void, void, void>::
29 out << "b::inv" << std::endl;
32 virtual void f(int x, boost::contract::virtual_* v = 0) = 0;
35 void b::f(int x, boost::contract::virtual_* v) {
36 BOOST_CONTRACT_OLD_PTR(
37 boost::contract::test::detail::unprotected_commas<int, void, void>::
40 (boost::contract::test::detail::unprotected_commas<void, void, void>::
43 (boost::contract::test::detail::unprotected_commas<void, void, void>::
46 BOOST_CONTRACT_PUBLIC_FUNCTION(
47 boost::contract::test::detail::unprotected_commas<void, void, void>::
49 boost::contract::test::detail::unprotected_commas<void, void, void>::
52 BOOST_CONTRACT_PRECONDITION([] {
53 boost::contract::test::detail::unprotected_commas<
54 void, void, void>::call();
55 out << "b::f::pre" << std::endl;
57 BOOST_CONTRACT_OLD([] {
58 boost::contract::test::detail::unprotected_commas<
59 void, void, void>::call();
60 out << "b::f::old" << std::endl;
62 BOOST_CONTRACT_POSTCONDITION([] {
63 boost::contract::test::detail::unprotected_commas<
64 void, void, void>::call();
65 out << "b::f::post" << std::endl;
68 out << "b::f::body" << std::endl;
72 #define BASES public boost::contract::test::detail::unprotected_commas< \
76 typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types;
77 BOOST_CONTRACT_OVERRIDE(f)
79 BOOST_CONTRACT_STATIC_INVARIANT({
80 boost::contract::test::detail::unprotected_commas<void, void, void>::
82 out << "a::static_inv" << std::endl;
85 BOOST_CONTRACT_INVARIANT({
86 boost::contract::test::detail::unprotected_commas<void, void, void>::
88 out << "a::inv" << std::endl;
91 virtual void f(int x, boost::contract::virtual_* v = 0) {
92 BOOST_CONTRACT_OLD_PTR(
93 boost::contract::test::detail::unprotected_commas<int, void, void>::
96 (boost::contract::test::detail::unprotected_commas<void, void,
99 (boost::contract::test::detail::unprotected_commas<void, void,
102 BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE(
103 boost::contract::test::detail::unprotected_commas<override_f, void,
106 boost::contract::test::detail::unprotected_commas<void, void, void>
109 boost::contract::test::detail::unprotected_commas<void, void, void>
111 boost::contract::test::detail::unprotected_commas<void, void, void>
114 BOOST_CONTRACT_PRECONDITION([] {
115 boost::contract::test::detail::unprotected_commas<
116 void, void, void>::call();
117 out << "a::f::pre" << std::endl;
119 BOOST_CONTRACT_OLD([] {
120 boost::contract::test::detail::unprotected_commas<
121 void, void, void>::call();
122 out << "a::f::old" << std::endl;
124 BOOST_CONTRACT_POSTCONDITION([] {
125 boost::contract::test::detail::unprotected_commas<
126 void, void, void>::call();
127 out << "a::f::post" << std::endl;
130 out << "a::f::body" << std::endl;
135 std::ostringstream ok;
141 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
142 << "b::static_inv" << std::endl
143 << "b::inv" << std::endl
144 << "a::static_inv" << std::endl
145 << "a::inv" << std::endl
147 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
148 << "b::f::pre" << std::endl
150 #ifndef BOOST_CONTRACT_NO_OLDS
151 << "b::f::old" << std::endl
152 << "a::f::old" << std::endl
154 << "a::f::body" << std::endl
155 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
156 << "b::static_inv" << std::endl
157 << "b::inv" << std::endl
158 << "a::static_inv" << std::endl
159 << "a::inv" << std::endl
161 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
162 << "b::f::old" << std::endl // Called by post (so under NO_POST).
163 << "b::f::post" << std::endl
164 << "a::f::post" << std::endl
167 BOOST_TEST(out.eq(ok.str()));
169 return boost::report_errors();