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 contract compilation on/off. 8 9 #include "../detail/oteststream.hpp" 10 #include <boost/contract/core/config.hpp> 11 #ifndef BOOST_CONTRACT_NO_FUNCTIONS 12 #include <boost/contract/function.hpp> 13 #include <boost/contract/check.hpp> 14 #include <boost/contract/old.hpp> 15 #endif 16 #include <boost/detail/lightweight_test.hpp> 17 #include <sstream> 18 19 boost::contract::test::detail::oteststream out; 20 f(int x)21void f(int x) { 22 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS 23 boost::contract::old_ptr<int> old_x = BOOST_CONTRACT_OLDOF(x); 24 #endif 25 #ifndef BOOST_CONTRACT_NO_FUNCTIONS 26 boost::contract::check c = boost::contract::function() 27 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS 28 .precondition([] { out << "f::pre" << std::endl; }) 29 #endif 30 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS 31 .old([] { out << "f::old" << std::endl; }) 32 .postcondition([] { out << "f::post" << std::endl; }) 33 #endif 34 ; 35 #endif 36 out << "f::body" << std::endl; 37 } 38 main()39int main() { 40 std::ostringstream ok; 41 out.str(""); 42 f(123); 43 ok.str(""); ok 44 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS 45 << "f::pre" << std::endl 46 #endif 47 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS 48 << "f::old" << std::endl 49 #endif 50 << "f::body" << std::endl 51 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS 52 << "f::post" << std::endl 53 #endif 54 ; 55 BOOST_TEST(out.eq(ok.str())); 56 return boost::report_errors(); 57 } 58 59