]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/contract/test/public_function/throwing_body_virtual_branch.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 virt pub func body throws with subcontr from middle of inheritance tree.
10 #include <boost/optional.hpp>
11 #include <boost/preprocessor/control/iif.hpp>
12 #include <boost/detail/lightweight_test.hpp>
16 std::ostringstream ok
;
18 c cc
; // Test call to class at mid- inheritance tree (as base with bases).
19 s_type s
; s
.value
= "X"; // So body will throw.
21 boost::optional
<result_type
&> r
;
25 } catch(except_error
const&) {
27 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
28 << "d::static_inv" << std::endl
29 << "d::inv" << std::endl
30 << "e::static_inv" << std::endl
31 << "e::inv" << std::endl
32 << "c::static_inv" << std::endl
33 << "c::inv" << std::endl
35 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
36 << "d::f::pre" << std::endl
38 #ifndef BOOST_CONTRACT_NO_OLDS
39 << "d::f::old" << std::endl
40 << "e::f::old" << std::endl
41 << "c::f::old" << std::endl
43 << "c::f::body" << std::endl
44 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
45 << "d::static_inv" << std::endl
46 << "d::inv" << std::endl
47 << "e::static_inv" << std::endl
48 << "e::inv" << std::endl
49 << "c::static_inv" << std::endl
50 << "c::inv" << std::endl
52 #ifndef BOOST_CONTRACT_NO_EXCEPTS
53 << "d::f::old" << std::endl
54 << "d::f::except" << std::endl
55 << "e::f::old" << std::endl
56 << "e::f::except" << std::endl
57 // No old call here because not a base object.
58 << "c::f::except" << std::endl
61 BOOST_TEST(out
.eq(ok
.str()));
63 #ifndef BOOST_CONTRACT_NO_OLDS
64 #define BOOST_CONTRACT_TEST_old 1u
66 #define BOOST_CONTRACT_TEST_old 0u
69 BOOST_TEST(!r
); // Boost.Optional result not init (as body threw).
70 BOOST_TEST_EQ(s
.value
, "X");
71 BOOST_TEST_EQ(s
.copies(), BOOST_CONTRACT_TEST_old
* 3);
72 BOOST_TEST_EQ(s
.evals(), BOOST_CONTRACT_TEST_old
* 3);
73 BOOST_TEST_EQ(s
.ctors(), s
.dtors() + 1); // 1 for local var.
75 BOOST_TEST_EQ(cc
.y
.value
, "c");
76 BOOST_TEST_EQ(cc
.y
.copies(), BOOST_CONTRACT_TEST_old
);
77 BOOST_TEST_EQ(cc
.y
.evals(), BOOST_CONTRACT_TEST_old
);
78 BOOST_TEST_EQ(cc
.y
.ctors(), cc
.y
.dtors() + 1); // 1 for member var.
80 BOOST_TEST_EQ(cc
.t
<'d'>::z
.value
, "d");
81 BOOST_TEST_EQ(cc
.t
<'d'>::z
.copies(), BOOST_CONTRACT_TEST_old
);
82 BOOST_TEST_EQ(cc
.t
<'d'>::z
.evals(), BOOST_CONTRACT_TEST_old
);
83 BOOST_TEST_EQ(cc
.t
<'d'>::z
.ctors(), cc
.t
<'d'>::z
.dtors() + 1); // 1 mem.
85 BOOST_TEST_EQ(cc
.t
<'e'>::z
.value
, "e");
86 BOOST_TEST_EQ(cc
.t
<'e'>::z
.copies(), BOOST_CONTRACT_TEST_old
);
87 BOOST_TEST_EQ(cc
.t
<'e'>::z
.evals(), BOOST_CONTRACT_TEST_old
);
88 BOOST_TEST_EQ(cc
.t
<'e'>::z
.ctors(), cc
.t
<'e'>::z
.dtors() + 1); // 1 mem.
90 #undef BOOST_CONTRACT_TEST_old
92 return boost::report_errors();