• 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 base classes without 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_ENTRY_INVARIANTS
20             << "c::static_inv" << std::endl
21             << "c::inv" << std::endl
22             << "b::static_inv" << std::endl
23             << "b::inv" << std::endl
24             << "a::static_inv" << std::endl
25             << "a::inv" << std::endl
26         #endif
27         #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
28             << "c::f::pre" << std::endl
29         #endif
30         #ifndef BOOST_CONTRACT_NO_OLDS
31             << "c::f::old" << std::endl
32             << "b::f::old" << std::endl
33             << "a::f::old" << std::endl
34         #endif
35         << "a::f::body" << std::endl
36         #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
37             << "c::static_inv" << std::endl
38             << "c::inv" << std::endl
39             << "b::static_inv" << std::endl
40             << "b::inv" << std::endl
41             << "a::static_inv" << std::endl
42             << "a::inv" << std::endl
43         #endif
44         #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
45             // No postconditions.
46             << "c::f::old" << std::endl
47             << "b::f::old" << std::endl
48         #endif
49     ;
50 
51     a aa;
52 
53     a_post = true;
54     b_post = true;
55     c_post = true;
56     out.str("");
57     aa.f();
58     BOOST_TEST(out.eq(ok.str()));
59 
60     a_post = false;
61     b_post = true;
62     c_post = true;
63     out.str("");
64     aa.f();
65     BOOST_TEST(out.eq(ok.str()));
66 
67     a_post = true;
68     b_post = false;
69     c_post = true;
70     out.str("");
71     aa.f();
72     BOOST_TEST(out.eq(ok.str()));
73 
74     a_post = true;
75     b_post = true;
76     c_post = false;
77     out.str("");
78     aa.f();
79     BOOST_TEST(out.eq(ok.str()));
80 
81     a_post = false;
82     b_post = false;
83     c_post = false;
84     out.str("");
85     aa.f();
86     BOOST_TEST(out.eq(ok.str()));
87 
88     return boost::report_errors();
89 }
90 
91