• 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 only middle base class with postconditions.
8 
9 #define BOOST_CONTRACT_TEST_NO_A_POST
10 #define BOOST_CONTRACT_TEST_NO_B_POST
11 #define BOOST_CONTRACT_TEST_NO_C_POST
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             << "c::inv" << std::endl
35         #endif
36 
37         #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
38             << "b::static_inv" << std::endl
39         #endif
40         #ifndef BOOST_CONTRACT_NO_OLDS
41             << "b::ctor::old" << std::endl
42         #endif
43         << "b::ctor::body" << std::endl
44         #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
45             << "b::static_inv" << std::endl
46             << "b::inv" << std::endl
47         #endif
48 
49         #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
50             << "a::static_inv" << std::endl
51         #endif
52         #ifndef BOOST_CONTRACT_NO_OLDS
53             << "a::ctor::old" << std::endl
54         #endif
55         << "a::ctor::body" << std::endl
56         #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
57             << "a::static_inv" << std::endl
58             << "a::inv" << std::endl
59         #endif
60     ;
61 
62     a_post = true;
63     b_post = true;
64     c_post = true;
65     {
66         out.str("");
67         a aa;
68         BOOST_TEST(out.eq(ok.str()));
69     }
70 
71     a_post = false;
72     b_post = true;
73     c_post = true;
74     {
75         out.str("");
76         a aa;
77         BOOST_TEST(out.eq(ok.str()));
78     }
79 
80     a_post = true;
81     b_post = false;
82     c_post = true;
83     {
84         out.str("");
85         a aa;
86         BOOST_TEST(out.eq(ok.str()));
87     }
88 
89     a_post = true;
90     b_post = true;
91     c_post = false;
92     {
93         out.str("");
94         a aa;
95         BOOST_TEST(out.eq(ok.str()));
96     }
97 
98     a_post = false;
99     b_post = false;
100     c_post = false;
101     {
102         out.str("");
103         a aa;
104         BOOST_TEST(out.eq(ok.str()));
105     }
106 
107     return boost::report_errors();
108 }
109 
110