diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/contract/test/constructor | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/contract/test/constructor')
30 files changed, 5130 insertions, 0 deletions
diff --git a/src/boost/libs/contract/test/constructor/access.cpp b/src/boost/libs/contract/test/constructor/access.cpp new file mode 100644 index 00000000..19eae17d --- /dev/null +++ b/src/boost/libs/contract/test/constructor/access.cpp @@ -0,0 +1,136 @@ + +// 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 making all contract extra declarations (base types, inv, etc.) private. + +#include "../detail/oteststream.hpp" +#include <boost/contract/constructor.hpp> +#include <boost/contract/base_types.hpp> +#include <boost/contract/check.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +class b + #define BASES private boost::contract::constructor_precondition<b> + : BASES +{ + friend class boost::contract::access; + + typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; + #undef BASES + + static void static_invariant() { out << "b::static_inv" << std::endl; } + void invariant() const { out << "b::inv" << std::endl; } + +public: + 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; + } +}; + +class a + #define BASES private boost::contract::constructor_precondition<a>, public b + : BASES +{ + friend class boost::contract::access; + + // Private base types (always OK because never used by ctors). + typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; + #undef BASES + + // Private invariants. + static void static_invariant() { out << "a::static_inv" << std::endl; } + void invariant() const { out << "a::inv" << std::endl; } + +public: + 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; + } +}; + +int main() { + std::ostringstream ok; + + out.str(""); + a aa; + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + out.str(""); + b bb; + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "b::ctor::pre" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/decl.hpp b/src/boost/libs/contract/test/constructor/decl.hpp new file mode 100644 index 00000000..59e42128 --- /dev/null +++ b/src/boost/libs/contract/test/constructor/decl.hpp @@ -0,0 +1,170 @@ + +#ifndef BOOST_CONTRACT_TEST_CONSTRUCTOR_DECL_HPP_ +#define BOOST_CONTRACT_TEST_CONSTRUCTOR_DECL_HPP_ + +// 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 pre, post, and inv declarations. + +#include "../detail/oteststream.hpp" +#include <boost/contract/constructor.hpp> +#include <boost/contract/base_types.hpp> +#include <boost/contract/check.hpp> +#include <boost/contract/assert.hpp> + +boost::contract::test::detail::oteststream out; + +bool c_pre = true, c_post = true; +bool c_entering_static_inv = true, c_entry_static_inv = true, + c_exit_static_inv = true; +bool c_exit_inv = true; // Only exit non-static inv for ctors. +struct c + #ifndef BOOST_CONTRACT_TEST_NO_C_PRE + : private boost::contract::constructor_precondition<c> + #endif +{ + #ifndef BOOST_CONTRACT_TEST_NO_C_STATIC_INV + static void static_invariant() { + out << "c::static_inv" << std::endl; + if(c_entering_static_inv) BOOST_CONTRACT_ASSERT(c_entry_static_inv); + else BOOST_CONTRACT_ASSERT(c_exit_static_inv); + c_entering_static_inv = false; + } + #endif + #ifndef BOOST_CONTRACT_TEST_NO_C_INV + void invariant() const { + out << "c::inv" << std::endl; + BOOST_CONTRACT_ASSERT(c_exit_inv); + } + #endif + + c() + #ifndef BOOST_CONTRACT_TEST_NO_C_PRE + : boost::contract::constructor_precondition<c>([] { + out << "c::ctor::pre" << std::endl; + BOOST_CONTRACT_ASSERT(c_pre); + }) + #endif + { + boost::contract::check c = boost::contract::constructor(this) + .old([] { out << "c::ctor::old" << std::endl; }) + #ifndef BOOST_CONTRACT_TEST_NO_C_POST + .postcondition([] { + out << "c::ctor::post" << std::endl; + BOOST_CONTRACT_ASSERT(c_post); + }) + #endif + ; + out << "c::ctor::body" << std::endl; + } +}; + +bool b_pre = true, b_post = true; +bool b_entering_static_inv = true, b_entry_static_inv = true, + b_exit_static_inv = true; +bool b_exit_inv = true; // Only exit non-static inv for ctors. +struct b + #ifndef BOOST_CONTRACT_TEST_NO_B_PRE + #define BASES \ + private boost::contract::constructor_precondition<b>, public c + #else + #define BASES public c + #endif + : BASES +{ + typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; + #undef BASES + + #ifndef BOOST_CONTRACT_TEST_NO_B_STATIC_INV + static void static_invariant() { + out << "b::static_inv" << std::endl; + if(b_entering_static_inv) BOOST_CONTRACT_ASSERT(b_entry_static_inv); + else BOOST_CONTRACT_ASSERT(b_exit_static_inv); + b_entering_static_inv = false; + } + #endif + #ifndef BOOST_CONTRACT_TEST_NO_B_INV + void invariant() const { + out << "b::inv" << std::endl; + BOOST_CONTRACT_ASSERT(b_exit_inv); + } + #endif + + b() + #ifndef BOOST_CONTRACT_TEST_NO_B_PRE + : boost::contract::constructor_precondition<b>([] { + out << "b::ctor::pre" << std::endl; + BOOST_CONTRACT_ASSERT(b_pre); + }) + #endif + { + boost::contract::check c = boost::contract::constructor(this) + .old([] { out << "b::ctor::old" << std::endl; }) + #ifndef BOOST_CONTRACT_TEST_NO_B_POST + .postcondition([] { + out << "b::ctor::post" << std::endl; + BOOST_CONTRACT_ASSERT(b_post); + }) + #endif + ; + out << "b::ctor::body" << std::endl; + } +}; + +bool a_pre = true, a_post = true; +bool a_entering_static_inv = true, a_entry_static_inv = true, + a_exit_static_inv = true; +bool a_exit_inv = true; // Only exit non-static inv for ctors. +struct a + #ifndef BOOST_CONTRACT_TEST_NO_A_PRE + #define BASES \ + private boost::contract::constructor_precondition<a>, public b + #else + #define BASES public b + #endif + : BASES +{ + typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; + #undef BASES + + #ifndef BOOST_CONTRACT_TEST_NO_A_STATIC_INV + static void static_invariant() { + out << "a::static_inv" << std::endl; + if(a_entering_static_inv) BOOST_CONTRACT_ASSERT(a_entry_static_inv); + else BOOST_CONTRACT_ASSERT(a_exit_static_inv); + a_entering_static_inv = false; + } + #endif + #ifndef BOOST_CONTRACT_TEST_NO_A_INV + void invariant() const { + out << "a::inv" << std::endl; + BOOST_CONTRACT_ASSERT(a_exit_inv); + } + #endif + + a() + #ifndef BOOST_CONTRACT_TEST_NO_A_PRE + : boost::contract::constructor_precondition<a>([] { + out << "a::ctor::pre" << std::endl; + BOOST_CONTRACT_ASSERT(a_pre); + }) + #endif + { + boost::contract::check c = boost::contract::constructor(this) + .old([] { out << "a::ctor::old" << std::endl; }) + #ifndef BOOST_CONTRACT_TEST_NO_A_POST + .postcondition([] { + out << "a::ctor::post" << std::endl; + BOOST_CONTRACT_ASSERT(a_post); + }) + #endif + ; + out << "a::ctor::body" << std::endl; + } +}; + +#endif // #include guard + diff --git a/src/boost/libs/contract/test/constructor/decl_entry_static_inv_all.cpp b/src/boost/libs/contract/test/constructor/decl_entry_static_inv_all.cpp new file mode 100644 index 00000000..b5f4ad6f --- /dev/null +++ b/src/boost/libs/contract/test/constructor/decl_entry_static_inv_all.cpp @@ -0,0 +1,219 @@ + +// 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 derived and base classes with entry static invariants. + +#undef BOOST_CONTRACT_TEST_NO_A_STATIC_INV +#undef BOOST_CONTRACT_TEST_NO_B_STATIC_INV +#undef BOOST_CONTRACT_TEST_NO_C_STATIC_INV +#include "decl.hpp" + +#include <boost/preprocessor/control/iif.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> +#include <string> + +std::string ok_c() { + std::ostringstream ok; ok << "" // Suppress a warning. + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "c::static_inv" << std::endl // Might fail. + #endif + ; + return ok.str(); +} + +std::string ok_b() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_OLDS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "b::static_inv" << std::endl // Might fail. + #endif + ; + return ok.str(); +} + +std::string ok_a() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl // Might fail. + #endif + ; + return ok.str(); +} + +std::string ok_end() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} + +struct err {}; // Global decl so visible in MSVC10 lambdas. + +int main() { + std::ostringstream ok; + + #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + #define BOOST_CONTRACT_TEST_entry_inv 0 + #else + #define BOOST_CONTRACT_TEST_entry_inv 1 + #endif + + a_entry_static_inv = true; + b_entry_static_inv = true; + c_entry_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + { + out.str(""); + a aa; + ok.str(""); ok // Test nothing failed. + << ok_c() + << ok_b() + << ok_a() + << ok_end() + ; + BOOST_TEST(out.eq(ok.str())); + } + + boost::contract::set_entry_invariant_failure( + [] (boost::contract::from) { throw err(); }); + + a_entry_static_inv = false; + b_entry_static_inv = true; + c_entry_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() + << ok_b() + << ok_a() // Test a::static_inv failed. + #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_entry_static_inv = true; + b_entry_static_inv = false; + c_entry_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() + << ok_b() // Test b::static_inv failed. + #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << ok_a() + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_entry_static_inv = true; + b_entry_static_inv = true; + c_entry_static_inv = false; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() // Test c::static_inv failed. + #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << ok_b() + << ok_a() + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_entry_static_inv = false; + b_entry_static_inv = false; + c_entry_static_inv = false; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() // Test c::static_inv failed (as all did). + #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << ok_b() + << ok_a() + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + #undef BOOST_CONTRACT_TEST_entry_inv + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/decl_entry_static_inv_ends.cpp b/src/boost/libs/contract/test/constructor/decl_entry_static_inv_ends.cpp new file mode 100644 index 00000000..32168cb9 --- /dev/null +++ b/src/boost/libs/contract/test/constructor/decl_entry_static_inv_ends.cpp @@ -0,0 +1,209 @@ + +// 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 only derived and grandparent classes (ends) with entry static inv. + +#undef BOOST_CONTRACT_TEST_NO_A_STATIC_INV +#define BOOST_CONTRACT_TEST_NO_B_STATIC_INV +#undef BOOST_CONTRACT_TEST_NO_C_STATIC_INV +#include "decl.hpp" + +#include <boost/preprocessor/control/iif.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> +#include <string> + +std::string ok_c() { + std::ostringstream ok; ok << "" // Suppress a warning. + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "c::static_inv" << std::endl // This might fail. + #endif + ; + return ok.str(); +} + +std::string ok_b() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_OLDS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "c::ctor::post" << std::endl + // No b::static_inv to fail. + #endif + ; + return ok.str(); +} + +std::string ok_a() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl // This might fail. + #endif + ; + return ok.str(); +} + +std::string ok_end() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} + +struct err {}; // Global decl so visible in MSVC10 lambdas. + +int main() { + std::ostringstream ok; + + #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + #define BOOST_CONTRACT_TEST_entry_inv 0 + #else + #define BOOST_CONTRACT_TEST_entry_inv 1 + #endif + + a_entry_static_inv = true; + b_entry_static_inv = true; + c_entry_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + { + out.str(""); + a aa; + ok.str(""); ok // Test nothing failed. + << ok_c() + << ok_b() + << ok_a() + << ok_end() + ; + BOOST_TEST(out.eq(ok.str())); + } + + boost::contract::set_entry_invariant_failure( + [] (boost::contract::from) { throw err(); }); + + a_entry_static_inv = false; + b_entry_static_inv = true; + c_entry_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() + << ok_b() + << ok_a() // Test a::static_inv failed. + #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_entry_static_inv = true; + b_entry_static_inv = false; + c_entry_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + { + out.str(""); + a aa; + ok.str(""); ok + << ok_c() + << ok_b() + << ok_a() + << ok_end() + ; + BOOST_TEST(out.eq(ok.str())); + } + + a_entry_static_inv = true; + b_entry_static_inv = true; + c_entry_static_inv = false; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() // Test c::static_inv failed. + #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << ok_b() + << ok_a() + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_entry_static_inv = false; + b_entry_static_inv = false; + c_entry_static_inv = false; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() // Test c::static_inv failed (as all did). + #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << ok_b() + << ok_a() + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + #undef BOOST_CONTRACT_TEST_entry_inv + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/decl_entry_static_inv_mid.cpp b/src/boost/libs/contract/test/constructor/decl_entry_static_inv_mid.cpp new file mode 100644 index 00000000..104388be --- /dev/null +++ b/src/boost/libs/contract/test/constructor/decl_entry_static_inv_mid.cpp @@ -0,0 +1,204 @@ + +// 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 only middle base class with entry static invariants. + +#define BOOST_CONTRACT_TEST_NO_A_STATIC_INV +#undef BOOST_CONTRACT_TEST_NO_B_STATIC_INV +#define BOOST_CONTRACT_TEST_NO_C_STATIC_INV +#include "decl.hpp" + +#include <boost/preprocessor/control/iif.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> +#include <string> + +std::string ok_c() { + std::ostringstream ok; ok << "" // Suppress a warning. + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + // No c::static_inv here. + ; + return ok.str(); +} + +std::string ok_b() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_OLDS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "b::static_inv" << std::endl // This might fail. + #endif + ; + return ok.str(); +} + +std::string ok_a() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + // No a::static_inv here. + ; + return ok.str(); +} + +std::string ok_end() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} + +struct err {}; // Global decl so visible in MSVC10 lambdas. + +int main() { + std::ostringstream ok; + + #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + #define BOOST_CONTRACT_TEST_entry_inv 0 + #else + #define BOOST_CONTRACT_TEST_entry_inv 1 + #endif + + a_entry_static_inv = true; + b_entry_static_inv = true; + c_entry_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + { + out.str(""); + a aa; + ok.str(""); ok // Test nothing failed. + << ok_c() + << ok_b() + << ok_a() + << ok_end() + ; + BOOST_TEST(out.eq(ok.str())); + } + + boost::contract::set_entry_invariant_failure( + [] (boost::contract::from) { throw err(); }); + + a_entry_static_inv = false; + b_entry_static_inv = true; + c_entry_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + { + out.str(""); + a aa; + ok.str(""); ok + << ok_c() + << ok_b() + << ok_a() // Test no a::static_inv so no failure. + << ok_end() + ; + BOOST_TEST(out.eq(ok.str())); + } + + std::cout << "---" << std::endl; + + a_entry_static_inv = true; + b_entry_static_inv = false; + c_entry_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() + << ok_b() // Test b::static_inv failed. + #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << ok_a() + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + std::cout << "===" << std::endl; + + a_entry_static_inv = true; + b_entry_static_inv = true; + c_entry_static_inv = false; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + { + out.str(""); + a aa; + ok.str(""); ok + << ok_c() // Test no c::static_inv so no failure. + << ok_b() + << ok_a() + << ok_end() + ; + BOOST_TEST(out.eq(ok.str())); + } + + a_entry_static_inv = false; + b_entry_static_inv = false; + c_entry_static_inv = false; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() + << ok_b() // Test b::static_inv failed (as all did). + #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << ok_a() + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + #undef BOOST_CONTRACT_TEST_entry_inv + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/decl_entry_static_inv_none.cpp b/src/boost/libs/contract/test/constructor/decl_entry_static_inv_none.cpp new file mode 100644 index 00000000..58b711d7 --- /dev/null +++ b/src/boost/libs/contract/test/constructor/decl_entry_static_inv_none.cpp @@ -0,0 +1,124 @@ + +// 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 only middle base class with entry static invariants. + +#define BOOST_CONTRACT_TEST_NO_A_STATIC_INV +#define BOOST_CONTRACT_TEST_NO_B_STATIC_INV +#define BOOST_CONTRACT_TEST_NO_C_STATIC_INV +#include "decl.hpp" + +#include <boost/preprocessor/control/iif.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +int main() { + std::ostringstream ok; ok // Test nothing fails. + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_OLDS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + + #ifdef BOOST_CONTRACT_ENTRY_INVARIANTS + #define BOOST_CONTRACT_TEST_entry_inv 0 + #else + #define BOOST_CONTRACT_TEST_entry_inv 1 + #endif + + a_entry_static_inv = true; + b_entry_static_inv = true; + c_entry_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + { + out.str(""); + a aa; + BOOST_TEST(out.eq(ok.str())); + } + + a_entry_static_inv = false; + b_entry_static_inv = true; + c_entry_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + { + out.str(""); + a aa; + BOOST_TEST(out.eq(ok.str())); + } + + a_entry_static_inv = true; + b_entry_static_inv = false; + c_entry_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + { + out.str(""); + a aa; + BOOST_TEST(out.eq(ok.str())); + } + + a_entry_static_inv = true; + b_entry_static_inv = true; + c_entry_static_inv = false; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + { + out.str(""); + a aa; + BOOST_TEST(out.eq(ok.str())); + } + + a_entry_static_inv = false; + b_entry_static_inv = false; + c_entry_static_inv = false; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + { + out.str(""); + a aa; + BOOST_TEST(out.eq(ok.str())); + } + + #undef BOOST_CONTRACT_TEST_entry_inv + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/decl_exit_inv_all.cpp b/src/boost/libs/contract/test/constructor/decl_exit_inv_all.cpp new file mode 100644 index 00000000..3aee1cc4 --- /dev/null +++ b/src/boost/libs/contract/test/constructor/decl_exit_inv_all.cpp @@ -0,0 +1,201 @@ + +// 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 derived and base classes with exit invariants. + +#undef BOOST_CONTRACT_TEST_NO_A_INV +#undef BOOST_CONTRACT_TEST_NO_B_INV +#undef BOOST_CONTRACT_TEST_NO_C_INV +#include "decl.hpp" + +#include <boost/detail/lightweight_test.hpp> +#include <sstream> +#include <string> + +std::string ok_c() { + std::ostringstream ok; ok << "" // Suppress a warning. + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl // This can fail. + #endif + ; + return ok.str(); +} + +std::string ok_b() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl // This can fail. + #endif + ; + return ok.str(); +} + +std::string ok_a() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl // This can fail. + #endif + ; + return ok.str(); +} + +std::string ok_end() { + std::ostringstream ok; ok << "" // Suppress a warning. + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} + +struct err {}; // Global decl so visible in MSVC10 lambdas. + +int main() { + std::ostringstream ok; + + a_exit_inv = true; + b_exit_inv = true; + c_exit_inv = true; + { + out.str(""); + a aa; + ok.str(""); ok // Test nothing fails. + << ok_c() + << ok_b() + << ok_a() + << ok_end() + ; + BOOST_TEST(out.eq(ok.str())); + } + + boost::contract::set_exit_invariant_failure( + [] (boost::contract::from) { throw err(); }); + + a_exit_inv = false; + b_exit_inv = true; + c_exit_inv = true; + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() + << ok_b() + << ok_a() // Test a::inv failed. + #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_exit_inv = true; + b_exit_inv = false; + c_exit_inv = true; + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() + << ok_b() // Test bb::inv failed. + #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << ok_a() + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_exit_inv = true; + b_exit_inv = true; + c_exit_inv = false; + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() // Test c::inv failed. + #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << ok_b() + << ok_a() + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_exit_inv = false; + b_exit_inv = false; + c_exit_inv = false; + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() // Test c::inv failed. + #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << ok_b() + << ok_a() + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/decl_exit_inv_ends.cpp b/src/boost/libs/contract/test/constructor/decl_exit_inv_ends.cpp new file mode 100644 index 00000000..ac45eac2 --- /dev/null +++ b/src/boost/libs/contract/test/constructor/decl_exit_inv_ends.cpp @@ -0,0 +1,195 @@ + +// 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 only derived and grandparent classes (ends) with exit invariants. + +#undef BOOST_CONTRACT_TEST_NO_A_INV +#define BOOST_CONTRACT_TEST_NO_B_INV +#undef BOOST_CONTRACT_TEST_NO_C_INV +#include "decl.hpp" + +#include <boost/detail/lightweight_test.hpp> +#include <sstream> +#include <string> + +std::string ok_c() { + std::ostringstream ok; ok << "" // Suppress a warning. + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl // This can fail. + #endif + ; + return ok.str(); +} + +std::string ok_b() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::static_inv" << std::endl + // No failure here. + #endif + ; + return ok.str(); +} + +std::string ok_a() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl // This can fail. + #endif + ; + return ok.str(); +} + +std::string ok_end() { + std::ostringstream ok; ok << "" // Suppress a warning. + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} + +struct err {}; // Global decl so visible in MSVC10 lambdas. + +int main() { + std::ostringstream ok; + + a_exit_inv = true; + b_exit_inv = true; + c_exit_inv = true; + { + out.str(""); + a aa; + ok.str(""); ok // Test no failure. + << ok_c() + << ok_b() + << ok_a() + << ok_end() + ; + BOOST_TEST(out.eq(ok.str())); + } + + boost::contract::set_exit_invariant_failure( + [] (boost::contract::from) { throw err(); }); + + a_exit_inv = false; + b_exit_inv = true; + c_exit_inv = true; + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() + << ok_b() + << ok_a() // Test a::inv failed. + #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_exit_inv = true; + b_exit_inv = false; + c_exit_inv = true; + try { + out.str(""); + a aa; + ok.str(""); ok + << ok_c() + << ok_b() // Test no b::inv so no failure. + << ok_a() + << ok_end() + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_exit_inv = true; + b_exit_inv = true; + c_exit_inv = false; + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() // Test c::inv failed. + #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << ok_b() + << ok_a() + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_exit_inv = false; + b_exit_inv = false; + c_exit_inv = false; + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() // Test c::inv failed. + #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << ok_b() + << ok_a() + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/decl_exit_inv_mid.cpp b/src/boost/libs/contract/test/constructor/decl_exit_inv_mid.cpp new file mode 100644 index 00000000..d9c8bcd4 --- /dev/null +++ b/src/boost/libs/contract/test/constructor/decl_exit_inv_mid.cpp @@ -0,0 +1,189 @@ + +// 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 only middle class with exit invariants. + +#define BOOST_CONTRACT_TEST_NO_A_INV +#undef BOOST_CONTRACT_TEST_NO_B_INV +#define BOOST_CONTRACT_TEST_NO_C_INV +#include "decl.hpp" + +#include <boost/detail/lightweight_test.hpp> +#include <sstream> +#include <string> + +std::string ok_c() { + std::ostringstream ok; ok << "" // Suppress a warning. + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::static_inv" << std::endl + // No failure here. + #endif + ; + return ok.str(); +} + +std::string ok_b() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl // This can fail. + #endif + ; + return ok.str(); +} + +std::string ok_a() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + // No failure here. + #endif + ; + return ok.str(); +} + +std::string ok_end() { + std::ostringstream ok; ok << "" // Suppress a warning. + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} + +struct err {}; // Global decl so visible in MSVC10 lambdas. + +int main() { + std::ostringstream ok; + + a_exit_inv = true; + b_exit_inv = true; + c_exit_inv = true; + { + out.str(""); + a aa; + ok.str(""); ok // Test nothing failed. + << ok_c() + << ok_b() + << ok_a() + << ok_end() + ; + BOOST_TEST(out.eq(ok.str())); + } + + boost::contract::set_exit_invariant_failure( + [] (boost::contract::from) { throw err(); }); + + a_exit_inv = false; + b_exit_inv = true; + c_exit_inv = true; + try { + out.str(""); + a aa; + ok.str(""); ok + << ok_c() + << ok_b() + << ok_a() // Test no failure here. + << ok_end() + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_exit_inv = true; + b_exit_inv = false; + c_exit_inv = true; + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() + << ok_b() // Test b::inv failed. + #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << ok_a() + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_exit_inv = true; + b_exit_inv = true; + c_exit_inv = false; + try { + out.str(""); + a aa; + ok.str(""); ok + << ok_c() // Test no failure here. + << ok_b() + << ok_a() + << ok_end() + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_exit_inv = false; + b_exit_inv = false; + c_exit_inv = false; + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() + << ok_b() // Test b::inv failed. + #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << ok_a() + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/decl_exit_inv_none.cpp b/src/boost/libs/contract/test/constructor/decl_exit_inv_none.cpp new file mode 100644 index 00000000..baf89813 --- /dev/null +++ b/src/boost/libs/contract/test/constructor/decl_exit_inv_none.cpp @@ -0,0 +1,115 @@ + +// 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 derived and grandparent classes (ends) with exit invariants. + +#define BOOST_CONTRACT_TEST_NO_A_INV +#define BOOST_CONTRACT_TEST_NO_B_INV +#define BOOST_CONTRACT_TEST_NO_C_INV +#include "decl.hpp" + +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +int main() { + std::ostringstream ok; ok // Test nothing fails. + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + + a_exit_inv = true; + b_exit_inv = true; + c_exit_inv = true; + { + out.str(""); + a aa; + BOOST_TEST(out.eq(ok.str())); + } + + a_exit_inv = false; + b_exit_inv = true; + c_exit_inv = true; + { + out.str(""); + a aa; + BOOST_TEST(out.eq(ok.str())); + } + + a_exit_inv = true; + b_exit_inv = false; + c_exit_inv = true; + { + out.str(""); + a aa; + BOOST_TEST(out.eq(ok.str())); + } + + a_exit_inv = true; + b_exit_inv = true; + c_exit_inv = false; + { + out.str(""); + a aa; + BOOST_TEST(out.eq(ok.str())); + } + + a_exit_inv = false; + b_exit_inv = false; + c_exit_inv = false; + { + out.str(""); + a aa; + BOOST_TEST(out.eq(ok.str())); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/decl_exit_static_inv_all.cpp b/src/boost/libs/contract/test/constructor/decl_exit_static_inv_all.cpp new file mode 100644 index 00000000..e33e4cd1 --- /dev/null +++ b/src/boost/libs/contract/test/constructor/decl_exit_static_inv_all.cpp @@ -0,0 +1,224 @@ + +// 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 derived and base classes with exit static invariants. + +#undef BOOST_CONTRACT_TEST_NO_A_STATIC_INV +#undef BOOST_CONTRACT_TEST_NO_B_STATIC_INV +#undef BOOST_CONTRACT_TEST_NO_C_STATIC_INV +#include "decl.hpp" + +#include <boost/preprocessor/control/iif.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> +#include <string> + +std::string ok_c() { + std::ostringstream ok; ok << "" // Suppress a warning. + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::static_inv" << std::endl // This can fail. + #endif + ; + return ok.str(); +} + +std::string ok_b() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::static_inv" << std::endl // This can fail. + #endif + ; + return ok.str(); +} + +std::string ok_a() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl // This can fail. + #endif + ; + return ok.str(); +} + +std::string ok_end() { + std::ostringstream ok; ok << "" // Suppress a warning. + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} + +struct err {}; // Global decl so visible in MSVC10 lambdas. + +int main() { + std::ostringstream ok; + + #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + #define BOOST_CONTRACT_TEST_entry_inv 0 + #else + #define BOOST_CONTRACT_TEST_entry_inv 1 + #endif + + a_exit_static_inv = true; + b_exit_static_inv = true; + c_exit_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + { + out.str(""); + a aa; + ok.str(""); ok // Test nothing failed. + << ok_c() + << ok_b() + << ok_a() + << ok_end() + ; + BOOST_TEST(out.eq(ok.str())); + } + + boost::contract::set_exit_invariant_failure( + [] (boost::contract::from) { throw err(); }); + + a_exit_static_inv = false; + b_exit_static_inv = true; + c_exit_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() + << ok_b() + << ok_a() // Test exit a::static_inv failed. + #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_exit_static_inv = true; + b_exit_static_inv = false; + c_exit_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() + << ok_b() // Test exit b::static_inv failed. + #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << ok_a() + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_exit_static_inv = true; + b_exit_static_inv = true; + c_exit_static_inv = false; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() // Test exit c::static_inv failed. + #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << ok_b() + << ok_a() + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_exit_static_inv = false; + b_exit_static_inv = false; + c_exit_static_inv = false; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() // Test exit c::static_inv failed (as all did). + #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << ok_b() + << ok_a() + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/decl_exit_static_inv_ends.cpp b/src/boost/libs/contract/test/constructor/decl_exit_static_inv_ends.cpp new file mode 100644 index 00000000..a8b2f5e6 --- /dev/null +++ b/src/boost/libs/contract/test/constructor/decl_exit_static_inv_ends.cpp @@ -0,0 +1,213 @@ + +// 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 derived and grandparent classes (ends) with exit static invariants. + +#undef BOOST_CONTRACT_TEST_NO_A_STATIC_INV +#define BOOST_CONTRACT_TEST_NO_B_STATIC_INV +#undef BOOST_CONTRACT_TEST_NO_C_STATIC_INV +#include "decl.hpp" + +#include <boost/preprocessor/control/iif.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> +#include <string> + +std::string ok_c() { + std::ostringstream ok; ok << "" // Suppress a warning. + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::static_inv" << std::endl // This can fail. + #endif + ; + return ok.str(); +} + +std::string ok_b() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + ; + return ok.str(); +} + +std::string ok_a() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + #endif + ; + return ok.str(); +} + +std::string ok_end() { + std::ostringstream ok; ok << "" // Suppress a warning. + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} + +struct err {}; // Global decl so visible in MSVC10 lambdas. + +int main() { + std::ostringstream ok; + + #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + #define BOOST_CONTRACT_TEST_entry_inv 0 + #else + #define BOOST_CONTRACT_TEST_entry_inv 1 + #endif + + a_exit_static_inv = true; + b_exit_static_inv = true; + c_exit_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + { + out.str(""); + a aa; + ok.str(""); ok // Test nothing failed. + << ok_c() + << ok_b() + << ok_a() + << ok_end() + ; + BOOST_TEST(out.eq(ok.str())); + } + + boost::contract::set_exit_invariant_failure( + [] (boost::contract::from) { throw err(); }); + + a_exit_static_inv = false; + b_exit_static_inv = true; + c_exit_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() + << ok_b() + << ok_a() // Test a::static_inv failed. + #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_exit_static_inv = true; + b_exit_static_inv = false; + c_exit_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + try { + out.str(""); + a aa; + ok.str(""); ok + << ok_c() + << ok_b() + << ok_a() + << ok_end() + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_exit_static_inv = true; + b_exit_static_inv = true; + c_exit_static_inv = false; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() // Test c::static_inv failed (as all did). + #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << ok_b() + << ok_a() + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_exit_static_inv = false; + b_exit_static_inv = false; + c_exit_static_inv = false; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() // Test c::static_inv failed (as all did). + #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << ok_b() + << ok_a() + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + #undef BOOST_CONTRACT_TEST_entry_inv + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/decl_exit_static_inv_mid.cpp b/src/boost/libs/contract/test/constructor/decl_exit_static_inv_mid.cpp new file mode 100644 index 00000000..c8a24bde --- /dev/null +++ b/src/boost/libs/contract/test/constructor/decl_exit_static_inv_mid.cpp @@ -0,0 +1,202 @@ + +// 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 only middle base class with exit static invariants. + +#define BOOST_CONTRACT_TEST_NO_A_STATIC_INV +#undef BOOST_CONTRACT_TEST_NO_B_STATIC_INV +#define BOOST_CONTRACT_TEST_NO_C_STATIC_INV +#include "decl.hpp" + +#include <boost/preprocessor/control/iif.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> +#include <string> + +std::string ok_c() { + std::ostringstream ok; ok << "" // Suppress a warning. + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_OLDS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + // No failure here. + ; + return ok.str(); +} + +std::string ok_b() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::static_inv" << std::endl // This can fail. + #endif + ; + return ok.str(); +} + +std::string ok_a() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + // No failure here. + ; + return ok.str(); +} + +std::string ok_end() { + std::ostringstream ok; ok << "" // Suppress a warning. + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} + +struct err {}; // Global decl so visible in MSVC10 lambdas. + +int main() { + std::ostringstream ok; + + #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + #define BOOST_CONTRACT_TEST_entry_inv 0 + #else + #define BOOST_CONTRACT_TEST_entry_inv 1 + #endif + + a_exit_static_inv = true; + b_exit_static_inv = true; + c_exit_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + { + out.str(""); + a aa; + ok.str(""); ok // Test nothing fails. + << ok_c() + << ok_b() + << ok_a() + << ok_end() + ; + BOOST_TEST(out.eq(ok.str())); + } + + boost::contract::set_exit_invariant_failure( + [] (boost::contract::from) { throw err(); }); + + a_exit_static_inv = false; + b_exit_static_inv = true; + c_exit_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + try { + out.str(""); + a aa; + ok.str(""); ok + << ok_c() + << ok_b() + << ok_a() // Test no a::static_inv so no failure. + << ok_end() + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_exit_static_inv = true; + b_exit_static_inv = false; + c_exit_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() + << ok_b() // Test b::static_inv failed. + #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << ok_a() + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_exit_static_inv = true; + b_exit_static_inv = true; + c_exit_static_inv = false; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + try { + out.str(""); + a aa; + ok.str(""); ok + << ok_c() // Test no c::static_inv so no failure. + << ok_b() + << ok_a() + << ok_end() + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_exit_static_inv = false; + b_exit_static_inv = false; + c_exit_static_inv = false; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() + << ok_b() // Test b::static_inv failed. + #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << ok_a() + << ok_end() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/decl_exit_static_inv_none.cpp b/src/boost/libs/contract/test/constructor/decl_exit_static_inv_none.cpp new file mode 100644 index 00000000..79ceaf79 --- /dev/null +++ b/src/boost/libs/contract/test/constructor/decl_exit_static_inv_none.cpp @@ -0,0 +1,123 @@ + +// 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 derived and base classes without exit static invariants. + +#define BOOST_CONTRACT_TEST_NO_A_STATIC_INV +#define BOOST_CONTRACT_TEST_NO_B_STATIC_INV +#define BOOST_CONTRACT_TEST_NO_C_STATIC_INV +#include "decl.hpp" + +#include <boost/preprocessor/control/iif.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +int main() { + std::ostringstream ok; ok // Test nothing fails. + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_OLDS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + + #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + #define BOOST_CONTRACT_TEST_entry_inv 0 + #else + #define BOOST_CONTRACT_TEST_entry_inv 1 + #endif + + a_exit_static_inv = true; + b_exit_static_inv = true; + c_exit_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + { + out.str(""); + a aa; + BOOST_TEST(out.eq(ok.str())); + } + + a_exit_static_inv = false; + b_exit_static_inv = true; + c_exit_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + { + out.str(""); + a aa; + BOOST_TEST(out.eq(ok.str())); + } + + a_exit_static_inv = true; + b_exit_static_inv = false; + c_exit_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + { + out.str(""); + a aa; + BOOST_TEST(out.eq(ok.str())); + } + + a_exit_static_inv = true; + b_exit_static_inv = true; + c_exit_static_inv = false; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + { + out.str(""); + a aa; + BOOST_TEST(out.eq(ok.str())); + } + + a_exit_static_inv = false; + b_exit_static_inv = false; + c_exit_static_inv = false; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); + { + out.str(""); + a aa; + BOOST_TEST(out.eq(ok.str())); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/decl_post_all.cpp b/src/boost/libs/contract/test/constructor/decl_post_all.cpp new file mode 100644 index 00000000..b4e38a1c --- /dev/null +++ b/src/boost/libs/contract/test/constructor/decl_post_all.cpp @@ -0,0 +1,186 @@ + +// 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 derived and base classes with postconditions. + +#undef BOOST_CONTRACT_TEST_NO_A_POST +#undef BOOST_CONTRACT_TEST_NO_B_POST +#undef BOOST_CONTRACT_TEST_NO_C_POST +#include "decl.hpp" + +#include <boost/detail/lightweight_test.hpp> +#include <sstream> +#include <string> + +std::string ok_c() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + ; + return ok.str(); +} + +std::string ok_b() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + ; + return ok.str(); +} + +std::string ok_a() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} + +struct err {}; // Global decl so visible in MSVC10 lambdas. + +int main() { + std::ostringstream ok; + + a_post = true; + b_post = true; + c_post = true; + out.str(""); + { + a aa; + ok.str(""); ok // Test nothing failed. + << ok_c() + << ok_b() + << ok_a() + ; + BOOST_TEST(out.eq(ok.str())); + } + + boost::contract::set_postcondition_failure( + [] (boost::contract::from) { throw err(); }); + + a_post = false; + b_post = true; + c_post = true; + out.str(""); + try { + a aa; + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() + << ok_b() + << ok_a() + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_post = true; + b_post = false; + c_post = true; + out.str(""); + try { + a aa; + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() + << ok_b() // Test b::ctor::post failed. + #ifdef BOOST_CONTRACT_NO_POSTCONDITIONS + << ok_a() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_post = true; + b_post = true; + c_post = false; + out.str(""); + try { + a aa; + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() // Test c::ctor::post failed. + #ifdef BOOST_CONTRACT_NO_POSTCONDITIONS + << ok_b() + << ok_a() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_post = false; + b_post = false; + c_post = false; + out.str(""); + try { + a aa; + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() // Test c::ctor::post failed (as all did) + #ifdef BOOST_CONTRACT_NO_POSTCONDITIONS + << ok_b() + << ok_a() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/decl_post_ends.cpp b/src/boost/libs/contract/test/constructor/decl_post_ends.cpp new file mode 100644 index 00000000..b98af74f --- /dev/null +++ b/src/boost/libs/contract/test/constructor/decl_post_ends.cpp @@ -0,0 +1,168 @@ + +// 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 only derived and grandparent classes (ends) with postconditions. + +#undef BOOST_CONTRACT_TEST_NO_A_POST +#define BOOST_CONTRACT_TEST_NO_B_POST +#undef BOOST_CONTRACT_TEST_NO_C_POST +#include "decl.hpp" + +#include <boost/detail/lightweight_test.hpp> +#include <sstream> +#include <string> + +std::string ok_c() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + ; + return ok.str(); +} + +std::string ok_ba() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + // No b::ctor::post here. + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} + +struct err {}; // Global decl so visible in MSVC10 lambdas. + +int main() { + std::ostringstream ok; + + a_post = true; + b_post = true; + c_post = true; + { + out.str(""); + a aa; + ok.str(""); ok // Test nothing failed. + << ok_c() + << ok_ba() + ; + BOOST_TEST(out.eq(ok.str())); + } + + boost::contract::set_postcondition_failure( + [] (boost::contract::from) { throw err(); }); + + a_post = false; + b_post = true; + c_post = true; + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() + << ok_ba() // Test a::ctor::post failed. + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_post = true; + b_post = false; + c_post = true; + { + out.str(""); + a aa; + ok.str(""); ok + << ok_c() + << ok_ba() // Test no b::ctor::post so no failure. + ; + BOOST_TEST(out.eq(ok.str())); + } + + a_post = true; + b_post = true; + c_post = false; + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() // Test c::ctor::post failed. + #ifdef BOOST_CONTRACT_NO_POSTCONDITIONS + << ok_ba() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_post = false; + b_post = false; + c_post = false; + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() // Test c::ctor::post failed (as all did). + #ifdef BOOST_CONTRACT_NO_POSTCONDITIONS + << ok_ba() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/decl_post_mid.cpp b/src/boost/libs/contract/test/constructor/decl_post_mid.cpp new file mode 100644 index 00000000..a6afce6b --- /dev/null +++ b/src/boost/libs/contract/test/constructor/decl_post_mid.cpp @@ -0,0 +1,160 @@ + +// 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 only middle base class with postconditions. + +#define BOOST_CONTRACT_TEST_NO_A_POST +#undef BOOST_CONTRACT_TEST_NO_B_POST +#define BOOST_CONTRACT_TEST_NO_C_POST +#include "decl.hpp" + +#include <boost/detail/lightweight_test.hpp> +#include <sstream> +#include <string> + +std::string ok_cb() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + ; + return ok.str(); +} + +std::string ok_a() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + ; + return ok.str(); +} + +struct err {}; // Global decl so visible in MSVC10 lambdas. + +int main() { + std::ostringstream ok; + + a_post = true; + b_post = true; + c_post = true; + { + out.str(""); + a aa; + ok.str(""); ok // Test nothing failed. + << ok_cb() + << ok_a() + ; + BOOST_TEST(out.eq(ok.str())); + } + + boost::contract::set_postcondition_failure( + [] (boost::contract::from) { throw err(); }); + + a_post = false; + b_post = true; + c_post = true; + { + out.str(""); + a aa; + ok.str(""); ok + << ok_cb() + << ok_a() // Test no a::ctor::post so no failure. + ; + BOOST_TEST(out.eq(ok.str())); + } + + a_post = true; + b_post = false; + c_post = true; + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_cb() // Test b::ctor::post failed. + #ifdef BOOST_CONTRACT_NO_POSTCONDITIONS + << ok_a() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_post = true; + b_post = true; + c_post = false; + { + out.str(""); + a aa; + ok.str(""); ok + << ok_cb() // Test no c::ctor::post so no failure. + << ok_a() + ; + BOOST_TEST(out.eq(ok.str())); + } + + a_post = false; + b_post = false; + c_post = false; + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_cb() // Test b::ctor::post failed (as all did). + #ifdef BOOST_CONTRACT_NO_POSTCONDITIONS + << ok_a() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/decl_post_none.cpp b/src/boost/libs/contract/test/constructor/decl_post_none.cpp new file mode 100644 index 00000000..2b837e19 --- /dev/null +++ b/src/boost/libs/contract/test/constructor/decl_post_none.cpp @@ -0,0 +1,109 @@ + +// 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 only middle base class with postconditions. + +#define BOOST_CONTRACT_TEST_NO_A_POST +#define BOOST_CONTRACT_TEST_NO_B_POST +#define BOOST_CONTRACT_TEST_NO_C_POST +#include "decl.hpp" + +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +int main() { + std::ostringstream ok; ok // Test nothing fails. + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + ; + + a_post = true; + b_post = true; + c_post = true; + { + out.str(""); + a aa; + BOOST_TEST(out.eq(ok.str())); + } + + a_post = false; + b_post = true; + c_post = true; + { + out.str(""); + a aa; + BOOST_TEST(out.eq(ok.str())); + } + + a_post = true; + b_post = false; + c_post = true; + { + out.str(""); + a aa; + BOOST_TEST(out.eq(ok.str())); + } + + a_post = true; + b_post = true; + c_post = false; + { + out.str(""); + a aa; + BOOST_TEST(out.eq(ok.str())); + } + + a_post = false; + b_post = false; + c_post = false; + { + out.str(""); + a aa; + BOOST_TEST(out.eq(ok.str())); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/decl_pre_all.cpp b/src/boost/libs/contract/test/constructor/decl_pre_all.cpp new file mode 100644 index 00000000..4714a742 --- /dev/null +++ b/src/boost/libs/contract/test/constructor/decl_pre_all.cpp @@ -0,0 +1,178 @@ + +// 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 derived and base classes with preconditions. + +#undef BOOST_CONTRACT_TEST_NO_A_PRE +#undef BOOST_CONTRACT_TEST_NO_B_PRE +#undef BOOST_CONTRACT_TEST_NO_C_PRE +#include "decl.hpp" + +#include <boost/detail/lightweight_test.hpp> +#include <sstream> +#include <string> + +std::string ok_after() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} + +struct err {}; // Global decl so visible in MSVC10 lambdas. + +int main() { + std::ostringstream ok; + + a_pre = true; + b_pre = true; + c_pre = true; + { + out.str(""); + a aa; + ok.str(""); ok // Test nothing failed. + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + << ok_after() + ; + BOOST_TEST(out.eq(ok.str())); + } + + boost::contract::set_precondition_failure( + [] (boost::contract::from) { throw err(); }); + + a_pre = false; + b_pre = true; + c_pre = true; + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl // Test this failed. + #else + << ok_after() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_pre = true; + b_pre = false; + c_pre = true; + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl // Test this failed. + #else + << ok_after() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_pre = true; + b_pre = true; + c_pre = false; + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl // Test this failed. + #else + << ok_after() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_pre = false; + b_pre = false; + c_pre = false; + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl // Test this failed (as all did). + #else + << ok_after() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/decl_pre_ends.cpp b/src/boost/libs/contract/test/constructor/decl_pre_ends.cpp new file mode 100644 index 00000000..6a6a1c13 --- /dev/null +++ b/src/boost/libs/contract/test/constructor/decl_pre_ends.cpp @@ -0,0 +1,172 @@ + +// 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 only derived and grandparent classes (ends) with preconditions. + +#undef BOOST_CONTRACT_TEST_NO_A_PRE +#define BOOST_CONTRACT_TEST_NO_B_PRE +#undef BOOST_CONTRACT_TEST_NO_C_PRE +#include "decl.hpp" + +#include <boost/detail/lightweight_test.hpp> +#include <sstream> +#include <string> + +std::string ok_after() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} + +struct err {}; // Global decl so visible in MSVC10 lambdas. + +int main() { + std::ostringstream ok; + + a_pre = true; + b_pre = true; + c_pre = true; + { + out.str(""); + a aa; + ok.str(""); ok // Test nothing failed. + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + << ok_after() + ; + BOOST_TEST(out.eq(ok.str())); + } + + boost::contract::set_precondition_failure( + [] (boost::contract::from) { throw err(); }); + + a_pre = false; + b_pre = true; + c_pre = true; + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl // Test this failed. + #else + << ok_after() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_pre = true; + b_pre = false; + c_pre = true; + { + out.str(""); + a aa; + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + // Test no failure here. + << "c::ctor::pre" << std::endl + #endif + << ok_after() + ; + BOOST_TEST(out.eq(ok.str())); + } + + a_pre = true; + b_pre = true; + c_pre = false; + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl // Test this failed. + #else + << ok_after() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + a_pre = false; + b_pre = false; + c_pre = false; + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl // Test this failed (as all did). + #else + << ok_after() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/decl_pre_mid.cpp b/src/boost/libs/contract/test/constructor/decl_pre_mid.cpp new file mode 100644 index 00000000..a4e7761e --- /dev/null +++ b/src/boost/libs/contract/test/constructor/decl_pre_mid.cpp @@ -0,0 +1,164 @@ + +// 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 only middle base classes with preconditions. + +#define BOOST_CONTRACT_TEST_NO_A_PRE +#undef BOOST_CONTRACT_TEST_NO_B_PRE +#define BOOST_CONTRACT_TEST_NO_C_PRE +#include "decl.hpp" + +#include <boost/detail/lightweight_test.hpp> +#include <sstream> +#include <string> + +std::string ok_after() { + std::ostringstream ok; ok + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} + +struct err {}; // Global decl so visible in MSVC10 lambdas. + +int main() { + std::ostringstream ok; + + a_pre = true; + b_pre = true; + c_pre = true; + { + out.str(""); + a aa; + ok.str(""); ok // Test nothing failed. + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "b::ctor::pre" << std::endl + #endif + << ok_after() + ; + BOOST_TEST(out.eq(ok.str())); + } + + boost::contract::set_precondition_failure( + [] (boost::contract::from) { throw err(); }); + + a_pre = false; + b_pre = true; + c_pre = true; + { + out.str(""); + a aa; + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "b::ctor::pre" << std::endl // Test no failure here. + #endif + << ok_after() + ; + BOOST_TEST(out.eq(ok.str())); + } + + a_pre = true; + b_pre = false; + c_pre = true; + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "b::ctor::pre" << std::endl // Test this failed. + #else + << ok_after() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + + a_pre = true; + b_pre = true; + c_pre = false; + { + out.str(""); + a aa; + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "b::ctor::pre" << std::endl // Test no failure here. + #endif + << ok_after() + ; + BOOST_TEST(out.eq(ok.str())); + } + + a_pre = false; + b_pre = false; + c_pre = false; + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "b::ctor::pre" << std::endl // Test this failed (as all did). + #else + << ok_after() + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/decl_pre_none.cpp b/src/boost/libs/contract/test/constructor/decl_pre_none.cpp new file mode 100644 index 00000000..4fa27f03 --- /dev/null +++ b/src/boost/libs/contract/test/constructor/decl_pre_none.cpp @@ -0,0 +1,114 @@ + +// 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 derived and base classes without preconditions. + +#define BOOST_CONTRACT_TEST_NO_A_PRE +#define BOOST_CONTRACT_TEST_NO_B_PRE +#define BOOST_CONTRACT_TEST_NO_C_PRE +#include "decl.hpp" + +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +int main() { + std::ostringstream ok; ok + // Test no preconditions here. + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + + a_pre = true; + b_pre = true; + c_pre = true; + { + out.str(""); + a aa; + BOOST_TEST(out.eq(ok.str())); + } + + a_pre = false; + b_pre = true; + c_pre = true; + { + out.str(""); + a aa; + BOOST_TEST(out.eq(ok.str())); + } + + a_pre = true; + b_pre = false; + c_pre = true; + { + out.str(""); + a aa; + BOOST_TEST(out.eq(ok.str())); + } + + a_pre = true; + b_pre = true; + c_pre = false; + { + out.str(""); + a aa; + BOOST_TEST(out.eq(ok.str())); + } + + a_pre = false; + b_pre = false; + c_pre = false; + { + out.str(""); + a aa; + BOOST_TEST(out.eq(ok.str())); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/ifdef.cpp b/src/boost/libs/contract/test/constructor/ifdef.cpp new file mode 100644 index 00000000..8f58c5b9 --- /dev/null +++ b/src/boost/libs/contract/test/constructor/ifdef.cpp @@ -0,0 +1,133 @@ + +// 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 contract compilation on/off. + +#include "../detail/oteststream.hpp" +#include <boost/contract/core/config.hpp> +#if !defined(BOOST_CONTRACT_NO_CONSTRUCTORS) || \ + !defined(BOOST_CONTRACT_NO_PRECONDITIONS) + #include <boost/contract/constructor.hpp> +#endif +#ifndef BOOST_CONTRACT_NO_CONSTRUCTORS + #include <boost/contract/check.hpp> + #include <boost/contract/old.hpp> +#endif +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +struct b + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + : private boost::contract::constructor_precondition<b> + #endif +{ + #ifndef BOOST_CONTRACT_NO_INVARIANTS + static void static_invariant() { out << "b::static_inv" << std::endl; } + void invariant() const { out << "b::inv" << std::endl; } + #endif + + explicit b(int x) + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + : boost::contract::constructor_precondition<b>([] { + out << "b::ctor::pre" << std::endl; + }) + #endif + { + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + boost::contract::old_ptr<int> old_x = BOOST_CONTRACT_OLDOF(x); + #endif + #ifndef BOOST_CONTRACT_NO_CONSTRUCTORS + boost::contract::check c = boost::contract::constructor(this) + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + .old([] { out << "b::f::old" << std::endl; }) + .postcondition([] { out << "b::ctor::post" << std::endl; }) + #endif + ; + #endif + out << "b::ctor::body" << std::endl; + } +}; + +struct a : + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + private boost::contract::constructor_precondition<a>, + #endif + public b +{ + #ifndef BOOST_CONTRACT_NO_INVARIANTS + static void static_invariant() { out << "a::static_inv" << std::endl; } + void invariant() const { out << "a::inv" << std::endl; } + #endif + + explicit a(int x) : + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + boost::contract::constructor_precondition<a>([] { + out << "a::ctor::pre" << std::endl; + }), + #endif + b(x) + { + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + boost::contract::old_ptr<int> old_x = BOOST_CONTRACT_OLDOF(x); + #endif + #ifndef BOOST_CONTRACT_NO_CONSTRUCTORS + boost::contract::check c = boost::contract::constructor(this) + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + .old([] { out << "a::f::old" << std::endl; }) + .postcondition([] { out << "a::ctor::post" << std::endl; }) + #endif + ; + #endif + out << "a::ctor::body" << std::endl; + } +}; + +int main() { + std::ostringstream ok; + out.str(""); + a aa(123); + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::f::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "a::f::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/ifdef_macro.cpp b/src/boost/libs/contract/test/constructor/ifdef_macro.cpp new file mode 100644 index 00000000..2041cdaa --- /dev/null +++ b/src/boost/libs/contract/test/constructor/ifdef_macro.cpp @@ -0,0 +1,157 @@ + +// 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 contract compilation on/off (using macro interface). + +#include "../detail/oteststream.hpp" +#include "../detail/unprotected_commas.hpp" +#include <boost/contract/core/config.hpp> +#include <boost/contract/constructor.hpp> // Outside #if below for ctor pre. +#include <boost/contract_macro.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +struct b : + private boost::contract::constructor_precondition<b> // OK, always in code. +{ + BOOST_CONTRACT_STATIC_INVARIANT({ + boost::contract::test::detail::unprotected_commas<void, void, void>:: + call(); + out << "b::static_inv" << std::endl; + }) + + BOOST_CONTRACT_INVARIANT({ + boost::contract::test::detail::unprotected_commas<void, void, void>:: + call(); + out << "b::inv" << std::endl; + }) + + explicit b(int x) : + BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION(b)([] { + boost::contract::test::detail::unprotected_commas<void, void, void> + ::call(); + out << "b::ctor::pre" << std::endl; + }) + { + BOOST_CONTRACT_OLD_PTR( + boost::contract::test::detail::unprotected_commas<int, void, + void>::type1 + )( + old_x, + (boost::contract::test::detail::unprotected_commas<void, void, + void>::same(x)) + ); + BOOST_CONTRACT_CONSTRUCTOR(this) + BOOST_CONTRACT_OLD([] { + boost::contract::test::detail::unprotected_commas< + void, void, void>::call(); + out << "b::f::old" << std::endl; + }) + BOOST_CONTRACT_POSTCONDITION([] { + boost::contract::test::detail::unprotected_commas< + void, void, void>::call(); + out << "b::ctor::post" << std::endl; + }) + ; + out << "b::ctor::body" << std::endl; + } +}; + +struct a: + private boost::contract::constructor_precondition<a>, // OK, always in code. + public b +{ + BOOST_CONTRACT_STATIC_INVARIANT({ + boost::contract::test::detail::unprotected_commas<void, void, void>:: + call(); + out << "a::static_inv" << std::endl; + }) + + BOOST_CONTRACT_INVARIANT({ + boost::contract::test::detail::unprotected_commas<void, void, void>:: + call(); + out << "a::inv" << std::endl; + }) + + explicit a(int x) : + BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION(a)([] { + boost::contract::test::detail::unprotected_commas<void, void, void> + ::call(); + out << "a::ctor::pre" << std::endl; } + ), + b(x) + { + BOOST_CONTRACT_OLD_PTR( + boost::contract::test::detail::unprotected_commas<int, void, + void>::type1 + )( + old_x, + (boost::contract::test::detail::unprotected_commas<void, void, + void>::same(x)) + ); + BOOST_CONTRACT_CONSTRUCTOR(boost::contract::test::detail:: + unprotected_commas<void, void, void>::same(this)) + BOOST_CONTRACT_OLD([] { + boost::contract::test::detail::unprotected_commas< + void, void, void>::call(); + out << "a::f::old" << std::endl; + }) + BOOST_CONTRACT_POSTCONDITION([] { + boost::contract::test::detail::unprotected_commas< + void, void, void>::call(); + out << "a::ctor::post" << std::endl; + }) + ; + out << "a::ctor::body" << std::endl; + } +}; + +int main() { + std::ostringstream ok; + out.str(""); + a aa(123); + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::f::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::f::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/pre_error.cpp b/src/boost/libs/contract/test/constructor/pre_error.cpp new file mode 100644 index 00000000..36e06c4c --- /dev/null +++ b/src/boost/libs/contract/test/constructor/pre_error.cpp @@ -0,0 +1,24 @@ + +// 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 constructor cannot use `.precondition(...)`. + +#include <boost/contract/constructor.hpp> +#include <boost/contract/check.hpp> + +struct a { + a() { + boost::contract::check c = boost::contract::constructor(this) + .precondition([] {}) // Error (must use constructor_precondition). + ; + } +}; + +int main() { + a aa; + return 0; +} + diff --git a/src/boost/libs/contract/test/constructor/smoke.cpp b/src/boost/libs/contract/test/constructor/smoke.cpp new file mode 100644 index 00000000..133cc140 --- /dev/null +++ b/src/boost/libs/contract/test/constructor/smoke.cpp @@ -0,0 +1,410 @@ + +// 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 constructor subcontracting. + +#include "../detail/oteststream.hpp" +#include "../detail/counter.hpp" +#include <boost/contract/constructor.hpp> +#include <boost/contract/base_types.hpp> +#include <boost/contract/assert.hpp> +#include <boost/contract/old.hpp> +#include <boost/contract/check.hpp> +#include <boost/bind.hpp> +#include <boost/ref.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +template<char Id> +struct t + #define BASES private boost::contract::constructor_precondition<t<Id> > + : BASES +{ + typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; + #undef BASES + + static void static_invariant() { + out << Id << "::static_inv" << std::endl; + BOOST_CONTRACT_ASSERT(l.value >= 0); + } + + void invariant() const { + out << Id << "::inv" << std::endl; + BOOST_CONTRACT_ASSERT(k_ < 0); + } + + struct l_tag; + typedef boost::contract::test::detail::counter<l_tag, int> l_type; + static l_type l; + + struct z_tag; + typedef boost::contract::test::detail::counter<z_tag, int> z_type; + + explicit t(z_type& z) : + boost::contract::constructor_precondition<t<Id> >([&] { + out << Id << "::ctor::pre" << std::endl; + BOOST_CONTRACT_ASSERT(z.value < 0); + }) + { + boost::contract::old_ptr<z_type> old_z; + boost::contract::old_ptr<l_type> old_l = + BOOST_CONTRACT_OLDOF(l_type::eval(l)); + boost::contract::check c = boost::contract::constructor(this) + .old([&] { + out << Id << "::ctor::old" << std::endl; + old_z = BOOST_CONTRACT_OLDOF(z_type::eval(z)); + }) + .postcondition([&] { + out << Id << "::ctor::post" << std::endl; + BOOST_CONTRACT_ASSERT(k_ == old_z->value); + BOOST_CONTRACT_ASSERT(z.value == l.value); + BOOST_CONTRACT_ASSERT(l.value == old_l->value + 1); + }) + ; + out << Id << "::ctor::body" << std::endl; + k_ = z.value; + z.value = ++l.value; + } + + virtual ~t() { --l.value; } + +private: + int k_; +}; +template<char Id> typename t<Id>::l_type t<Id>::l; + +// Test deep inheritance (2 vertical levels), multiple inheritance (4 +// horizontal levels), and that all public/protected/private part of +// subcontracting for constructors (not just public, because all access levels +// are part of C++ object construction mechanism). +struct c + #define BASES private boost::contract::constructor_precondition<c>, \ + public t<'d'>, protected t<'p'>, private t<'q'>, public t<'e'> + : BASES +{ + typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; + #undef BASES + + static void static_invariant() { + out << "c::static_inv" << std::endl; + BOOST_CONTRACT_ASSERT(m.value >= 0); + } + + void invariant() const { + out << "c::inv" << std::endl; + BOOST_CONTRACT_ASSERT(j_ < 0); + } + + struct m_tag; + typedef boost::contract::test::detail::counter<m_tag, int> m_type; + static m_type m; + + struct y_tag; + typedef boost::contract::test::detail::counter<y_tag, int> y_type; + + explicit c(y_type& y, t<'d'>::z_type& dz, t<'p'>::z_type& pz, + t<'q'>::z_type& qz, t<'e'>::z_type& ez) : + boost::contract::constructor_precondition<c>([&] { + out << "c::ctor::pre" << std::endl; + BOOST_CONTRACT_ASSERT(y.value < 0); + }), + t<'d'>(dz), t<'p'>(pz), t<'q'>(qz), t<'e'>(ez) + { + boost::contract::old_ptr<y_type> old_y = + BOOST_CONTRACT_OLDOF(y_type::eval(y)); + boost::contract::old_ptr<m_type> old_m; + boost::contract::check c = boost::contract::constructor(this) + .old([&] { + out << "c::ctor::old" << std::endl; + old_m = BOOST_CONTRACT_OLDOF(m_type::eval(m)); + }) + .postcondition([&] { + out << "c::ctor::post" << std::endl; + BOOST_CONTRACT_ASSERT(j_ == old_y->value); + BOOST_CONTRACT_ASSERT(y.value == m.value); + BOOST_CONTRACT_ASSERT(m.value == old_m->value + 1); + }) + ; + out << "c::ctor::body" << std::endl; + j_ = y.value; + y.value = ++m.value; + } + + virtual ~c() { --m.value; } + +private: + int j_; +}; +c::m_type c::m; + +// Test not (fully) contracted base is not part of constructor subcontracting. +struct b + #define BASES private boost::contract::constructor_precondition<b> + : BASES +{ + typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; + #undef BASES + + static void static_invariant() { out << "b::static_inv" << std::endl; } + void invariant() const { out << "b::inv" << std::endl; } + + explicit b() {} // No contract. + virtual ~b() {} +}; + +// Test constructor with both non-contracted and contracted bases. +struct a + #define BASES private boost::contract::constructor_precondition<a>, \ + public b, public c + : BASES +{ + typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; + #undef BASES + + static void static_invariant() { + out << "a::static_inv" << std::endl; + BOOST_CONTRACT_ASSERT(n.value >= 0); + } + + void invariant() const { + out << "a::inv" << std::endl; + BOOST_CONTRACT_ASSERT(i_ < 0); + } + + struct n_tag; + typedef boost::contract::test::detail::counter<n_tag, int> n_type; + static n_type n; + + struct x_tag; + typedef boost::contract::test::detail::counter<x_tag, int> x_type; + + explicit a(x_type& x, c::y_type& y, t<'d'>::z_type& dz, + t<'p'>::z_type& pz, t<'q'>::z_type& qz, t<'e'>::z_type& ez) : + boost::contract::constructor_precondition<a>([&] { + out << "a::ctor::pre" << std::endl; + BOOST_CONTRACT_ASSERT(x.value < 0); + }), + b(), c(y, dz, pz, qz, ez) + { + boost::contract::old_ptr<x_type> old_x; + boost::contract::old_ptr<n_type> old_n = + BOOST_CONTRACT_OLDOF(n_type::eval(n)); + boost::contract::check c = boost::contract::constructor(this) + .old([&] { + out << "a::ctor::old" << std::endl; + old_x = BOOST_CONTRACT_OLDOF(x_type::eval(x)); + }) + .postcondition([&] { + out << "a::ctor::post" << std::endl; + BOOST_CONTRACT_ASSERT(i_ == old_x->value); + BOOST_CONTRACT_ASSERT(x.value == n.value); + BOOST_CONTRACT_ASSERT(n.value == old_n->value + 1); + }) + ; + out << "a::ctor::body" << std::endl; + i_ = x.value; + x.value = ++n.value; + } + + virtual ~a() { --n.value; } + +private: + int i_; +}; +a::n_type a::n; + +int main() { + std::ostringstream ok; + + { + t<'e'>::z_type ez; ez.value = -5; + t<'q'>::z_type qz; qz.value = -5; + t<'p'>::z_type pz; pz.value = -4; + t<'d'>::z_type dz; dz.value = -3; + c::y_type y; y.value = -2; + a::x_type x; x.value = -1; + + out.str(""); + a aa(x, y, dz, pz, qz, ez); + ok.str(""); ok + // Test all constructor pre checked first. + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + // Test static inv, but not const inv, checked before ctor body. + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "d::ctor::pre" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "d::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "d::ctor::old" << std::endl + #endif + << "d::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "d::static_inv" << std::endl + << "d::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "d::ctor::post" << std::endl + #endif + + // Test check also protected bases (because part of C++ constr.). + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "p::ctor::pre" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "p::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "p::ctor::old" << std::endl + #endif + << "p::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "p::static_inv" << std::endl + << "p::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "p::ctor::post" << std::endl + #endif + + // Test check also private bases (because part of C++ constr.). + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "q::ctor::pre" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "q::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "q::ctor::old" << std::endl + #endif + << "q::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "q::static_inv" << std::endl + << "q::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "q::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "e::ctor::pre" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "e::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "e::ctor::old" << std::endl + #endif + << "e::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "e::static_inv" << std::endl + << "e::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "e::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } + + #ifndef BOOST_CONTRACT_NO_OLDS + #define BOOST_CONTRACT_TEST_old 1u + #else + #define BOOST_CONTRACT_TEST_old 0u + #endif + + std::clog << a::x_type::copies() << std::endl; + std::clog << BOOST_CONTRACT_TEST_old << std::endl; + BOOST_TEST_EQ(a::x_type::copies(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(a::x_type::evals(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(a::x_type::ctors(), a::x_type::dtors()); // No leak. + + BOOST_TEST_EQ(c::y_type::copies(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(c::y_type::evals(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(c::y_type::ctors(), c::y_type::dtors()); // No leak. + + BOOST_TEST_EQ(t<'d'>::z_type::copies(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(t<'d'>::z_type::evals(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(t<'d'>::z_type::ctors(), t<'d'>::z_type::dtors()); // No leak. + + BOOST_TEST_EQ(t<'p'>::z_type::copies(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(t<'p'>::z_type::evals(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(t<'p'>::z_type::ctors(), t<'p'>::z_type::dtors()); // No leak. + + BOOST_TEST_EQ(t<'q'>::z_type::copies(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(t<'q'>::z_type::evals(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(t<'q'>::z_type::ctors(), t<'q'>::z_type::dtors()); // No leak. + + BOOST_TEST_EQ(t<'e'>::z_type::copies(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(t<'e'>::z_type::evals(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(t<'e'>::z_type::ctors(), t<'e'>::z_type::dtors()); // No leak. + + // Following destroy only copies (actual objects are static data members). + + BOOST_TEST_EQ(a::n_type::copies(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(a::n_type::evals(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(a::n_type::copies(), a::n_type::dtors()); // No leak. + + BOOST_TEST_EQ(c::m_type::copies(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(c::m_type::evals(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(c::m_type::copies(), c::m_type::dtors()); // No leak. + + BOOST_TEST_EQ(t<'d'>::l_type::copies(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(t<'d'>::l_type::evals(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(t<'e'>::l_type::copies(), t<'e'>::l_type::dtors()); // No leak + + BOOST_TEST_EQ(t<'p'>::l_type::copies(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(t<'p'>::l_type::evals(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(t<'e'>::l_type::copies(), t<'e'>::l_type::dtors()); // No leak + + BOOST_TEST_EQ(t<'q'>::l_type::copies(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(t<'q'>::l_type::evals(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(t<'e'>::l_type::copies(), t<'e'>::l_type::dtors()); // No leak + + BOOST_TEST_EQ(t<'e'>::l_type::copies(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(t<'e'>::l_type::evals(), BOOST_CONTRACT_TEST_old); + BOOST_TEST_EQ(t<'e'>::l_type::copies(), t<'e'>::l_type::dtors()); // No leak + + #undef BOOST_CONTRACT_TEST_old + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/throwing_body.cpp b/src/boost/libs/contract/test/constructor/throwing_body.cpp new file mode 100644 index 00000000..cb385eb7 --- /dev/null +++ b/src/boost/libs/contract/test/constructor/throwing_body.cpp @@ -0,0 +1,145 @@ + +// 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 throw form constructor body (in middle branch of inheritance tree). + +#include "../detail/oteststream.hpp" +#include <boost/contract/constructor.hpp> +#include <boost/contract/base_types.hpp> +#include <boost/contract/check.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +struct c + #define BASES private boost::contract::constructor_precondition<c> + : BASES +{ + typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; + #undef BASES + + static void static_invariant() { out << "c::static_inv" << std::endl; } + void invariant() const { out << "c::inv" << std::endl; } + + c() : + boost::contract::constructor_precondition<c>([] { + out << "c::ctor::pre" << std::endl; + }) + { + boost::contract::check c = boost::contract::constructor(this) + .old([] { out << "c::ctor::old" << std::endl; }) + .postcondition([] { out << "c::ctor::post" << std::endl; }) + .except([] { out << "c::ctor::except" << std::endl; }) + ; + out << "c::ctor::body" << std::endl; + // Do not throw (from inheritance root). + } +}; + +struct b_err {}; // Global decl so visible in MSVC10 lambdas. + +struct b + #define BASES private boost::contract::constructor_precondition<b>, public c + : BASES +{ + typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; + #undef BASES + + static void static_invariant() { out << "b::static_inv" << std::endl; } + void invariant() const { out << "b::inv" << std::endl; } + + 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; }) + .except([] { out << "b::ctor::except" << std::endl; }) + ; + out << "b::ctor::body" << std::endl; + throw b_err(); // Test body throws (from inheritance mid branch). + } +}; + +struct a + #define BASES private boost::contract::constructor_precondition<a>, public b + : BASES +{ + typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; + #undef BASES + + static void static_invariant() { out << "a::static_inv" << std::endl; } + void invariant() const { out << "a::inv" << std::endl; } + + 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; }) + .except([] { out << "a::ctor::except" << std::endl; }) + ; + out << "a::ctor::body" << std::endl; + // Do not throw (from inheritance leaf). + } +}; + +int main() { + std::ostringstream ok; + + try { + out.str(""); + a aa; + BOOST_TEST(false); + } catch(b_err const&) { + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl // Test this threw... + // ... so check only following after (no post, no a ctor, etc.). + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_EXCEPTS + << "b::ctor::except" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/throwing_old.cpp b/src/boost/libs/contract/test/constructor/throwing_old.cpp new file mode 100644 index 00000000..432641e1 --- /dev/null +++ b/src/boost/libs/contract/test/constructor/throwing_old.cpp @@ -0,0 +1,158 @@ + +// 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 throw form constructor .old() (in middle branch of inheritance tree). + +#include "../detail/oteststream.hpp" +#include <boost/contract/constructor.hpp> +#include <boost/contract/base_types.hpp> +#include <boost/contract/check.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +struct c + #define BASES private boost::contract::constructor_precondition<c> + : BASES +{ + typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; + #undef BASES + + static void static_invariant() { out << "c::static_inv" << std::endl; } + void invariant() const { out << "c::inv" << std::endl; } + + c() : + boost::contract::constructor_precondition<c>([] { + out << "c::ctor::pre" << std::endl; + }) + { + boost::contract::check c = boost::contract::constructor(this) + .old([] { out << "c::ctor::old" << std::endl; }) + .postcondition([] { out << "c::ctor::post" << std::endl; }) + .except([] { out << "c::ctor::except" << std::endl; }) + ; + out << "c::ctor::body" << std::endl; + // Do not throw (from inheritance root). + } +}; + +struct b_err {}; // Global decl so visible in MSVC10 lambdas. + +struct b + #define BASES private boost::contract::constructor_precondition<b>, public c + : BASES +{ + typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; + #undef BASES + + static void static_invariant() { out << "b::static_inv" << std::endl; } + void invariant() const { out << "b::inv" << std::endl; } + + 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; + throw b_err(); // Test this throws (from mid branch). + }) + .postcondition([] { out << "b::ctor::post" << std::endl; }) + .except([] { out << "b::ctor::except" << std::endl; }) + ; + out << "b::ctor::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 + + static void static_invariant() { out << "a::static_inv" << std::endl; } + void invariant() const { out << "a::inv" << std::endl; } + + 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; }) + .except([] { out << "a::ctor::except" << std::endl; }) + ; + out << "a::ctor::body" << std::endl; + // Do not throw (from inheritance leaf). + } +}; + +int main() { + std::ostringstream ok; + + boost::contract::set_old_failure([] (boost::contract::from) { throw; }); + + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_OLDS + BOOST_TEST(false); + } catch(b_err const&) { + #endif + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl // Test this threw. + #else + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + + #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::inv" << std::endl + #endif + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/throwing_post.cpp b/src/boost/libs/contract/test/constructor/throwing_post.cpp new file mode 100644 index 00000000..beaa31ac --- /dev/null +++ b/src/boost/libs/contract/test/constructor/throwing_post.cpp @@ -0,0 +1,164 @@ + +// 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 throw form constructor .post() (in middle branch of inheritance tree). + +#include "../detail/oteststream.hpp" +#include <boost/contract/constructor.hpp> +#include <boost/contract/base_types.hpp> +#include <boost/contract/check.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +struct c + #define BASES private boost::contract::constructor_precondition<c> + : BASES +{ + typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; + #undef BASES + + static void static_invariant() { out << "c::static_inv" << std::endl; } + void invariant() const { out << "c::inv" << std::endl; } + + c() : + boost::contract::constructor_precondition<c>([] { + out << "c::ctor::pre" << std::endl; + }) + { + boost::contract::check c = boost::contract::constructor(this) + .old([] { out << "c::ctor::old" << std::endl; }) + .postcondition([] { out << "c::ctor::post" << std::endl; }) + .except([] { out << "c::ctor::except" << std::endl; }) + ; + out << "c::ctor::body" << std::endl; + // Do not throw (from inheritance root). + } +}; + +struct b_err {}; // Global decl so visible in MSVC10 lambdas. + +struct b + #define BASES private boost::contract::constructor_precondition<b>, public c + : BASES +{ + typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; + #undef BASES + + static void static_invariant() { out << "b::static_inv" << std::endl; } + void invariant() const { out << "b::inv" << std::endl; } + + 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; + throw b_err(); // Test this throws (from mid branch). + }) + .except([] { out << "b::ctor::except" << std::endl; }) + ; + out << "b::ctor::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 + + static void static_invariant() { out << "a::static_inv" << std::endl; } + void invariant() const { out << "a::inv" << std::endl; } + + 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; }) + .except([] { out << "a::ctor::except" << std::endl; }) + ; + out << "a::ctor::body" << std::endl; + // Do not throw (from inheritance leaf). + } +}; + +int main() { + std::ostringstream ok; + + boost::contract::set_postcondition_failure( + [] (boost::contract::from) { throw; }); + + try { + out.str(""); + a aa; + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + BOOST_TEST(false); + } catch(b_err const&) { + #endif + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::ctor::post" << std::endl // Test this threw. + #else + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/constructor/throwing_pre.cpp b/src/boost/libs/contract/test/constructor/throwing_pre.cpp new file mode 100644 index 00000000..e06a8542 --- /dev/null +++ b/src/boost/libs/contract/test/constructor/throwing_pre.cpp @@ -0,0 +1,164 @@ + +// 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 throw form constructor .pre() (in middle branch of inheritance tree). + +#include "../detail/oteststream.hpp" +#include <boost/contract/constructor.hpp> +#include <boost/contract/base_types.hpp> +#include <boost/contract/check.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +struct c + #define BASES private boost::contract::constructor_precondition<c> + : BASES +{ + typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; + #undef BASES + + static void static_invariant() { out << "c::static_inv" << std::endl; } + void invariant() const { out << "c::inv" << std::endl; } + + c() : + boost::contract::constructor_precondition<c>([] { + out << "c::ctor::pre" << std::endl; + }) + { + boost::contract::check c = boost::contract::constructor(this) + .old([] { out << "c::ctor::old" << std::endl; }) + .postcondition([] { out << "c::ctor::post" << std::endl; }) + .except([] { out << "c::ctor::except" << std::endl; }) + ; + out << "c::ctor::body" << std::endl; + // Do not throw (from inheritance root). + } +}; + +struct b_err {}; // Global decl so visible in MSVC10 lambdas. + +struct b + #define BASES private boost::contract::constructor_precondition<b>, public c + : BASES +{ + typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; + #undef BASES + + static void static_invariant() { out << "b::static_inv" << std::endl; } + void invariant() const { out << "b::inv" << std::endl; } + + b() : + boost::contract::constructor_precondition<b>([] { + out << "b::ctor::pre" << std::endl; + throw b_err(); // Test this throws (from mid branch). + }) + { + boost::contract::check c = boost::contract::constructor(this) + .old([] { out << "b::ctor::old" << std::endl; }) + .postcondition([] { out << "b::ctor::post" << std::endl; }) + .except([] { out << "b::ctor::except" << std::endl; }) + ; + out << "b::ctor::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 + + static void static_invariant() { out << "a::static_inv" << std::endl; } + void invariant() const { out << "a::inv" << std::endl; } + + 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; }) + .except([] { out << "a::ctor::except" << std::endl; }) + ; + out << "a::ctor::body" << std::endl; + // Do not throw (from inheritance leaf). + } +}; + +int main() { + std::ostringstream ok; + + boost::contract::set_precondition_failure( + [] (boost::contract::from) { throw; }); + + try { + out.str(""); + a aa; +#ifndef BOOST_CONTRACT_NO_PRECONDITIONS + BOOST_TEST(false); + } catch(b_err const&) { +#endif + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl // Test this threw. + #else + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + return boost::report_errors(); +} + |