• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 public function subcontracting from middle branch of inheritance tree.
8 
9 #include "smoke.hpp"
10 #include <boost/detail/lightweight_test.hpp>
11 #include <sstream>
12 
main()13 int main() {
14     std::ostringstream ok;
15 
16     c cc; // Test call to class at mid- inheritance tree (a base with bases).
17     s_type s; s.value = "C";
18     out.str("");
19     result_type& r = cc.f(s);
20 
21     ok.str(""); ok
22         #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
23             << "d::static_inv" << std::endl
24             << "d::inv" << std::endl
25             << "e::static_inv" << std::endl
26             << "e::inv" << std::endl
27             << "c::static_inv" << std::endl
28             << "c::inv" << std::endl
29         #endif
30         #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
31             << "d::f::pre" << std::endl
32             << "e::f::pre" << std::endl
33             << "c::f::pre" << std::endl
34         #endif
35         #ifndef BOOST_CONTRACT_NO_OLDS
36             << "d::f::old" << std::endl
37             << "e::f::old" << std::endl
38             << "c::f::old" << std::endl
39         #endif
40         << "c::f::body" << std::endl
41         #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
42             << "d::static_inv" << std::endl
43             << "d::inv" << std::endl
44             << "e::static_inv" << std::endl
45             << "e::inv" << std::endl
46             << "c::static_inv" << std::endl
47             << "c::inv" << std::endl
48         #endif
49         #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
50             << "d::f::old" << std::endl
51             << "d::f::post" << std::endl
52             << "e::f::old" << std::endl
53             << "e::f::post" << std::endl
54             // No old call here because not a base object.
55             << "c::f::post" << std::endl
56         #endif
57     ;
58     BOOST_TEST(out.eq(ok.str()));
59 
60     #ifndef BOOST_CONTRACT_NO_OLDS
61         #define BOOST_CONTRACT_TEST_old 1u
62     #else
63         #define BOOST_CONTRACT_TEST_old 0u
64     #endif
65 
66     BOOST_TEST_EQ(r.value, "C");
67     BOOST_TEST_EQ(s.value, "cde");
68     BOOST_TEST_EQ(s.copies(), BOOST_CONTRACT_TEST_old * 3);
69     BOOST_TEST_EQ(s.evals(), BOOST_CONTRACT_TEST_old * 3);
70     BOOST_TEST_EQ(s.ctors(), s.dtors() + 1); // 1 local var.
71 
72     BOOST_TEST_EQ(cc.y.value, "cC");
73     BOOST_TEST_EQ(cc.y.copies(), BOOST_CONTRACT_TEST_old);
74     BOOST_TEST_EQ(cc.y.evals(), BOOST_CONTRACT_TEST_old);
75     BOOST_TEST_EQ(cc.y.ctors(), cc.y.dtors() + 1); // 1 data member.
76 
77     BOOST_TEST_EQ(cc.t<'d'>::z.value, "dC");
78     BOOST_TEST_EQ(cc.t<'d'>::z.copies(), BOOST_CONTRACT_TEST_old);
79     BOOST_TEST_EQ(cc.t<'d'>::z.evals(), BOOST_CONTRACT_TEST_old);
80     BOOST_TEST_EQ(cc.t<'d'>::z.ctors(), cc.t<'d'>::z.dtors() + 1); // 1 member.
81 
82     BOOST_TEST_EQ(cc.t<'e'>::z.value, "eC");
83     BOOST_TEST_EQ(cc.t<'e'>::z.copies(), BOOST_CONTRACT_TEST_old);
84     BOOST_TEST_EQ(cc.t<'e'>::z.evals(), BOOST_CONTRACT_TEST_old);
85     BOOST_TEST_EQ(cc.t<'e'>::z.ctors(), cc.t<'e'>::z.dtors() + 1); // 1 member.
86 
87     #undef BOOST_CONTRACT_TEST_old
88     return boost::report_errors();
89 }
90 
91