diff options
Diffstat (limited to 'src/boost/libs/contract/test/invariant')
32 files changed, 1673 insertions, 0 deletions
diff --git a/src/boost/libs/contract/test/invariant/decl.hpp b/src/boost/libs/contract/test/invariant/decl.hpp new file mode 100644 index 00000000..b4ae9a48 --- /dev/null +++ b/src/boost/libs/contract/test/invariant/decl.hpp @@ -0,0 +1,840 @@ + +// 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(); +} + diff --git a/src/boost/libs/contract/test/invariant/decl_const.cpp b/src/boost/libs/contract/test/invariant/decl_const.cpp new file mode 100644 index 00000000..b936449d --- /dev/null +++ b/src/boost/libs/contract/test/invariant/decl_const.cpp @@ -0,0 +1,13 @@ + +// 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 all invariants (static, cv, and const-only). + +#undef BOOST_CONTRACT_TEST_STATIC_INV +#undef BOOST_CONTRACT_TEST_CV_INV +#define BOOST_CONTRACT_TEST_CONST_INV +#include "decl.hpp" + diff --git a/src/boost/libs/contract/test/invariant/decl_cv.cpp b/src/boost/libs/contract/test/invariant/decl_cv.cpp new file mode 100644 index 00000000..5607dafb --- /dev/null +++ b/src/boost/libs/contract/test/invariant/decl_cv.cpp @@ -0,0 +1,13 @@ + +// 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 all invariants (static, cv, and const-only). + +#undef BOOST_CONTRACT_TEST_STATIC_INV +#define BOOST_CONTRACT_TEST_CV_INV +#undef BOOST_CONTRACT_TEST_CONST_INV +#include "decl.hpp" + diff --git a/src/boost/libs/contract/test/invariant/decl_cv_const.cpp b/src/boost/libs/contract/test/invariant/decl_cv_const.cpp new file mode 100644 index 00000000..c762bbbc --- /dev/null +++ b/src/boost/libs/contract/test/invariant/decl_cv_const.cpp @@ -0,0 +1,13 @@ + +// 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 all invariants (static, cv, and const-only). + +#undef BOOST_CONTRACT_TEST_STATIC_INV +#define BOOST_CONTRACT_TEST_CV_INV +#define BOOST_CONTRACT_TEST_CONST_INV +#include "decl.hpp" + diff --git a/src/boost/libs/contract/test/invariant/decl_nothing.cpp b/src/boost/libs/contract/test/invariant/decl_nothing.cpp new file mode 100644 index 00000000..ad89d1f1 --- /dev/null +++ b/src/boost/libs/contract/test/invariant/decl_nothing.cpp @@ -0,0 +1,13 @@ + +// 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 all invariants (static, cv, and const-only). + +#undef BOOST_CONTRACT_TEST_STATIC_INV +#undef BOOST_CONTRACT_TEST_CV_INV +#undef BOOST_CONTRACT_TEST_CONST_INV +#include "decl.hpp" + diff --git a/src/boost/libs/contract/test/invariant/decl_static.cpp b/src/boost/libs/contract/test/invariant/decl_static.cpp new file mode 100644 index 00000000..8db92edc --- /dev/null +++ b/src/boost/libs/contract/test/invariant/decl_static.cpp @@ -0,0 +1,13 @@ + +// 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 all invariants (static, cv, and const-only). + +#define BOOST_CONTRACT_TEST_STATIC_INV +#undef BOOST_CONTRACT_TEST_CV_INV +#undef BOOST_CONTRACT_TEST_CONST_INV +#include "decl.hpp" + diff --git a/src/boost/libs/contract/test/invariant/decl_static_const.cpp b/src/boost/libs/contract/test/invariant/decl_static_const.cpp new file mode 100644 index 00000000..7060c21c --- /dev/null +++ b/src/boost/libs/contract/test/invariant/decl_static_const.cpp @@ -0,0 +1,13 @@ + +// 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 all invariants (static, cv, and const-only). + +#define BOOST_CONTRACT_TEST_STATIC_INV +#undef BOOST_CONTRACT_TEST_CV_INV +#define BOOST_CONTRACT_TEST_CONST_INV +#include "decl.hpp" + diff --git a/src/boost/libs/contract/test/invariant/decl_static_cv.cpp b/src/boost/libs/contract/test/invariant/decl_static_cv.cpp new file mode 100644 index 00000000..a87be0f2 --- /dev/null +++ b/src/boost/libs/contract/test/invariant/decl_static_cv.cpp @@ -0,0 +1,13 @@ + +// 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 all invariants (static, cv, and const-only). + +#define BOOST_CONTRACT_TEST_STATIC_INV +#define BOOST_CONTRACT_TEST_CV_INV +#undef BOOST_CONTRACT_TEST_CONST_INV +#include "decl.hpp" + diff --git a/src/boost/libs/contract/test/invariant/decl_static_cv_const.cpp b/src/boost/libs/contract/test/invariant/decl_static_cv_const.cpp new file mode 100644 index 00000000..a4c97760 --- /dev/null +++ b/src/boost/libs/contract/test/invariant/decl_static_cv_const.cpp @@ -0,0 +1,13 @@ + +// 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 all invariants (static, cv, and const-only). + +#define BOOST_CONTRACT_TEST_STATIC_INV +#define BOOST_CONTRACT_TEST_CV_INV +#define BOOST_CONTRACT_TEST_CONST_INV +#include "decl.hpp" + diff --git a/src/boost/libs/contract/test/invariant/ifdef.cpp b/src/boost/libs/contract/test/invariant/ifdef.cpp new file mode 100644 index 00000000..16ebf75f --- /dev/null +++ b/src/boost/libs/contract/test/invariant/ifdef.cpp @@ -0,0 +1,174 @@ + +// 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 invariant compilation on/off. + +#include "../detail/oteststream.hpp" +#include <boost/contract/constructor.hpp> +#include <boost/contract/destructor.hpp> +#include <boost/contract/public_function.hpp> +#include <boost/contract/check.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +class a { +public: + #ifndef BOOST_CONTRACT_NO_INVARIANTS + static void static_invariant() { + out << "a::static_inv" << std::endl; + } + + void invariant() const volatile { + out << "a::cv_inv" << std::endl; + } + + void invariant() const { + out << "a::const_inv" << std::endl; + } + #endif + + a() { // Test check both cv and const invariant (at exit if no throw). + #ifndef BOOST_CONTRACT_NO_CONSTRUCTORS + boost::contract::check c= boost::contract::constructor(this); + #endif + out << "a::ctor::body" << std::endl; + } + + ~a() { // Test check both cv and const invariant (at entry). + #ifndef BOOSTT_CONTRACT_NO_DESTRUCTORS + boost::contract::check c = boost::contract::destructor(this); + #endif + out << "a::dtor::body" << std::endl; + } + + void m() { // Test check const invariant (at entry and exit). + #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS + boost::contract::check c = boost::contract::public_function(this); + #endif + out << "a::m::body" << std::endl; + } + + void c() const { // Test check const invariant (at entry and exit). + #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS + boost::contract::check c = boost::contract::public_function(this); + #endif + out << "a::c::body" << std::endl; + } + + void v() volatile { // Test check cv invariant (at entry and exit). + #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS + boost::contract::check c = boost::contract::public_function(this); + #endif + out << "a::v::body" << std::endl; + } + + void cv() const volatile { // Test check cv invariant (at entry and exit). + #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS + boost::contract::check c = boost::contract::public_function(this); + #endif + out << "a::cv::body" << std::endl; + } +}; + +int main() { + std::ostringstream ok; + + { + out.str(""); + a aa; + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::cv_inv" << std::endl + << "a::const_inv" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + out.str(""); + aa.m(); + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::const_inv" << std::endl + #endif + << "a::m::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::const_inv" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + out.str(""); + aa.c(); + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::const_inv" << std::endl + #endif + << "a::c::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::const_inv" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + out.str(""); + aa.v(); + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::cv_inv" << std::endl + #endif + << "a::v::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::cv_inv" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + out.str(""); + aa.cv(); + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::cv_inv" << std::endl + #endif + << "a::cv::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::cv_inv" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + out.str(""); + } // Call dtor. + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::cv_inv" << std::endl + << "a::const_inv" << std::endl + #endif + << "a::dtor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/invariant/ifdef_macro.cpp b/src/boost/libs/contract/test/invariant/ifdef_macro.cpp new file mode 100644 index 00000000..5955fa01 --- /dev/null +++ b/src/boost/libs/contract/test/invariant/ifdef_macro.cpp @@ -0,0 +1,170 @@ + +// 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 invariant compilation on/off (using macro interface). + +#include "../detail/oteststream.hpp" +#include "../detail/unprotected_commas.hpp" +#include <boost/contract_macro.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +class a { +public: + BOOST_CONTRACT_STATIC_INVARIANT({ + boost::contract::test::detail::unprotected_commas<void, void, void>:: + call(); + out << "a::static_inv" << std::endl; + }) + + BOOST_CONTRACT_INVARIANT_VOLATILE({ + boost::contract::test::detail::unprotected_commas<void, void, void>:: + call(); + out << "a::cv_inv" << std::endl; + }) + + BOOST_CONTRACT_INVARIANT({ + boost::contract::test::detail::unprotected_commas<void, void, void>:: + call(); + out << "a::const_inv" << std::endl; + }) + + a() { // Test check both cv and const invariant (at exit if no throw). + BOOST_CONTRACT_CONSTRUCTOR(boost::contract::test::detail:: + unprotected_commas<void, void, void>::same(this)); + out << "a::ctor::body" << std::endl; + } + + ~a() { // Test check both cv and const invariant (at entry). + BOOST_CONTRACT_DESTRUCTOR(boost::contract::test::detail:: + unprotected_commas<void, void, void>::same(this)); + out << "a::dtor::body" << std::endl; + } + + void m() { // Test check const invariant (at entry and exit). + BOOST_CONTRACT_PUBLIC_FUNCTION(boost::contract::test::detail:: + unprotected_commas<void, void, void>::same(this)); + out << "a::m::body" << std::endl; + } + + void c() const { // Test check const invariant (at entry and exit). + BOOST_CONTRACT_PUBLIC_FUNCTION(boost::contract::test::detail:: + unprotected_commas<void, void, void>::same(this)); + out << "a::c::body" << std::endl; + } + + void v() volatile { // Test check cv invariant (at entry and exit). + BOOST_CONTRACT_PUBLIC_FUNCTION(boost::contract::test::detail:: + unprotected_commas<void, void, void>::same(this)); + out << "a::v::body" << std::endl; + } + + void cv() const volatile { // Test check cv invariant (at entry and exit). + BOOST_CONTRACT_PUBLIC_FUNCTION(boost::contract::test::detail:: + unprotected_commas<void, void, void>::same(this)); + out << "a::cv::body" << std::endl; + } +}; + +int main() { + std::ostringstream ok; + + { + out.str(""); + a aa; + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::cv_inv" << std::endl + << "a::const_inv" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + out.str(""); + aa.m(); + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::const_inv" << std::endl + #endif + << "a::m::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::const_inv" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + out.str(""); + aa.c(); + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::const_inv" << std::endl + #endif + << "a::c::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::const_inv" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + out.str(""); + aa.v(); + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::cv_inv" << std::endl + #endif + << "a::v::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::cv_inv" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + out.str(""); + aa.cv(); + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::cv_inv" << std::endl + #endif + << "a::cv::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::cv_inv" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + out.str(""); + } // Call dtor. + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::cv_inv" << std::endl + << "a::const_inv" << std::endl + #endif + << "a::dtor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/invariant/mutable.hpp b/src/boost/libs/contract/test/invariant/mutable.hpp new file mode 100644 index 00000000..0940bc98 --- /dev/null +++ b/src/boost/libs/contract/test/invariant/mutable.hpp @@ -0,0 +1,28 @@ + +// 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 error if non-static inv declared mutable (unless PERMISSIVE #defined). + +#include <boost/contract/public_function.hpp> +#include <boost/contract/check.hpp> + +struct a { + void invariant() {} + + void f() { + // Same for ctor and dtor (because they all use check_pre_post_inv). + boost::contract::check c = boost::contract::public_function(this); + } +}; + +int main() { + a aa; + aa.f(); + return 0; +} + diff --git a/src/boost/libs/contract/test/invariant/mutable_error.cpp b/src/boost/libs/contract/test/invariant/mutable_error.cpp new file mode 100644 index 00000000..97a26785 --- /dev/null +++ b/src/boost/libs/contract/test/invariant/mutable_error.cpp @@ -0,0 +1,14 @@ + +// 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 compiler error when invariant() not declared const. + +#undef BOOST_CONTRACT_PERMISSIVE +#include "mutable.hpp" +#ifdef BOOST_CONTRACT_NO_INVARIANTS + #error "Forcing error even when invariants not checked" +#endif + diff --git a/src/boost/libs/contract/test/invariant/mutable_permissive.cpp b/src/boost/libs/contract/test/invariant/mutable_permissive.cpp new file mode 100644 index 00000000..fb098ee1 --- /dev/null +++ b/src/boost/libs/contract/test/invariant/mutable_permissive.cpp @@ -0,0 +1,13 @@ + +// 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 no error if permissive even if invariant() not declared const. + +#ifndef BOOST_CONTRACT_PERMISSIVE + #error "build must define PERMISSIVE" +#endif +#include "mutable.hpp" + diff --git a/src/boost/libs/contract/test/invariant/static.hpp b/src/boost/libs/contract/test/invariant/static.hpp new file mode 100644 index 00000000..75e4da3f --- /dev/null +++ b/src/boost/libs/contract/test/invariant/static.hpp @@ -0,0 +1,28 @@ + +// 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 error if non-static inv declared static (unless PERMISSIVE #defined). + +#include <boost/contract/public_function.hpp> +#include <boost/contract/check.hpp> + +struct a { + static void invariant() {} + + void f() { + // Same for ctor and dtor (because they all use check_pre_post_inv). + boost::contract::check c = boost::contract::public_function(this); + } +}; + +int main() { + a aa; + aa.f(); + return 0; +} + diff --git a/src/boost/libs/contract/test/invariant/static_const.hpp b/src/boost/libs/contract/test/invariant/static_const.hpp new file mode 100644 index 00000000..ea2f9961 --- /dev/null +++ b/src/boost/libs/contract/test/invariant/static_const.hpp @@ -0,0 +1,28 @@ + +// 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 error if static inv declared const (unless PERMISSIVE #defined). + +#include <boost/contract/public_function.hpp> +#include <boost/contract/check.hpp> + +struct a { + void static_invariant() const {} + + void f() { + // Same for ctor and dtor (because they all use check_pre_post_inv). + boost::contract::check c = boost::contract::public_function(this); + } +}; + +int main() { + a aa; + aa.f(); + return 0; +} + diff --git a/src/boost/libs/contract/test/invariant/static_const_error.cpp b/src/boost/libs/contract/test/invariant/static_const_error.cpp new file mode 100644 index 00000000..e9ef5e66 --- /dev/null +++ b/src/boost/libs/contract/test/invariant/static_const_error.cpp @@ -0,0 +1,14 @@ + +// 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 error if static inv declared const. + +#undef BOOST_CONTRACT_PERMISSIVE +#include "static_const.hpp" +#ifdef BOOST_CONTRACT_NO_INVARIANTS + #error "Forcing error even when invariants not checked" +#endif + diff --git a/src/boost/libs/contract/test/invariant/static_const_permissive.cpp b/src/boost/libs/contract/test/invariant/static_const_permissive.cpp new file mode 100644 index 00000000..efe33407 --- /dev/null +++ b/src/boost/libs/contract/test/invariant/static_const_permissive.cpp @@ -0,0 +1,13 @@ + +// 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 no error if permissive even when static inv declared const. + +#ifndef BOOST_CONTRACT_PERMISSIVE + #error "build must define PERMISSIVE" +#endif +#include "static_const.hpp" + diff --git a/src/boost/libs/contract/test/invariant/static_cv.hpp b/src/boost/libs/contract/test/invariant/static_cv.hpp new file mode 100644 index 00000000..bca082e2 --- /dev/null +++ b/src/boost/libs/contract/test/invariant/static_cv.hpp @@ -0,0 +1,28 @@ + +// 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 error if static inv declared cv (unless PERMISSIVE #defined). + +#include <boost/contract/public_function.hpp> +#include <boost/contract/check.hpp> + +struct a { + void static_invariant() const volatile {} + + void f() { + // Same for ctor and dtor (because they all use check_pre_post_inv). + boost::contract::check c = boost::contract::public_function(this); + } +}; + +int main() { + a aa; + aa.f(); + return 0; +} + diff --git a/src/boost/libs/contract/test/invariant/static_cv_error.cpp b/src/boost/libs/contract/test/invariant/static_cv_error.cpp new file mode 100644 index 00000000..84f9ca0d --- /dev/null +++ b/src/boost/libs/contract/test/invariant/static_cv_error.cpp @@ -0,0 +1,14 @@ + +// 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 error if static inv declared cv. + +#undef BOOST_CONTRACT_PERMISSIVE +#include "static_cv.hpp" +#ifdef BOOST_CONTRACT_NO_INVARIANTS + #error "Forcing error even when invariants not checked" +#endif + diff --git a/src/boost/libs/contract/test/invariant/static_cv_permissive.cpp b/src/boost/libs/contract/test/invariant/static_cv_permissive.cpp new file mode 100644 index 00000000..9ffee38f --- /dev/null +++ b/src/boost/libs/contract/test/invariant/static_cv_permissive.cpp @@ -0,0 +1,13 @@ + +// 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 no error if permissive even when static inv declared cv. + +#ifndef BOOST_CONTRACT_PERMISSIVE + #error "build must define PERMISSIVE" +#endif +#include "static_cv.hpp" + diff --git a/src/boost/libs/contract/test/invariant/static_error.cpp b/src/boost/libs/contract/test/invariant/static_error.cpp new file mode 100644 index 00000000..eeaa85f2 --- /dev/null +++ b/src/boost/libs/contract/test/invariant/static_error.cpp @@ -0,0 +1,14 @@ + +// 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 compiler error if invariant() declared static. + +#undef BOOST_CONTRACT_PERMISSIVE +#include "static.hpp" +#ifdef BOOST_CONTRACT_NO_INVARIANTS + #error "Forcing error even when invariants not checked" +#endif + diff --git a/src/boost/libs/contract/test/invariant/static_mutable.hpp b/src/boost/libs/contract/test/invariant/static_mutable.hpp new file mode 100644 index 00000000..1cf1f424 --- /dev/null +++ b/src/boost/libs/contract/test/invariant/static_mutable.hpp @@ -0,0 +1,28 @@ + +// 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 error if static inv declared mutable (unless PERMISSIVE #defined). + +#include <boost/contract/public_function.hpp> +#include <boost/contract/check.hpp> + +struct a { + void static_invariant() {} // Error (unless PERMISSIVE). + + void f() { + // Same for ctor and dtor (because they all use check_pre_post_inv). + boost::contract::check c = boost::contract::public_function(this); + } +}; + +int main() { + a aa; + aa.f(); + return 0; +} + diff --git a/src/boost/libs/contract/test/invariant/static_mutable_error.cpp b/src/boost/libs/contract/test/invariant/static_mutable_error.cpp new file mode 100644 index 00000000..0e45af43 --- /dev/null +++ b/src/boost/libs/contract/test/invariant/static_mutable_error.cpp @@ -0,0 +1,14 @@ + +// 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 error if static inv declared mutable. + +#undef BOOST_CONTRACT_PERMISSIVE +#include "static_mutable.hpp" +#ifdef BOOST_CONTRACT_NO_INVARIANTS + #error "Forcing error even when invariants not checked" +#endif + diff --git a/src/boost/libs/contract/test/invariant/static_mutable_permissive.cpp b/src/boost/libs/contract/test/invariant/static_mutable_permissive.cpp new file mode 100644 index 00000000..d6f6bcbb --- /dev/null +++ b/src/boost/libs/contract/test/invariant/static_mutable_permissive.cpp @@ -0,0 +1,13 @@ + +// 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 error if permissive even when static inv declared mutable. + +#ifndef BOOST_CONTRACT_PERMISSIVE + #error "build must define PERMISSIVE" +#endif +#include "static_mutable.hpp" + diff --git a/src/boost/libs/contract/test/invariant/static_permissive.cpp b/src/boost/libs/contract/test/invariant/static_permissive.cpp new file mode 100644 index 00000000..710240cb --- /dev/null +++ b/src/boost/libs/contract/test/invariant/static_permissive.cpp @@ -0,0 +1,13 @@ + +// 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 no compiler error if permissive even when invariant() declared static. + +#ifndef BOOST_CONTRACT_PERMISSIVE + #error "build must define PERMISSIVE" +#endif +#include "static.hpp" + diff --git a/src/boost/libs/contract/test/invariant/static_volatile.hpp b/src/boost/libs/contract/test/invariant/static_volatile.hpp new file mode 100644 index 00000000..ba3bb351 --- /dev/null +++ b/src/boost/libs/contract/test/invariant/static_volatile.hpp @@ -0,0 +1,28 @@ + +// 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 error if static inv declared volatile (unless PERMISSIVE #defined). + +#include <boost/contract/public_function.hpp> +#include <boost/contract/check.hpp> + +struct a { + void static_invariant() volatile {} + + void f() { + // Same for ctor and dtor (because they all use check_pre_post_inv). + boost::contract::check c = boost::contract::public_function(this); + } +}; + +int main() { + a aa; + aa.f(); + return 0; +} + diff --git a/src/boost/libs/contract/test/invariant/static_volatile_error.cpp b/src/boost/libs/contract/test/invariant/static_volatile_error.cpp new file mode 100644 index 00000000..66cc9d2c --- /dev/null +++ b/src/boost/libs/contract/test/invariant/static_volatile_error.cpp @@ -0,0 +1,14 @@ + +// 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 error if static inv declared volatile. + +#undef BOOST_CONTRACT_PERMISSIVE +#include "static_volatile.hpp" +#ifdef BOOST_CONTRACT_NO_INVARIANTS + #error "Forcing error even when invariants not checked" +#endif + diff --git a/src/boost/libs/contract/test/invariant/static_volatile_permissive.cpp b/src/boost/libs/contract/test/invariant/static_volatile_permissive.cpp new file mode 100644 index 00000000..fd92e273 --- /dev/null +++ b/src/boost/libs/contract/test/invariant/static_volatile_permissive.cpp @@ -0,0 +1,13 @@ + +// 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 error if permissive even when static inv declared volatile. + +#ifndef BOOST_CONTRACT_PERMISSIVE + #error "build must define PERMISSIVE" +#endif +#include "static_volatile.hpp" + diff --git a/src/boost/libs/contract/test/invariant/volatile.hpp b/src/boost/libs/contract/test/invariant/volatile.hpp new file mode 100644 index 00000000..0e7ede02 --- /dev/null +++ b/src/boost/libs/contract/test/invariant/volatile.hpp @@ -0,0 +1,28 @@ + +// 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 error if non-static inv declared volatile (unless PERMISSIVE #defined). + +#include <boost/contract/public_function.hpp> +#include <boost/contract/check.hpp> + +struct a { + void invariant() volatile {} + + void f() { + // Same for ctor and dtor (because they all use check_pre_post_inv). + boost::contract::check c = boost::contract::public_function(this); + } +}; + +int main() { + a aa; + aa.f(); + return 0; +} + diff --git a/src/boost/libs/contract/test/invariant/volatile_error.cpp b/src/boost/libs/contract/test/invariant/volatile_error.cpp new file mode 100644 index 00000000..3372a35d --- /dev/null +++ b/src/boost/libs/contract/test/invariant/volatile_error.cpp @@ -0,0 +1,14 @@ + +// 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 error if non-static inv declared volatile. + +#undef BOOST_CONTRACT_PERMISSIVE +#include "volatile.hpp" +#ifdef BOOST_CONTRACT_NO_INVARIANTS + #error "Forcing error even when invariants not checked" +#endif + diff --git a/src/boost/libs/contract/test/invariant/volatile_permissive.cpp b/src/boost/libs/contract/test/invariant/volatile_permissive.cpp new file mode 100644 index 00000000..a3d1b987 --- /dev/null +++ b/src/boost/libs/contract/test/invariant/volatile_permissive.cpp @@ -0,0 +1,13 @@ + +// 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 no error if permissive even when non-static inv declared volatile. + +#ifndef BOOST_CONTRACT_PERMISSIVE + #error "build must define PERMISSIVE" +#endif +#include "volatile.hpp" + |