decl.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef BOOST_CONTRACT_TEST_FUNCTION_DECL_HPP_
  2. #define BOOST_CONTRACT_TEST_FUNCTION_DECL_HPP_
  3. // Copyright (C) 2008-2018 Lorenzo Caminiti
  4. // Distributed under the Boost Software License, Version 1.0 (see accompanying
  5. // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
  6. // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
  7. // Test with and without pre and post declarations.
  8. #include "../detail/oteststream.hpp"
  9. #include <boost/contract/function.hpp>
  10. #include <boost/contract/check.hpp>
  11. #include <boost/contract/assert.hpp>
  12. boost::contract::test::detail::oteststream out;
  13. bool f_pre = true, f_post = true;
  14. void f() {
  15. boost::contract::check c = boost::contract::function()
  16. #ifndef BOOST_CONTRACT_TEST_NO_F_PRE
  17. .precondition([] {
  18. out << "f::pre" << std::endl;
  19. BOOST_CONTRACT_ASSERT(f_pre);
  20. })
  21. #endif
  22. .old([] { out << "f::old" << std::endl; })
  23. #ifndef BOOST_CONTRACT_TEST_NO_F_POST
  24. .postcondition([] {
  25. out << "f::post" << std::endl;
  26. BOOST_CONTRACT_ASSERT(f_post);
  27. })
  28. #endif
  29. ;
  30. out << "f::body" << std::endl;
  31. }
  32. #endif // #include guard