]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/contract/test/function/throwing_old.cpp
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
7 // Test throw from free function .old().
9 #include "../detail/oteststream.hpp"
10 #include <boost/contract/function.hpp>
11 #include <boost/contract/check.hpp>
12 #include <boost/detail/lightweight_test.hpp>
15 boost::contract::test::detail::oteststream out
;
17 struct err
{}; // Global decl so visible in MSVC10 lambdas.
20 boost::contract::check c
= boost::contract::function()
21 .precondition([] { out
<< "f::pre" << std::endl
; })
23 out
<< "f::old" << std::endl
;
24 throw err(); // Test this throws.
26 .postcondition([] { out
<< "f::post" << std::endl
; })
27 .except([] { out
<< "f::except" << std::endl
; })
29 out
<< "f::body" << std::endl
;
33 std::ostringstream ok
;
35 boost::contract::set_old_failure([] (boost::contract::from
) { throw; });
40 #ifndef BOOST_CONTRACT_NO_OLDS
45 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
46 << "f::pre" << std::endl
48 #ifndef BOOST_CONTRACT_NO_OLDS
49 << "f::old" << std::endl
// Test this threw.
51 << "f::body" << std::endl
54 BOOST_TEST(out
.eq(ok
.str()));
55 } catch(...) { BOOST_TEST(false); }
57 return boost::report_errors();