123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840 |
- // no #include guard
- // Copyright (C) 2008-2018 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 with and without all invariants (static/cv/const-only) declarations.
- #include "../detail/oteststream.hpp"
- #include <boost/contract/base_types.hpp>
- #include <boost/contract/constructor.hpp>
- #include <boost/contract/destructor.hpp>
- #include <boost/contract/public_function.hpp>
- #include <boost/contract/function.hpp>
- #include <boost/contract/override.hpp>
- #include <boost/contract/check.hpp>
- #include <boost/contract/assert.hpp>
- #include <boost/detail/lightweight_test.hpp>
- #include <sstream>
- boost::contract::test::detail::oteststream out;
- struct b : private boost::contract::constructor_precondition<b> {
- // Test also with no base_types.
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- static void static_invariant() { out << "b::static_inv" << std::endl; }
- #endif
- #ifdef BOOST_CONTRACT_TEST_CV_INV
- void invariant() const volatile { out << "b::cv_inv" << std::endl; }
- #endif
- #ifdef BOOST_CONTRACT_TEST_CONST_INV
- void invariant() const { out << "b::const_inv" << std::endl; }
- #endif
-
- b() : boost::contract::constructor_precondition<b>([] {
- out << "b::ctor::pre" << std::endl;
- }) {
- boost::contract::check c = boost::contract::constructor(this)
- .old([] { out << "b::ctor::old" << std::endl; })
- .postcondition([] { out << "b::ctor::post" << std::endl; })
- ;
- out << "b::ctor::body" << std::endl;
- }
- virtual ~b() {
- boost::contract::check c = boost::contract::destructor(this)
- .old([] { out << "b::dtor::old" << std::endl; })
- .postcondition([] { out << "b::dtor::post" << std::endl; })
- ;
- out << "b::dtor::body" << std::endl;
- }
- virtual void f(char x, boost::contract::virtual_* v = 0) volatile {
- boost::contract::check c = boost::contract::public_function(v, this)
- .precondition([&] {
- out << "b::f::volatile_pre" << std::endl;
- BOOST_CONTRACT_ASSERT(x == 'b');
- })
- .old([] { out << "b::f::volatile_old" << std::endl; })
- .postcondition([] { out << "b::f::volatile_post" << std::endl; })
- ;
- out << "b::f::volatile_body" << std::endl;
- }
-
- virtual void f(char x, boost::contract::virtual_* v = 0) {
- boost::contract::check c = boost::contract::public_function(v, this)
- .precondition([&] {
- out << "b::f::pre" << std::endl;
- BOOST_CONTRACT_ASSERT(x == 'b');
- })
- .old([] { out << "b::f::old" << std::endl; })
- .postcondition([] { out << "b::f::post" << std::endl; })
- ;
- out << "b::f::body" << std::endl;
- }
- };
- struct a
- #define BASES private boost::contract::constructor_precondition<a>, public b
- : BASES
- {
- typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types;
- #undef BASES
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- static void static_invariant() { out << "a::static_inv" << std::endl; }
- #endif
- #ifdef BOOST_CONTRACT_TEST_CV_INV
- void invariant() const volatile { out << "a::cv_inv" << std::endl; }
- #endif
- #ifdef BOOST_CONTRACT_TEST_CONST_INV
- void invariant() const { out << "a::const_inv" << std::endl; }
- #endif
- a() : boost::contract::constructor_precondition<a>([] {
- out << "a::ctor::pre" << std::endl;
- }) {
- boost::contract::check c = boost::contract::constructor(this)
- .old([] { out << "a::ctor::old" << std::endl; })
- .postcondition([] { out << "a::ctor::post" << std::endl; })
- ;
- out << "a::ctor::body" << std::endl;
- }
-
- virtual ~a() {
- boost::contract::check c = boost::contract::destructor(this)
- .old([] { out << "a::dtor::old" << std::endl; })
- .postcondition([] { out << "a::dtor::post" << std::endl; })
- ;
- out << "a::dtor::body" << std::endl;
- }
- virtual void f(char x, boost::contract::virtual_* v = 0)
- volatile /* override */ {
- boost::contract::check c = boost::contract::public_function<
- override_f>(
- v,
- static_cast<void (a::*)(char x, boost::contract::virtual_*)
- volatile>(&a::f),
- this, x
- )
- .precondition([&] {
- out << "a::f::volatile_pre" << std::endl;
- BOOST_CONTRACT_ASSERT(x == 'a');
- })
- .old([] { out << "a::f::volatile_old" << std::endl; })
- .postcondition([] { out << "a::f::volatile_post" << std::endl; })
- ;
- out << "a::f::volatile_body" << std::endl;
- }
-
- virtual void f(char x, boost::contract::virtual_* v = 0) /* override */ {
- boost::contract::check c = boost::contract::public_function<
- override_f>(
- v,
- static_cast<void (a::*)(char x, boost::contract::virtual_*)>(&a::f),
- this, x
- )
- .precondition([&] {
- out << "a::f::pre" << std::endl;
- BOOST_CONTRACT_ASSERT(x == 'a');
- })
- .old([] { out << "a::f::old" << std::endl; })
- .postcondition([] { out << "a::f::post" << std::endl; })
- ;
- out << "a::f::body" << std::endl;
- }
- static void s() {
- boost::contract::check c = boost::contract::public_function<a>()
- .precondition([] { out << "a::s::pre" << std::endl; })
- .old([] { out << "a::s::old" << std::endl; })
- .postcondition([] { out << "a::s::post" << std::endl; })
- ;
- out << "a::s::body" << std::endl;
- }
- protected:
- void p() volatile {
- boost::contract::check c = boost::contract::function()
- .precondition([] { out << "a::p::volatile_pre" << std::endl; })
- .old([] { out << "a::p::volatile_old" << std::endl; })
- .postcondition([] { out << "a::p::volatile_post" << std::endl; })
- ;
- out << "a::p::volatile_body" << std::endl;
- }
-
- void p() {
- boost::contract::check c = boost::contract::function()
- .precondition([] { out << "a::p::pre" << std::endl; })
- .old([] { out << "a::p::old" << std::endl; })
- .postcondition([] { out << "a::p::post" << std::endl; })
- ;
- out << "a::p::body" << std::endl;
- }
- public:
- void call_p() volatile { p(); }
- void call_p() { p(); }
- private:
- void q() volatile {
- boost::contract::check c = boost::contract::function()
- .precondition([] { out << "a::q::volatile_pre" << std::endl; })
- .old([] { out << "a::q::volatile_old" << std::endl; })
- .postcondition([] { out << "a::q::volatile_post" << std::endl; })
- ;
- out << "a::q::volatile_body" << std::endl;
- }
-
- void q() {
- boost::contract::check c = boost::contract::function()
- .precondition([] { out << "a::q::pre" << std::endl; })
- .old([] { out << "a::q::old" << std::endl; })
- .postcondition([] { out << "a::q::post" << std::endl; })
- ;
- out << "a::q::body" << std::endl;
- }
- public:
- void call_q() volatile { q(); }
- void call_q() { q(); }
- BOOST_CONTRACT_OVERRIDE(f)
- };
- int main() {
- std::ostringstream ok;
- { // Test volatile call with bases.
- out.str("");
- a volatile av;
- ok.str(""); ok // Ctors always check const_inv (even if volatile).
- #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
- << "a::ctor::pre" << std::endl
- << "b::ctor::pre" << std::endl
- #endif
- #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "b::static_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_OLDS
- << "b::ctor::old" << std::endl
- #endif
- << "b::ctor::body" << std::endl
- #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "b::static_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CV_INV
- << "b::cv_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CONST_INV
- << "b::const_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
- << "b::ctor::post" << std::endl
- #endif
- #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "a::static_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_OLDS
- << "a::ctor::old" << std::endl
- #endif
- << "a::ctor::body" << std::endl
- #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "a::static_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CV_INV
- << "a::cv_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CONST_INV
- << "a::const_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
- << "a::ctor::post" << std::endl
- #endif
- ;
- BOOST_TEST(out.eq(ok.str()));
- out.str("");
- av.f('a');
- ok.str(""); ok // Volatile checks static and cv (but not const) inv.
- #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "b::static_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CV_INV
- << "b::cv_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "a::static_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CV_INV
- << "a::cv_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
- << "b::f::volatile_pre" << std::endl
- << "a::f::volatile_pre" << std::endl
- #endif
- #ifndef BOOST_CONTRACT_NO_OLDS
- << "b::f::volatile_old" << std::endl
- << "a::f::volatile_old" << std::endl
- #endif
- << "a::f::volatile_body" << std::endl
- #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "b::static_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CV_INV
- << "b::cv_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "a::static_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CV_INV
- << "a::cv_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
- << "b::f::volatile_old" << std::endl
- << "b::f::volatile_post" << std::endl
- << "a::f::volatile_post" << std::endl
- #endif
- ;
- BOOST_TEST(out.eq(ok.str()));
-
- out.str("");
- av.s(); // Test static call.
- ok.str(""); ok
- #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "a::static_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
- << "a::s::pre" << std::endl
- #endif
- #ifndef BOOST_CONTRACT_NO_OLDS
- << "a::s::old" << std::endl
- #endif
- << "a::s::body" << std::endl
- #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "a::static_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
- << "a::s::post" << std::endl
- #endif
- ;
- BOOST_TEST(out.eq(ok.str()));
-
- out.str("");
- av.call_p(); // Test (indirect) protected call.
- ok.str(""); ok
- #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
- << "a::p::volatile_pre" << std::endl
- #endif
- #ifndef BOOST_CONTRACT_NO_OLDS
- << "a::p::volatile_old" << std::endl
- #endif
- << "a::p::volatile_body" << std::endl
- #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
- << "a::p::volatile_post" << std::endl
- #endif
- ;
- BOOST_TEST(out.eq(ok.str()));
-
- out.str("");
- av.call_q(); // Test (indirect) private call.
- ok.str(""); ok
- #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
- << "a::q::volatile_pre" << std::endl
- #endif
- #ifndef BOOST_CONTRACT_NO_OLDS
- << "a::q::volatile_old" << std::endl
- #endif
- << "a::q::volatile_body" << std::endl
- #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
- << "a::q::volatile_post" << std::endl
- #endif
- ;
- BOOST_TEST(out.eq(ok.str()));
-
- out.str("");
- } // Call a's destructor.
- ok.str(""); ok // Dtors always check const_inv (even if volatile).
- #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "a::static_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CV_INV
- << "a::cv_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CONST_INV
- << "a::const_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_OLDS
- << "a::dtor::old" << std::endl
- #endif
- << "a::dtor::body" << std::endl
- #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "a::static_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
- << "a::dtor::post" << std::endl
- #endif
- #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "b::static_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CV_INV
- << "b::cv_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CONST_INV
- << "b::const_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_OLDS
- << "b::dtor::old" << std::endl
- #endif
- << "b::dtor::body" << std::endl
- #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "b::static_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
- << "b::dtor::post" << std::endl
- #endif
- ;
- BOOST_TEST(out.eq(ok.str()));
-
- { // Test non-volatile call with bases.
- out.str("");
- a aa;
- ok.str(""); ok // Ctors always check cv_inv (even if not volatile).
- #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
- << "a::ctor::pre" << std::endl
- << "b::ctor::pre" << std::endl
- #endif
- #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "b::static_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_OLDS
- << "b::ctor::old" << std::endl
- #endif
- << "b::ctor::body" << std::endl
- #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "b::static_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CV_INV
- << "b::cv_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CONST_INV
- << "b::const_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
- << "b::ctor::post" << std::endl
- #endif
- #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "a::static_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_OLDS
- << "a::ctor::old" << std::endl
- #endif
- << "a::ctor::body" << std::endl
- #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "a::static_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CV_INV
- << "a::cv_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CONST_INV
- << "a::const_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
- << "a::ctor::post" << std::endl
- #endif
- ;
- BOOST_TEST(out.eq(ok.str()));
- out.str("");
- aa.f('a');
- ok.str(""); ok // Non-cv checks static and const (but not cv) inv.
- #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "b::static_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CONST_INV
- << "b::const_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "a::static_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CONST_INV
- << "a::const_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
- << "b::f::pre" << std::endl
- << "a::f::pre" << std::endl
- #endif
- #ifndef BOOST_CONTRACT_NO_OLDS
- << "b::f::old" << std::endl
- << "a::f::old" << std::endl
- #endif
- << "a::f::body" << std::endl
- #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "b::static_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CONST_INV
- << "b::const_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "a::static_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CONST_INV
- << "a::const_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
- << "b::f::old" << std::endl
- << "b::f::post" << std::endl
- << "a::f::post" << std::endl
- #endif
- ;
- BOOST_TEST(out.eq(ok.str()));
-
- out.str("");
- aa.s(); // Test static call.
- ok.str(""); ok
- #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "a::static_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
- << "a::s::pre" << std::endl
- #endif
- #ifndef BOOST_CONTRACT_NO_OLDS
- << "a::s::old" << std::endl
- #endif
- << "a::s::body" << std::endl
- #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "a::static_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
- << "a::s::post" << std::endl
- #endif
- ;
- BOOST_TEST(out.eq(ok.str()));
-
- out.str("");
- aa.call_p(); // Test (indirect) protected call.
- ok.str(""); ok
- #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
- << "a::p::pre" << std::endl
- #endif
- #ifndef BOOST_CONTRACT_NO_OLDS
- << "a::p::old" << std::endl
- #endif
- << "a::p::body" << std::endl
- #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
- << "a::p::post" << std::endl
- #endif
- ;
- BOOST_TEST(out.eq(ok.str()));
-
- out.str("");
- aa.call_q(); // Test (indirect) private call.
- ok.str(""); ok
- #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
- << "a::q::pre" << std::endl
- #endif
- #ifndef BOOST_CONTRACT_NO_OLDS
- << "a::q::old" << std::endl
- #endif
- << "a::q::body" << std::endl
- #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
- << "a::q::post" << std::endl
- #endif
- ;
- BOOST_TEST(out.eq(ok.str()));
- out.str("");
- } // Call a's destructor.
- ok.str(""); ok // Dtors always check cv_inv (even if not volatile).
- #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "a::static_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CV_INV
- << "a::cv_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CONST_INV
- << "a::const_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_OLDS
- << "a::dtor::old" << std::endl
- #endif
- << "a::dtor::body" << std::endl
- #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "a::static_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
- << "a::dtor::post" << std::endl
- #endif
- #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "b::static_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CV_INV
- << "b::cv_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CONST_INV
- << "b::const_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_OLDS
- << "b::dtor::old" << std::endl
- #endif
- << "b::dtor::body" << std::endl
- #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "b::static_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
- << "b::dtor::post" << std::endl
- #endif
- ;
- BOOST_TEST(out.eq(ok.str()));
-
- { // Test volatile call with no bases.
- out.str("");
- b volatile bv;
- ok.str(""); ok // Ctors always check const_inv (even if volatile).
- #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
- << "b::ctor::pre" << std::endl
- #endif
- #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "b::static_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_OLDS
- << "b::ctor::old" << std::endl
- #endif
- << "b::ctor::body" << std::endl
- #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "b::static_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CV_INV
- << "b::cv_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CONST_INV
- << "b::const_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
- << "b::ctor::post" << std::endl
- #endif
- ;
- BOOST_TEST(out.eq(ok.str()));
-
- out.str("");
- bv.f('b');
- ok.str(""); ok // Volatile checks static and cv (but not const) inv.
- #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "b::static_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CV_INV
- << "b::cv_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
- << "b::f::volatile_pre" << std::endl
- #endif
- #ifndef BOOST_CONTRACT_NO_OLDS
- << "b::f::volatile_old" << std::endl
- #endif
- << "b::f::volatile_body" << std::endl
- #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "b::static_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CV_INV
- << "b::cv_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
- << "b::f::volatile_post" << std::endl
- #endif
- ;
- BOOST_TEST(out.eq(ok.str()));
-
- out.str("");
- } // Call b's destructor.
- ok.str(""); ok // Dtors always check const_inv (even if volatile).
- #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "b::static_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CV_INV
- << "b::cv_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CONST_INV
- << "b::const_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_OLDS
- << "b::dtor::old" << std::endl
- #endif
- << "b::dtor::body" << std::endl
- #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "b::static_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
- << "b::dtor::post" << std::endl
- #endif
- ;
- BOOST_TEST(out.eq(ok.str()));
-
- { // Test non-volatile call with no bases.
- out.str("");
- b bb;
- ok.str(""); ok // Ctors always check cv_inv (even if not volatile).
- #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
- << "b::ctor::pre" << std::endl
- #endif
-
- #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "b::static_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_OLDS
- << "b::ctor::old" << std::endl
- #endif
- << "b::ctor::body" << std::endl
- #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "b::static_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CV_INV
- << "b::cv_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CONST_INV
- << "b::const_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
- << "b::ctor::post" << std::endl
- #endif
- ;
- BOOST_TEST(out.eq(ok.str()));
- out.str("");
- bb.f('b');
- ok.str(""); ok // Non-cv checks static and const (but not cv) inv.
- #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "b::static_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CONST_INV
- << "b::const_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
- << "b::f::pre" << std::endl
- #endif
- #ifndef BOOST_CONTRACT_NO_OLDS
- << "b::f::old" << std::endl
- #endif
- << "b::f::body" << std::endl
- #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "b::static_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CONST_INV
- << "b::const_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
- << "b::f::post" << std::endl
- #endif
- ;
- BOOST_TEST(out.eq(ok.str()));
-
- out.str("");
- } // Call b's destructor.
- ok.str(""); ok // Dtors always check cv_inv (even if not volatile).
- #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "b::static_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CV_INV
- << "b::cv_inv" << std::endl
- #endif
- #ifdef BOOST_CONTRACT_TEST_CONST_INV
- << "b::const_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_OLDS
- << "b::dtor::old" << std::endl
- #endif
- << "b::dtor::body" << std::endl
- #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
- #ifdef BOOST_CONTRACT_TEST_STATIC_INV
- << "b::static_inv" << std::endl
- #endif
- #endif
- #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
- << "b::dtor::post" << std::endl
- #endif
- ;
- BOOST_TEST(out.eq(ok.str()));
- return boost::report_errors();
- }
|