]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/contract/test/public_function/decl_entry_static_inv_mid.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / contract / test / public_function / decl_entry_static_inv_mid.cpp
1
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
6
7 // Test only middle base class with entry static invariants.
8
9 #define BOOST_CONTRACT_TEST_NO_A_STATIC_INV
10 #undef BOOST_CONTRACT_TEST_NO_B_STATIC_INV
11 #define BOOST_CONTRACT_TEST_NO_C_STATIC_INV
12 #include "decl.hpp"
13
14 #include <boost/preprocessor/control/iif.hpp>
15 #include <boost/detail/lightweight_test.hpp>
16 #include <sstream>
17 #include <string>
18
19 std::string ok_end() {
20 std::ostringstream ok; ok
21 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
22 << "c::f::pre" << std::endl
23 #endif
24 #ifndef BOOST_CONTRACT_NO_OLDS
25 << "c::f::old" << std::endl
26 << "b::f::old" << std::endl
27 << "a::f::old" << std::endl
28 #endif
29 << "a::f::body" << std::endl
30 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
31 << "c::inv" << std::endl
32 << "b::static_inv" << std::endl
33 << "b::inv" << std::endl
34 << "a::inv" << std::endl
35 #endif
36 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
37 << "c::f::old" << std::endl
38 << "c::f::post" << std::endl
39 << "b::f::old" << std::endl
40 << "b::f::post" << std::endl
41 << "a::f::post" << std::endl
42 #endif
43 ;
44 return ok.str();
45 }
46
47 struct err {}; // Global decl so visible in MSVC10 lambdas.
48
49 int main() {
50 std::ostringstream ok;
51
52 #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
53 #define BOOST_CONTRACT_TEST_entry_inv 0
54 #else
55 #define BOOST_CONTRACT_TEST_entry_inv 1
56 #endif
57
58 a aa;
59
60 a_entry_static_inv = true;
61 b_entry_static_inv = true;
62 c_entry_static_inv = true;
63 a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =
64 BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false);
65 out.str("");
66 aa.f();
67 ok.str(""); ok // Test nothing failed.
68 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
69 << "c::inv" << std::endl
70 << "b::static_inv" << std::endl
71 << "b::inv" << std::endl
72 << "a::inv" << std::endl
73 #endif
74 << ok_end()
75 ;
76 BOOST_TEST(out.eq(ok.str()));
77
78 boost::contract::set_entry_invariant_failure(
79 [] (boost::contract::from) { throw err(); });
80
81 a_entry_static_inv = false;
82 b_entry_static_inv = true;
83 c_entry_static_inv = true;
84 a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true;
85 out.str("");
86 try {
87 aa.f();
88 ok.str(""); ok
89 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
90 << "c::inv" << std::endl
91 << "b::static_inv" << std::endl
92 << "b::inv" << std::endl
93 << "a::inv" << std::endl
94 #endif
95 << ok_end()
96 ;
97 BOOST_TEST(out.eq(ok.str()));
98 } catch(...) { BOOST_TEST(false); }
99
100 a_entry_static_inv = true;
101 b_entry_static_inv = false;
102 c_entry_static_inv = true;
103 a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =
104 BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false);
105 out.str("");
106 try {
107 aa.f();
108 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
109 BOOST_TEST(false);
110 } catch(err const&) {
111 #endif
112 ok.str(""); ok
113 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
114 << "c::inv" << std::endl
115 << "b::static_inv" << std::endl // Test this fail.
116 #else
117 << ok_end()
118 #endif
119 ;
120 BOOST_TEST(out.eq(ok.str()));
121 } catch(...) { BOOST_TEST(false); }
122
123 a_entry_static_inv = true;
124 b_entry_static_inv = true;
125 c_entry_static_inv = false;
126 a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true;
127 out.str("");
128 try {
129 aa.f();
130 ok.str(""); ok
131 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
132 << "c::inv" << std::endl
133 << "b::static_inv" << std::endl
134 << "b::inv" << std::endl
135 << "a::inv" << std::endl
136 #endif
137 << ok_end()
138 ;
139 BOOST_TEST(out.eq(ok.str()));
140 } catch(...) { BOOST_TEST(false); }
141
142 a_entry_static_inv = false;
143 b_entry_static_inv = false;
144 c_entry_static_inv = false;
145 a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =
146 BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false);
147 out.str("");
148 try {
149 aa.f();
150 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
151 BOOST_TEST(false);
152 } catch(err const&) {
153 #endif
154 ok.str(""); ok
155 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
156 << "c::inv" << std::endl
157 // Test this failed (as all did).
158 << "b::static_inv" << std::endl
159 #else
160 << ok_end()
161 #endif
162 ;
163 BOOST_TEST(out.eq(ok.str()));
164 } catch(...) { BOOST_TEST(false); }
165
166 #undef BOOST_CONTRACT_TEST_entry_inv
167 return boost::report_errors();
168 }
169