Files
contract/test/function/ifdef_macro.cpp
2017-02-10 21:41:58 -08:00

46 lines
1.3 KiB
C++

// Copyright (C) 2008-2016 Lorenzo Caminiti
// Distributed under the Boost Software License, Version 1.0 (see accompanying
// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
// Test contract compilation on/off (using macro interface).
#include "../detail/oteststream.hpp"
#include <boost/contract_macro.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <sstream>
boost::contract::test::detail::oteststream out;
void f(int x) {
BOOST_CONTRACT_OLD_PTR(int)(old_x, x);
BOOST_CONTRACT_FUNCTION()
BOOST_CONTRACT_PRECONDITION([] { out << "f::pre" << std::endl; })
BOOST_CONTRACT_OLD([] { out << "f::old" << std::endl; })
BOOST_CONTRACT_POSTCONDITION([] { out << "f::post" << std::endl; })
;
out << "f::body" << std::endl;
}
int main() {
std::ostringstream ok;
out.str("");
f(123);
ok.str(""); ok
#ifndef BOOST_CONTRACT_NO_PRECONDITIONS
<< "f::pre" << std::endl
#endif
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
<< "f::old" << std::endl
#endif
<< "f::body" << std::endl
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
<< "f::post" << std::endl
#endif
;
BOOST_TEST(out.eq(ok.str()));
return boost::report_errors();
}