• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 #ifndef BOOST_CONTRACT_TEST_FUNCTION_DECL_HPP_
3 #define BOOST_CONTRACT_TEST_FUNCTION_DECL_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 // Test with and without pre and post declarations.
11 
12 #include "../detail/oteststream.hpp"
13 #include <boost/contract/function.hpp>
14 #include <boost/contract/check.hpp>
15 #include <boost/contract/assert.hpp>
16 
17 boost::contract::test::detail::oteststream out;
18 
19 bool f_pre = true, f_post = true;
f()20 void f() {
21     boost::contract::check c = boost::contract::function()
22         #ifndef BOOST_CONTRACT_TEST_NO_F_PRE
23             .precondition([] {
24                 out << "f::pre" << std::endl;
25                 BOOST_CONTRACT_ASSERT(f_pre);
26             })
27         #endif
28         .old([] { out << "f::old" << std::endl; })
29         #ifndef BOOST_CONTRACT_TEST_NO_F_POST
30             .postcondition([] {
31                 out << "f::post" << std::endl;
32                 BOOST_CONTRACT_ASSERT(f_post);
33             })
34         #endif
35     ;
36     out << "f::body" << std::endl;
37 }
38 
39 #endif // #include guard
40 
41