From 63372678f334ffd640254b32bf7edcd37ab1af6b Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Fri, 8 Jan 2016 05:08:53 -0800 Subject: [PATCH] compiled all tests with contracts on/off on msvc, gcc, and clang --- test/Jamfile.v2 | 30 +- test/destructor/decl_entry_inv_all.cpp | 2 - .../destructor/decl_entry_static_inv_ends.cpp | 2 - test/destructor/decl_post_all.cpp | 12 +- test/destructor/decl_post_ends.cpp | 10 +- test/destructor/decl_post_mid.cpp | 6 +- test/disable/checking.cpp | 63 +- test/function/decl_post_all.cpp | 37 +- test/function/decl_pre_all.cpp | 34 +- test/invariant/combinations.hpp | 657 -------------- test/invariant/decl.hpp | 852 ++++++++++++++++++ .../{only_const.cpp => decl_const.cpp} | 2 +- test/invariant/{only_cv.cpp => decl_cv.cpp} | 2 +- .../{both_cv_const.cpp => decl_cv_const.cpp} | 2 +- .../{no_inv.cpp => decl_nothing.cpp} | 2 +- .../{only_static.cpp => decl_static.cpp} | 2 +- ...static_const.cpp => decl_static_const.cpp} | 2 +- ...{both_static_cv.cpp => decl_static_cv.cpp} | 2 +- ..._cv_const.cpp => decl_static_cv_const.cpp} | 2 +- test/old/no_equal.cpp | 10 +- test/old/no_macros.cpp | 50 +- test/old/noncopyable.cpp | 24 +- test/public_function/decl_entry_inv_all.cpp | 152 +--- test/public_function/decl_entry_inv_ends.cpp | 144 +-- test/public_function/decl_entry_inv_mid.cpp | 138 +-- .../decl_entry_static_inv_all.cpp | 156 +--- .../decl_entry_static_inv_ends.cpp | 122 +-- .../decl_entry_static_inv_mid.cpp | 138 +-- test/public_function/decl_exit_inv_all.cpp | 151 +--- test/public_function/decl_exit_inv_ends.cpp | 149 +-- test/public_function/decl_exit_inv_mid.cpp | 141 +-- .../decl_exit_static_inv_all.cpp | 149 +-- .../decl_exit_static_inv_ends.cpp | 149 +-- .../decl_exit_static_inv_mid.cpp | 145 +-- test/public_function/decl_post_all.cpp | 136 +-- test/public_function/decl_post_ends.cpp | 134 +-- test/public_function/decl_post_mid.cpp | 134 +-- test/public_function/decl_pre_all.cpp | 191 ++-- test/public_function/decl_pre_ends.cpp | 168 ++-- test/public_function/decl_pre_mid.cpp | 146 +-- test/result/mixed_optional.hpp | 280 +++--- test/set/{only_old.cpp => old.cpp} | 4 +- test/set/{both_old_post.cpp => old_post.cpp} | 8 +- test/set/{only_post.cpp => post.cpp} | 4 +- test/set/{only_pre.cpp => pre.cpp} | 4 +- test/set/{both_pre_old.cpp => pre_old.cpp} | 8 +- ...{all_pre_old_post.cpp => pre_old_post.cpp} | 12 +- test/set/{both_pre_post.cpp => pre_post.cpp} | 8 +- 48 files changed, 1940 insertions(+), 2836 deletions(-) delete mode 100644 test/invariant/combinations.hpp create mode 100644 test/invariant/decl.hpp rename test/invariant/{only_const.cpp => decl_const.cpp} (86%) rename test/invariant/{only_cv.cpp => decl_cv.cpp} (86%) rename test/invariant/{both_cv_const.cpp => decl_cv_const.cpp} (86%) rename test/invariant/{no_inv.cpp => decl_nothing.cpp} (86%) rename test/invariant/{only_static.cpp => decl_static.cpp} (86%) rename test/invariant/{both_static_const.cpp => decl_static_const.cpp} (86%) rename test/invariant/{both_static_cv.cpp => decl_static_cv.cpp} (86%) rename test/invariant/{all_static_cv_const.cpp => decl_static_cv_const.cpp} (86%) rename test/set/{only_old.cpp => old.cpp} (87%) rename test/set/{both_old_post.cpp => old_post.cpp} (79%) rename test/set/{only_post.cpp => post.cpp} (87%) rename test/set/{only_pre.cpp => pre.cpp} (87%) rename test/set/{both_pre_old.cpp => pre_old.cpp} (79%) rename test/set/{all_pre_old_post.cpp => pre_old_post.cpp} (73%) rename test/set/{both_pre_post.cpp => pre_post.cpp} (79%) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 9eb5fea..644cc4a 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -145,14 +145,14 @@ test-suite function test-suite invariant : - [ subdir-run-withno invariant : all_static_cv_const ] - [ subdir-run-withno invariant : both_static_cv ] - [ subdir-run-withno invariant : both_cv_const ] - [ subdir-run-withno invariant : both_static_const ] - [ subdir-run-withno invariant : only_static ] - [ subdir-run-withno invariant : only_cv ] - [ subdir-run-withno invariant : only_const ] - [ subdir-run-withno invariant : no_inv ] + [ subdir-run-withno invariant : decl_static_cv_const ] + [ subdir-run-withno invariant : decl_static_cv ] + [ subdir-run-withno invariant : decl_cv_const ] + [ subdir-run-withno invariant : decl_static_const ] + [ subdir-run-withno invariant : decl_static ] + [ subdir-run-withno invariant : decl_cv ] + [ subdir-run-withno invariant : decl_const ] + [ subdir-run-withno invariant : decl_nothing ] [ subdir-compile-fail invariant : static_inv_mutable_error ] [ subdir-run-withno invariant : static_inv_mutable_permissive ] @@ -200,13 +200,13 @@ test-suite disable test-suite set : - [ subdir-run-withno set : all_pre_old_post ] - [ subdir-run-withno set : both_pre_old ] - [ subdir-run-withno set : both_old_post ] - [ subdir-run-withno set : both_pre_post ] - [ subdir-run-withno set : only_pre ] - [ subdir-run-withno set : only_old ] - [ subdir-run-withno set : only_post ] + [ subdir-run-withno set : pre_old_post ] + [ subdir-run-withno set : pre_old ] + [ subdir-run-withno set : old_post ] + [ subdir-run-withno set : pre_post ] + [ subdir-run-withno set : pre ] + [ subdir-run-withno set : old ] + [ subdir-run-withno set : post ] [ subdir-run-withno set : nothing ] [ subdir-run-withno set : no_guard ] diff --git a/test/destructor/decl_entry_inv_all.cpp b/test/destructor/decl_entry_inv_all.cpp index 0987bb4..88404d4 100644 --- a/test/destructor/decl_entry_inv_all.cpp +++ b/test/destructor/decl_entry_inv_all.cpp @@ -80,8 +80,6 @@ std::string ok_c(checked check = passed) { 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; diff --git a/test/destructor/decl_entry_static_inv_ends.cpp b/test/destructor/decl_entry_static_inv_ends.cpp index 3be69d8..c26b329 100644 --- a/test/destructor/decl_entry_static_inv_ends.cpp +++ b/test/destructor/decl_entry_static_inv_ends.cpp @@ -31,8 +31,6 @@ std::string ok_a() { 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 diff --git a/test/destructor/decl_post_all.cpp b/test/destructor/decl_post_all.cpp index b392c96..b2a68ce 100644 --- a/test/destructor/decl_post_all.cpp +++ b/test/destructor/decl_post_all.cpp @@ -30,7 +30,7 @@ std::string ok_a() { return ok.str(); } -std::string ok_b(bool failure = false) { +std::string ok_b(bool threw = false) { std::ostringstream ok; ok #if BOOST_CONTRACT_ENTRY_INVARIANTS << "b::static_inv" << std::endl @@ -42,16 +42,16 @@ std::string ok_b(bool failure = false) { << "b::dtor::body" << std::endl #if BOOST_CONTRACT_EXIT_INVARIANTS << "b::static_inv" << std::endl - << (failure ? "b::inv\n" : "") + << (threw ? "b::inv\n" : "") #endif #if BOOST_CONTRACT_POSTCONDITIONS - << (!failure ? "b::dtor::post\n" : "") // This can fail. + << (!threw ? "b::dtor::post\n" : "") // This can fail. #endif ; return ok.str(); } -std::string ok_c(bool failure = false) { +std::string ok_c(bool threw = false) { std::ostringstream ok; ok #if BOOST_CONTRACT_ENTRY_INVARIANTS << "c::static_inv" << std::endl @@ -63,10 +63,10 @@ std::string ok_c(bool failure = false) { << "c::dtor::body" << std::endl #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::static_inv" << std::endl - << (failure ? "c::inv\n" : "") + << (threw ? "c::inv\n" : "") #endif #if BOOST_CONTRACT_POSTCONDITIONS - << (!failure ? "c::dtor::post\n" : "") // This can fail. + << (!threw ? "c::dtor::post\n" : "") // This can fail. #endif ; return ok.str(); diff --git a/test/destructor/decl_post_ends.cpp b/test/destructor/decl_post_ends.cpp index c58026d..aeb3195 100644 --- a/test/destructor/decl_post_ends.cpp +++ b/test/destructor/decl_post_ends.cpp @@ -30,7 +30,7 @@ std::string ok_a() { return ok.str(); } -std::string ok_b(bool failure = false) { +std::string ok_b(bool threw = false) { std::ostringstream ok; ok #if BOOST_CONTRACT_ENTRY_INVARIANTS << "b::static_inv" << std::endl @@ -42,13 +42,13 @@ std::string ok_b(bool failure = false) { << "b::dtor::body" << std::endl #if BOOST_CONTRACT_EXIT_INVARIANTS << "b::static_inv" << std::endl - << (failure ? "b::inv\n" : "") + << (threw ? "b::inv\n" : "") #endif ; return ok.str(); } -std::string ok_c(bool failure = false) { +std::string ok_c(bool threw = false) { std::ostringstream ok; ok #if BOOST_CONTRACT_ENTRY_INVARIANTS << "c::static_inv" << std::endl @@ -60,10 +60,10 @@ std::string ok_c(bool failure = false) { << "c::dtor::body" << std::endl #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::static_inv" << std::endl - << (failure ? "c::inv\n" : "") + << (threw ? "c::inv\n" : "") #endif #if BOOST_CONTRACT_POSTCONDITIONS - << (!failure ? "c::dtor::post\n" : "") // This can fail. + << (!threw ? "c::dtor::post\n" : "") // This can fail. #endif ; return ok.str(); diff --git a/test/destructor/decl_post_mid.cpp b/test/destructor/decl_post_mid.cpp index 2b59e6a..d3b24f5 100644 --- a/test/destructor/decl_post_mid.cpp +++ b/test/destructor/decl_post_mid.cpp @@ -27,7 +27,7 @@ std::string ok_a() { return ok.str(); } -std::string ok_b(bool failure = false) { +std::string ok_b() { std::ostringstream ok; ok #if BOOST_CONTRACT_ENTRY_INVARIANTS << "b::static_inv" << std::endl @@ -47,7 +47,7 @@ std::string ok_b(bool failure = false) { return ok.str(); } -std::string ok_c(bool failure = false) { +std::string ok_c(bool threw = false) { std::ostringstream ok; ok #if BOOST_CONTRACT_ENTRY_INVARIANTS << "c::static_inv" << std::endl @@ -59,7 +59,7 @@ std::string ok_c(bool failure = false) { << "c::dtor::body" << std::endl #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::static_inv" << std::endl - << (failure ? "c::inv\n" : "") + << (threw ? "c::inv\n" : "") #endif ; return ok.str(); diff --git a/test/disable/checking.cpp b/test/disable/checking.cpp index b8548a7..5d62184 100644 --- a/test/disable/checking.cpp +++ b/test/disable/checking.cpp @@ -72,24 +72,28 @@ int main() { out.str(""); bb.g(); ok.str(""); ok - << "b::static_inv" << std::endl - << "b::inv" << std::endl - - << "b::g::pre" << std::endl - // Test only f's body (but not its contract) executed here. - << "a::f::body" << std::endl - - << "b::g::old" << std::endl - + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_PRECONDITIONS + << "b::g::pre" << std::endl + // Test call while checking executes body (but no contracts). + << "a::f::body" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::g::old" << std::endl + #endif << "b::g::body" << std::endl - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - - // No old call here because not a base object. - << "b::g::post" << std::endl - // Test only f's body (but not its contract) executed here. - << "a::f::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::g::post" << std::endl + // Test call while checking executes body (but no contracts). + << "a::f::body" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); @@ -102,15 +106,24 @@ int main() { call_f(); // Double check a call to f outside another contract checks f's contracts. ok.str(""); ok - << "a::static_inv" << std::endl - << "a::inv" << std::endl - << "a::f::pre" << std::endl - << "a::f::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_PRECONDITIONS + << "a::f::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::f::old" << std::endl + #endif << "a::f::body" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - // No old call here because not a base object. - << "a::f::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/function/decl_post_all.cpp b/test/function/decl_post_all.cpp index 57926d2..69423e3 100644 --- a/test/function/decl_post_all.cpp +++ b/test/function/decl_post_all.cpp @@ -6,14 +6,10 @@ #include #include - -int main() { - std::ostringstream ok; - - f_post = true; - out.str(""); - f(); - ok.str(""); ok +#include + +std::string ok_f() { + std::ostringstream ok; ok #if BOOST_CONTRACT_PRECONDITIONS << "f::pre" << std::endl #endif @@ -22,9 +18,21 @@ int main() { #endif << "f::body" << std::endl #if BOOST_CONTRACT_POSTCONDITIONS - << "f::post" << std::endl // Test no failure here. + << "f::post" << std::endl // This can fail. #endif ; + return ok.str(); +} + +int main() { + std::ostringstream ok; + + f_post = true; + out.str(""); + f(); + ok.str(""); ok // Test nothing failed. + << ok_f() + ; BOOST_TEST(out.eq(ok.str())); struct err {}; @@ -40,16 +48,7 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_PRECONDITIONS - << "f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "f::old" << std::endl - #endif - << "f::body" << std::endl - #if BOOST_CONTRACT_POSTCONDITIONS - << "f::post" << std::endl // Test this failed. - #endif + << ok_f() // Test f::post failed. ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/function/decl_pre_all.cpp b/test/function/decl_pre_all.cpp index f3f637b..4a1123c 100644 --- a/test/function/decl_pre_all.cpp +++ b/test/function/decl_pre_all.cpp @@ -6,6 +6,25 @@ #include #include +#include + +std::string ok_f(bool failed = false) { + std::ostringstream ok; ok + #if BOOST_CONTRACT_PRECONDITIONS + << "f::pre" << std::endl // Test no failure here. + #endif + ; + if(!failed) ok + #if BOOST_CONTRACT_POSTCONDITIONS + << "f::old" << std::endl + #endif + << "f::body" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "f::post" << std::endl + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -14,16 +33,7 @@ int main() { out.str(""); f(); ok.str(""); ok - #if BOOST_CONTRACT_PRECONDITIONS - << "f::pre" << std::endl // Test no failure here. - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "f::old" << std::endl - #endif - << "f::body" << std::endl - #if BOOST_CONTRACT_POSTCONDITIONS - << "f::post" << std::endl - #endif + << ok_f() ; BOOST_TEST(out.eq(ok.str())); @@ -40,9 +50,7 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_PRECONDITIONS - << "f::pre" << std::endl // Test this failed. - #endif + << ok_f(BOOST_CONTRACT_PRECONDITIONS) ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/invariant/combinations.hpp b/test/invariant/combinations.hpp deleted file mode 100644 index a2abdb9..0000000 --- a/test/invariant/combinations.hpp +++ /dev/null @@ -1,657 +0,0 @@ - -// no #include guard - -// Test all invariants combinations (static/cv/const-only) for all operations. - -#include "../aux_/oteststream.hpp" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -boost::contract::aux::test::oteststream out; - -struct b : private boost::contract::constructor_precondition { - // Test also with no base_types. - -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - static void static_invariant() { out << "b::static_inv" << std::endl; } -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - void invariant() const volatile { out << "b::cv_inv" << std::endl; } -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV - void invariant() const { out << "b::const_inv" << std::endl; } -#endif - - b() : boost::contract::constructor_precondition([] { - out << "b::ctor::pre" << std::endl; - }) { - boost::contract::guard c = boost::contract::constructor(this) - .old([] { out << "b::ctor::old" << std::endl; }) - .postcondition([] { out << "b::ctor::post" << std::endl; }) - ; - out << "b::ctor::body" << std::endl; - } - - virtual ~b() { - boost::contract::guard c = boost::contract::destructor(this) - .old([] { out << "b::dtor::old" << std::endl; }) - .postcondition([] { out << "b::dtor::post" << std::endl; }) - ; - out << "b::dtor::body" << std::endl; - } - - virtual void f(char x, boost::contract::virtual_* v = 0) volatile { - boost::contract::guard c = boost::contract::public_function(v, this) - .precondition([&] { - out << "b::f::volatile_pre" << std::endl; - BOOST_CONTRACT_ASSERT(x == 'b'); - }) - .old([] { out << "b::f::volatile_old" << std::endl; }) - .postcondition([] { out << "b::f::volatile_post" << std::endl; }) - ; - out << "b::f::volatile_body" << std::endl; - } - - virtual void f(char x, boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::public_function(v, this) - .precondition([&] { - out << "b::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(x == 'b'); - }) - .old([] { out << "b::f::old" << std::endl; }) - .postcondition([] { out << "b::f::post" << std::endl; }) - ; - out << "b::f::body" << std::endl; - } -}; - -struct a - #define BASES private boost::contract::constructor_precondition, public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - static void static_invariant() { out << "a::static_inv" << std::endl; } -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - void invariant() const volatile { out << "a::cv_inv" << std::endl; } -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV - void invariant() const { out << "a::const_inv" << std::endl; } -#endif - - a() : boost::contract::constructor_precondition([] { - out << "a::ctor::pre" << std::endl; - }) { - boost::contract::guard c = boost::contract::constructor(this) - .old([] { out << "a::ctor::old" << std::endl; }) - .postcondition([] { out << "a::ctor::post" << std::endl; }) - ; - out << "a::ctor::body" << std::endl; - } - - virtual ~a() { - boost::contract::guard c = boost::contract::destructor(this) - .old([] { out << "a::dtor::old" << std::endl; }) - .postcondition([] { out << "a::dtor::post" << std::endl; }) - ; - out << "a::dtor::body" << std::endl; - } - - virtual void f(char x, boost::contract::virtual_* v = 0) - volatile /* override */ { - boost::contract::guard c = boost::contract::public_function< - override_f>( - v, - static_cast(&a::f), - this, x - ) - .precondition([&] { - out << "a::f::volatile_pre" << std::endl; - BOOST_CONTRACT_ASSERT(x == 'a'); - }) - .old([] { out << "a::f::volatile_old" << std::endl; }) - .postcondition([] { out << "a::f::volatile_post" << std::endl; }) - ; - out << "a::f::volatile_body" << std::endl; - } - - virtual void f(char x, boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function< - override_f>( - v, - static_cast(&a::f), - this, x - ) - .precondition([&] { - out << "a::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(x == 'a'); - }) - .old([] { out << "a::f::old" << std::endl; }) - .postcondition([] { out << "a::f::post" << std::endl; }) - ; - out << "a::f::body" << std::endl; - } - - static void s() { - boost::contract::guard c = boost::contract::public_function() - .precondition([] { out << "a::s::pre" << std::endl; }) - .old([] { out << "a::s::old" << std::endl; }) - .postcondition([] { out << "a::s::post" << std::endl; }) - ; - out << "a::s::body" << std::endl; - } - -protected: - void p() volatile { - boost::contract::guard c = boost::contract::function() - .precondition([] { out << "a::p::volatile_pre" << std::endl; }) - .old([] { out << "a::p::volatile_old" << std::endl; }) - .postcondition([] { out << "a::p::volatile_post" << std::endl; }) - ; - out << "a::p::volatile_body" << std::endl; - } - - void p() { - boost::contract::guard c = boost::contract::function() - .precondition([] { out << "a::p::pre" << std::endl; }) - .old([] { out << "a::p::old" << std::endl; }) - .postcondition([] { out << "a::p::post" << std::endl; }) - ; - out << "a::p::body" << std::endl; - } -public: - void call_p() volatile { p(); } - void call_p() { p(); } - -private: - void q() volatile { - boost::contract::guard c = boost::contract::function() - .precondition([] { out << "a::q::volatile_pre" << std::endl; }) - .old([] { out << "a::q::volatile_old" << std::endl; }) - .postcondition([] { out << "a::q::volatile_post" << std::endl; }) - ; - out << "a::q::volatile_body" << std::endl; - } - - void q() { - boost::contract::guard c = boost::contract::function() - .precondition([] { out << "a::q::pre" << std::endl; }) - .old([] { out << "a::q::old" << std::endl; }) - .postcondition([] { out << "a::q::post" << std::endl; }) - ; - out << "a::q::body" << std::endl; - } -public: - void call_q() volatile { q(); } - void call_q() { q(); } - - BOOST_CONTRACT_OVERRIDE(f) -}; - -int main() { - std::ostringstream ok; - - { // Test volatile call with bases. - out.str(""); - a volatile av; - ok.str(""); ok // Ctors always check const_inv (even if volatile). - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "b::static_inv" << std::endl -#endif - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "b::static_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - << "b::cv_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV - << "b::const_inv" << std::endl -#endif - << "b::ctor::post" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "a::static_inv" << std::endl -#endif - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "a::static_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - << "a::cv_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV - << "a::const_inv" << std::endl -#endif - << "a::ctor::post" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - av.f('a'); - ok.str(""); ok // Volatile checks static and cv (but not const) inv. -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "b::static_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - << "b::cv_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "a::static_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - << "a::cv_inv" << std::endl -#endif - << "b::f::volatile_pre" << std::endl - << "a::f::volatile_pre" << std::endl - << "b::f::volatile_old" << std::endl - << "a::f::volatile_old" << std::endl - << "a::f::volatile_body" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "b::static_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - << "b::cv_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "a::static_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - << "a::cv_inv" << std::endl -#endif - << "b::f::volatile_old" << std::endl - << "b::f::volatile_post" << std::endl - // No old call here because not a base object. - << "a::f::volatile_post" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - av.s(); // Test static call. - ok.str(""); ok -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "a::static_inv" << std::endl -#endif - << "a::s::pre" << std::endl - << "a::s::old" << std::endl - << "a::s::body" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "a::static_inv" << std::endl -#endif - << "a::s::post" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - av.call_p(); // Test (indirect) protected call. - ok.str(""); ok - << "a::p::volatile_pre" << std::endl - << "a::p::volatile_old" << std::endl - << "a::p::volatile_body" << std::endl - << "a::p::volatile_post" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - av.call_q(); // Test (indirect) private call. - ok.str(""); ok - << "a::q::volatile_pre" << std::endl - << "a::q::volatile_old" << std::endl - << "a::q::volatile_body" << std::endl - << "a::q::volatile_post" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - } // Call a's destructor. - ok.str(""); ok // Dtors always check const_inv (even if volatile). -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "a::static_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - << "a::cv_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV - << "a::const_inv" << std::endl -#endif - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "a::static_inv" << std::endl -#endif - << "a::dtor::post" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "b::static_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - << "b::cv_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV - << "b::const_inv" << std::endl -#endif - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "b::static_inv" << std::endl -#endif - << "b::dtor::post" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - { // Test non-volatile call with bases. - out.str(""); - a aa; - ok.str(""); ok - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "b::static_inv" << std::endl -#endif - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "b::static_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - << "b::cv_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV - << "b::const_inv" << std::endl -#endif - << "b::ctor::post" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "a::static_inv" << std::endl -#endif - << "a::ctor::old" << std::endl - << "a::ctor::body" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "a::static_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - << "a::cv_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV - << "a::const_inv" << std::endl -#endif - << "a::ctor::post" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - aa.f('a'); - ok.str(""); ok // Mutable checks static, cv, and const-only inv. -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "b::static_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - << "b::cv_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV - << "b::const_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "a::static_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - << "a::cv_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV - << "a::const_inv" << std::endl -#endif - << "b::f::pre" << std::endl - << "a::f::pre" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - << "a::f::body" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "b::static_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - << "b::cv_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV - << "b::const_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "a::static_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - << "a::cv_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV - << "a::const_inv" << std::endl -#endif - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - aa.s(); // Test static call. - ok.str(""); ok -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "a::static_inv" << std::endl -#endif - << "a::s::pre" << std::endl - << "a::s::old" << std::endl - << "a::s::body" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "a::static_inv" << std::endl -#endif - << "a::s::post" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - aa.call_p(); // Test (indirect) protected call. - ok.str(""); ok - << "a::p::pre" << std::endl - << "a::p::old" << std::endl - << "a::p::body" << std::endl - << "a::p::post" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - aa.call_q(); // Test (indirect) private call. - ok.str(""); ok - << "a::q::pre" << std::endl - << "a::q::old" << std::endl - << "a::q::body" << std::endl - << "a::q::post" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - } // Call a's destructor. - ok.str(""); ok -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "a::static_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - << "a::cv_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV - << "a::const_inv" << std::endl -#endif - << "a::dtor::old" << std::endl - << "a::dtor::body" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "a::static_inv" << std::endl -#endif - << "a::dtor::post" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "b::static_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - << "b::cv_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV - << "b::const_inv" << std::endl -#endif - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "b::static_inv" << std::endl -#endif - << "b::dtor::post" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - - { // Test volatile call with no bases. - out.str(""); - b volatile bv; - ok.str(""); ok // Ctors always check const_inv (even if volatile). - << "b::ctor::pre" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "b::static_inv" << std::endl -#endif - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "b::static_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - << "b::cv_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV - << "b::const_inv" << std::endl -#endif - << "b::ctor::post" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - bv.f('b'); - ok.str(""); ok // Volatile checks static and cv (but not const) inv. -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "b::static_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - << "b::cv_inv" << std::endl -#endif - << "b::f::volatile_pre" << std::endl - << "b::f::volatile_old" << std::endl - << "b::f::volatile_body" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "b::static_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - << "b::cv_inv" << std::endl -#endif - << "b::f::volatile_post" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - } // Call b's destructor. - ok.str(""); ok // Dtors always check const_inv (even if volatile). -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "b::static_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - << "b::cv_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV - << "b::const_inv" << std::endl -#endif - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "b::static_inv" << std::endl -#endif - << "b::dtor::post" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - { // Test non-volatile call with no bases. - out.str(""); - b bb; - ok.str(""); ok - << "b::ctor::pre" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "b::static_inv" << std::endl -#endif - << "b::ctor::old" << std::endl - << "b::ctor::body" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "b::static_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - << "b::cv_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV - << "b::const_inv" << std::endl -#endif - << "b::ctor::post" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - bb.f('b'); - ok.str(""); ok // Mutable checks static, cv, and const-only inv. -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "b::static_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - << "b::cv_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV - << "b::const_inv" << std::endl -#endif - << "b::f::pre" << std::endl - << "b::f::old" << std::endl - << "b::f::body" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "b::static_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - << "b::cv_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV - << "b::const_inv" << std::endl -#endif - << "b::f::post" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - } // Call b's destructor. - ok.str(""); ok -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "b::static_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV - << "b::cv_inv" << std::endl -#endif -#ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV - << "b::const_inv" << std::endl -#endif - << "b::dtor::old" << std::endl - << "b::dtor::body" << std::endl -#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV - << "b::static_inv" << std::endl -#endif - << "b::dtor::post" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/invariant/decl.hpp b/test/invariant/decl.hpp new file mode 100644 index 0000000..95ca74a --- /dev/null +++ b/test/invariant/decl.hpp @@ -0,0 +1,852 @@ + +// no #include guard + +// Test with and without all invariants (static/cv/const-only) declarations. + +#include "../aux_/oteststream.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +boost::contract::aux::test::oteststream out; + +struct b : private boost::contract::constructor_precondition { + // Test also with no base_types. + +#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + static void static_invariant() { out << "b::static_inv" << std::endl; } +#endif +#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + void invariant() const volatile { out << "b::cv_inv" << std::endl; } +#endif +#ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV + void invariant() const { out << "b::const_inv" << std::endl; } +#endif + + b() : boost::contract::constructor_precondition([] { + out << "b::ctor::pre" << std::endl; + }) { + boost::contract::guard c = boost::contract::constructor(this) + .old([] { out << "b::ctor::old" << std::endl; }) + .postcondition([] { out << "b::ctor::post" << std::endl; }) + ; + out << "b::ctor::body" << std::endl; + } + + virtual ~b() { + boost::contract::guard c = boost::contract::destructor(this) + .old([] { out << "b::dtor::old" << std::endl; }) + .postcondition([] { out << "b::dtor::post" << std::endl; }) + ; + out << "b::dtor::body" << std::endl; + } + + virtual void f(char x, boost::contract::virtual_* v = 0) volatile { + boost::contract::guard c = boost::contract::public_function(v, this) + .precondition([&] { + out << "b::f::volatile_pre" << std::endl; + BOOST_CONTRACT_ASSERT(x == 'b'); + }) + .old([] { out << "b::f::volatile_old" << std::endl; }) + .postcondition([] { out << "b::f::volatile_post" << std::endl; }) + ; + out << "b::f::volatile_body" << std::endl; + } + + virtual void f(char x, boost::contract::virtual_* v = 0) { + boost::contract::guard c = boost::contract::public_function(v, this) + .precondition([&] { + out << "b::f::pre" << std::endl; + BOOST_CONTRACT_ASSERT(x == 'b'); + }) + .old([] { out << "b::f::old" << std::endl; }) + .postcondition([] { out << "b::f::post" << std::endl; }) + ; + out << "b::f::body" << std::endl; + } +}; + +struct a + #define BASES private boost::contract::constructor_precondition, public b + : BASES +{ + typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; + #undef BASES + +#ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + static void static_invariant() { out << "a::static_inv" << std::endl; } +#endif +#ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + void invariant() const volatile { out << "a::cv_inv" << std::endl; } +#endif +#ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV + void invariant() const { out << "a::const_inv" << std::endl; } +#endif + + a() : boost::contract::constructor_precondition([] { + out << "a::ctor::pre" << std::endl; + }) { + boost::contract::guard c = boost::contract::constructor(this) + .old([] { out << "a::ctor::old" << std::endl; }) + .postcondition([] { out << "a::ctor::post" << std::endl; }) + ; + out << "a::ctor::body" << std::endl; + } + + virtual ~a() { + boost::contract::guard c = boost::contract::destructor(this) + .old([] { out << "a::dtor::old" << std::endl; }) + .postcondition([] { out << "a::dtor::post" << std::endl; }) + ; + out << "a::dtor::body" << std::endl; + } + + virtual void f(char x, boost::contract::virtual_* v = 0) + volatile /* override */ { + boost::contract::guard c = boost::contract::public_function< + override_f>( + v, + static_cast(&a::f), + this, x + ) + .precondition([&] { + out << "a::f::volatile_pre" << std::endl; + BOOST_CONTRACT_ASSERT(x == 'a'); + }) + .old([] { out << "a::f::volatile_old" << std::endl; }) + .postcondition([] { out << "a::f::volatile_post" << std::endl; }) + ; + out << "a::f::volatile_body" << std::endl; + } + + virtual void f(char x, boost::contract::virtual_* v = 0) /* override */ { + boost::contract::guard c = boost::contract::public_function< + override_f>( + v, + static_cast(&a::f), + this, x + ) + .precondition([&] { + out << "a::f::pre" << std::endl; + BOOST_CONTRACT_ASSERT(x == 'a'); + }) + .old([] { out << "a::f::old" << std::endl; }) + .postcondition([] { out << "a::f::post" << std::endl; }) + ; + out << "a::f::body" << std::endl; + } + + static void s() { + boost::contract::guard c = boost::contract::public_function() + .precondition([] { out << "a::s::pre" << std::endl; }) + .old([] { out << "a::s::old" << std::endl; }) + .postcondition([] { out << "a::s::post" << std::endl; }) + ; + out << "a::s::body" << std::endl; + } + +protected: + void p() volatile { + boost::contract::guard c = boost::contract::function() + .precondition([] { out << "a::p::volatile_pre" << std::endl; }) + .old([] { out << "a::p::volatile_old" << std::endl; }) + .postcondition([] { out << "a::p::volatile_post" << std::endl; }) + ; + out << "a::p::volatile_body" << std::endl; + } + + void p() { + boost::contract::guard c = boost::contract::function() + .precondition([] { out << "a::p::pre" << std::endl; }) + .old([] { out << "a::p::old" << std::endl; }) + .postcondition([] { out << "a::p::post" << std::endl; }) + ; + out << "a::p::body" << std::endl; + } +public: + void call_p() volatile { p(); } + void call_p() { p(); } + +private: + void q() volatile { + boost::contract::guard c = boost::contract::function() + .precondition([] { out << "a::q::volatile_pre" << std::endl; }) + .old([] { out << "a::q::volatile_old" << std::endl; }) + .postcondition([] { out << "a::q::volatile_post" << std::endl; }) + ; + out << "a::q::volatile_body" << std::endl; + } + + void q() { + boost::contract::guard c = boost::contract::function() + .precondition([] { out << "a::q::pre" << std::endl; }) + .old([] { out << "a::q::old" << std::endl; }) + .postcondition([] { out << "a::q::post" << std::endl; }) + ; + out << "a::q::body" << std::endl; + } +public: + void call_q() volatile { q(); } + void call_q() { q(); } + + BOOST_CONTRACT_OVERRIDE(f) +}; + +int main() { + std::ostringstream ok; + + { // Test volatile call with bases. + out.str(""); + a volatile av; + ok.str(""); ok // Ctors always check const_inv (even if volatile). + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "b::static_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "b::static_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + << "b::cv_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV + << "b::const_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "a::static_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "a::static_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + << "a::cv_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV + << "a::const_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + out.str(""); + av.f('a'); + ok.str(""); ok // Volatile checks static and cv (but not const) inv. + #if BOOST_CONTRACT_ENTRY_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "b::static_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + << "b::cv_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "a::static_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + << "a::cv_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_PRECONDITIONS + << "b::f::volatile_pre" << std::endl + << "a::f::volatile_pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::f::volatile_old" << std::endl + << "a::f::volatile_old" << std::endl + #endif + << "a::f::volatile_body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "b::static_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + << "b::cv_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "a::static_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + << "a::cv_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::f::volatile_old" << std::endl + << "b::f::volatile_post" << std::endl + << "a::f::volatile_post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + out.str(""); + av.s(); // Test static call. + ok.str(""); ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "a::static_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_PRECONDITIONS + << "a::s::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::s::old" << std::endl + #endif + << "a::s::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "a::static_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::s::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + out.str(""); + av.call_p(); // Test (indirect) protected call. + ok.str(""); ok + #if BOOST_CONTRACT_PRECONDITIONS + << "a::p::volatile_pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::p::volatile_old" << std::endl + #endif + << "a::p::volatile_body" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::p::volatile_post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + out.str(""); + av.call_q(); // Test (indirect) private call. + ok.str(""); ok + #if BOOST_CONTRACT_PRECONDITIONS + << "a::q::volatile_pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::q::volatile_old" << std::endl + #endif + << "a::q::volatile_body" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::q::volatile_post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + out.str(""); + } // Call a's destructor. + ok.str(""); ok // Dtors always check const_inv (even if volatile). + #if BOOST_CONTRACT_ENTRY_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "a::static_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + << "a::cv_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV + << "a::const_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::old" << std::endl + #endif + << "a::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "a::static_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "b::static_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + << "b::cv_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV + << "b::const_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::old" << std::endl + #endif + << "b::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "b::static_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + { // Test non-volatile call with bases. + out.str(""); + a aa; + ok.str(""); ok + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "b::static_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "b::static_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + << "b::cv_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV + << "b::const_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "a::static_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "a::static_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + << "a::cv_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV + << "a::const_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + out.str(""); + aa.f('a'); + ok.str(""); ok // Mutable checks static, cv, and const-only inv. + #if BOOST_CONTRACT_ENTRY_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "b::static_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + << "b::cv_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV + << "b::const_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "a::static_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + << "a::cv_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV + << "a::const_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_PRECONDITIONS + << "b::f::pre" << std::endl + << "a::f::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::f::old" << std::endl + << "a::f::old" << std::endl + #endif + << "a::f::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "b::static_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + << "b::cv_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV + << "b::const_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "a::static_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + << "a::cv_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV + << "a::const_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::f::old" << std::endl + << "b::f::post" << std::endl + << "a::f::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + out.str(""); + aa.s(); // Test static call. + ok.str(""); ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "a::static_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_PRECONDITIONS + << "a::s::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::s::old" << std::endl + #endif + << "a::s::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "a::static_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::s::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + out.str(""); + aa.call_p(); // Test (indirect) protected call. + ok.str(""); ok + #if BOOST_CONTRACT_PRECONDITIONS + << "a::p::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::p::old" << std::endl + #endif + << "a::p::body" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::p::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + out.str(""); + aa.call_q(); // Test (indirect) private call. + ok.str(""); ok + #if BOOST_CONTRACT_PRECONDITIONS + << "a::q::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::q::old" << std::endl + #endif + << "a::q::body" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::q::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + out.str(""); + } // Call a's destructor. + ok.str(""); ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "a::static_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + << "a::cv_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV + << "a::const_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::old" << std::endl + #endif + << "a::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "a::static_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "b::static_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + << "b::cv_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV + << "b::const_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::old" << std::endl + #endif + << "b::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "b::static_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + + { // Test volatile call with no bases. + out.str(""); + b volatile bv; + ok.str(""); ok // Ctors always check const_inv (even if volatile). + #if BOOST_CONTRACT_PRECONDITIONS + << "b::ctor::pre" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "b::static_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "b::static_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + << "b::cv_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV + << "b::const_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + out.str(""); + bv.f('b'); + ok.str(""); ok // Volatile checks static and cv (but not const) inv. + #if BOOST_CONTRACT_ENTRY_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "b::static_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + << "b::cv_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_PRECONDITIONS + << "b::f::volatile_pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::f::volatile_old" << std::endl + #endif + << "b::f::volatile_body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "b::static_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + << "b::cv_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::f::volatile_post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + out.str(""); + } // Call b's destructor. + ok.str(""); ok // Dtors always check const_inv (even if volatile). + #if BOOST_CONTRACT_ENTRY_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "b::static_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + << "b::cv_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV + << "b::const_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::old" << std::endl + #endif + << "b::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "b::static_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + { // Test non-volatile call with no bases. + out.str(""); + b bb; + ok.str(""); ok + #if BOOST_CONTRACT_PRECONDITIONS + << "b::ctor::pre" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "b::static_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "b::static_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + << "b::cv_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV + << "b::const_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + out.str(""); + bb.f('b'); + ok.str(""); ok // Mutable checks static, cv, and const-only inv. + #if BOOST_CONTRACT_ENTRY_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "b::static_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + << "b::cv_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV + << "b::const_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_PRECONDITIONS + << "b::f::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::f::old" << std::endl + #endif + << "b::f::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "b::static_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + << "b::cv_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV + << "b::const_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::f::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + out.str(""); + } // Call b's destructor. + ok.str(""); ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "b::static_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CV_INV + << "b::cv_inv" << std::endl + #endif + #ifdef BOOST_CONTRACT_AUX_TEST_CONST_INV + << "b::const_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::old" << std::endl + #endif + << "b::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + #ifdef BOOST_CONTRACT_AUX_TEST_STATIC_INV + << "b::static_inv" << std::endl + #endif + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + return boost::report_errors(); +} + diff --git a/test/invariant/only_const.cpp b/test/invariant/decl_const.cpp similarity index 86% rename from test/invariant/only_const.cpp rename to test/invariant/decl_const.cpp index a708b94..b6d5066 100644 --- a/test/invariant/only_const.cpp +++ b/test/invariant/decl_const.cpp @@ -4,5 +4,5 @@ #undef BOOST_CONTRACT_AUX_TEST_STATIC_INV #undef BOOST_CONTRACT_AUX_TEST_CV_INV #define BOOST_CONTRACT_AUX_TEST_CONST_INV -#include "combinations.hpp" +#include "decl.hpp" diff --git a/test/invariant/only_cv.cpp b/test/invariant/decl_cv.cpp similarity index 86% rename from test/invariant/only_cv.cpp rename to test/invariant/decl_cv.cpp index 6ca2f7c..e4362c3 100644 --- a/test/invariant/only_cv.cpp +++ b/test/invariant/decl_cv.cpp @@ -4,5 +4,5 @@ #undef BOOST_CONTRACT_AUX_TEST_STATIC_INV #define BOOST_CONTRACT_AUX_TEST_CV_INV #undef BOOST_CONTRACT_AUX_TEST_CONST_INV -#include "combinations.hpp" +#include "decl.hpp" diff --git a/test/invariant/both_cv_const.cpp b/test/invariant/decl_cv_const.cpp similarity index 86% rename from test/invariant/both_cv_const.cpp rename to test/invariant/decl_cv_const.cpp index 6c87aaf..4bd61c8 100644 --- a/test/invariant/both_cv_const.cpp +++ b/test/invariant/decl_cv_const.cpp @@ -4,5 +4,5 @@ #undef BOOST_CONTRACT_AUX_TEST_STATIC_INV #define BOOST_CONTRACT_AUX_TEST_CV_INV #define BOOST_CONTRACT_AUX_TEST_CONST_INV -#include "combinations.hpp" +#include "decl.hpp" diff --git a/test/invariant/no_inv.cpp b/test/invariant/decl_nothing.cpp similarity index 86% rename from test/invariant/no_inv.cpp rename to test/invariant/decl_nothing.cpp index 433acf7..0291227 100644 --- a/test/invariant/no_inv.cpp +++ b/test/invariant/decl_nothing.cpp @@ -4,5 +4,5 @@ #undef BOOST_CONTRACT_AUX_TEST_STATIC_INV #undef BOOST_CONTRACT_AUX_TEST_CV_INV #undef BOOST_CONTRACT_AUX_TEST_CONST_INV -#include "combinations.hpp" +#include "decl.hpp" diff --git a/test/invariant/only_static.cpp b/test/invariant/decl_static.cpp similarity index 86% rename from test/invariant/only_static.cpp rename to test/invariant/decl_static.cpp index 7862e5b..efd7e00 100644 --- a/test/invariant/only_static.cpp +++ b/test/invariant/decl_static.cpp @@ -4,5 +4,5 @@ #define BOOST_CONTRACT_AUX_TEST_STATIC_INV #undef BOOST_CONTRACT_AUX_TEST_CV_INV #undef BOOST_CONTRACT_AUX_TEST_CONST_INV -#include "combinations.hpp" +#include "decl.hpp" diff --git a/test/invariant/both_static_const.cpp b/test/invariant/decl_static_const.cpp similarity index 86% rename from test/invariant/both_static_const.cpp rename to test/invariant/decl_static_const.cpp index 540b05f..9404e41 100644 --- a/test/invariant/both_static_const.cpp +++ b/test/invariant/decl_static_const.cpp @@ -4,5 +4,5 @@ #define BOOST_CONTRACT_AUX_TEST_STATIC_INV #undef BOOST_CONTRACT_AUX_TEST_CV_INV #define BOOST_CONTRACT_AUX_TEST_CONST_INV -#include "combinations.hpp" +#include "decl.hpp" diff --git a/test/invariant/both_static_cv.cpp b/test/invariant/decl_static_cv.cpp similarity index 86% rename from test/invariant/both_static_cv.cpp rename to test/invariant/decl_static_cv.cpp index 59d9dd3..579ca48 100644 --- a/test/invariant/both_static_cv.cpp +++ b/test/invariant/decl_static_cv.cpp @@ -4,5 +4,5 @@ #define BOOST_CONTRACT_AUX_TEST_STATIC_INV #define BOOST_CONTRACT_AUX_TEST_CV_INV #undef BOOST_CONTRACT_AUX_TEST_CONST_INV -#include "combinations.hpp" +#include "decl.hpp" diff --git a/test/invariant/all_static_cv_const.cpp b/test/invariant/decl_static_cv_const.cpp similarity index 86% rename from test/invariant/all_static_cv_const.cpp rename to test/invariant/decl_static_cv_const.cpp index 75e368e..62d391e 100644 --- a/test/invariant/all_static_cv_const.cpp +++ b/test/invariant/decl_static_cv_const.cpp @@ -4,5 +4,5 @@ #define BOOST_CONTRACT_AUX_TEST_STATIC_INV #define BOOST_CONTRACT_AUX_TEST_CV_INV #define BOOST_CONTRACT_AUX_TEST_CONST_INV -#include "combinations.hpp" +#include "decl.hpp" diff --git a/test/old/no_equal.cpp b/test/old/no_equal.cpp index c665461..b1c5a92 100644 --- a/test/old/no_equal.cpp +++ b/test/old/no_equal.cpp @@ -40,12 +40,20 @@ int main() { equal_skips = 0; push_back(vi, 123); BOOST_TEST_EQ(equal_skips, 0); + + unsigned const cnt = + #if BOOST_CONTRACT_POSTCONDITIONS + 1 + #else + 0 + #endif + ; j jj(456); std::vector vj; equal_skips = 0; push_back(vj, jj); - BOOST_TEST_EQ(equal_skips, 1); + BOOST_TEST_EQ(equal_skips, cnt); return boost::report_errors(); } diff --git a/test/old/no_macros.cpp b/test/old/no_macros.cpp index e548ab0..8b7d6cb 100644 --- a/test/old/no_macros.cpp +++ b/test/old/no_macros.cpp @@ -112,20 +112,34 @@ int main() { swap(x, y); ok.str(""); ok - << "swap::pre" << std::endl - << "swap::old" << std::endl + #if BOOST_CONTRACT_PRECONDITIONS + << "swap::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "swap::old" << std::endl + #endif << "swap::body" << std::endl - << "swap::post" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "swap::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); + + unsigned const cnt = + #if BOOST_CONTRACT_POSTCONDITIONS + 1 + #else + 0 + #endif + ; BOOST_TEST_EQ(x.value, 'b'); - BOOST_TEST_EQ(x.copies(), 1); - BOOST_TEST_EQ(x.evals(), 1); + BOOST_TEST_EQ(x.copies(), cnt); + BOOST_TEST_EQ(x.evals(), cnt); BOOST_TEST_EQ(y.value, 'a'); - BOOST_TEST_EQ(y.copies(), 1); - BOOST_TEST_EQ(y.evals(), 1); + BOOST_TEST_EQ(y.copies(), cnt); + BOOST_TEST_EQ(y.evals(), cnt); a aa; i_type i; i.value = 1; @@ -134,21 +148,27 @@ int main() { aa.swap(i, j); ok.str(""); ok - << "b::swap::pre" << std::endl - << "b::swap::old" << std::endl + #if BOOST_CONTRACT_PRECONDITIONS + << "b::swap::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::swap::old" << std::endl + #endif << "a::swap::body" << std::endl - << "b::swap::old" << std::endl - << "b::swap::post" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::swap::old" << std::endl + << "b::swap::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); BOOST_TEST_EQ(i.value, 2); - BOOST_TEST_EQ(i.copies(), 1); - BOOST_TEST_EQ(i.evals(), 1); + BOOST_TEST_EQ(i.copies(), cnt); + BOOST_TEST_EQ(i.evals(), cnt); BOOST_TEST_EQ(j.value, 1); - BOOST_TEST_EQ(j.copies(), 1); - BOOST_TEST_EQ(j.evals(), 1); + BOOST_TEST_EQ(j.copies(), cnt); + BOOST_TEST_EQ(j.evals(), cnt); return boost::report_errors(); } diff --git a/test/old/noncopyable.cpp b/test/old/noncopyable.cpp index 6ba19b3..da9e289 100644 --- a/test/old/noncopyable.cpp +++ b/test/old/noncopyable.cpp @@ -101,29 +101,45 @@ int main() { // Test free functions (old values without `v`). + unsigned cnt = + #if BOOST_CONTRACT_POSTCONDITIONS + 1 + #else + 0 + #endif + ; + old_checks = 0; next(i); - BOOST_TEST_EQ(old_checks, 1); + BOOST_TEST_EQ(old_checks, cnt); old_checks = 0; next(c); - BOOST_TEST_EQ(old_checks, 1); + BOOST_TEST_EQ(old_checks, cnt); old_checks = 0; next(n); BOOST_TEST_EQ(old_checks, 0); // Test virtual functions (old values with `v`). + + cnt = + #if BOOST_CONTRACT_POSTCONDITIONS + 2 + #else + 0 + #endif + ; a ai; old_checks = 0; ai.next(i); - BOOST_TEST_EQ(old_checks, 2); + BOOST_TEST_EQ(old_checks, cnt); a ac; old_checks = 0; ac.next(c); - BOOST_TEST_EQ(old_checks, 2); + BOOST_TEST_EQ(old_checks, cnt); a an; old_checks = 0; diff --git a/test/public_function/decl_entry_inv_all.cpp b/test/public_function/decl_entry_inv_all.cpp index 3c7f52b..fca4114 100644 --- a/test/public_function/decl_entry_inv_all.cpp +++ b/test/public_function/decl_entry_inv_all.cpp @@ -9,28 +9,10 @@ #include #include #include - -int main() { - std::ostringstream ok; - - a aa; - - a_entry_inv = true; - b_entry_inv = true; - c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif +#include + +std::string ok_end() { + std::ostringstream ok; ok #if BOOST_CONTRACT_PRECONDITIONS << "c::f::pre" << std::endl #endif @@ -56,6 +38,32 @@ int main() { << "a::f::post" << std::endl #endif ; + return ok.str(); +} + +int main() { + std::ostringstream ok; + + a aa; + + a_entry_inv = true; + b_entry_inv = true; + c_entry_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); + out.str(""); + aa.f(); + ok.str(""); ok // Test nothing failed. + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + << "b::static_inv" << std::endl + << "b::inv" << std::endl + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + << ok_end() + ; BOOST_TEST(out.eq(ok.str())); struct err {}; @@ -83,30 +91,7 @@ int main() { << "a::static_inv" << std::endl << "a::inv" << std::endl // Test this failed. #else - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -131,30 +116,7 @@ int main() { << "b::static_inv" << std::endl << "b::inv" << std::endl // Test this failed. #else - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -177,30 +139,7 @@ int main() { << "c::static_inv" << std::endl << "c::inv" << std::endl // Test this failed. #else - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -223,30 +162,7 @@ int main() { << "c::static_inv" << std::endl << "c::inv" << std::endl // Test this failed (as all did). #else - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/public_function/decl_entry_inv_ends.cpp b/test/public_function/decl_entry_inv_ends.cpp index 69e7469..2a1f606 100644 --- a/test/public_function/decl_entry_inv_ends.cpp +++ b/test/public_function/decl_entry_inv_ends.cpp @@ -9,27 +9,10 @@ #include #include #include +#include -int main() { - std::ostringstream ok; - - a aa; - - a_entry_inv = true; - b_entry_inv = true; - c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif +std::string ok_end() { + std::ostringstream ok; ok #if BOOST_CONTRACT_PRECONDITIONS << "c::f::pre" << std::endl #endif @@ -54,6 +37,31 @@ int main() { << "a::f::post" << std::endl #endif ; + return ok.str(); +} + +int main() { + std::ostringstream ok; + + a aa; + + a_entry_inv = true; + b_entry_inv = true; + c_entry_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); + out.str(""); + aa.f(); + ok.str(""); ok // Test nothing failed. + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + << "b::static_inv" << std::endl + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + << ok_end() + ; BOOST_TEST(out.eq(ok.str())); struct err {}; @@ -80,29 +88,7 @@ int main() { << "a::static_inv" << std::endl << "a::inv" << std::endl // Test this failed. #else - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -124,29 +110,7 @@ int main() { << "a::static_inv" << std::endl << "a::inv" << std::endl #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -168,29 +132,7 @@ int main() { << "c::static_inv" << std::endl << "c::inv" << std::endl // Test this failed. #else - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -213,29 +155,7 @@ int main() { << "c::static_inv" << std::endl << "c::inv" << std::endl // Test this failed (as all did). #else - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/public_function/decl_entry_inv_mid.cpp b/test/public_function/decl_entry_inv_mid.cpp index 3349df3..10095ac 100644 --- a/test/public_function/decl_entry_inv_mid.cpp +++ b/test/public_function/decl_entry_inv_mid.cpp @@ -9,26 +9,10 @@ #include #include #include +#include -int main() { - std::ostringstream ok; - - a aa; - - a_entry_inv = true; - b_entry_inv = true; - c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - #endif +std::string ok_end() { + std::ostringstream ok; ok #if BOOST_CONTRACT_PRECONDITIONS << "c::f::pre" << std::endl #endif @@ -52,6 +36,30 @@ int main() { << "a::f::post" << std::endl #endif ; + return ok.str(); +} + +int main() { + std::ostringstream ok; + + a aa; + + a_entry_inv = true; + b_entry_inv = true; + c_entry_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); + out.str(""); + aa.f(); + ok.str(""); ok // Test nothing failed. + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "b::static_inv" << std::endl + << "b::inv" << std::endl + << "a::static_inv" << std::endl + #endif + << ok_end() + ; BOOST_TEST(out.eq(ok.str())); struct err {}; @@ -73,28 +81,7 @@ int main() { << "b::inv" << std::endl << "a::static_inv" << std::endl #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -117,28 +104,7 @@ int main() { << "b::static_inv" << std::endl << "b::inv" << std::endl // Test this fail. #else - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -159,28 +125,7 @@ int main() { << "b::inv" << std::endl << "a::static_inv" << std::endl #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -203,28 +148,7 @@ int main() { << "b::static_inv" << std::endl << "b::inv" << std::endl // Test this failed (as all did). #else - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/public_function/decl_entry_static_inv_all.cpp b/test/public_function/decl_entry_static_inv_all.cpp index 7cc28b9..38cfea3 100644 --- a/test/public_function/decl_entry_static_inv_all.cpp +++ b/test/public_function/decl_entry_static_inv_all.cpp @@ -9,6 +9,37 @@ #include #include #include +#include + +std::string ok_end() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_PRECONDITIONS + << "c::f::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::f::old" << std::endl + << "b::f::old" << std::endl + << "a::f::old" << std::endl + #endif + << "a::f::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + << "b::static_inv" << std::endl + << "b::inv" << std::endl + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::f::old" << std::endl + << "c::f::post" << std::endl + << "b::f::old" << std::endl + << "b::f::post" << std::endl + << "a::f::post" << std::endl + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -32,30 +63,7 @@ int main() { << "a::static_inv" << std::endl << "a::inv" << std::endl #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl // Test only c pre checked. - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() ; BOOST_TEST(out.eq(ok.str())); @@ -84,30 +92,7 @@ int main() { << "b::inv" << std::endl << "a::static_inv" << std::endl // Test this failed. #else - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -132,30 +117,7 @@ int main() { << "c::inv" << std::endl << "b::static_inv" << std::endl // Test this failed. #else - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -178,30 +140,7 @@ int main() { #if BOOST_CONTRACT_ENTRY_INVARIANTS << "c::static_inv" << std::endl // Test this failed. #else - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -225,30 +164,7 @@ int main() { // Test this failed (as all did). << "c::static_inv" << std::endl #else - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/public_function/decl_entry_static_inv_ends.cpp b/test/public_function/decl_entry_static_inv_ends.cpp index 44a0328..4da7c6a 100644 --- a/test/public_function/decl_entry_static_inv_ends.cpp +++ b/test/public_function/decl_entry_static_inv_ends.cpp @@ -9,27 +9,10 @@ #include #include #include - -int main() { - std::ostringstream ok; - - a aa; - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); - out.str(""); - aa.f(); - ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif +#include + +std::string ok_end() { + std::ostringstream ok; ok #if BOOST_CONTRACT_PRECONDITIONS << "c::f::pre" << std::endl #endif @@ -54,6 +37,31 @@ int main() { << "a::f::post" << std::endl #endif ; + return ok.str(); +} + +int main() { + std::ostringstream ok; + + a aa; + + a_entry_static_inv = true; + b_entry_static_inv = true; + c_entry_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); + out.str(""); + aa.f(); + ok.str(""); ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + << "b::inv" << std::endl + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + << ok_end() + ; BOOST_TEST(out.eq(ok.str())); struct err {}; @@ -79,29 +87,7 @@ int main() { << "b::inv" << std::endl << "a::static_inv" << std::endl // Test this failed. #else - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -165,29 +151,7 @@ int main() { #if BOOST_CONTRACT_ENTRY_INVARIANTS << "c::static_inv" << std::endl // Test this failed. #else - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -210,29 +174,7 @@ int main() { // Test this failed (as all did). << "c::static_inv" << std::endl #else - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/public_function/decl_entry_static_inv_mid.cpp b/test/public_function/decl_entry_static_inv_mid.cpp index 433c6b4..562bd2b 100644 --- a/test/public_function/decl_entry_static_inv_mid.cpp +++ b/test/public_function/decl_entry_static_inv_mid.cpp @@ -9,26 +9,10 @@ #include #include #include +#include -int main() { - std::ostringstream ok; - - a aa; - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - #endif +std::string ok_end() { + std::ostringstream ok; ok #if BOOST_CONTRACT_PRECONDITIONS << "c::f::pre" << std::endl #endif @@ -52,6 +36,30 @@ int main() { << "a::f::post" << std::endl #endif ; + return ok.str(); +} + +int main() { + std::ostringstream ok; + + a aa; + + a_entry_static_inv = true; + b_entry_static_inv = true; + c_entry_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); + out.str(""); + aa.f(); + ok.str(""); ok // Test nothing failed. + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::inv" << std::endl + << "b::static_inv" << std::endl + << "b::inv" << std::endl + << "a::inv" << std::endl + #endif + << ok_end() + ; BOOST_TEST(out.eq(ok.str())); struct err {}; @@ -72,28 +80,7 @@ int main() { << "b::inv" << std::endl << "a::inv" << std::endl #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -115,28 +102,7 @@ int main() { << "c::inv" << std::endl << "b::static_inv" << std::endl // Test this fail. #else - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -156,28 +122,7 @@ int main() { << "b::inv" << std::endl << "a::inv" << std::endl #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -200,28 +145,7 @@ int main() { // Test this failed (as all did). << "b::static_inv" << std::endl #else - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/public_function/decl_exit_inv_all.cpp b/test/public_function/decl_exit_inv_all.cpp index 5b051c2..b42badb 100644 --- a/test/public_function/decl_exit_inv_all.cpp +++ b/test/public_function/decl_exit_inv_all.cpp @@ -9,20 +9,10 @@ #include #include #include +#include -int main() { - std::ostringstream ok; - - a aa; - - a_exit_inv = true; - b_exit_inv = true; - c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. +std::string ok_begin() { + std::ostringstream ok; ok #if BOOST_CONTRACT_ENTRY_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl @@ -40,6 +30,37 @@ int main() { << "a::f::old" << std::endl #endif << "a::f::body" << std::endl + ; + return ok.str(); +} + +std::string ok_end() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::f::old" << std::endl + << "c::f::post" << std::endl + << "b::f::old" << std::endl + << "b::f::post" << std::endl + << "a::f::post" << std::endl + #endif + ; + return ok.str(); +} + +int main() { + std::ostringstream ok; + + a aa; + + a_exit_inv = true; + b_exit_inv = true; + c_exit_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); + out.str(""); + aa.f(); + ok.str(""); ok // Test nothing failed. + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl @@ -48,13 +69,7 @@ int main() { << "a::static_inv" << std::endl << "a::inv" << std::endl #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() ; BOOST_TEST(out.eq(ok.str())); @@ -75,23 +90,7 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl @@ -100,11 +99,7 @@ int main() { << "a::static_inv" << std::endl << "a::inv" << std::endl // Test this failed. #elif BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -123,34 +118,14 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl << "b::static_inv" << std::endl << "b::inv" << std::endl // Test this failed. #elif BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -169,32 +144,12 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl // Test this failed. #elif BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -213,32 +168,12 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl // Test this failed (as all did). #elif BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/public_function/decl_exit_inv_ends.cpp b/test/public_function/decl_exit_inv_ends.cpp index 951495f..8f7d543 100644 --- a/test/public_function/decl_exit_inv_ends.cpp +++ b/test/public_function/decl_exit_inv_ends.cpp @@ -9,20 +9,10 @@ #include #include #include +#include -int main() { - std::ostringstream ok; - - a aa; - - a_exit_inv = true; - b_exit_inv = true; - c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. +std::string ok_begin() { + std::ostringstream ok; ok #if BOOST_CONTRACT_ENTRY_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl @@ -39,13 +29,12 @@ int main() { << "a::f::old" << std::endl #endif << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif + ; + return ok.str(); +} + +std::string ok_end() { + std::ostringstream ok; ok #if BOOST_CONTRACT_POSTCONDITIONS << "c::f::old" << std::endl << "c::f::post" << std::endl @@ -54,6 +43,32 @@ int main() { << "a::f::post" << std::endl #endif ; + return ok.str(); +} + +int main() { + std::ostringstream ok; + + a aa; + + a_exit_inv = true; + b_exit_inv = true; + c_exit_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); + out.str(""); + aa.f(); + ok.str(""); ok // Test nothing failed. + << ok_begin() + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + << "b::static_inv" << std::endl + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + << ok_end() + ; BOOST_TEST(out.eq(ok.str())); struct err {}; @@ -73,22 +88,7 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl @@ -96,11 +96,7 @@ int main() { << "a::static_inv" << std::endl << "a::inv" << std::endl // Test this failed. #elif BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -115,22 +111,7 @@ int main() { try { aa.f(); ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl @@ -138,13 +119,7 @@ int main() { << "a::static_inv" << std::endl << "a::inv" << std::endl #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -162,31 +137,12 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl // Test this failed. #elif BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -205,31 +161,12 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl // Test this failed (as all did). #elif BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/public_function/decl_exit_inv_mid.cpp b/test/public_function/decl_exit_inv_mid.cpp index a8a6963..c41dd5c 100644 --- a/test/public_function/decl_exit_inv_mid.cpp +++ b/test/public_function/decl_exit_inv_mid.cpp @@ -9,20 +9,10 @@ #include #include #include +#include -int main() { - std::ostringstream ok; - - a aa; - - a_exit_inv = true; - b_exit_inv = true; - c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. +std::string ok_begin() { + std::ostringstream ok; ok #if BOOST_CONTRACT_ENTRY_INVARIANTS << "c::static_inv" << std::endl << "b::static_inv" << std::endl @@ -38,12 +28,12 @@ int main() { << "a::f::old" << std::endl #endif << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - #endif + ; + return ok.str(); +} + +std::string ok_end() { + std::ostringstream ok; ok #if BOOST_CONTRACT_POSTCONDITIONS << "c::f::old" << std::endl << "c::f::post" << std::endl @@ -52,6 +42,31 @@ int main() { << "a::f::post" << std::endl #endif ; + return ok.str(); +} + +int main() { + std::ostringstream ok; + + a aa; + + a_exit_inv = true; + b_exit_inv = true; + c_exit_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); + out.str(""); + aa.f(); + ok.str(""); ok // Test nothing failed. + << ok_begin() + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "b::static_inv" << std::endl + << "b::inv" << std::endl + << "a::static_inv" << std::endl + #endif + << ok_end() + ; BOOST_TEST(out.eq(ok.str())); struct err {}; @@ -67,21 +82,7 @@ int main() { try { aa.f(); ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::static_inv" << std::endl << "b::static_inv" << std::endl @@ -90,11 +91,7 @@ int main() { // Test no failure here. #endif #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -113,31 +110,13 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::static_inv" << std::endl << "b::static_inv" << std::endl << "b::inv" << std::endl // Test this failed. #elif BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -152,21 +131,7 @@ int main() { try { aa.f(); ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::static_inv" << std::endl << "b::static_inv" << std::endl @@ -174,11 +139,7 @@ int main() { << "a::static_inv" << std::endl #endif #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -197,31 +158,13 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::static_inv" << std::endl << "b::static_inv" << std::endl << "b::inv" << std::endl // Test this failed (as all did). #elif BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/public_function/decl_exit_static_inv_all.cpp b/test/public_function/decl_exit_static_inv_all.cpp index f57ee63..7cd9334 100644 --- a/test/public_function/decl_exit_static_inv_all.cpp +++ b/test/public_function/decl_exit_static_inv_all.cpp @@ -9,20 +9,10 @@ #include #include #include +#include -int main() { - std::ostringstream ok; - - a aa; - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. +std::string ok_begin() { + std::ostringstream ok; ok #if BOOST_CONTRACT_ENTRY_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl @@ -40,6 +30,37 @@ int main() { << "a::f::old" << std::endl #endif << "a::f::body" << std::endl + ; + return ok.str(); +} + +std::string ok_end() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::f::old" << std::endl + << "c::f::post" << std::endl + << "b::f::old" << std::endl + << "b::f::post" << std::endl + << "a::f::post" << std::endl + #endif + ; + return ok.str(); +} + +int main() { + std::ostringstream ok; + + a aa; + + a_exit_static_inv = true; + b_exit_static_inv = true; + c_exit_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); + out.str(""); + aa.f(); + ok.str(""); ok // Test nothing failed. + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl @@ -49,11 +70,7 @@ int main() { << "a::inv" << std::endl #endif #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -75,23 +92,7 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl @@ -99,11 +100,7 @@ int main() { << "b::inv" << std::endl << "a::static_inv" << std::endl // Test this failed. #elif BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -122,33 +119,13 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl << "b::static_inv" << std::endl // Test this failed. #elif BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -167,31 +144,11 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::static_inv" << std::endl // Test this failed. #elif BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -210,32 +167,12 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS // Test this failed (as all did). << "c::static_inv" << std::endl #elif BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/public_function/decl_exit_static_inv_ends.cpp b/test/public_function/decl_exit_static_inv_ends.cpp index 6d9f272..a936020 100644 --- a/test/public_function/decl_exit_static_inv_ends.cpp +++ b/test/public_function/decl_exit_static_inv_ends.cpp @@ -9,20 +9,10 @@ #include #include #include - -int main() { - std::ostringstream ok; - - a aa; - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. +#include + +std::string ok_begin() { + std::ostringstream ok; ok #if BOOST_CONTRACT_ENTRY_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl @@ -39,13 +29,12 @@ int main() { << "a::f::old" << std::endl #endif << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif + ; + return ok.str(); +} + +std::string ok_end() { + std::ostringstream ok; ok #if BOOST_CONTRACT_POSTCONDITIONS << "c::f::old" << std::endl << "c::f::post" << std::endl @@ -54,6 +43,32 @@ int main() { << "a::f::post" << std::endl #endif ; + return ok.str(); +} + +int main() { + std::ostringstream ok; + + a aa; + + a_exit_static_inv = true; + b_exit_static_inv = true; + c_exit_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); + out.str(""); + aa.f(); + ok.str(""); ok // Test nothing failed. + << ok_begin() + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + << "b::inv" << std::endl + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + << ok_end() + ; BOOST_TEST(out.eq(ok.str())); struct err {}; @@ -73,33 +88,14 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl << "b::inv" << std::endl << "a::static_inv" << std::endl // Test this failed. #elif BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -114,22 +110,7 @@ int main() { try { aa.f(); ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl @@ -139,11 +120,7 @@ int main() { << "a::inv" << std::endl #endif #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -162,30 +139,11 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::static_inv" << std::endl // Test this failed. #elif BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -204,31 +162,12 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS // Test this failed (as all did). << "c::static_inv" << std::endl #elif BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/public_function/decl_exit_static_inv_mid.cpp b/test/public_function/decl_exit_static_inv_mid.cpp index 3278f43..cec8d21 100644 --- a/test/public_function/decl_exit_static_inv_mid.cpp +++ b/test/public_function/decl_exit_static_inv_mid.cpp @@ -9,20 +9,10 @@ #include #include #include - -int main() { - std::ostringstream ok; - - a aa; - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. +#include + +std::string ok_begin() { + std::ostringstream ok; ok #if BOOST_CONTRACT_ENTRY_INVARIANTS << "c::inv" << std::endl << "b::static_inv" << std::endl @@ -38,6 +28,37 @@ int main() { << "a::f::old" << std::endl #endif << "a::f::body" << std::endl + ; + return ok.str(); +} + +std::string ok_end() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::f::old" << std::endl + << "c::f::post" << std::endl + << "b::f::old" << std::endl + << "b::f::post" << std::endl + << "a::f::post" << std::endl + #endif + ; + return ok.str(); +} + +int main() { + std::ostringstream ok; + + a aa; + + a_exit_static_inv = true; + b_exit_static_inv = true; + c_exit_static_inv = true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); + out.str(""); + aa.f(); + ok.str(""); ok // Test nothing failed. + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::inv" << std::endl << "b::static_inv" << std::endl @@ -45,11 +66,7 @@ int main() { << "a::inv" << std::endl #endif #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -67,34 +84,16 @@ int main() { try { aa.f(); ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS + << ok_begin() + #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::inv" << std::endl << "b::static_inv" << std::endl << "b::inv" << std::endl // Test no failure here. << "a::inv" << std::endl #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -113,30 +112,12 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::inv" << std::endl << "b::static_inv" << std::endl // Test this failed. #elif BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -151,21 +132,7 @@ int main() { try { aa.f(); ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::inv" << std::endl // Test no failure here. @@ -174,11 +141,7 @@ int main() { << "a::inv" << std::endl #endif #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); @@ -197,31 +160,13 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl + << ok_begin() #if BOOST_CONTRACT_EXIT_INVARIANTS << "c::inv" << std::endl // Test this failed (as all did). << "b::static_inv" << std::endl #elif BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl + << ok_end() #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/public_function/decl_post_all.cpp b/test/public_function/decl_post_all.cpp index c49e96d..34b8274 100644 --- a/test/public_function/decl_post_all.cpp +++ b/test/public_function/decl_post_all.cpp @@ -8,18 +8,10 @@ #include #include - -int main() { - std::ostringstream ok; - - a aa; - - a_post = true; - b_post = true; - c_post = true; - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. +#include + +std::string ok_begin() { + std::ostringstream ok; ok #if BOOST_CONTRACT_ENTRY_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl @@ -45,6 +37,22 @@ int main() { << "a::static_inv" << std::endl << "a::inv" << std::endl #endif + ; + return ok.str(); +} + +int main() { + std::ostringstream ok; + + a aa; + + a_post = true; + b_post = true; + c_post = true; + out.str(""); + aa.f(); + ok.str(""); ok // Test nothing failed. + << ok_begin() #if BOOST_CONTRACT_POSTCONDITIONS << "c::f::old" << std::endl << "c::f::post" << std::endl @@ -70,31 +78,7 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif + << ok_begin() #if BOOST_CONTRACT_POSTCONDITIONS << "c::f::old" << std::endl << "c::f::post" << std::endl @@ -117,31 +101,7 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif + << ok_begin() #if BOOST_CONTRACT_POSTCONDITIONS << "c::f::old" << std::endl << "c::f::post" << std::endl @@ -163,31 +123,7 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif + << ok_begin() #if BOOST_CONTRACT_POSTCONDITIONS << "c::f::old" << std::endl << "c::f::post" << std::endl // Test this failed. @@ -207,31 +143,7 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif + << ok_begin() #if BOOST_CONTRACT_POSTCONDITIONS << "c::f::old" << std::endl << "c::f::post" << std::endl // Test this failed (as all did). diff --git a/test/public_function/decl_post_ends.cpp b/test/public_function/decl_post_ends.cpp index b237acf..fa33336 100644 --- a/test/public_function/decl_post_ends.cpp +++ b/test/public_function/decl_post_ends.cpp @@ -8,18 +8,10 @@ #include #include +#include -int main() { - std::ostringstream ok; - - a aa; - - a_post = true; - b_post = true; - c_post = true; - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. +std::string ok_begin() { + std::ostringstream ok; ok #if BOOST_CONTRACT_ENTRY_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl @@ -45,6 +37,22 @@ int main() { << "a::static_inv" << std::endl << "a::inv" << std::endl #endif + ; + return ok.str(); +} + +int main() { + std::ostringstream ok; + + a aa; + + a_post = true; + b_post = true; + c_post = true; + out.str(""); + aa.f(); + ok.str(""); ok // Test nothing failed. + << ok_begin() #if BOOST_CONTRACT_POSTCONDITIONS << "c::f::old" << std::endl << "c::f::post" << std::endl @@ -69,31 +77,7 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif + << ok_begin() #if BOOST_CONTRACT_POSTCONDITIONS << "c::f::old" << std::endl << "c::f::post" << std::endl @@ -111,31 +95,7 @@ int main() { try { aa.f(); ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif + << ok_begin() #if BOOST_CONTRACT_POSTCONDITIONS << "c::f::old" << std::endl << "c::f::post" << std::endl @@ -158,31 +118,7 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif + << ok_begin() #if BOOST_CONTRACT_POSTCONDITIONS << "c::f::old" << std::endl << "c::f::post" << std::endl // Test this failed. @@ -202,31 +138,7 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif + << ok_begin() #if BOOST_CONTRACT_POSTCONDITIONS << "c::f::old" << std::endl << "c::f::post" << std::endl // Test this failed (as all did). diff --git a/test/public_function/decl_post_mid.cpp b/test/public_function/decl_post_mid.cpp index 31fcd3e..f2bd273 100644 --- a/test/public_function/decl_post_mid.cpp +++ b/test/public_function/decl_post_mid.cpp @@ -8,18 +8,10 @@ #include #include +#include -int main() { - std::ostringstream ok; - - a aa; - - a_post = true; - b_post = true; - c_post = true; - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. +std::string ok_begin() { + std::ostringstream ok; ok #if BOOST_CONTRACT_ENTRY_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl @@ -45,6 +37,22 @@ int main() { << "a::static_inv" << std::endl << "a::inv" << std::endl #endif + ; + return ok.str(); +} + +int main() { + std::ostringstream ok; + + a aa; + + a_post = true; + b_post = true; + c_post = true; + out.str(""); + aa.f(); + ok.str(""); ok // Test nothing failed. + << ok_begin() #if BOOST_CONTRACT_POSTCONDITIONS << "c::f::old" << std::endl << "b::f::old" << std::endl @@ -64,31 +72,7 @@ int main() { try { aa.f(); ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif + << ok_begin() #if BOOST_CONTRACT_POSTCONDITIONS << "c::f::old" << std::endl << "b::f::old" << std::endl @@ -110,31 +94,7 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif + << ok_begin() #if BOOST_CONTRACT_POSTCONDITIONS << "c::f::old" << std::endl << "b::f::old" << std::endl @@ -151,31 +111,7 @@ int main() { try { aa.f(); ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif + << ok_begin() #if BOOST_CONTRACT_POSTCONDITIONS << "c::f::old" << std::endl // Test no failure here. @@ -197,31 +133,7 @@ int main() { } catch(err const&) { #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif + << ok_begin() #if BOOST_CONTRACT_POSTCONDITIONS << "c::f::old" << std::endl << "b::f::old" << std::endl diff --git a/test/public_function/decl_pre_all.cpp b/test/public_function/decl_pre_all.cpp index e77f09f..056fce8 100644 --- a/test/public_function/decl_pre_all.cpp +++ b/test/public_function/decl_pre_all.cpp @@ -8,6 +8,48 @@ #include #include +#include + +std::string ok_begin() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + << "b::static_inv" << std::endl + << "b::inv" << std::endl + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + ; + return ok.str(); +} + +std::string ok_end() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::f::old" << std::endl + << "b::f::old" << std::endl + << "a::f::old" << std::endl + #endif + << "a::f::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + << "b::static_inv" << std::endl + << "b::inv" << std::endl + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::f::old" << std::endl + << "c::f::post" << std::endl + << "b::f::old" << std::endl + << "b::f::post" << std::endl + << "a::f::post" << std::endl + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -20,38 +62,11 @@ int main() { out.str(""); aa.f(); ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif + << ok_begin() #if BOOST_CONTRACT_PRECONDITIONS << "c::f::pre" << std::endl // Test only c::f::pre checked. #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() ; BOOST_TEST(out.eq(ok.str())); @@ -61,40 +76,13 @@ int main() { out.str(""); aa.f(); ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif + << ok_begin() #if BOOST_CONTRACT_PRECONDITIONS << "c::f::pre" << std::endl << "b::f::pre" << std::endl << "a::f::pre" << std::endl // Test all pre checked. #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() ; BOOST_TEST(out.eq(ok.str())); @@ -104,40 +92,13 @@ int main() { out.str(""); aa.f(); ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif + << ok_begin() #if BOOST_CONTRACT_PRECONDITIONS << "c::f::pre" << std::endl << "b::f::pre" << std::endl // Test only a::f::pre not checked. #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() ; BOOST_TEST(out.eq(ok.str())); @@ -147,38 +108,11 @@ int main() { out.str(""); aa.f(); ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif + << ok_begin() #if BOOST_CONTRACT_PRECONDITIONS << "c::f::pre" << std::endl // Test only c::f::pre checked. #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() ; BOOST_TEST(out.eq(ok.str())); @@ -192,23 +126,20 @@ int main() { out.str(""); try { aa.f(); -#if BOOST_CONTRACT_PRECONDITIONS - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_PRECONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl + << ok_begin() + #if BOOST_CONTRACT_PRECONDITIONS + << "c::f::pre" << std::endl + << "b::f::pre" << std::endl + << "a::f::pre" << std::endl // Test all pre checked and failed. + #else + << ok_end() #endif - << "c::f::pre" << std::endl - << "b::f::pre" << std::endl - << "a::f::pre" << std::endl // Test all pre checked and failed. ; -#endif BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/public_function/decl_pre_ends.cpp b/test/public_function/decl_pre_ends.cpp index 9cbe642..3ad8c4a 100644 --- a/test/public_function/decl_pre_ends.cpp +++ b/test/public_function/decl_pre_ends.cpp @@ -8,6 +8,48 @@ #include #include +#include + +std::string ok_begin() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + << "b::static_inv" << std::endl + << "b::inv" << std::endl + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + ; + return ok.str(); +} + +std::string ok_end() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::f::old" << std::endl + << "b::f::old" << std::endl + << "a::f::old" << std::endl + #endif + << "a::f::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + << "b::static_inv" << std::endl + << "b::inv" << std::endl + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::f::old" << std::endl + << "c::f::post" << std::endl + << "b::f::old" << std::endl + << "b::f::post" << std::endl + << "a::f::post" << std::endl + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -20,38 +62,11 @@ int main() { out.str(""); aa.f(); ok.str(""); ok // Test nothing failed. - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif + << ok_begin() #if BOOST_CONTRACT_PRECONDITIONS << "c::f::pre" << std::endl // Test only c pre checked. #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() ; BOOST_TEST(out.eq(ok.str())); @@ -61,40 +76,13 @@ int main() { out.str(""); aa.f(); ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif + << ok_begin() #if BOOST_CONTRACT_PRECONDITIONS << "c::f::pre" << std::endl // Test b's pre not checked. << "a::f::pre" << std::endl #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() ; BOOST_TEST(out.eq(ok.str())); @@ -104,38 +92,11 @@ int main() { out.str(""); aa.f(); ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif + << ok_begin() #if BOOST_CONTRACT_PRECONDITIONS << "c::f::pre" << std::endl // Test only c pre checked. #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() ; BOOST_TEST(out.eq(ok.str())); @@ -143,21 +104,6 @@ int main() { boost::contract::set_precondition_failure( [] (boost::contract::from) { throw err(); }); - #if BOOST_CONTRACT_PRECONDITIONS - ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - << "c::f::pre" << std::endl - << "a::f::pre" << std::endl // Only ends' pre checked and failed. - ; - #endif - a_pre = false; b_pre = true; c_pre = false; @@ -168,6 +114,15 @@ int main() { BOOST_TEST(false); } catch(err const&) { #endif + ok.str(""); ok + << ok_begin() + #if BOOST_CONTRACT_PRECONDITIONS + << "c::f::pre" << std::endl + << "a::f::pre" << std::endl // Only ends pre checked and failed. + #else + << ok_end() + #endif + ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -181,6 +136,15 @@ int main() { BOOST_TEST(false); } catch(err const&) { #endif + ok.str(""); ok + << ok_begin() + #if BOOST_CONTRACT_PRECONDITIONS + << "c::f::pre" << std::endl + << "a::f::pre" << std::endl // Only ends pre checked and failed. + #else + << ok_end() + #endif + ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/public_function/decl_pre_mid.cpp b/test/public_function/decl_pre_mid.cpp index e37c52e..0826f5b 100644 --- a/test/public_function/decl_pre_mid.cpp +++ b/test/public_function/decl_pre_mid.cpp @@ -8,6 +8,48 @@ #include #include +#include + +std::string ok_begin() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + << "b::static_inv" << std::endl + << "b::inv" << std::endl + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + ; + return ok.str(); +} + +std::string ok_end() { + std::ostringstream ok; ok + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::f::old" << std::endl + << "b::f::old" << std::endl + << "a::f::old" << std::endl + #endif + << "a::f::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + << "b::static_inv" << std::endl + << "b::inv" << std::endl + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::f::old" << std::endl + << "c::f::post" << std::endl + << "b::f::old" << std::endl + << "b::f::post" << std::endl + << "a::f::post" << std::endl + #endif + ; + return ok.str(); +} int main() { std::ostringstream ok; @@ -20,38 +62,11 @@ int main() { out.str(""); aa.f(); ok.str(""); ok // Test nothing failed. - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif + << ok_begin() #if BOOST_CONTRACT_PRECONDITIONS << "b::f::pre" << std::endl #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() ; BOOST_TEST(out.eq(ok.str())); @@ -61,39 +76,12 @@ int main() { out.str(""); aa.f(); ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif + << ok_begin() #if BOOST_CONTRACT_PRECONDITIONS // Test only middle pre checked and no fail. << "b::f::pre" << std::endl #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #if BOOST_CONTRACT_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #if BOOST_CONTRACT_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif + << ok_end() ; BOOST_TEST(out.eq(ok.str())); @@ -101,21 +89,6 @@ int main() { boost::contract::set_precondition_failure( [] (boost::contract::from) { throw err(); }); - #if BOOST_CONTRACT_PRECONDITIONS - ok.str(""); ok - #if BOOST_CONTRACT_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - // Test only middle pre checked and failed. - << "b::f::pre" << std::endl - ; - #endif - a_pre = true; b_pre = false; c_pre = false; @@ -126,6 +99,15 @@ int main() { BOOST_TEST(false); } catch(err const&) { #endif + ok.str(""); ok + << ok_begin() + #if BOOST_CONTRACT_PRECONDITIONS + // Test only middle pre checked and failed. + << "b::f::pre" << std::endl + #else + << ok_end() + #endif + ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -139,6 +121,15 @@ int main() { BOOST_TEST(false); } catch(err const&) { #endif + ok.str(""); ok + << ok_begin() + #if BOOST_CONTRACT_PRECONDITIONS + // Test only middle pre checked and failed. + << "b::f::pre" << std::endl + #else + << ok_end() + #endif + ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -152,6 +143,15 @@ int main() { BOOST_TEST(false); } catch(err const&) { #endif + ok.str(""); ok + << ok_begin() + #if BOOST_CONTRACT_PRECONDITIONS + // Test only middle pre checked and failed. + << "b::f::pre" << std::endl + #else + << ok_end() + #endif + ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/result/mixed_optional.hpp b/test/result/mixed_optional.hpp index 98909ef..b6544fc 100644 --- a/test/result/mixed_optional.hpp +++ b/test/result/mixed_optional.hpp @@ -22,12 +22,12 @@ struct ch_tag; typedef boost::contract::aux::test::counter ch_type; #ifdef BOOST_CONTRACT_AUX_TEST_ref // Test with result types by reference. -# define BOOST_CONTRACT_AUX_TEST_ch_type ch_type& -# define BOOST_CONTRACT_AUX_TEST_ch_init = ch_init -ch_type ch_init; + #define BOOST_CONTRACT_AUX_TEST_ch_type ch_type& + #define BOOST_CONTRACT_AUX_TEST_ch_init = ch_init + ch_type ch_init; #else // Test with result types by value. -# define BOOST_CONTRACT_AUX_TEST_ch_type ch_type -# define BOOST_CONTRACT_AUX_TEST_ch_init /* nothing */ + #define BOOST_CONTRACT_AUX_TEST_ch_type ch_type + #define BOOST_CONTRACT_AUX_TEST_ch_init /* nothing */ #endif bool tested_d_copies = false; @@ -206,9 +206,9 @@ struct e int main() { std::ostringstream ok; ch_type ch; -#ifdef BOOST_CONTRACT_AUX_TEST_ref - ch_init.value = '\0'; -#endif + #ifdef BOOST_CONTRACT_AUX_TEST_ref + ch_init.value = '\0'; + #endif // Test optional in overriding a::f and non-optional in overridden b::f. a aa; @@ -216,44 +216,48 @@ int main() { out.str(""); aa.f(ch); ok.str(""); ok - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - - << "d::f::pre" << std::endl - << "c::f::pre" << std::endl - << "b::f::pre" << std::endl - << "a::f::pre" << std::endl - - << "d::f::old" << std::endl - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "d::static_inv" << std::endl + << "d::inv" << std::endl + << "c::static_inv" << std::endl + << "c::inv" << std::endl + << "b::static_inv" << std::endl + << "b::inv" << std::endl + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_PRECONDITIONS + << "d::f::pre" << std::endl + << "c::f::pre" << std::endl + << "b::f::pre" << std::endl + << "a::f::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "d::f::old" << std::endl + << "c::f::old" << std::endl + << "b::f::old" << std::endl + << "a::f::old" << std::endl + #endif << "a::f::body" << std::endl - - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - - << "d::f::old" << std::endl - << "d::f::post" << std::endl - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - // No old call here because not a base object. - << "a::f::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "d::static_inv" << std::endl + << "d::inv" << std::endl + << "c::static_inv" << std::endl + << "c::inv" << std::endl + << "b::static_inv" << std::endl + << "b::inv" << std::endl + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "d::f::old" << std::endl + << "d::f::post" << std::endl + << "c::f::old" << std::endl + << "c::f::post" << std::endl + << "b::f::old" << std::endl + << "b::f::post" << std::endl + << "a::f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); BOOST_TEST(tested_a_copies); @@ -264,36 +268,40 @@ int main() { out.str(""); bb.f(ch); ok.str(""); ok - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - - << "d::f::pre" << std::endl - << "c::f::pre" << std::endl - << "b::f::pre" << std::endl - - << "d::f::old" << std::endl - << "c::f::old" << std::endl - << "b::f::old" << std::endl - + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "d::static_inv" << std::endl + << "d::inv" << std::endl + << "c::static_inv" << std::endl + << "c::inv" << std::endl + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_PRECONDITIONS + << "d::f::pre" << std::endl + << "c::f::pre" << std::endl + << "b::f::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "d::f::old" << std::endl + << "c::f::old" << std::endl + << "b::f::old" << std::endl + #endif << "b::f::body" << std::endl - - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - - << "d::f::old" << std::endl - << "d::f::post" << std::endl - << "c::f::old" << std::endl - << "c::f::post" << std::endl - // No old call here because not a base object. - << "b::f::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "d::static_inv" << std::endl + << "d::inv" << std::endl + << "c::static_inv" << std::endl + << "c::inv" << std::endl + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "d::f::old" << std::endl + << "d::f::post" << std::endl + << "c::f::old" << std::endl + << "c::f::post" << std::endl + << "b::f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); BOOST_TEST(tested_b_copies); @@ -304,28 +312,32 @@ int main() { out.str(""); cc.f(ch); ok.str(""); ok - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - - << "d::f::pre" << std::endl - << "c::f::pre" << std::endl - - << "d::f::old" << std::endl - << "c::f::old" << std::endl - + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "d::static_inv" << std::endl + << "d::inv" << std::endl + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_PRECONDITIONS + << "d::f::pre" << std::endl + << "c::f::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "d::f::old" << std::endl + << "c::f::old" << std::endl + #endif << "c::f::body" << std::endl - - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - - << "d::f::old" << std::endl - << "d::f::post" << std::endl - // No old call here because not a base object. - << "c::f::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "d::static_inv" << std::endl + << "d::inv" << std::endl + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "d::f::old" << std::endl + << "d::f::post" << std::endl + << "c::f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); BOOST_TEST(tested_c_copies); @@ -336,44 +348,48 @@ int main() { out.str(""); ee.f(ch); ok.str(""); ok - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - - << "d::f::pre" << std::endl - << "c::f::pre" << std::endl - << "b::f::pre" << std::endl - << "e::f::pre" << std::endl - - << "d::f::old" << std::endl - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "e::f::old" << std::endl - + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "d::static_inv" << std::endl + << "d::inv" << std::endl + << "c::static_inv" << std::endl + << "c::inv" << std::endl + << "b::static_inv" << std::endl + << "b::inv" << std::endl + << "e::static_inv" << std::endl + << "e::inv" << std::endl + #endif + #if BOOST_CONTRACT_PRECONDITIONS + << "d::f::pre" << std::endl + << "c::f::pre" << std::endl + << "b::f::pre" << std::endl + << "e::f::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "d::f::old" << std::endl + << "c::f::old" << std::endl + << "b::f::old" << std::endl + << "e::f::old" << std::endl + #endif << "e::f::body" << std::endl - - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - - << "d::f::old" << std::endl - << "d::f::post" << std::endl - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - // No old call here because not a base object. - << "e::f::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "d::static_inv" << std::endl + << "d::inv" << std::endl + << "c::static_inv" << std::endl + << "c::inv" << std::endl + << "b::static_inv" << std::endl + << "b::inv" << std::endl + << "e::static_inv" << std::endl + << "e::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "d::f::old" << std::endl + << "d::f::post" << std::endl + << "c::f::old" << std::endl + << "c::f::post" << std::endl + << "b::f::old" << std::endl + << "b::f::post" << std::endl + << "e::f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); BOOST_TEST(tested_e_copies); diff --git a/test/set/only_old.cpp b/test/set/old.cpp similarity index 87% rename from test/set/only_old.cpp rename to test/set/old.cpp index 25ab566..87aced2 100644 --- a/test/set/only_old.cpp +++ b/test/set/old.cpp @@ -22,7 +22,9 @@ int main() { out.str(""); f(); ok.str(""); ok - << "f::old" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "f::old" << std::endl + #endif << "f::body" << std::endl ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/set/both_old_post.cpp b/test/set/old_post.cpp similarity index 79% rename from test/set/both_old_post.cpp rename to test/set/old_post.cpp index 1e4dc60..2936131 100644 --- a/test/set/both_old_post.cpp +++ b/test/set/old_post.cpp @@ -24,9 +24,13 @@ int main() { f(); ok.str(""); ok - << "f::old" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "f::old" << std::endl + #endif << "f::body" << std::endl - << "f::post" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/set/only_post.cpp b/test/set/post.cpp similarity index 87% rename from test/set/only_post.cpp rename to test/set/post.cpp index 0b3cc7d..0c978b3 100644 --- a/test/set/only_post.cpp +++ b/test/set/post.cpp @@ -23,7 +23,9 @@ int main() { f(); ok.str(""); ok << "f::body" << std::endl - << "f::post" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/set/only_pre.cpp b/test/set/pre.cpp similarity index 87% rename from test/set/only_pre.cpp rename to test/set/pre.cpp index 675a26d..82d22b5 100644 --- a/test/set/only_pre.cpp +++ b/test/set/pre.cpp @@ -22,7 +22,9 @@ int main() { out.str(""); f(); ok.str(""); ok - << "f::pre" << std::endl + #if BOOST_CONTRACT_PRECONDITIONS + << "f::pre" << std::endl + #endif << "f::body" << std::endl ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/set/both_pre_old.cpp b/test/set/pre_old.cpp similarity index 79% rename from test/set/both_pre_old.cpp rename to test/set/pre_old.cpp index a9be36a..1a0eaa3 100644 --- a/test/set/both_pre_old.cpp +++ b/test/set/pre_old.cpp @@ -24,8 +24,12 @@ int main() { f(); ok.str(""); ok - << "f::pre" << std::endl - << "f::old" << std::endl + #if BOOST_CONTRACT_PRECONDITIONS + << "f::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "f::old" << std::endl + #endif << "f::body" << std::endl ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/set/all_pre_old_post.cpp b/test/set/pre_old_post.cpp similarity index 73% rename from test/set/all_pre_old_post.cpp rename to test/set/pre_old_post.cpp index 2dbbc22..9537ea4 100644 --- a/test/set/all_pre_old_post.cpp +++ b/test/set/pre_old_post.cpp @@ -25,10 +25,16 @@ int main() { f(); ok.str(""); ok - << "f::pre" << std::endl - << "f::old" << std::endl + #if BOOST_CONTRACT_PRECONDITIONS + << "f::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "f::old" << std::endl + #endif << "f::body" << std::endl - << "f::post" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/set/both_pre_post.cpp b/test/set/pre_post.cpp similarity index 79% rename from test/set/both_pre_post.cpp rename to test/set/pre_post.cpp index ed70489..877b54d 100644 --- a/test/set/both_pre_post.cpp +++ b/test/set/pre_post.cpp @@ -24,9 +24,13 @@ int main() { f(); ok.str(""); ok - << "f::pre" << std::endl + #if BOOST_CONTRACT_PRECONDITIONS + << "f::pre" << std::endl + #endif << "f::body" << std::endl - << "f::post" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str()));