From c927e7293ce3ad309a1b984f6ed856b989e72cd5 Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Mon, 4 Jan 2016 07:21:27 -0800 Subject: [PATCH] added contract on/off to all constructor tests --- test/constructor/access.cpp | 64 +++-- test/constructor/bases.cpp | 205 ++++++++++----- test/constructor/body_throw.cpp | 42 ++- .../constructor/decl_entry_static_inv_all.cpp | 244 +++++++++++------- .../decl_entry_static_inv_ends.cpp | 213 ++++++++------- .../constructor/decl_entry_static_inv_mid.cpp | 212 ++++++++------- .../decl_entry_static_inv_none.cpp | 72 ++++-- test/constructor/decl_exit_inv_all.cpp | 220 +++++++++------- test/constructor/decl_exit_inv_ends.cpp | 218 +++++++++------- test/constructor/decl_exit_inv_mid.cpp | 219 ++++++++-------- test/constructor/decl_exit_inv_none.cpp | 66 +++-- test/constructor/decl_exit_static_inv_all.cpp | 236 ++++++++++------- .../constructor/decl_exit_static_inv_ends.cpp | 225 +++++++++------- test/constructor/decl_exit_static_inv_mid.cpp | 223 ++++++++-------- .../constructor/decl_exit_static_inv_none.cpp | 70 +++-- test/constructor/decl_post_all.cpp | 197 +++++++------- test/constructor/decl_post_ends.cpp | 192 +++++++------- test/constructor/decl_post_mid.cpp | 192 ++++++-------- test/constructor/decl_post_none.cpp | 62 +++-- test/constructor/decl_pre_all.cpp | 145 +++++++---- test/constructor/decl_pre_ends.cpp | 157 ++++++----- test/constructor/decl_pre_mid.cpp | 163 ++++++------ test/constructor/decl_pre_none.cpp | 64 +++-- test/constructor/old_throw.cpp | 57 +++- 24 files changed, 2188 insertions(+), 1570 deletions(-) diff --git a/test/constructor/access.cpp b/test/constructor/access.cpp index 9200b9e..85a3c14 100644 --- a/test/constructor/access.cpp +++ b/test/constructor/access.cpp @@ -66,35 +66,63 @@ int main() { out.str(""); a aa; ok.str(""); ok - << "a::ctor::pre" << std::endl + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + #endif - << "b::ctor::pre" << std::endl - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::old" << std::endl + #endif << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); out.str(""); b bb; ok.str(""); ok - << "b::ctor::pre" << std::endl - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl + #if BOOST_CONTRACT_PRECONDITIONS + << "b::ctor::pre" << std::endl + #endif + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/constructor/bases.cpp b/test/constructor/bases.cpp index 02275da..1a0565d 100644 --- a/test/constructor/bases.cpp +++ b/test/constructor/bases.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -228,110 +229,192 @@ int main() { a aa(x, y, dz, pz, qz, ez); ok.str(""); ok // Test all constructor pre checked first. - << "a::ctor::pre" << std::endl - - << "c::ctor::pre" << std::endl + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif // Test static inv, but not const inv, checked before ctor body. - << "d::ctor::pre" << std::endl - << "d::static_inv" << std::endl - << "d::ctor::old" << std::endl + #if BOOST_CONTRACT_PRECONDITIONS + << "d::ctor::pre" << std::endl + #endif + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "d::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "d::ctor::old" << std::endl + #endif << "d::ctor::body" << std::endl - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "d::ctor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "d::static_inv" << std::endl + << "d::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "d::ctor::post" << std::endl + #endif // Test check also protected bases (because part of C++ constr.). - << "p::ctor::pre" << std::endl - << "p::static_inv" << std::endl - << "p::ctor::old" << std::endl + #if BOOST_CONTRACT_PRECONDITIONS + << "p::ctor::pre" << std::endl + #endif + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "p::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "p::ctor::old" << std::endl + #endif << "p::ctor::body" << std::endl - << "p::static_inv" << std::endl - << "p::inv" << std::endl - << "p::ctor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "p::static_inv" << std::endl + << "p::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "p::ctor::post" << std::endl + #endif // Test check also private bases (because part of C++ constr.). - << "q::ctor::pre" << std::endl - << "q::static_inv" << std::endl - << "q::ctor::old" << std::endl + #if BOOST_CONTRACT_PRECONDITIONS + << "q::ctor::pre" << std::endl + #endif + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "q::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "q::ctor::old" << std::endl + #endif << "q::ctor::body" << std::endl - << "q::static_inv" << std::endl - << "q::inv" << std::endl - << "q::ctor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "q::static_inv" << std::endl + << "q::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "q::ctor::post" << std::endl + #endif - << "e::ctor::pre" << std::endl - << "e::static_inv" << std::endl - << "e::ctor::old" << std::endl + #if BOOST_CONTRACT_PRECONDITIONS + << "e::ctor::pre" << std::endl + #endif + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "e::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "e::ctor::old" << std::endl + #endif << "e::ctor::body" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - << "e::ctor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "e::static_inv" << std::endl + << "e::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "e::ctor::post" << std::endl + #endif - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::old" << std::endl + #endif << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::old" << std::endl + #endif << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); } - BOOST_TEST_EQ(a::x_type::copies(), 1); - BOOST_TEST_EQ(a::x_type::evals(), 1); + BOOST_TEST_EQ(a::x_type::copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); + BOOST_TEST_EQ(a::x_type::evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); BOOST_TEST_EQ(a::x_type::ctors(), a::x_type::dtors()); // No leak. + // TODO: I should check these ctors() == dtors() every where cnt_type is used, in all tests. - BOOST_TEST_EQ(c::y_type::copies(), 1); - BOOST_TEST_EQ(c::y_type::evals(), 1); + BOOST_TEST_EQ(c::y_type::copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); + BOOST_TEST_EQ(c::y_type::evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); BOOST_TEST_EQ(c::y_type::ctors(), c::y_type::dtors()); // No leak. - BOOST_TEST_EQ(t<'d'>::z_type::copies(), 1); - BOOST_TEST_EQ(t<'d'>::z_type::evals(), 1); + BOOST_TEST_EQ(t<'d'>::z_type::copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); + BOOST_TEST_EQ(t<'d'>::z_type::evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); BOOST_TEST_EQ(t<'d'>::z_type::ctors(), t<'d'>::z_type::dtors()); // No leak. - BOOST_TEST_EQ(t<'p'>::z_type::copies(), 1); - BOOST_TEST_EQ(t<'p'>::z_type::evals(), 1); + BOOST_TEST_EQ(t<'p'>::z_type::copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); + BOOST_TEST_EQ(t<'p'>::z_type::evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); BOOST_TEST_EQ(t<'p'>::z_type::ctors(), t<'p'>::z_type::dtors()); // No leak. - BOOST_TEST_EQ(t<'q'>::z_type::copies(), 1); - BOOST_TEST_EQ(t<'q'>::z_type::evals(), 1); + BOOST_TEST_EQ(t<'q'>::z_type::copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); + BOOST_TEST_EQ(t<'q'>::z_type::evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); BOOST_TEST_EQ(t<'q'>::z_type::ctors(), t<'q'>::z_type::dtors()); // No leak. - BOOST_TEST_EQ(t<'e'>::z_type::copies(), 1); - BOOST_TEST_EQ(t<'e'>::z_type::evals(), 1); + BOOST_TEST_EQ(t<'e'>::z_type::copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); + BOOST_TEST_EQ(t<'e'>::z_type::evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); 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(), 1); - BOOST_TEST_EQ(a::n_type::evals(), 1); + BOOST_TEST_EQ(a::n_type::copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); + BOOST_TEST_EQ(a::n_type::evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); BOOST_TEST_EQ(a::n_type::copies(), a::n_type::dtors()); // No leak. - BOOST_TEST_EQ(c::m_type::copies(), 1); - BOOST_TEST_EQ(c::m_type::evals(), 1); + BOOST_TEST_EQ(c::m_type::copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); + BOOST_TEST_EQ(c::m_type::evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); BOOST_TEST_EQ(c::m_type::copies(), c::m_type::dtors()); // No leak. - BOOST_TEST_EQ(t<'d'>::l_type::copies(), 1); - BOOST_TEST_EQ(t<'d'>::l_type::evals(), 1); + BOOST_TEST_EQ(t<'d'>::l_type::copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); + BOOST_TEST_EQ(t<'d'>::l_type::evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); BOOST_TEST_EQ(t<'e'>::l_type::copies(), t<'e'>::l_type::dtors()); // No leak - BOOST_TEST_EQ(t<'p'>::l_type::copies(), 1); - BOOST_TEST_EQ(t<'p'>::l_type::evals(), 1); + BOOST_TEST_EQ(t<'p'>::l_type::copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); + BOOST_TEST_EQ(t<'p'>::l_type::evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); BOOST_TEST_EQ(t<'e'>::l_type::copies(), t<'e'>::l_type::dtors()); // No leak - BOOST_TEST_EQ(t<'q'>::l_type::copies(), 1); - BOOST_TEST_EQ(t<'q'>::l_type::evals(), 1); + BOOST_TEST_EQ(t<'q'>::l_type::copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); + BOOST_TEST_EQ(t<'q'>::l_type::evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); BOOST_TEST_EQ(t<'e'>::l_type::copies(), t<'e'>::l_type::dtors()); // No leak - BOOST_TEST_EQ(t<'e'>::l_type::copies(), 1); - BOOST_TEST_EQ(t<'e'>::l_type::evals(), 1); + BOOST_TEST_EQ(t<'e'>::l_type::copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); + BOOST_TEST_EQ(t<'e'>::l_type::evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); BOOST_TEST_EQ(t<'e'>::l_type::copies(), t<'e'>::l_type::dtors()); // No leak return boost::report_errors(); diff --git a/test/constructor/body_throw.cpp b/test/constructor/body_throw.cpp index 47282cc..e012746 100644 --- a/test/constructor/body_throw.cpp +++ b/test/constructor/body_throw.cpp @@ -93,21 +93,37 @@ int main() { BOOST_TEST(false); } catch(b::err const&) { ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - - << "c::ctor::pre" << std::endl - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::old" << std::endl + #endif << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif << "b::ctor::body" << std::endl // Test this threw... - << "b::static_inv" << std::endl // ... so check only this after. + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl // ... so check only this after. + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/constructor/decl_entry_static_inv_all.cpp b/test/constructor/decl_entry_static_inv_all.cpp index feae0fc..95d7842 100644 --- a/test/constructor/decl_entry_static_inv_all.cpp +++ b/test/constructor/decl_entry_static_inv_all.cpp @@ -6,8 +6,84 @@ #undef BOOST_CONTRACT_AUX_TEST_NO_C_STATIC_INV #include "decl.hpp" +#include #include #include +#include + +std::string ok_c() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl // Might fail. + #endif + ; + return ok.str(); +} + +std::string ok_b() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl // Might fail. + #endif + ; + return ok.str(); +} + +std::string ok_a() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl // Might fail. + #endif + ; + return ok.str(); +} + +std::string ok_end() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -15,35 +91,16 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { + out.str(""); a aa; ok.str(""); ok // Test nothing failed. - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + << ok_c() + << ok_b() + << ok_a() + << ok_end() ; BOOST_TEST(out.eq(ok.str())); } @@ -51,81 +108,76 @@ int main() { struct err {}; boost::contract::set_entry_invariant_failure( [] (boost::contract::from) { throw err(); }); - + + std::cout << "---" << std::endl; + 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl // Test this failed. - ; - 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 =true; - out.str(""); - try { - a aa; - BOOST_TEST(false); - } catch(err const&) { - ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl // Test this failed. + << ok_c() + << ok_b() + << ok_a() // Test a::static_inv failed. + #if !BOOST_CONTRACT_ENTRY_INVARIANTS + << 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 = false; + c_entry_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); + try { + out.str(""); + a aa; + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok.str(""); ok + << ok_c() + << ok_b() // Test b::static_inv failed. + #if !BOOST_CONTRACT_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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl // Test this failed. + << ok_c() // Test c::static_inv failed. + #if !BOOST_CONTRACT_ENTRY_INVARIANTS + << ok_b() + << ok_a() + << ok_end() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -133,18 +185,22 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl // Test this failed (as all did). + << ok_c() // Test c::static_inv failed (as all did). + #if !BOOST_CONTRACT_ENTRY_INVARIANTS + << ok_b() + << ok_a() + << ok_end() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/constructor/decl_entry_static_inv_ends.cpp b/test/constructor/decl_entry_static_inv_ends.cpp index 932c120..aaaacc5 100644 --- a/test/constructor/decl_entry_static_inv_ends.cpp +++ b/test/constructor/decl_entry_static_inv_ends.cpp @@ -6,8 +6,80 @@ #undef BOOST_CONTRACT_AUX_TEST_NO_C_STATIC_INV #include "decl.hpp" +#include #include #include +#include + +std::string ok_c() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl // This might fail. + #endif + ; + return ok.str(); +} + +std::string ok_b() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::post" << std::endl + // No b::static_inv to fail. + #endif + ; + return ok.str(); +} + +std::string ok_a() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl // This might fail. + #endif + ; + return ok.str(); +} + +std::string ok_end() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -15,33 +87,16 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { + out.str(""); a aa; ok.str(""); ok // Test nothing failed. - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + << ok_c() + << ok_b() + << ok_a() + << ok_end() ; BOOST_TEST(out.eq(ok.str())); } @@ -53,30 +108,22 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl // Test this failed. + << ok_c() + << ok_b() + << ok_a() // Test a::static_inv failed. + #if !BOOST_CONTRACT_ENTRY_INVARIANTS + << ok_end() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -84,34 +131,16 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { + out.str(""); a aa; ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - // Test no failure here. - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + << ok_c() + << ok_b() + << ok_a() + << ok_end() ; BOOST_TEST(out.eq(ok.str())); } @@ -119,18 +148,22 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl // Test this failed. + << ok_c() // Test c::static_inv failed. + #if !BOOST_CONTRACT_ENTRY_INVARIANTS + << ok_b() + << ok_a() + << ok_end() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -138,18 +171,22 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl // Test this failed (as all did). + << ok_c() // Test c::static_inv failed (as all did). + #if !BOOST_CONTRACT_ENTRY_INVARIANTS + << ok_b() + << ok_a() + << ok_end() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/constructor/decl_entry_static_inv_mid.cpp b/test/constructor/decl_entry_static_inv_mid.cpp index 6d1dfc8..83bdd7b 100644 --- a/test/constructor/decl_entry_static_inv_mid.cpp +++ b/test/constructor/decl_entry_static_inv_mid.cpp @@ -6,8 +6,77 @@ #define BOOST_CONTRACT_AUX_TEST_NO_C_STATIC_INV #include "decl.hpp" +#include #include #include +#include + +std::string ok_c() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_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 + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl // This might fail. + #endif + ; + return ok.str(); +} + +std::string ok_a() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + // No a::static_inv here. + ; + return ok.str(); +} + +std::string ok_end() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -15,31 +84,16 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { + out.str(""); a aa; ok.str(""); ok // Test nothing failed. - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + << ok_c() + << ok_b() + << ok_a() + << ok_end() ; BOOST_TEST(out.eq(ok.str())); } @@ -51,32 +105,16 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { + out.str(""); a aa; ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - // Test no failure here. - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + << ok_c() + << ok_b() + << ok_a() // Test no a::static_inv so no failure. + << ok_end() ; BOOST_TEST(out.eq(ok.str())); } @@ -84,23 +122,22 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl // Test this failed. + << ok_c() + << ok_b() // Test b::static_inv failed. + #if !BOOST_CONTRACT_ENTRY_INVARIANTS + << ok_a() + << ok_end() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -108,32 +145,16 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { + out.str(""); a aa; ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - // Test no failure here. - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + << ok_c() // Test no c::static_inv so no failure. + << ok_b() + << ok_a() + << ok_end() ; BOOST_TEST(out.eq(ok.str())); } @@ -141,23 +162,22 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl // Test this failed (as all did). + << ok_c() + << ok_b() // Test b::static_inv failed (as all did). + #if !BOOST_CONTRACT_ENTRY_INVARIANTS + << ok_a() + << ok_end() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/constructor/decl_entry_static_inv_none.cpp b/test/constructor/decl_entry_static_inv_none.cpp index 9fbd42c..3f9686c 100644 --- a/test/constructor/decl_entry_static_inv_none.cpp +++ b/test/constructor/decl_entry_static_inv_none.cpp @@ -6,37 +6,59 @@ #define BOOST_CONTRACT_AUX_TEST_NO_C_STATIC_INV #include "decl.hpp" +#include #include #include int main() { std::ostringstream ok; ok // Test nothing fails. - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif - << "c::ctor::old" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::old" << std::endl + #endif << "c::ctor::body" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::ctor::old" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif << "b::ctor::body" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif - << "a::ctor::old" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::old" << std::endl + #endif << "a::ctor::body" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::post" << std::endl + #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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { + out.str(""); a aa; BOOST_TEST(out.eq(ok.str())); } @@ -44,9 +66,10 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { + out.str(""); a aa; BOOST_TEST(out.eq(ok.str())); } @@ -54,9 +77,10 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { + out.str(""); a aa; BOOST_TEST(out.eq(ok.str())); } @@ -64,9 +88,10 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { + out.str(""); a aa; BOOST_TEST(out.eq(ok.str())); } @@ -74,9 +99,10 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { + out.str(""); a aa; BOOST_TEST(out.eq(ok.str())); } diff --git a/test/constructor/decl_exit_inv_all.cpp b/test/constructor/decl_exit_inv_all.cpp index 06c8a08..1eeb38a 100644 --- a/test/constructor/decl_exit_inv_all.cpp +++ b/test/constructor/decl_exit_inv_all.cpp @@ -8,6 +8,81 @@ #include #include +#include + +std::string ok_c() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #if BOOST_CONTRACT_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 + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #if BOOST_CONTRACT_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 + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #if BOOST_CONTRACT_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 + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -15,34 +90,14 @@ int main() { a_exit_inv = true; b_exit_inv = true; c_exit_inv = true; - out.str(""); { + out.str(""); a aa; - ok.str(""); ok // Test nothing failed. - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + ok.str(""); ok // Test nothing fails. + << ok_c() + << ok_b() + << ok_a() + << ok_end() ; BOOST_TEST(out.eq(ok.str())); } @@ -54,35 +109,20 @@ int main() { a_exit_inv = false; b_exit_inv = true; c_exit_inv = true; - out.str(""); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl // Test this failed. + << ok_c() + << ok_b() + << ok_a() // Test a::inv failed. + #if !BOOST_CONTRACT_EXIT_INVARIANTS + << ok_end() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -90,28 +130,20 @@ int main() { a_exit_inv = true; b_exit_inv = false; c_exit_inv = true; - out.str(""); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl // Test this failed. + << ok_c() + << ok_b() // Test bb::inv failed. + #if !BOOST_CONTRACT_EXIT_INVARIANTS + << ok_a() + << ok_end() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -119,21 +151,20 @@ int main() { a_exit_inv = true; b_exit_inv = true; c_exit_inv = false; - out.str(""); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl // Test this failed. + << ok_c() // Test c::inv failed. + #if !BOOST_CONTRACT_EXIT_INVARIANTS + << ok_b() + << ok_a() + << ok_end() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -141,21 +172,20 @@ int main() { a_exit_inv = false; b_exit_inv = false; c_exit_inv = false; - out.str(""); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl // Test this failed (as all did). + << ok_c() // Test c::inv failed. + #if !BOOST_CONTRACT_EXIT_INVARIANTS + << ok_b() + << ok_a() + << ok_end() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/constructor/decl_exit_inv_ends.cpp b/test/constructor/decl_exit_inv_ends.cpp index 7bad3cf..e526fe1 100644 --- a/test/constructor/decl_exit_inv_ends.cpp +++ b/test/constructor/decl_exit_inv_ends.cpp @@ -8,6 +8,81 @@ #include #include +#include + +std::string ok_c() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #if BOOST_CONTRACT_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 + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + // No failure here. + #endif + ; + return ok.str(); +} + +std::string ok_a() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #if BOOST_CONTRACT_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 + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -15,33 +90,14 @@ int main() { a_exit_inv = true; b_exit_inv = true; c_exit_inv = true; - out.str(""); { + out.str(""); a aa; - ok.str(""); ok // Test nothing failed. - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + ok.str(""); ok // Test no failure. + << ok_c() + << ok_b() + << ok_a() + << ok_end() ; BOOST_TEST(out.eq(ok.str())); } @@ -53,34 +109,20 @@ int main() { a_exit_inv = false; b_exit_inv = true; c_exit_inv = true; - out.str(""); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl // Test this failed. + << ok_c() + << ok_b() + << ok_a() // Test a::inv failed. + #if !BOOST_CONTRACT_EXIT_INVARIANTS + << ok_end() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -88,34 +130,14 @@ int main() { a_exit_inv = true; b_exit_inv = false; c_exit_inv = true; - out.str(""); try { + out.str(""); a aa; ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - // Test no failure here. - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + << 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); } @@ -123,21 +145,20 @@ int main() { a_exit_inv = true; b_exit_inv = true; c_exit_inv = false; - out.str(""); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl // Test this failed. + << ok_c() // Test c::inv failed. + #if !BOOST_CONTRACT_EXIT_INVARIANTS + << ok_b() + << ok_a() + << ok_end() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -145,21 +166,20 @@ int main() { a_exit_inv = false; b_exit_inv = false; c_exit_inv = false; - out.str(""); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl // Test this failed (as all did). + << ok_c() // Test c::inv failed. + #if !BOOST_CONTRACT_EXIT_INVARIANTS + << ok_b() + << ok_a() + << ok_end() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/constructor/decl_exit_inv_mid.cpp b/test/constructor/decl_exit_inv_mid.cpp index 904d67a..81c365b 100644 --- a/test/constructor/decl_exit_inv_mid.cpp +++ b/test/constructor/decl_exit_inv_mid.cpp @@ -8,6 +8,81 @@ #include #include +#include + +std::string ok_c() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + // No failure here. + #endif + ; + return ok.str(); +} + +std::string ok_b() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #if BOOST_CONTRACT_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 + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + // No failure here. + #endif + ; + return ok.str(); +} + +std::string ok_end() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -15,32 +90,14 @@ int main() { a_exit_inv = true; b_exit_inv = true; c_exit_inv = true; - out.str(""); { + out.str(""); a aa; ok.str(""); ok // Test nothing failed. - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::ctor::post" << std::endl + << ok_c() + << ok_b() + << ok_a() + << ok_end() ; BOOST_TEST(out.eq(ok.str())); } @@ -52,33 +109,14 @@ int main() { a_exit_inv = false; b_exit_inv = true; c_exit_inv = true; - out.str(""); try { + out.str(""); a aa; ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - // Test no failure here. - << "a::ctor::post" << std::endl + << ok_c() + << ok_b() + << ok_a() // Test no failure here. + << ok_end() ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -86,27 +124,20 @@ int main() { a_exit_inv = true; b_exit_inv = false; c_exit_inv = true; - out.str(""); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl // Test this failed. + << ok_c() + << ok_b() // Test b::inv failed. + #if !BOOST_CONTRACT_EXIT_INVARIANTS + << ok_a() + << ok_end() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -114,33 +145,14 @@ int main() { a_exit_inv = true; b_exit_inv = true; c_exit_inv = false; - out.str(""); try { + out.str(""); a aa; ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - // Test no failure here. - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::ctor::post" << std::endl + << ok_c() // Test no failure here. + << ok_b() + << ok_a() + << ok_end() ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -148,27 +160,20 @@ int main() { a_exit_inv = false; b_exit_inv = false; c_exit_inv = false; - out.str(""); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl // Test this failed (as all did). + << ok_c() + << ok_b() // Test b::inv failed. + #if !BOOST_CONTRACT_EXIT_INVARIANTS + << ok_a() + << ok_end() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/constructor/decl_exit_inv_none.cpp b/test/constructor/decl_exit_inv_none.cpp index 51a5fb5..74c7efd 100644 --- a/test/constructor/decl_exit_inv_none.cpp +++ b/test/constructor/decl_exit_inv_none.cpp @@ -11,34 +11,60 @@ int main() { std::ostringstream ok; ok // Test nothing fails. - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::old" << std::endl + #endif << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::ctor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::ctor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::old" << std::endl + #endif << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::ctor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif ; a_exit_inv = true; b_exit_inv = true; c_exit_inv = true; - out.str(""); { + out.str(""); a aa; BOOST_TEST(out.eq(ok.str())); } @@ -46,8 +72,8 @@ int main() { a_exit_inv = false; b_exit_inv = true; c_exit_inv = true; - out.str(""); { + out.str(""); a aa; BOOST_TEST(out.eq(ok.str())); } @@ -55,8 +81,8 @@ int main() { a_exit_inv = true; b_exit_inv = false; c_exit_inv = true; - out.str(""); { + out.str(""); a aa; BOOST_TEST(out.eq(ok.str())); } @@ -64,8 +90,8 @@ int main() { a_exit_inv = true; b_exit_inv = true; c_exit_inv = false; - out.str(""); { + out.str(""); a aa; BOOST_TEST(out.eq(ok.str())); } @@ -73,8 +99,8 @@ int main() { a_exit_inv = false; b_exit_inv = false; c_exit_inv = false; - out.str(""); { + out.str(""); a aa; BOOST_TEST(out.eq(ok.str())); } diff --git a/test/constructor/decl_exit_static_inv_all.cpp b/test/constructor/decl_exit_static_inv_all.cpp index 71235a7..d8d5bf8 100644 --- a/test/constructor/decl_exit_static_inv_all.cpp +++ b/test/constructor/decl_exit_static_inv_all.cpp @@ -6,8 +6,90 @@ #undef BOOST_CONTRACT_AUX_TEST_NO_C_STATIC_INV #include "decl.hpp" +#include #include #include +#include + +std::string ok_c() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl // This can fail. + #endif + ; + return ok.str(); +} + +std::string ok_b() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl // This can fail. + #endif + ; + return ok.str(); +} + +std::string ok_a() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl // This can fail. + #endif + ; + return ok.str(); +} + +std::string ok_end() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -15,35 +97,16 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { + out.str(""); a aa; ok.str(""); ok // Test nothing failed. - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + << ok_c() + << ok_b() + << ok_a() + << ok_end() ; BOOST_TEST(out.eq(ok.str())); } @@ -55,35 +118,22 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl // Test this failed. + << ok_c() + << ok_b() + << ok_a() // Test exit a::static_inv failed. + #if !BOOST_CONTRACT_EXIT_INVARIANTS + << ok_end() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -91,28 +141,22 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl // Test this failed. + << ok_c() + << ok_b() // Test exit b::static_inv failed. + #if !BOOST_CONTRACT_EXIT_INVARIANTS + << ok_a() + << ok_end() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -120,21 +164,22 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl // Test this failed. + << ok_c() // Test exit c::static_inv failed. + #if !BOOST_CONTRACT_EXIT_INVARIANTS + << ok_b() + << ok_a() + << ok_end() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -142,21 +187,22 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl // Test this failed (as all did). + << ok_c() // Test exit c::static_inv failed (as all did). + #if !BOOST_CONTRACT_EXIT_INVARIANTS + << ok_b() + << ok_a() + << ok_end() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/constructor/decl_exit_static_inv_ends.cpp b/test/constructor/decl_exit_static_inv_ends.cpp index 6476c5a..4b080d9 100644 --- a/test/constructor/decl_exit_static_inv_ends.cpp +++ b/test/constructor/decl_exit_static_inv_ends.cpp @@ -6,8 +6,84 @@ #undef BOOST_CONTRACT_AUX_TEST_NO_C_STATIC_INV #include "decl.hpp" +#include #include #include +#include + +std::string ok_c() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl // This can fail. + #endif + ; + return ok.str(); +} + +std::string ok_b() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + ; + return ok.str(); +} + +std::string ok_a() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + #endif + ; + return ok.str(); +} + +std::string ok_end() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -15,33 +91,16 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { + out.str(""); a aa; ok.str(""); ok // Test nothing failed. - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + << ok_c() + << ok_b() + << ok_a() + << ok_end() ; BOOST_TEST(out.eq(ok.str())); } @@ -53,33 +112,22 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl // Test this failed. + << ok_c() + << ok_b() + << ok_a() // Test a::static_inv failed. + #if !BOOST_CONTRACT_EXIT_INVARIANTS + << ok_end() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -87,33 +135,16 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { + out.str(""); a aa; ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + << ok_c() + << ok_b() + << ok_a() + << ok_end() ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -121,21 +152,22 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl // Test this failed. + << ok_c() // Test c::static_inv failed (as all did). + #if !BOOST_CONTRACT_EXIT_INVARIANTS + << ok_b() + << ok_a() + << ok_end() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -143,21 +175,22 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl // Test this failed (as all did). + << ok_c() // Test c::static_inv failed (as all did). + #if !BOOST_CONTRACT_EXIT_INVARIANTS + << ok_b() + << ok_a() + << ok_end() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/constructor/decl_exit_static_inv_mid.cpp b/test/constructor/decl_exit_static_inv_mid.cpp index 10eb00f..a451f91 100644 --- a/test/constructor/decl_exit_static_inv_mid.cpp +++ b/test/constructor/decl_exit_static_inv_mid.cpp @@ -6,8 +6,80 @@ #define BOOST_CONTRACT_AUX_TEST_NO_C_STATIC_INV #include "decl.hpp" +#include #include #include +#include + +std::string ok_c() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #if BOOST_CONTRACT_POSTCONDITIONS + << "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 + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl // This can fail. + #endif + ; + return ok.str(); +} + +std::string ok_a() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_POSTCONDITIONS + << "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 + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -15,31 +87,16 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { + out.str(""); a aa; - ok.str(""); ok // Test nothing failed. - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + ok.str(""); ok // Test nothing fails. + << ok_c() + << ok_b() + << ok_a() + << ok_end() ; BOOST_TEST(out.eq(ok.str())); } @@ -51,32 +108,16 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { + out.str(""); a aa; ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - // Test no failure here. - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + << 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); } @@ -84,26 +125,22 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl // Test this failed. + << ok_c() + << ok_b() // Test b::static_inv failed. + #if !BOOST_CONTRACT_EXIT_INVARIANTS + << ok_a() + << ok_end() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -111,32 +148,16 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { + out.str(""); a aa; ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - // Test no failure here. - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + << 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); } @@ -144,26 +165,22 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl // Test this failed. + << ok_c() + << ok_b() // Test b::static_inv failed. + #if !BOOST_CONTRACT_EXIT_INVARIANTS + << ok_a() + << ok_end() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/constructor/decl_exit_static_inv_none.cpp b/test/constructor/decl_exit_static_inv_none.cpp index c5dd7e5..1055dc5 100644 --- a/test/constructor/decl_exit_static_inv_none.cpp +++ b/test/constructor/decl_exit_static_inv_none.cpp @@ -6,37 +6,59 @@ #define BOOST_CONTRACT_AUX_TEST_NO_C_STATIC_INV #include "decl.hpp" +#include #include #include int main() { std::ostringstream ok; ok // Test nothing fails. - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif - << "c::ctor::old" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::old" << std::endl + #endif << "c::ctor::body" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif - << "b::ctor::old" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif << "b::ctor::body" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif - << "a::ctor::old" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::old" << std::endl + #endif << "a::ctor::body" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::post" << std::endl + #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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { + out.str(""); a aa; BOOST_TEST(out.eq(ok.str())); } @@ -44,9 +66,10 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { + out.str(""); a aa; BOOST_TEST(out.eq(ok.str())); } @@ -54,9 +77,10 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { + out.str(""); a aa; BOOST_TEST(out.eq(ok.str())); } @@ -64,9 +88,10 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { + out.str(""); a aa; BOOST_TEST(out.eq(ok.str())); } @@ -74,9 +99,10 @@ int main() { 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 =true; - out.str(""); + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { + out.str(""); a aa; BOOST_TEST(out.eq(ok.str())); } diff --git a/test/constructor/decl_post_all.cpp b/test/constructor/decl_post_all.cpp index 3069e00..d66b629 100644 --- a/test/constructor/decl_post_all.cpp +++ b/test/constructor/decl_post_all.cpp @@ -8,6 +8,73 @@ #include #include +#include + +std::string ok_c() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + ; + return ok.str(); +} + +std::string ok_b() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + ; + return ok.str(); +} + +std::string ok_a() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -19,30 +86,9 @@ int main() { { a aa; ok.str(""); ok // Test nothing failed. - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + << ok_c() + << ok_b() + << ok_a() ; BOOST_TEST(out.eq(ok.str())); } @@ -57,33 +103,14 @@ int main() { out.str(""); try { a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl // Test this failed. + << ok_c() + << ok_b() + << ok_a() ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -94,26 +121,16 @@ int main() { out.str(""); try { a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl // Test this failed. + << ok_c() + << ok_b() // Test b::ctor::post failed. + #if !BOOST_CONTRACT_POSTCONDITIONS + << ok_a() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -124,19 +141,16 @@ int main() { out.str(""); try { a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl // Test this failed. + << ok_c() // Test c::ctor::post failed. + #if !BOOST_CONTRACT_POSTCONDITIONS + << ok_b() + << ok_a() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -147,19 +161,16 @@ int main() { out.str(""); try { a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl // Test this failed (as all did). + << ok_c() // Test c::ctor::post failed (as all did) + #if !BOOST_CONTRACT_POSTCONDITIONS + << ok_b() + << ok_a() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/constructor/decl_post_ends.cpp b/test/constructor/decl_post_ends.cpp index 54b227f..30d4f49 100644 --- a/test/constructor/decl_post_ends.cpp +++ b/test/constructor/decl_post_ends.cpp @@ -8,6 +8,66 @@ #include #include +#include + +std::string ok_c() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + ; + return ok.str(); +} + +std::string ok_ba() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + // No b::ctor::post here. + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -15,33 +75,12 @@ int main() { a_post = true; b_post = true; c_post = true; - out.str(""); { + out.str(""); a aa; ok.str(""); ok // Test nothing failed. - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + << ok_c() + << ok_ba() ; BOOST_TEST(out.eq(ok.str())); } @@ -53,35 +92,16 @@ int main() { a_post = false; b_post = true; c_post = true; - out.str(""); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl // Test this failed. + << ok_c() + << ok_ba() // Test a::ctor::post failed. ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -89,34 +109,12 @@ int main() { a_post = true; b_post = false; c_post = true; - out.str(""); { + out.str(""); a aa; ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - // Test no failure here. - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + << ok_c() + << ok_ba() // Test no b::ctor::post so no failure. ; BOOST_TEST(out.eq(ok.str())); } @@ -124,22 +122,18 @@ int main() { a_post = true; b_post = true; c_post = false; - out.str(""); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl // Test this failed. + << ok_c() // Test c::ctor::post failed. + #if !BOOST_CONTRACT_POSTCONDITIONS + << ok_ba() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -147,22 +141,18 @@ int main() { a_post = false; b_post = false; c_post = false; - out.str(""); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl // Test this failed (as all did). + << ok_c() // Test c::ctor::post failed (as all did). + #if !BOOST_CONTRACT_POSTCONDITIONS + << ok_ba() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/constructor/decl_post_mid.cpp b/test/constructor/decl_post_mid.cpp index 5e21b74..65fb6df 100644 --- a/test/constructor/decl_post_mid.cpp +++ b/test/constructor/decl_post_mid.cpp @@ -8,6 +8,62 @@ #include #include +#include + +std::string ok_cb() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + ; + return ok.str(); +} + +std::string ok_a() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -15,32 +71,12 @@ int main() { a_post = true; b_post = true; c_post = true; - out.str(""); { + out.str(""); a aa; ok.str(""); ok // Test nothing failed. - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl + << ok_cb() + << ok_a() ; BOOST_TEST(out.eq(ok.str())); } @@ -52,33 +88,12 @@ int main() { a_post = false; b_post = true; c_post = true; - out.str(""); { + out.str(""); a aa; ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - // Test no failure here. + << ok_cb() + << ok_a() // Test no a::ctor::post so no failure. ; BOOST_TEST(out.eq(ok.str())); } @@ -86,28 +101,18 @@ int main() { a_post = true; b_post = false; c_post = true; - out.str(""); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl // Test this failed. + << ok_cb() // Test b::ctor::post failed. + #if !BOOST_CONTRACT_POSTCONDITIONS + << ok_a() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -115,33 +120,12 @@ int main() { a_post = true; b_post = true; c_post = false; - out.str(""); { + out.str(""); a aa; ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - // Test no failure here. - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl + << ok_cb() // Test no c::ctor::post so no failure. + << ok_a() ; BOOST_TEST(out.eq(ok.str())); } @@ -149,28 +133,18 @@ int main() { a_post = false; b_post = false; c_post = false; - out.str(""); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl // Test this failed. + << ok_cb() // Test b::ctor::post failed (as all did). + #if !BOOST_CONTRACT_POSTCONDITIONS + << ok_a() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/constructor/decl_post_none.cpp b/test/constructor/decl_post_none.cpp index 5887348..8e908e3 100644 --- a/test/constructor/decl_post_none.cpp +++ b/test/constructor/decl_post_none.cpp @@ -11,34 +11,54 @@ int main() { std::ostringstream ok; ok // Test nothing fails. - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::old" << std::endl + #endif << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::old" << std::endl + #endif << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif ; a_post = true; b_post = true; c_post = true; - out.str(""); { + out.str(""); a aa; BOOST_TEST(out.eq(ok.str())); } @@ -46,8 +66,8 @@ int main() { a_post = false; b_post = true; c_post = true; - out.str(""); { + out.str(""); a aa; BOOST_TEST(out.eq(ok.str())); } @@ -55,8 +75,8 @@ int main() { a_post = true; b_post = false; c_post = true; - out.str(""); { + out.str(""); a aa; BOOST_TEST(out.eq(ok.str())); } @@ -64,8 +84,8 @@ int main() { a_post = true; b_post = true; c_post = false; - out.str(""); { + out.str(""); a aa; BOOST_TEST(out.eq(ok.str())); } @@ -73,8 +93,8 @@ int main() { a_post = false; b_post = false; c_post = false; - out.str(""); { + out.str(""); a aa; BOOST_TEST(out.eq(ok.str())); } diff --git a/test/constructor/decl_pre_all.cpp b/test/constructor/decl_pre_all.cpp index e2dad76..de74743 100644 --- a/test/constructor/decl_pre_all.cpp +++ b/test/constructor/decl_pre_all.cpp @@ -8,6 +8,57 @@ #include #include +#include + +std::string ok_after() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -15,34 +66,16 @@ int main() { a_pre = true; b_pre = true; c_pre = true; - out.str(""); { + out.str(""); a aa; ok.str(""); ok // Test nothing failed. - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + #if BOOST_CONTRACT_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())); } @@ -54,13 +87,19 @@ int main() { a_pre = false; b_pre = true; c_pre = true; - out.str(""); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_PRECONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl // Test this failed. + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl // Test this failed. + #else + << ok_after() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -68,14 +107,20 @@ int main() { a_pre = true; b_pre = false; c_pre = true; - out.str(""); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_PRECONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl // Test this failed. + #if BOOST_CONTRACT_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); } @@ -83,15 +128,21 @@ int main() { a_pre = true; b_pre = true; c_pre = false; - out.str(""); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_PRECONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl // Test this failed. + #if BOOST_CONTRACT_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); } @@ -99,13 +150,19 @@ int main() { a_pre = false; b_pre = false; c_pre = false; - out.str(""); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_PRECONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl // Test this failed (as all did). + #if BOOST_CONTRACT_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); } diff --git a/test/constructor/decl_pre_ends.cpp b/test/constructor/decl_pre_ends.cpp index 4c7ae8f..91eca8d 100644 --- a/test/constructor/decl_pre_ends.cpp +++ b/test/constructor/decl_pre_ends.cpp @@ -8,6 +8,57 @@ #include #include +#include + +std::string ok_after() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -15,33 +66,15 @@ int main() { a_pre = true; b_pre = true; c_pre = true; - out.str(""); { + out.str(""); a aa; ok.str(""); ok // Test nothing failed. - << "a::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + << ok_after() ; BOOST_TEST(out.eq(ok.str())); } @@ -53,13 +86,19 @@ int main() { a_pre = false; b_pre = true; c_pre = true; - out.str(""); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_PRECONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl // Test this failed. + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl // Test this failed. + #else + << ok_after() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -67,34 +106,16 @@ int main() { a_pre = true; b_pre = false; c_pre = true; - out.str(""); { + out.str(""); a aa; ok.str(""); ok - << "a::ctor::pre" << std::endl - // Test no failure here. - << "c::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl + // Test no failure here. + << "c::ctor::pre" << std::endl + #endif + << ok_after() ; BOOST_TEST(out.eq(ok.str())); } @@ -102,14 +123,20 @@ int main() { a_pre = true; b_pre = true; c_pre = false; - out.str(""); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_PRECONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl // Test this failed. + #if BOOST_CONTRACT_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); } @@ -117,13 +144,19 @@ int main() { a_pre = false; b_pre = false; c_pre = false; - out.str(""); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_PRECONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl // Test this failed (as all did). + #if BOOST_CONTRACT_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); } diff --git a/test/constructor/decl_pre_mid.cpp b/test/constructor/decl_pre_mid.cpp index e2c1af6..04a8d0d 100644 --- a/test/constructor/decl_pre_mid.cpp +++ b/test/constructor/decl_pre_mid.cpp @@ -8,6 +8,57 @@ #include #include +#include + +std::string ok_after() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::old" << std::endl + #endif + << "c::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -15,32 +66,14 @@ int main() { a_pre = true; b_pre = true; c_pre = true; - out.str(""); { + out.str(""); a aa; ok.str(""); ok // Test nothing failed. - << "b::ctor::pre" << std::endl - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + #if BOOST_CONTRACT_PRECONDITIONS + << "b::ctor::pre" << std::endl + #endif + << ok_after() ; BOOST_TEST(out.eq(ok.str())); } @@ -52,32 +85,14 @@ int main() { a_pre = false; b_pre = true; c_pre = true; - out.str(""); { + out.str(""); a aa; ok.str(""); ok - << "b::ctor::pre" << std::endl // Test no failure here. - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + #if BOOST_CONTRACT_PRECONDITIONS + << "b::ctor::pre" << std::endl // Test no failure here. + #endif + << ok_after() ; BOOST_TEST(out.eq(ok.str())); } @@ -85,13 +100,19 @@ int main() { a_pre = true; b_pre = false; c_pre = true; - out.str(""); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_PRECONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "b::ctor::pre" << std::endl // Test this failed. + #if BOOST_CONTRACT_PRECONDITIONS + << "b::ctor::pre" << std::endl // Test this failed. + #else + << ok_after() + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -100,32 +121,14 @@ int main() { a_pre = true; b_pre = true; c_pre = false; - out.str(""); { + out.str(""); a aa; ok.str(""); ok - << "b::ctor::pre" << std::endl // Test no failure here. - - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl - << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl - - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + #if BOOST_CONTRACT_PRECONDITIONS + << "b::ctor::pre" << std::endl // Test no failure here. + #endif + << ok_after() ; BOOST_TEST(out.eq(ok.str())); } @@ -133,13 +136,19 @@ int main() { a_pre = false; b_pre = false; c_pre = false; - out.str(""); try { + out.str(""); a aa; - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_PRECONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "b::ctor::pre" << std::endl // Test this failed (as all did). + #if BOOST_CONTRACT_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); } diff --git a/test/constructor/decl_pre_none.cpp b/test/constructor/decl_pre_none.cpp index f5f0154..d3c2fca 100644 --- a/test/constructor/decl_pre_none.cpp +++ b/test/constructor/decl_pre_none.cpp @@ -13,33 +13,57 @@ int main() { std::ostringstream ok; ok // Test no preconditions here. - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::old" << std::endl + #endif << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif << "b::ctor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::ctor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif - << "a::static_inv" << std::endl - << "a::ctor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::old" << std::endl + #endif << "a::ctor::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::ctor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif ; a_pre = true; b_pre = true; c_pre = true; - out.str(""); { + out.str(""); a aa; BOOST_TEST(out.eq(ok.str())); } @@ -47,8 +71,8 @@ int main() { a_pre = false; b_pre = true; c_pre = true; - out.str(""); { + out.str(""); a aa; BOOST_TEST(out.eq(ok.str())); } @@ -56,8 +80,8 @@ int main() { a_pre = true; b_pre = false; c_pre = true; - out.str(""); { + out.str(""); a aa; BOOST_TEST(out.eq(ok.str())); } @@ -65,8 +89,8 @@ int main() { a_pre = true; b_pre = true; c_pre = false; - out.str(""); { + out.str(""); a aa; BOOST_TEST(out.eq(ok.str())); } @@ -74,8 +98,8 @@ int main() { a_pre = false; b_pre = false; c_pre = false; - out.str(""); { + out.str(""); a aa; BOOST_TEST(out.eq(ok.str())); } diff --git a/test/constructor/old_throw.cpp b/test/constructor/old_throw.cpp index f0722d3..e4a7f2f 100644 --- a/test/constructor/old_throw.cpp +++ b/test/constructor/old_throw.cpp @@ -95,22 +95,53 @@ int main() { try { out.str(""); a aa; - BOOST_TEST(false); - } catch(b::err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(b::err const&) { + #endif ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - - << "c::ctor::pre" << std::endl - << "c::static_inv" << std::endl - << "c::ctor::old" << std::endl + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + << "c::ctor::pre" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::old" << std::endl + #endif << "c::ctor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::ctor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::ctor::post" << std::endl + #endif - << "b::static_inv" << std::endl - << "b::ctor::old" << std::endl // Test this threw. + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl // Test this threw. + #else + << "b::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + << "a::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); }