• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 #ifndef BOOST_CONTRACT_TEST_LIB_B_INLINED_HPP_
3 #define BOOST_CONTRACT_TEST_LIB_B_INLINED_HPP_
4 
5 // Copyright (C) 2008-2018 Lorenzo Caminiti
6 // Distributed under the Boost Software License, Version 1.0 (see accompanying
7 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
8 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
9 
10 #include "lib_b.hpp"
11 #include "lib_a.hpp"
12 #include "../detail/oteststream.hpp"
13 #include <boost/contract.hpp> // All headers to test ODR for entire lib.
14 
call_f()15 bool call_f() {
16     a aa;
17     a::x_type x; x.value = -123;
18     return aa.f(x) == -123;
19 }
20 
static_invariant()21 void b::static_invariant() {
22     using boost::contract::test::detail::out;
23     out("b::static_inv\n");
24 }
25 
invariant() const26 void b::invariant() const {
27     using boost::contract::test::detail::out;
28     out("b::inv\n");
29 }
30 
g()31 void b::g() {
32     using boost::contract::test::detail::out;
33     boost::contract::check c = boost::contract::public_function(this)
34         .precondition([&] {
35             out("b::g::pre\n");
36             BOOST_CONTRACT_ASSERT(call_f());
37         })
38         .old([&] { out("b::g::old\n"); })
39         .postcondition([&] {
40             out("b::g::post\n");
41             BOOST_CONTRACT_ASSERT(call_f());
42         })
43     ;
44     out("b::g::body\n");
45 }
46 
test_disable_pre_failure()47 bool b::test_disable_pre_failure() {
48     using boost::contract::test::detail::out;
49     a::disable_pre_failure();
50     out("");
51     boost::contract::precondition_failure(boost::contract::from());
52     return boost::contract::test::detail::oteststream::eq(out(),
53             "a::pre_failure\n");
54 }
55 
test_disable_post_failure()56 bool b::test_disable_post_failure() {
57     using boost::contract::test::detail::out;
58     a::disable_post_failure();
59     out("");
60     boost::contract::postcondition_failure(boost::contract::from());
61     return boost::contract::test::detail::oteststream::eq(out(),
62             "a::post_failure\n");
63 }
64 
test_disable_entry_inv_failure()65 bool b::test_disable_entry_inv_failure() {
66     using boost::contract::test::detail::out;
67     a::disable_entry_inv_failure();
68     out("");
69     boost::contract::entry_invariant_failure(boost::contract::from());
70     return boost::contract::test::detail::oteststream::eq(out(),
71             "a::entry_inv_failure\n");
72 }
73 
test_disable_exit_inv_failure()74 bool b::test_disable_exit_inv_failure() {
75     using boost::contract::test::detail::out;
76     a::disable_exit_inv_failure();
77     out("");
78     boost::contract::exit_invariant_failure(boost::contract::from());
79     return boost::contract::test::detail::oteststream::eq(out(),
80             "a::exit_inv_failure\n");
81 }
82 
test_disable_inv_failure()83 bool b::test_disable_inv_failure() {
84     using boost::contract::test::detail::out;
85 
86     a::disable_inv_failure();
87     out("");
88     boost::contract::entry_invariant_failure(boost::contract::from());
89     bool entry_inv = boost::contract::test::detail::oteststream::eq(out(),
90             "a::inv_failure\n");
91     out("");
92     boost::contract::exit_invariant_failure(boost::contract::from());
93     bool exit_inv = boost::contract::test::detail::oteststream::eq(out(),
94             "a::inv_failure\n");
95 
96     return entry_inv && exit_inv;
97 }
98 
test_disable_failure()99 bool b::test_disable_failure() {
100     using boost::contract::test::detail::out;
101 
102     a::disable_failure();
103     out("");
104     boost::contract::precondition_failure(boost::contract::from());
105     bool pre = boost::contract::test::detail::oteststream::eq(out(),
106             "a::failure\n");
107     out("");
108     boost::contract::postcondition_failure(boost::contract::from());
109     bool post = boost::contract::test::detail::oteststream::eq(out(),
110             "a::failure\n");
111     out("");
112     boost::contract::entry_invariant_failure(boost::contract::from());
113     bool entry_inv = boost::contract::test::detail::oteststream::eq(out(),
114             "a::failure\n");
115     out("");
116     boost::contract::exit_invariant_failure(boost::contract::from());
117     bool exit_inv = boost::contract::test::detail::oteststream::eq(out(),
118             "a::failure\n");
119 
120     return pre && post && entry_inv && exit_inv;
121 }
122 
123 #endif // #include guard
124 
125