• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 grandparent classes (ends) with exit 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/detail/lightweight_test.hpp>
15 #include <sstream>
16 
main()17 int main() {
18     std::ostringstream ok; ok // Test nothing fails.
19         #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
20             << "a::ctor::pre" << std::endl
21             << "b::ctor::pre" << std::endl
22             << "c::ctor::pre" << std::endl
23         #endif
24 
25         #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
26             << "c::static_inv" << std::endl
27         #endif
28         #ifndef BOOST_CONTRACT_NO_OLDS
29             << "c::ctor::old" << std::endl
30         #endif
31         << "c::ctor::body" << std::endl
32         #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
33             << "c::static_inv" << std::endl
34         #endif
35         #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
36             << "c::ctor::post" << std::endl
37         #endif
38 
39         #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
40             << "b::static_inv" << std::endl
41         #endif
42         #ifndef BOOST_CONTRACT_NO_OLDS
43             << "b::ctor::old" << std::endl
44         #endif
45         << "b::ctor::body" << std::endl
46         #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
47             << "b::static_inv" << std::endl
48         #endif
49         #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
50             << "b::ctor::post" << std::endl
51         #endif
52 
53         #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
54             << "a::static_inv" << std::endl
55         #endif
56         #ifndef BOOST_CONTRACT_NO_OLDS
57             << "a::ctor::old" << std::endl
58         #endif
59         << "a::ctor::body" << std::endl
60         #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
61             << "a::static_inv" << std::endl
62         #endif
63         #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
64             << "a::ctor::post" << std::endl
65         #endif
66     ;
67 
68     a_exit_inv = true;
69     b_exit_inv = true;
70     c_exit_inv = true;
71     {
72         out.str("");
73         a aa;
74         BOOST_TEST(out.eq(ok.str()));
75     }
76 
77     a_exit_inv = false;
78     b_exit_inv = true;
79     c_exit_inv = true;
80     {
81         out.str("");
82         a aa;
83         BOOST_TEST(out.eq(ok.str()));
84     }
85 
86     a_exit_inv = true;
87     b_exit_inv = false;
88     c_exit_inv = true;
89     {
90         out.str("");
91         a aa;
92         BOOST_TEST(out.eq(ok.str()));
93     }
94 
95     a_exit_inv = true;
96     b_exit_inv = true;
97     c_exit_inv = false;
98     {
99         out.str("");
100         a aa;
101         BOOST_TEST(out.eq(ok.str()));
102     }
103 
104     a_exit_inv = false;
105     b_exit_inv = false;
106     c_exit_inv = false;
107     {
108         out.str("");
109         a aa;
110         BOOST_TEST(out.eq(ok.str()));
111     }
112 
113     return boost::report_errors();
114 }
115 
116