1 2 #ifndef BOOST_CONTRACT_TEST_LIB_A_INLINED_HPP_ 3 #define BOOST_CONTRACT_TEST_LIB_A_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_a.hpp" 11 #include <boost/contract.hpp> // All headers so test ODR for entire lib. 12 13 #ifdef BOOST_CONTRACT_HEADER_ONLY 14 #define BOOST_CONTRACT_TEST_LIB_A_DECLINLINE inline 15 #else 16 #define BOOST_CONTRACT_TEST_LIB_A_DECLINLINE /* nothing */ 17 #endif 18 19 BOOST_CONTRACT_TEST_LIB_A_DECLINLINE static_invariant()20void a::static_invariant() { 21 using boost::contract::test::detail::out; 22 out("a::static_inv\n"); 23 } 24 25 BOOST_CONTRACT_TEST_LIB_A_DECLINLINE invariant() const26void a::invariant() const { 27 using boost::contract::test::detail::out; 28 out("a::inv\n"); 29 } 30 31 BOOST_CONTRACT_TEST_LIB_A_DECLINLINE f(x_type & x)32int a::f(x_type& x) { 33 using boost::contract::test::detail::out; 34 int result; 35 boost::contract::old_ptr<x_type> old_x = 36 BOOST_CONTRACT_OLDOF(x_type::eval(x)); 37 boost::contract::check c = boost::contract::public_function(this) 38 // Capturing [&] so out() visible in MSVC10 lambdas. 39 .precondition([&] { out("a::f::pre\n"); }) 40 .old([&] { out("a::f::old\n"); }) 41 .postcondition([&] { 42 out("a::f::post\n"); 43 BOOST_CONTRACT_ASSERT(x.value == -old_x->value); 44 BOOST_CONTRACT_ASSERT(result == old_x->value); 45 }) 46 ; 47 out("a::f::body\n"); 48 result = x.value; 49 x.value = -x.value; 50 return result; 51 } 52 53 BOOST_CONTRACT_TEST_LIB_A_DECLINLINE disable_pre_failure()54void a::disable_pre_failure() { 55 using boost::contract::test::detail::out; 56 boost::contract::set_precondition_failure([] (boost::contract::from) 57 { out("a::pre_failure\n"); }); 58 } 59 60 BOOST_CONTRACT_TEST_LIB_A_DECLINLINE disable_post_failure()61void a::disable_post_failure() { 62 using boost::contract::test::detail::out; 63 boost::contract::set_postcondition_failure([] (boost::contract::from) 64 { out("a::post_failure\n"); }); 65 } 66 67 BOOST_CONTRACT_TEST_LIB_A_DECLINLINE disable_entry_inv_failure()68void a::disable_entry_inv_failure() { 69 using boost::contract::test::detail::out; 70 boost::contract::set_entry_invariant_failure([] (boost::contract::from) 71 { out("a::entry_inv_failure\n"); }); 72 } 73 74 BOOST_CONTRACT_TEST_LIB_A_DECLINLINE disable_exit_inv_failure()75void a::disable_exit_inv_failure() { 76 using boost::contract::test::detail::out; 77 boost::contract::set_exit_invariant_failure([] (boost::contract::from) 78 { out("a::exit_inv_failure\n"); }); 79 } 80 81 BOOST_CONTRACT_TEST_LIB_A_DECLINLINE disable_inv_failure()82void a::disable_inv_failure() { 83 using boost::contract::test::detail::out; 84 boost::contract::set_invariant_failure([] (boost::contract::from) 85 { out("a::inv_failure\n"); }); 86 } 87 88 BOOST_CONTRACT_TEST_LIB_A_DECLINLINE disable_failure()89void a::disable_failure() { 90 using boost::contract::test::detail::out; 91 boost::contract::set_precondition_failure( 92 boost::contract::set_postcondition_failure( 93 boost::contract::set_except_failure( 94 boost::contract::set_old_failure( 95 boost::contract::set_invariant_failure( 96 [] (boost::contract::from) { out("a::failure\n"); } 97 ))))); 98 } 99 100 #endif // #include guard 101 102