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 all derived and base classes without entry static invariants.
8
9#define BOOST_CONTRACT_TEST_NO_A_STATIC_INV
10#define 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
18int main() {
19 std::ostringstream ok; ok // Test nothing fails.
20 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
21 << "a::inv" << std::endl
22 #endif
23 #ifndef BOOST_CONTRACT_NO_OLDS
24 << "a::dtor::old" << std::endl
25 #endif
26 << "a::dtor::body" << std::endl
27 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
28 << "a::dtor::post" << std::endl
29 #endif
30
31 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
32 << "b::inv" << std::endl
33 #endif
34 #ifndef BOOST_CONTRACT_NO_OLDS
35 << "b::dtor::old" << std::endl
36 #endif
37 << "b::dtor::body" << std::endl
38 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
39 << "b::dtor::post" << std::endl
40 #endif
41
42 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
43 << "c::inv" << std::endl
44 #endif
45 #ifndef BOOST_CONTRACT_NO_OLDS
46 << "c::dtor::old" << std::endl
47 #endif
48 << "c::dtor::body" << std::endl
49 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
50 << "c::dtor::post" << std::endl
51 #endif
52 ;
53
54 #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
55 #define BOOST_CONTRACT_TEST_entry_inv 0
56 #else
57 #define BOOST_CONTRACT_TEST_entry_inv 1
58 #endif
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 {
66 a aa;
67 out.str(s: "");
68 }
69 BOOST_TEST(out.eq(ok.str()));
70
71 a_entry_static_inv = false;
72 b_entry_static_inv = true;
73 c_entry_static_inv = true;
74 a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =
75 BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false);
76 {
77 a aa;
78 out.str(s: "");
79 }
80 BOOST_TEST(out.eq(ok.str()));
81
82 a_entry_static_inv = true;
83 b_entry_static_inv = false;
84 c_entry_static_inv = true;
85 a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =
86 BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false);
87 {
88 a aa;
89 out.str(s: "");
90 }
91 BOOST_TEST(out.eq(ok.str()));
92
93 a_entry_static_inv = true;
94 b_entry_static_inv = true;
95 c_entry_static_inv = false;
96 a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =
97 BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false);
98 {
99 a aa;
100 out.str(s: "");
101 }
102 BOOST_TEST(out.eq(ok.str()));
103
104 a_entry_static_inv = false;
105 b_entry_static_inv = false;
106 c_entry_static_inv = false;
107 a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =
108 BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false);
109 {
110 a aa;
111 out.str(s: "");
112 }
113 BOOST_TEST(out.eq(ok.str()));
114
115 #undef BOOST_CONTRACT_TEST_entry_inv
116 return boost::report_errors();
117}
118
119

source code of boost/libs/contract/test/destructor/decl_entry_static_inv_none.cpp