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 invariants.
8
9 #define BOOST_CONTRACT_TEST_NO_A_INV
10 #define BOOST_CONTRACT_TEST_NO_B_INV
11 #define BOOST_CONTRACT_TEST_NO_C_INV
12 #include "decl.hpp"
13
14 #include <boost/preprocessor/control/iif.hpp>
15 #include <boost/detail/lightweight_test.hpp>
16 #include <sstream>
17
main()18 int main() {
19 std::ostringstream ok;
20 ok.str(""); ok // Test nothing fails.
21 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
22 << "c::static_inv" << std::endl
23 << "b::static_inv" << std::endl
24 << "a::static_inv" << std::endl
25 #endif
26 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
27 << "c::f::pre" << std::endl
28 #endif
29 #ifndef BOOST_CONTRACT_NO_OLDS
30 << "c::f::old" << std::endl
31 << "b::f::old" << std::endl
32 << "a::f::old" << std::endl
33 #endif
34 << "a::f::body" << std::endl
35 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
36 << "c::static_inv" << std::endl
37 << "b::static_inv" << std::endl
38 << "a::static_inv" << std::endl
39 #endif
40 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
41 << "c::f::old" << std::endl
42 << "c::f::post" << std::endl
43 << "b::f::old" << std::endl
44 << "b::f::post" << std::endl
45 << "a::f::post" << std::endl
46 #endif
47 ;
48
49 #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
50 #define BOOST_CONTRACT_TEST_entry_inv 0
51 #else
52 #define BOOST_CONTRACT_TEST_entry_inv 1
53 #endif
54
55 a aa;
56
57 a_entry_inv = true;
58 b_entry_inv = true;
59 c_entry_inv = true;
60 a_entering_inv = b_entering_inv = c_entering_inv =
61 BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false);
62 out.str("");
63 aa.f();
64 BOOST_TEST(out.eq(ok.str()));
65
66 a_entry_inv = false;
67 b_entry_inv = true;
68 c_entry_inv = true;
69 a_entering_inv = b_entering_inv = c_entering_inv =
70 BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false);
71 out.str("");
72 aa.f();
73 BOOST_TEST(out.eq(ok.str()));
74
75 a_entry_inv = true;
76 b_entry_inv = false;
77 c_entry_inv = true;
78 a_entering_inv = b_entering_inv = c_entering_inv =
79 BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false);
80 out.str("");
81 aa.f();
82 BOOST_TEST(out.eq(ok.str()));
83
84 a_entry_inv = true;
85 b_entry_inv = true;
86 c_entry_inv = false;
87 a_entering_inv = b_entering_inv = c_entering_inv =
88 BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false);
89 out.str("");
90 aa.f();
91 BOOST_TEST(out.eq(ok.str()));
92
93 a_entry_inv = false;
94 b_entry_inv = false;
95 c_entry_inv = false;
96 a_entering_inv = b_entering_inv = c_entering_inv =
97 BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false);
98 out.str("");
99 aa.f();
100 BOOST_TEST(out.eq(ok.str()));
101
102 #undef BOOST_CONTRACT_TEST_entry_inv
103 return boost::report_errors();
104 }
105
106