From 095d72ade4fb33337b36fbce5ccf1f49da224d44 Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Tue, 5 Jan 2016 18:30:20 -0800 Subject: [PATCH] compiled contracts on/off for all destructor tests --- test/destructor/access.cpp | 54 +++-- test/destructor/bases.cpp | 147 ++++++++---- test/destructor/body_throw.cpp | 53 +++-- test/destructor/decl_entry_inv_all.cpp | 212 ++++++++++------- test/destructor/decl_entry_inv_ends.cpp | 188 ++++++++------- test/destructor/decl_entry_inv_mid.cpp | 173 +++++++------- test/destructor/decl_entry_inv_none.cpp | 50 +++- test/destructor/decl_entry_static_inv_all.cpp | 216 ++++++++++------- .../destructor/decl_entry_static_inv_ends.cpp | 207 +++++++++------- test/destructor/decl_entry_static_inv_mid.cpp | 188 ++++++++------- .../destructor/decl_entry_static_inv_none.cpp | 54 +++-- test/destructor/decl_exit_static_inv_all.cpp | 224 +++++++++--------- test/destructor/decl_exit_static_inv_ends.cpp | 206 ++++++++-------- test/destructor/decl_exit_static_inv_mid.cpp | 189 +++++++-------- test/destructor/decl_exit_static_inv_none.cpp | 54 +++-- test/destructor/decl_post_all.cpp | 207 ++++++++-------- test/destructor/decl_post_ends.cpp | 189 +++++++-------- test/destructor/decl_post_mid.cpp | 177 +++++++------- test/destructor/decl_post_none.cpp | 44 +++- test/destructor/old_throw.cpp | 61 +++-- 20 files changed, 1616 insertions(+), 1277 deletions(-) diff --git a/test/destructor/access.cpp b/test/destructor/access.cpp index 0e99a38..f796f53 100644 --- a/test/destructor/access.cpp +++ b/test/destructor/access.cpp @@ -58,19 +58,35 @@ int main() { out.str(""); } // Call aa's destructor. ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::old" << std::endl + #endif << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::post" << std::endl + #endif - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::old" << std::endl + #endif << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); @@ -79,12 +95,20 @@ int main() { out.str(""); } // Call bb's destructor. ok.str(""); ok - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::old" << std::endl + #endif << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/destructor/bases.cpp b/test/destructor/bases.cpp index f57861a..d714413 100644 --- a/test/destructor/bases.cpp +++ b/test/destructor/bases.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -163,77 +164,137 @@ int main() { out.str(""); } // Call aa's destructor. ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::old" << std::endl + #endif << "a::dtor::body" << std::endl // Test static inv, but not const inv, checked after destructor body. - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::post" << std::endl + #endif - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::dtor::old" << std::endl + #endif << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::dtor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::dtor::post" << std::endl + #endif - << "e::static_inv" << std::endl - << "e::inv" << std::endl - << "e::dtor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "e::static_inv" << std::endl + << "e::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "e::dtor::old" << std::endl + #endif << "e::dtor::body" << std::endl - << "e::static_inv" << std::endl - << "e::dtor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "e::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "e::dtor::post" << std::endl + #endif // Test check also private bases (because part of C++ destruction). - << "q::static_inv" << std::endl - << "q::inv" << std::endl - << "q::dtor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "q::static_inv" << std::endl + << "q::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "q::dtor::old" << std::endl + #endif << "q::dtor::body" << std::endl - << "q::static_inv" << std::endl - << "q::dtor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "q::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "q::dtor::post" << std::endl + #endif // Test check also protected bases (because part of C++ destruction). - << "p::static_inv" << std::endl - << "p::inv" << std::endl - << "p::dtor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "p::static_inv" << std::endl + << "p::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "p::dtor::old" << std::endl + #endif << "p::dtor::body" << std::endl - << "p::static_inv" << std::endl - << "p::dtor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "p::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "p::dtor::post" << std::endl + #endif - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "d::dtor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "d::static_inv" << std::endl + << "d::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "d::dtor::old" << std::endl + #endif << "d::dtor::body" << std::endl - << "d::static_inv" << std::endl - << "d::dtor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "d::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "d::dtor::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); - // Following destroy only copies (actual objects are static data members). + // Followings 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<'d'>::l_type::copies(), t<'d'>::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<'p'>::l_type::copies(), t<'p'>::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<'q'>::l_type::copies(), t<'q'>::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/destructor/body_throw.cpp b/test/destructor/body_throw.cpp index 436635c..210a494 100644 --- a/test/destructor/body_throw.cpp +++ b/test/destructor/body_throw.cpp @@ -78,30 +78,49 @@ int main() { BOOST_TEST(false); } catch(b::err const&) { ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::old" << std::endl + #endif << "a::dtor::body" << std::endl // Test a destructed (so only static_inv and post, but no inv). - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::post" << std::endl + #endif - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::old" << std::endl + #endif << "b::dtor::body" << std::endl // Test this threw. - // Test b not destructed (so both static_inv and inv, but no post). - << "b::static_inv" << std::endl - << "b::inv" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::dtor::old" << std::endl + #endif << "c::dtor::body" << std::endl // Test c not destructed (so both static_inv and inv, but no post). - << "c::static_inv" << std::endl - << "c::inv" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/destructor/decl_entry_inv_all.cpp b/test/destructor/decl_entry_inv_all.cpp index a855760..0987bb4 100644 --- a/test/destructor/decl_entry_inv_all.cpp +++ b/test/destructor/decl_entry_inv_all.cpp @@ -8,6 +8,79 @@ #include #include +#include + +std::string ok_a(bool failed = false) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl // This can fail. + #endif + ; + if(!failed) ok + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::old" << std::endl + #endif + << "a::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::post" << std::endl + #endif + ; + return ok.str(); +} + +enum checked { passed, failed, threw }; + +std::string ok_b(checked check = passed) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl // This can fail. + #endif + ; + if(check != failed) ok + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::old" << std::endl + #endif + << "b::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << (check == threw ? "b::inv\n" : "") + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << (check == passed ? "b::dtor::post\n" : "") + #endif + ; + return ok.str(); +} + +std::string ok_c(checked check = passed) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl // This can fail. + #endif + ; + if(check != failed) ok + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::dtor::old" << std::endl + #endif + << "c::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << (check == threw ? "c::inv\n" : "") + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << (check == passed ? "c::dtor::post\n" : "") + #endif + ; + return ok.str(); +} + +// TODO: In all test file names, named entry_inv and exit_inv as entryinv and exitinv (to be consistent with the ...-no_entryinv/exitinv generated by Jamroot rules). int main() { std::ostringstream ok; @@ -20,33 +93,16 @@ int main() { out.str(""); } ok.str(""); ok // Test nothing failed. - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::dtor::post" << std::endl + << ok_a() + << ok_b() + << ok_c() ; BOOST_TEST(out.eq(ok.str())); struct err {}; boost::contract::set_entry_invariant_failure([&ok] (boost::contract::from) { - BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws... - throw err(); // for testing (as dtors should never throw anyways). + BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws. + throw err(); // For testing only (dtors should never throw otherwise). }); a_entry_inv = false; @@ -56,27 +112,18 @@ int main() { { a aa; ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl // Test this failed... + // Test entry a::inv failed... + << ok_a(BOOST_CONTRACT_ENTRY_INVARIANTS) ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { - ok // ... then exec other dtors and check inv on throw (as dtor threw). - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok // ...then exec other dtors and check inv on throw (as dtor threw). + << ok_b(BOOST_CONTRACT_ENTRY_INVARIANTS ? threw : passed) + << ok_c(BOOST_CONTRACT_ENTRY_INVARIANTS ? threw : passed) ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -88,27 +135,18 @@ int main() { { a aa; ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl // Test this failed... + << ok_a() + // Test entry b::inv failed... + << ok_b(BOOST_CONTRACT_ENTRY_INVARIANTS ? failed : passed) ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { - ok // ... then exec other dtors and check inv on throw (as dtor threw). - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok // ...then exec other dtors and check inv on throw (as dtor threw). + << ok_c(BOOST_CONTRACT_ENTRY_INVARIANTS ? threw : passed) ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -120,34 +158,24 @@ int main() { { a aa; ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl // Test this failed. + << ok_a() + << ok_b() + // Test entry c::inv failed... + << ok_c(BOOST_CONTRACT_ENTRY_INVARIANTS ? failed : passed) ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { - // ... then exec other dtors and check inv on throw (as dtor threw). + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + // ...then exec other dtors and check inv on throw (as dtor threw). BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } boost::contract::set_entry_invariant_failure([] (boost::contract::from) { - // Testing multiple failures so dtors must not throw multiple - // exceptions, just ignore failure and continue test program... + // Testing multiple failures so dtors must not throw multiple except, + // just ignore failure and continue test program (for testing only). }); a_entry_inv = false; @@ -158,17 +186,23 @@ int main() { out.str(""); } ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl // Test this failed (as all did)... - << "a::dtor::body" << std::endl + // Test entry a::inv failed (as all did). + << ok_a(BOOST_CONTRACT_ENTRY_INVARIANTS) + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::dtor::body" << std::endl + #endif + + // Test entry b::inv failed (as all did). + << ok_b(BOOST_CONTRACT_ENTRY_INVARIANTS ? failed : passed) + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::dtor::body" << std::endl + #endif - << "b::static_inv" << std::endl - << "b::inv" << std::endl // Test this failed (as all did)... - << "b::dtor::body" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl // Test this failed (as all did)... - << "c::dtor::body" << std::endl + // Test entry c::inv failed (as all did). + << ok_c(BOOST_CONTRACT_ENTRY_INVARIANTS ? failed : passed) + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::dtor::body" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/destructor/decl_entry_inv_ends.cpp b/test/destructor/decl_entry_inv_ends.cpp index 2cddc20..2bcefea 100644 --- a/test/destructor/decl_entry_inv_ends.cpp +++ b/test/destructor/decl_entry_inv_ends.cpp @@ -8,6 +8,74 @@ #include #include +#include + +std::string ok_a(bool failed = false) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl // This can fail. + #endif + ; + if(!failed) ok + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::old" << std::endl + #endif + << "a::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::post" << std::endl + #endif + ; + return ok.str(); +} + +std::string ok_b(bool threw = false) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::old" << std::endl + #endif + << "b::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + // No b::inv here (not even when threw). + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << (!threw ? "b::dtor::post\n" : "") + #endif + ; + return ok.str(); +} + +enum checked { passed, failed, threw }; + +std::string ok_c(checked check = passed) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl // This can fail. + #endif + ; + if(check != failed) ok + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::dtor::old" << std::endl + #endif + << "c::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << (check == threw ? "c::inv\n" : "") + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << (check == passed ? "c::dtor::post\n" : "") + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -20,25 +88,9 @@ int main() { out.str(""); } ok.str(""); ok // Test nothing failed. - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::dtor::post" << std::endl + << ok_a() + << ok_b() + << ok_c() ; BOOST_TEST(out.eq(ok.str())); @@ -55,25 +107,18 @@ int main() { { a aa; ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl // Test this failed... + // Test entry a::inv failed... + << ok_a(BOOST_CONTRACT_ENTRY_INVARIANTS) ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { - ok // ... then exec other dtors and check inv on throw (as dtor threw). - << "b::static_inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok // ...then exec other dtors and check inv on throw (as dtor threw). + << ok_b(BOOST_CONTRACT_ENTRY_INVARIANTS) + << ok_c(BOOST_CONTRACT_ENTRY_INVARIANTS ? threw : passed) ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -86,26 +131,9 @@ int main() { out.str(""); } ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - // Test no failure here. - << "b::static_inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::dtor::post" << std::endl + << ok_a() + << ok_b() // Test no entry b::inv so no failure here. + << ok_c() ; BOOST_TEST(out.eq(ok.str())); @@ -116,27 +144,18 @@ int main() { { a aa; ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl // Test this failed... + << ok_a() + << ok_b() + // Test entry c::inv failed... + << ok_c(BOOST_CONTRACT_ENTRY_INVARIANTS ? failed : passed) ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { - // ... then exec other dtors and check inv on throw (as dtor threw). + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + // ...then exec other dtors and check inv on throw (as dtor threw). BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -153,20 +172,19 @@ int main() { out.str(""); } ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl // Test this failed (as all did)... - << "a::dtor::body" << std::endl + // Test entry a::inv failed (as all did). + << ok_a(BOOST_CONTRACT_ENTRY_INVARIANTS) + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::dtor::body" << std::endl + #endif - // Test no failure here. - << "b::static_inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl + << ok_b() // Test no entry b::inv so no failure here. - << "c::static_inv" << std::endl - << "c::inv" << std::endl // Test this failed (as all did)... - << "c::dtor::body" << std::endl + // Test entry c::inv failed (as all did). + << ok_c(BOOST_CONTRACT_ENTRY_INVARIANTS ? failed : passed) + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::dtor::body" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/destructor/decl_entry_inv_mid.cpp b/test/destructor/decl_entry_inv_mid.cpp index 0d5b4ce..958a9c6 100644 --- a/test/destructor/decl_entry_inv_mid.cpp +++ b/test/destructor/decl_entry_inv_mid.cpp @@ -8,6 +8,68 @@ #include #include +#include + +std::string ok_a() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::old" << std::endl + #endif + << "a::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::post" << std::endl + #endif + ; + return ok.str(); +} + +std::string ok_b(bool failed = false) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl // This can fail. + #endif + ; + if(!failed) ok + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::old" << std::endl + #endif + << "b::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::post" << std::endl + #endif + ; + return ok.str(); +} + +std::string ok_c(bool threw = false) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::dtor::old" << std::endl + #endif + << "c::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + // No b::inv here (not even when threw). + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << (!threw ? "c::dtor::post\n" : "") + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -20,24 +82,9 @@ int main() { out.str(""); } ok.str(""); ok // Test nothing failed. - << "a::static_inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl - - << "c::static_inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::dtor::post" << std::endl + << ok_a() + << ok_b() + << ok_c() ; BOOST_TEST(out.eq(ok.str())); @@ -57,25 +104,9 @@ int main() { out.str(""); } ok.str(""); ok - // Test no failure here. - << "a::static_inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl - - << "c::static_inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::dtor::post" << std::endl + << ok_a() // Test no entry a::inv so no failure here. + << ok_b() + << ok_c() ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -87,24 +118,18 @@ int main() { { a aa; ok.str(""); ok - << "a::static_inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl // Test this failed... + << ok_a() + // Test entry b::inv failed... + << ok_b(BOOST_CONTRACT_ENTRY_INVARIANTS) ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { - ok // ... then exec other dtors and check inv on throw (as dtor threw). - << "c::static_inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok // ...then exec other dtors and check inv on throw (as dtor threw). + << ok_c(BOOST_CONTRACT_ENTRY_INVARIANTS) ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -119,25 +144,9 @@ int main() { out.str(""); } ok.str(""); ok - << "a::static_inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl - - // Test no failure here. - << "c::static_inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::dtor::post" << std::endl + << ok_a() + << ok_b() + << ok_c() // Test no entry c::inv so no failure here. ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -155,23 +164,15 @@ int main() { out.str(""); } ok.str(""); ok - // Test no faliure here. - << "a::static_inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl + << ok_a() // Test no entry a::inv so no failure here. - << "b::static_inv" << std::endl - << "b::inv" << std::endl // Test this failed (as all did)... - << "b::dtor::body" << std::endl + // Test entry b::inv failed (as all did). + << ok_b(BOOST_CONTRACT_ENTRY_INVARIANTS) + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::dtor::body" << std::endl + #endif - // Test no failure here. - << "c::static_inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::dtor::post" << std::endl + << ok_c() // Test no entry c::inv so no failure here. ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/destructor/decl_entry_inv_none.cpp b/test/destructor/decl_entry_inv_none.cpp index 1da05ce..ffcc492 100644 --- a/test/destructor/decl_entry_inv_none.cpp +++ b/test/destructor/decl_entry_inv_none.cpp @@ -11,23 +11,47 @@ int main() { std::ostringstream ok; ok // Test nothing fails. - << "a::static_inv" << std::endl - << "a::dtor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::old" << std::endl + #endif << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::post" << std::endl + #endif - << "b::static_inv" << std::endl - << "b::dtor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::old" << std::endl + #endif << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl - - << "c::static_inv" << std::endl - << "c::dtor::old" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::dtor::old" << std::endl + #endif << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::dtor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::dtor::post" << std::endl + #endif ; a_entry_inv = true; diff --git a/test/destructor/decl_entry_static_inv_all.cpp b/test/destructor/decl_entry_static_inv_all.cpp index 8f00795..bbb7eeb 100644 --- a/test/destructor/decl_entry_static_inv_all.cpp +++ b/test/destructor/decl_entry_static_inv_all.cpp @@ -6,8 +6,72 @@ #undef BOOST_CONTRACT_AUX_TEST_NO_C_STATIC_INV #include "decl.hpp" +#include #include #include +#include + +std::string ok_a() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::old" << std::endl + #endif + << "a::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::post" << std::endl + #endif + ; + return ok.str(); +} + +std::string ok_b(bool threw = false) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::old" << std::endl + #endif + << "b::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << (threw ? "b::inv\n" : "") + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << (!threw ? "b::dtor::post\n" : "") + #endif + ; + return ok.str(); +} + +std::string ok_c(bool threw = false) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::dtor::old" << std::endl + #endif + << "c::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << (threw ? "c::inv\n" : "") + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << (!threw ? "c::dtor::post\n" : "") + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -15,69 +79,49 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { a aa; out.str(""); } ok.str(""); ok // Test nothing failed. - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::dtor::post" << std::endl + << ok_a() + << ok_b() + << ok_c() ; BOOST_TEST(out.eq(ok.str())); struct err {}; boost::contract::set_entry_invariant_failure([&ok] (boost::contract::from) { - BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws... - throw err(); // for testing (as dtors should never throw anyways). + BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws. + throw err(); // For testing only (dtors should never throw otherwise). }); 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { { a aa; ok.str(""); ok - << "a::static_inv" << std::endl // Test this failed... + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl // Test this failed... + #else + << ok_a() + #endif ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { - ok // ... then exec other dtors and check inv on throw (as dtor threw). - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok // ...then exec other dtors and check inv on throw (as dtor threw). + << ok_b(BOOST_CONTRACT_ENTRY_INVARIANTS) + << ok_c(BOOST_CONTRACT_ENTRY_INVARIANTS) ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -85,31 +129,27 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { { a aa; ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl // Test this failed... + << ok_a() + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl // Test this failed... + #else + << ok_b() + #endif ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { - ok // ... then exec other dtors and check inv on throw (as dtor threw). - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok // ...then exec other dtors and check inv on throw (as dtor threw). + << ok_c(BOOST_CONTRACT_ENTRY_INVARIANTS) ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -117,32 +157,27 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { { a aa; ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl - - << "c::static_inv" << std::endl // Test this failed. + << ok_a() + << ok_b() + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl // Test this failed... + #else + << ok_c() + #endif ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { - // ... then exec other dtors and check inv on throw (as dtor threw). + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + // ...then exec other dtors and check inv on throw (as dtor threw). BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -154,20 +189,27 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { a aa; out.str(""); } ok.str(""); ok - << "a::static_inv" << std::endl // Test this failed (as all did)... - << "a::dtor::body" << std::endl - - << "b::static_inv" << std::endl // Test this failed (as all did)... - << "b::dtor::body" << std::endl - - << "c::static_inv" << std::endl // Test this failed (as all did)... - << "c::dtor::body" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl // Test this failed (as all did)... + << "a::dtor::body" << std::endl + + << "b::static_inv" << std::endl // Test this failed (as all did)... + << "b::dtor::body" << std::endl + + << "c::static_inv" << std::endl // Test this failed (as all did)... + << "c::dtor::body" << std::endl + #else + << ok_a() + << ok_b() + << ok_c() + #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/destructor/decl_entry_static_inv_ends.cpp b/test/destructor/decl_entry_static_inv_ends.cpp index f358790..3be69d8 100644 --- a/test/destructor/decl_entry_static_inv_ends.cpp +++ b/test/destructor/decl_entry_static_inv_ends.cpp @@ -6,8 +6,72 @@ #undef BOOST_CONTRACT_AUX_TEST_NO_C_STATIC_INV #include "decl.hpp" +#include #include #include +#include + +std::string ok_a() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::old" << std::endl + #endif + << "a::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::post" << std::endl + #endif + ; + return ok.str(); +} + +// TODO: Commonize all decl_* programs using threw instead of failure bool param, similar code comments, etc. + +std::string ok_b(bool threw = false) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::old" << std::endl + #endif + << "b::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << (threw ? "b::inv\n" : "") + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << (!threw ? "b::dtor::post\n" : "") + #endif + ; + return ok.str(); +} + +std::string ok_c(bool threw = false) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::dtor::old" << std::endl + #endif + << "c::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << (threw ? "c::inv\n" : "") + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << (!threw ? "c::dtor::post\n" : "") + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -15,65 +79,49 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { a aa; out.str(""); } ok.str(""); ok // Test nothing failed. - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::dtor::post" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::dtor::post" << std::endl + << ok_a() + << ok_b() + << ok_c() ; BOOST_TEST(out.eq(ok.str())); struct err {}; boost::contract::set_entry_invariant_failure([&ok] (boost::contract::from) { - BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws... - throw err(); // for testing (as dtors should never throw anyways). + BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws. + throw err(); // For testing only (dtors should never throw otherwise). }); 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { { a aa; ok.str(""); ok - << "a::static_inv" << std::endl // Test this failed... + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl // Test this failed... + #else + << ok_a() + #endif ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { - ok // ... then exec other dtors and check inv on throw (as dtor threw). - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::inv" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok // ...then exec other dtors and check inv on throw (as dtor threw). + << ok_b(BOOST_CONTRACT_ENTRY_INVARIANTS) + << ok_c(BOOST_CONTRACT_ENTRY_INVARIANTS) ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -81,89 +129,74 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { a aa; out.str(""); } ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - // Test no failure here. - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::dtor::post" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::dtor::post" << std::endl + << ok_a() + << ok_b() // Test no b::static_inv so no failure here. + << ok_c() ; BOOST_TEST(out.eq(ok.str())); a_entry_static_inv = true; b_entry_static_inv = true; c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { { a aa; ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::dtor::post" << std::endl - - << "c::static_inv" << std::endl // Test this failed... + << ok_a() + << ok_b() + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl // Test this failed... + #else + << ok_c() + #endif ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { - // ... then exec other dtors and check inv on throw (as dtor threw). + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + // ...then exec other dtors and check inv on throw (as dtor threw). BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } boost::contract::set_entry_invariant_failure([] (boost::contract::from) { // Testing multiple failures so dtors must not throw multiple - // exceptions, just ignore failure and continue test program... + // exceptions, just ignore failure and continue test program. }); 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { a aa; out.str(""); } ok.str(""); ok - << "a::static_inv" << std::endl // Test this failed (as all did)... - << "a::dtor::body" << std::endl - - // Test no failure here. - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::dtor::post" << std::endl - - << "c::static_inv" << std::endl // Test this failed (as all did)... - << "c::dtor::body" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl // Test this failed (as all did). + << "a::dtor::body" << std::endl + + << ok_b() // Test no b::static_inv so no failure here. + + << "c::static_inv" << std::endl // Test this failed (as all did). + << "c::dtor::body" << std::endl + #else + << ok_a() + << ok_b() + << ok_c() + #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/destructor/decl_entry_static_inv_mid.cpp b/test/destructor/decl_entry_static_inv_mid.cpp index 0b29ba4..242b30f 100644 --- a/test/destructor/decl_entry_static_inv_mid.cpp +++ b/test/destructor/decl_entry_static_inv_mid.cpp @@ -6,8 +6,65 @@ #define BOOST_CONTRACT_AUX_TEST_NO_C_STATIC_INV #include "decl.hpp" +#include #include #include +#include + +std::string ok_a() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::old" << std::endl + #endif + << "a::dtor::body" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::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 + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::old" << std::endl + #endif + << "b::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::post" << std::endl + #endif + ; + return ok.str(); +} + +std::string ok_c(bool threw = false) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::dtor::old" << std::endl + #endif + << "c::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << (threw ? "c::inv\n" : "") + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << (!threw ? "c::dtor::post\n" : "") + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -15,65 +72,39 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { a aa; out.str(""); } ok.str(""); ok // Test nothing failed. - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl - - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::dtor::post" << std::endl + << ok_a() + << ok_b() + << ok_c() ; BOOST_TEST(out.eq(ok.str())); struct err {}; boost::contract::set_entry_invariant_failure([&ok] (boost::contract::from) { - BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws... - throw err(); // for testing (as dtors should never throw anyways). + BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws. + throw err(); // For testing only (dtors should never throw otherwise). }); 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { { a aa; - ok.str(""); out.str(""); } ok.str(""); ok - // Test no failure here. - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl - - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::dtor::post" << std::endl + << ok_a() // Test no a::static_inv so no failure here. + << ok_b() + << ok_c() ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -81,27 +112,27 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { { a aa; ok.str(""); ok - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl // Test this failed... + << ok_a() + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl // Test this failed... + #else + << ok_b() + #endif ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { - ok // ... then exec other dtors and check inv on throw (as dtor threw). - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::inv" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok // ...then exec other dtors and check inv on throw (as dtor threw). + << ok_c(BOOST_CONTRACT_ENTRY_INVARIANTS) ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -109,31 +140,17 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { { a aa; - ok.str(""); out.str(""); } ok.str(""); ok - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl - - // Test no failure here. - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::dtor::post" << std::endl + << ok_a() + << ok_b() + << ok_c() // Test no c::static_inv so no failure here. ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -146,26 +163,25 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { a aa; out.str(""); } ok.str(""); ok - // Test no faliure here. - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl // Test this failed (as all did)... - << "b::dtor::body" << std::endl - - // Test no failure here. - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::dtor::post" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << ok_a() // Test no a::static_inv so no failure here. + + << "b::static_inv" << std::endl // Test this failed (as all did)... + << "b::dtor::body" << std::endl + + << ok_c() // Test no c::static_inv so no failure here. + #else + << ok_a() + << ok_b() + << ok_c() + #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/destructor/decl_entry_static_inv_none.cpp b/test/destructor/decl_entry_static_inv_none.cpp index a965eb5..0ca89ca 100644 --- a/test/destructor/decl_entry_static_inv_none.cpp +++ b/test/destructor/decl_entry_static_inv_none.cpp @@ -6,31 +6,51 @@ #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::inv" << std::endl - << "a::dtor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::old" << std::endl + #endif << "a::dtor::body" << std::endl - << "a::dtor::post" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::post" << std::endl + #endif - << "b::inv" << std::endl - << "b::dtor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::old" << std::endl + #endif << "b::dtor::body" << std::endl - << "b::dtor::post" << std::endl - - << "c::inv" << std::endl - << "c::dtor::old" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::dtor::old" << std::endl + #endif << "c::dtor::body" << std::endl - << "c::dtor::post" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::dtor::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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { a aa; out.str(""); @@ -40,7 +60,8 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { a aa; out.str(""); @@ -50,7 +71,8 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { a aa; out.str(""); @@ -60,7 +82,8 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { a aa; out.str(""); @@ -70,7 +93,8 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { a aa; out.str(""); diff --git a/test/destructor/decl_exit_static_inv_all.cpp b/test/destructor/decl_exit_static_inv_all.cpp index 9ff8327..87cc21f 100644 --- a/test/destructor/decl_exit_static_inv_all.cpp +++ b/test/destructor/decl_exit_static_inv_all.cpp @@ -6,8 +6,74 @@ #undef BOOST_CONTRACT_AUX_TEST_NO_C_STATIC_INV #include "decl.hpp" +#include #include #include +#include + +std::string ok_a(bool failed = false) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::old" << std::endl + #endif + << "a::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl // This can fail. + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << (!failed ? "a::dtor::post\n" : "") + #endif + ; + return ok.str(); +} + +enum checked { passed, failed, threw }; + +std::string ok_b(checked check = passed) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::old" << std::endl + #endif + << "b::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl // This can fail. + << (check == threw ? "b::inv\n" : "") + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << (check == passed ? "b::dtor::post\n" : "") + #endif + ; + return ok.str(); +} + +std::string ok_c(checked check = passed) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::dtor::old" << std::endl + #endif + << "c::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl // This can fail. + << (check == threw ? "c::inv\n" : "") + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << (check == passed ? "c::dtor::post\n" : "") + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -15,73 +81,46 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { a aa; out.str(""); } ok.str(""); ok // Test nothing failed. - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::dtor::post" << std::endl + << ok_a() + << ok_b() + << ok_c() ; BOOST_TEST(out.eq(ok.str())); struct err {}; boost::contract::set_exit_invariant_failure([&ok] (boost::contract::from) { - BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws... - throw err(); // for testing (as dtors should never throw anyways). + BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws. + throw err(); // For testing only (as dtors should not throw otherwise). }); 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { { a aa; ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl // Test this failed... + // Test a::static_inv failed... + << ok_a(BOOST_CONTRACT_EXIT_INVARIANTS) ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { - ok // ... then exec other dtors and check inv on throw (as dtor threw). - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok // ...then exec other dtors and check inv on throw (as dtor threw). + << ok_b(BOOST_CONTRACT_EXIT_INVARIANTS ? threw : passed) + << ok_c(BOOST_CONTRACT_EXIT_INVARIANTS ? threw : passed) ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -89,35 +128,24 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { { a aa; ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl // Test this failed... + << ok_a() + // Test b::static_inv failed... + << ok_b(BOOST_CONTRACT_EXIT_INVARIANTS ? failed : passed) ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { - ok // ... then exec other dtors and check inv on throw (as dtor threw). - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok // ...then exec other dtors and check inv on throw (as dtor threw). + << ok_c(BOOST_CONTRACT_EXIT_INVARIANTS ? threw : passed) ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -125,70 +153,48 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { { a aa; ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl // Test this failed. + << ok_a() + << ok_b() + // Test exit c::static_inv failed. + << ok_c(BOOST_CONTRACT_EXIT_INVARIANTS ? failed : passed) ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif // ... then exec other dtors and check inv on throw (as dtor threw). BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } boost::contract::set_exit_invariant_failure([] (boost::contract::from) { - // Testing multiple failures so dtors must not throw multiple - // exceptions, just ignore failure and continue test program... + // Testing multiple failures but dtors must not throw multiple except, + // just ignore failure and continue test program (for testing only). }); 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { a aa; out.str(""); } ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl // Test this failed (as all did)... - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl // Test this failed (as all did)... - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl // Test this failed (as all did)... + // Test exit a::static_inv failed (as all did). + << ok_a(BOOST_CONTRACT_EXIT_INVARIANTS) + // Test exit b::static_inv failed (as all did). + << ok_b(BOOST_CONTRACT_EXIT_INVARIANTS ? failed : passed) + // Test exit c::static_inv failed (as all did). + << ok_c(BOOST_CONTRACT_EXIT_INVARIANTS ? failed : passed) ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/destructor/decl_exit_static_inv_ends.cpp b/test/destructor/decl_exit_static_inv_ends.cpp index f9bc478..b8412c3 100644 --- a/test/destructor/decl_exit_static_inv_ends.cpp +++ b/test/destructor/decl_exit_static_inv_ends.cpp @@ -6,8 +6,72 @@ #undef BOOST_CONTRACT_AUX_TEST_NO_C_STATIC_INV #include "decl.hpp" +#include #include #include +#include + +std::string ok_a(bool failed = false) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::old" << std::endl + #endif + << "a::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl // This can fail. + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << (!failed ? "a::dtor::post\n" : "") + #endif + ; + return ok.str(); +} + +std::string ok_b(bool threw = false) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::old" << std::endl + #endif + << "b::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << (threw ? "b::inv\n" : "") + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << (!threw ? "b::dtor::post\n" : "") + #endif + ; + return ok.str(); +} + +enum checked { passed, failed, threw }; + +std::string ok_c(checked check = passed) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::dtor::old" << std::endl + #endif + << "c::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl // This can fail. + << (check == threw ? "c::inv\n" : "") + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << (check == passed ? "c::dtor::post\n" : "") + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -15,69 +79,46 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { a aa; out.str(""); } ok.str(""); ok // Test nothing failed. - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::dtor::post" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::dtor::post" << std::endl + << ok_a() + << ok_b() + << ok_c() ; BOOST_TEST(out.eq(ok.str())); struct err {}; boost::contract::set_exit_invariant_failure([&ok] (boost::contract::from) { - BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws... - throw err(); // for testing (as dtors should never throw anyways). + BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws. + throw err(); // For testing only (as dtors should not throw otherwise). }); 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { { a aa; ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl // Test this failed... + // Test a::static_inv failed... + << ok_a(BOOST_CONTRACT_EXIT_INVARIANTS) ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { - ok // ... then exec other dtors and check inv on throw (as dtor threw). - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::inv" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok // ...then exec other dtors and check inv on throw (as dtor threw). + << ok_b(BOOST_CONTRACT_EXIT_INVARIANTS) + << ok_c(BOOST_CONTRACT_EXIT_INVARIANTS ? threw : passed) ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -85,65 +126,40 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { a aa; out.str(""); } ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - // Test no failure here. - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::dtor::post" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::dtor::post" << std::endl + << ok_a() + << ok_b() // Test no exit b::static_inv so no failure here. + << ok_c() ; BOOST_TEST(out.eq(ok.str())); a_exit_static_inv = true; b_exit_static_inv = true; c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { { a aa; ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::dtor::post" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl // Test this failed... + << ok_a() + << ok_b() + // Test c::static_inv failed... + << ok_c(BOOST_CONTRACT_EXIT_INVARIANTS ? failed : passed) ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { - // ... then exec other dtors and check inv on throw (as dtor threw). + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + // ...then exec other dtors and check inv on throw (as dtor threw). BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -155,29 +171,19 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { a aa; out.str(""); } ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl // Test this failed (as all did)... - - // Test no failure here. - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::dtor::post" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl // Test this failed (as all did)... + // Test a::static_inv failed (as all did). + << ok_a(BOOST_CONTRACT_EXIT_INVARIANTS) + // Test no exit b::static_inv so no failure here. + << ok_b() + // Test c::static_inv failed (as all did). + << ok_c(BOOST_CONTRACT_EXIT_INVARIANTS ? failed : passed) ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/destructor/decl_exit_static_inv_mid.cpp b/test/destructor/decl_exit_static_inv_mid.cpp index 8876884..f7f181b 100644 --- a/test/destructor/decl_exit_static_inv_mid.cpp +++ b/test/destructor/decl_exit_static_inv_mid.cpp @@ -6,8 +6,65 @@ #define BOOST_CONTRACT_AUX_TEST_NO_C_STATIC_INV #include "decl.hpp" +#include #include #include +#include + +std::string ok_a() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::old" << std::endl + #endif + << "a::dtor::body" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::post" << std::endl + #endif + ; + return ok.str(); +} + +std::string ok_b(bool failed = false) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::old" << std::endl + #endif + << "b::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl // This can fail. + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << (!failed ? "b::dtor::post\n" : "") + #endif + ; + return ok.str(); +} + +std::string ok_c(bool threw = false) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::dtor::old" << std::endl + #endif + << "c::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << (threw ? "c::inv\n" : "") + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << (!threw ? "c::dtor::post\n" : "") + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -15,41 +72,30 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { a aa; out.str(""); } ok.str(""); ok // Test nothing failed. - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl - - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::dtor::post" << std::endl + << ok_a() + << ok_b() + << ok_c() ; BOOST_TEST(out.eq(ok.str())); struct err {}; boost::contract::set_exit_invariant_failure([&ok] (boost::contract::from) { - BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws... - throw err(); // for testing (as dtors should never throw anyways). + BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws. + throw err(); // For testing only (as dtors should not throw otherwise). }); 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { { a aa; @@ -57,23 +103,9 @@ int main() { out.str(""); } ok.str(""); ok - // Test no failure here. - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl - - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::dtor::post" << std::endl + << ok_a() // Test no exit a::static_inv so no failure here. + << ok_b() + << ok_c() ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -81,31 +113,24 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { { a aa; ok.str(""); ok - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl // Test this failed... + << ok_a() + // Test exit b::static_inv failed... + << ok_b(BOOST_CONTRACT_EXIT_INVARIANTS) ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { - ok // ... then exec other dtors and check inv on throw (as dtor threw). - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::inv" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok // ...then exec other dtors and check inv on throw (as dtor threw). + << ok_c(BOOST_CONTRACT_EXIT_INVARIANTS) ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -113,7 +138,8 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); try { { a aa; @@ -121,58 +147,35 @@ int main() { out.str(""); } ok.str(""); ok - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl - - // Test no failure here. - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::dtor::post" << std::endl + << ok_a() + << ok_b() + // Test no exit c::static_inv so no failure here. + << ok_c() ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } boost::contract::set_exit_invariant_failure([] (boost::contract::from) { - // Testing multiple failures so dtors must not throw multiple - // exceptions, just ignore failure and continue test program... + // Testing multiple failures so dtors must not throw multiple except, + // just ignore failure and continue test program (for testing only). }); 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { a aa; out.str(""); } ok.str(""); ok - // Test no faliure here. - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl // Test this failed (as all did)... - - // Test no failure here. - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::dtor::post" << std::endl + // Test no exit a::static_inv so no faliure here. + << ok_a() + // Test exit b::static_inv failed (as all did). + << ok_b(BOOST_CONTRACT_EXIT_INVARIANTS) + // Test no exit c::static_inv so no failure here. + << ok_c() ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/destructor/decl_exit_static_inv_none.cpp b/test/destructor/decl_exit_static_inv_none.cpp index d94aa1a..12d2cc8 100644 --- a/test/destructor/decl_exit_static_inv_none.cpp +++ b/test/destructor/decl_exit_static_inv_none.cpp @@ -6,31 +6,51 @@ #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::inv" << std::endl - << "a::dtor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::old" << std::endl + #endif << "a::dtor::body" << std::endl - << "a::dtor::post" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::post" << std::endl + #endif - << "b::inv" << std::endl - << "b::dtor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::old" << std::endl + #endif << "b::dtor::body" << std::endl - << "b::dtor::post" << std::endl - - << "c::inv" << std::endl - << "c::dtor::old" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::dtor::old" << std::endl + #endif << "c::dtor::body" << std::endl - << "c::dtor::post" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::dtor::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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { a aa; out.str(""); @@ -40,7 +60,8 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { a aa; out.str(""); @@ -50,7 +71,8 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { a aa; out.str(""); @@ -60,7 +82,8 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { a aa; out.str(""); @@ -70,7 +93,8 @@ 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; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); { a aa; out.str(""); diff --git a/test/destructor/decl_post_all.cpp b/test/destructor/decl_post_all.cpp index 24b33e1..b392c96 100644 --- a/test/destructor/decl_post_all.cpp +++ b/test/destructor/decl_post_all.cpp @@ -8,6 +8,69 @@ #include #include +#include + +std::string ok_a() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::old" << std::endl + #endif + << "a::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::post" << std::endl // This can fail. + #endif + ; + return ok.str(); +} + +std::string ok_b(bool failure = false) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::old" << std::endl + #endif + << "b::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << (failure ? "b::inv\n" : "") + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << (!failure ? "b::dtor::post\n" : "") // This can fail. + #endif + ; + return ok.str(); +} + +std::string ok_c(bool failure = false) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::dtor::old" << std::endl + #endif + << "c::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << (failure ? "c::inv\n" : "") + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << (!failure ? "c::dtor::post\n" : "") // This can fail. + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -20,26 +83,9 @@ int main() { out.str(""); } ok.str(""); ok // Test nothing failed. - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::dtor::post" << std::endl + << ok_a() + << ok_b() + << ok_c() ; BOOST_TEST(out.eq(ok.str())); @@ -56,31 +102,17 @@ int main() { { a aa; ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl // Test this failed... + << ok_a() // Test a::dtor::post failed... ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { - ok // ... then exec other dtors and check inv on throw (as dtor threw). - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok // ...then exec other dtors and check inv on throw (as dtor threw). + << ok_b(BOOST_CONTRACT_POSTCONDITIONS) + << ok_c(BOOST_CONTRACT_POSTCONDITIONS) ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -92,31 +124,17 @@ int main() { { a aa; ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl // Test this failed. + << ok_a() + << ok_b() // Test b::dtor::post failed... ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { - ok // ... then exec other dtors and check inv on throw (as dtor threw). - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok // ...then exec other dtors and check inv on throw (as dtor threw). + << ok_c(BOOST_CONTRACT_POSTCONDITIONS) ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -128,32 +146,17 @@ int main() { { a aa; ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::dtor::post" << std::endl // Test this failed. + << ok_a() + << ok_b() + << ok_c() // Test c::dtor::post failed... ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { - // ... then exec other dtors and check inv on throw (as dtor threw). + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif + // ...then exec other dtors and check inv on throw (as dtor threw). BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -164,31 +167,17 @@ int main() { { a aa; ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl // Test this failed... + << ok_a() // Test a::dtor::post failed... ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { - ok // ... then exec other dtors and check inv on throw (as dtor threw). - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif + ok // ...then exec other dtors and check inv on throw (as dtor threw). + << ok_b(BOOST_CONTRACT_POSTCONDITIONS) + << ok_c(BOOST_CONTRACT_POSTCONDITIONS) ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/destructor/decl_post_ends.cpp b/test/destructor/decl_post_ends.cpp index 377d01e..c58026d 100644 --- a/test/destructor/decl_post_ends.cpp +++ b/test/destructor/decl_post_ends.cpp @@ -8,6 +8,66 @@ #include #include +#include + +std::string ok_a() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::old" << std::endl + #endif + << "a::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::post" << std::endl // This can fail. + #endif + ; + return ok.str(); +} + +std::string ok_b(bool failure = false) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::old" << std::endl + #endif + << "b::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << (failure ? "b::inv\n" : "") + #endif + ; + return ok.str(); +} + +std::string ok_c(bool failure = false) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::dtor::old" << std::endl + #endif + << "c::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << (failure ? "c::inv\n" : "") + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << (!failure ? "c::dtor::post\n" : "") // This can fail. + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -20,25 +80,9 @@ int main() { out.str(""); } ok.str(""); ok // Test nothing failed. - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::dtor::post" << std::endl + << ok_a() + << ok_b() + << ok_c() ; BOOST_TEST(out.eq(ok.str())); @@ -55,31 +99,17 @@ int main() { { a aa; ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl // Test this failed... + << ok_a() // Test a::dtor::post failed. ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok // ... then exec other dtors and check inv on throw (as dtor threw). - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl + << ok_b(BOOST_CONTRACT_POSTCONDITIONS) + << ok_c(BOOST_CONTRACT_POSTCONDITIONS) ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -93,26 +123,9 @@ int main() { out.str(""); } ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - // Test no failure here. - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::dtor::post" << std::endl + << ok_a() + << ok_b() // Test no b::dtor::post so no failure here. + << ok_c() ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -124,30 +137,16 @@ int main() { { a aa; ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::dtor::post" << std::endl // Test this failed. + << ok_a() + << ok_b() + << ok_c() // Test c::dtor::post failed. ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif // ... then exec other dtors and check inv on throw (as dtor threw). BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -159,31 +158,17 @@ int main() { { a aa; ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl // Test this failed... + << ok_a() // Test a::dtor::post failed. ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok // ... then exec other dtors and check inv on throw (as dtor threw). - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl + << ok_b(BOOST_CONTRACT_POSTCONDITIONS) + << ok_c(BOOST_CONTRACT_POSTCONDITIONS) ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/destructor/decl_post_mid.cpp b/test/destructor/decl_post_mid.cpp index 39e5865..2b59e6a 100644 --- a/test/destructor/decl_post_mid.cpp +++ b/test/destructor/decl_post_mid.cpp @@ -8,6 +8,62 @@ #include #include +#include + +std::string ok_a() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::old" << std::endl + #endif + << "a::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + #endif + ; + return ok.str(); +} + +std::string ok_b(bool failure = false) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::old" << std::endl + #endif + << "b::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::post" << std::endl // This can fail. + #endif + ; + return ok.str(); +} + +std::string ok_c(bool failure = false) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::dtor::old" << std::endl + #endif + << "c::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << (failure ? "c::inv\n" : "") + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -20,24 +76,9 @@ int main() { out.str(""); } ok.str(""); ok // Test nothing failed. - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl + << ok_a() + << ok_b() + << ok_c() ; BOOST_TEST(out.eq(ok.str())); @@ -55,25 +96,10 @@ int main() { a aa; out.str(""); } - ok.str(""); ok // Test nothing failed. - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl + ok.str(""); ok + << ok_a() // Test no a::dtor::post so no failure here. + << ok_b() + << ok_c() ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -85,30 +111,17 @@ int main() { { a aa; ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl // Test this failed. + << ok_a() + << ok_b() // Test b::dtor::post failed. ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok // ... then exec other dtors and check inv on throw (as dtor threw). - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl + << ok_c(BOOST_CONTRACT_POSTCONDITIONS) ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -121,25 +134,10 @@ int main() { a aa; out.str(""); } - ok.str(""); ok // Test nothing failed. - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl + ok.str(""); ok + << ok_a() + << ok_b() + << ok_c() // Test no c::dtor::post so no failure here. ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -151,30 +149,17 @@ int main() { { a aa; ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - << "b::dtor::post" << std::endl // Test this failed. + << ok_a() + << ok_b() // Test b::dtor::post failed. ; out.str(""); } - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok // ... then exec other dtors and check inv on throw (as dtor threw). - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl - << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl + << ok_c(BOOST_CONTRACT_POSTCONDITIONS) ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/destructor/decl_post_none.cpp b/test/destructor/decl_post_none.cpp index 4f29515..57d7cd6 100644 --- a/test/destructor/decl_post_none.cpp +++ b/test/destructor/decl_post_none.cpp @@ -11,23 +11,41 @@ int main() { std::ostringstream ok; ok // Test nothing fails. - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::old" << std::endl + #endif << "a::dtor::body" << std::endl - << "a::static_inv" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + #endif - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::old" << std::endl + #endif << "b::dtor::body" << std::endl - << "b::static_inv" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::dtor::old" << std::endl + #endif << "c::dtor::body" << std::endl - << "c::static_inv" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + #endif ; a_post = true; diff --git a/test/destructor/old_throw.cpp b/test/destructor/old_throw.cpp index 67985d4..4418e1f 100644 --- a/test/destructor/old_throw.cpp +++ b/test/destructor/old_throw.cpp @@ -80,28 +80,55 @@ int main() { a aa; out.str(""); } - BOOST_TEST(false); - } catch(b::err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(b::err const&) { + #endif ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::dtor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::old" << std::endl + #endif << "a::dtor::body" << std::endl - // Test a destructed (so only static_inv and post, but no inv). - << "a::static_inv" << std::endl - << "a::dtor::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + // Test a destructed (so only static_inv and post, but no inv). + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::post" << std::endl + #endif - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::dtor::old" << std::endl // Test this threw. + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::old" << std::endl // Test this threw. + #else + << "b::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + #endif + #endif - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::dtor::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::dtor::old" << std::endl + #endif << "c::dtor::body" << std::endl - // Test c not destructed (so both static_inv and inv, but no post). - << "c::static_inv" << std::endl - << "c::inv" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + // Test c not destructed (so both static_inv and inv). + << "c::inv" << std::endl + #endif + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); }