From ff8b35f9f2911942b78bee584f1890a81c9a143c Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Thu, 24 Dec 2015 22:32:35 -0800 Subject: [PATCH] started to implement and test contract compilation on/off --- Jamroot | 227 ++++++++++-- include/boost/contract/assert.hpp | 18 +- .../contract/aux_/condition/check_base.hpp | 69 ++-- .../aux_/condition/check_pre_post.hpp | 100 +++--- .../aux_/condition/check_pre_post_inv.hpp | 323 ++++++++++-------- .../check_subcontracted_pre_post_inv.hpp | 289 ++++++++-------- .../contract/aux_/operation/constructor.hpp | 61 ++-- .../contract/aux_/operation/destructor.hpp | 61 ++-- .../contract/aux_/operation/function.hpp | 34 +- .../aux_/operation/public_function.hpp | 76 +++-- .../aux_/operation/public_static_function.hpp | 43 ++- include/boost/contract/base_types.hpp | 7 +- include/boost/contract/constructor.hpp | 16 +- include/boost/contract/core/access.hpp | 102 +++--- include/boost/contract/core/config.hpp | 96 ++++-- include/boost/contract/core/exception.hpp | 38 ++- include/boost/contract/core/set_nothing.hpp | 1 - .../contract/core/set_old_postcondition.hpp | 17 +- .../contract/core/set_postcondition_only.hpp | 11 +- .../set_precondition_old_postcondition.hpp | 23 +- include/boost/contract/core/virtual.hpp | 53 ++- include/boost/contract/guard.hpp | 2 +- include/boost/contract/old.hpp | 125 ++++--- include/boost/contract/override.hpp | 130 +++---- include/boost/contract/public_function.hpp | 50 +-- test/Jamfile.v2 | 273 ++++++++------- test/aux_/oteststream.hpp | 14 +- test/constructor/no_contracts.cpp | 125 +++++++ test/destructor/no_contracts.cpp | 106 ++++++ test/function/body_throw.cpp | 8 +- test/function/decl.hpp | 24 +- test/function/decl_post_all.cpp | 30 +- test/function/decl_post_none.cpp | 8 +- test/function/decl_pre_all.cpp | 20 +- test/function/decl_pre_none.cpp | 8 +- test/function/func.cpp | 25 +- test/function/no_contracts.cpp | 53 +++ test/function/old_throw.cpp | 12 +- test/public_function/access.cpp | 71 ++-- test/public_function/bases.cpp | 112 +++--- test/public_function/bases_branch.cpp | 89 +++-- test/public_function/bases_sparse.cpp | 309 ++++++++++------- test/public_function/bases_virtual.cpp | 112 +++--- test/public_function/body_throw.cpp | 50 +-- test/public_function/decl.hpp | 168 ++++----- test/public_function/decl_entry_inv_all.cpp | 233 ++++++++++--- test/public_function/decl_entry_inv_ends.cpp | 236 +++++++++---- test/public_function/decl_entry_inv_mid.cpp | 237 ++++++++----- test/public_function/decl_entry_inv_none.cpp | 61 ++-- .../decl_entry_static_inv_all.cpp | 231 ++++++++++--- .../decl_entry_static_inv_ends.cpp | 228 +++++++++---- .../decl_entry_static_inv_mid.cpp | 228 ++++++++----- .../decl_entry_static_inv_none.cpp | 61 ++-- test/public_function/decl_exit_inv_all.cpp | 277 +++++++++------ test/public_function/decl_exit_inv_ends.cpp | 266 +++++++++------ test/public_function/decl_exit_inv_mid.cpp | 257 ++++++++------ test/public_function/decl_exit_inv_none.cpp | 63 ++-- .../decl_exit_static_inv_all.cpp | 272 +++++++++------ .../decl_exit_static_inv_ends.cpp | 263 ++++++++------ .../decl_exit_static_inv_mid.cpp | 256 ++++++++------ .../decl_exit_static_inv_none.cpp | 63 ++-- test/public_function/decl_post_all.cpp | 295 +++++++++------- test/public_function/decl_post_ends.cpp | 287 +++++++++------- test/public_function/decl_post_mid.cpp | 281 ++++++++------- test/public_function/decl_post_none.cpp | 53 +-- test/public_function/decl_pre_all.cpp | 255 +++++++------- test/public_function/decl_pre_ends.cpp | 212 ++++++------ test/public_function/decl_pre_mid.cpp | 157 +++++---- test/public_function/decl_pre_none.cpp | 53 +-- test/public_function/no_contracts.cpp | 116 +++++++ test/public_function/old_throw.cpp | 64 ++-- test/public_function/static.cpp | 34 +- test/public_function/static_body_throw.cpp | 47 +-- test/public_function/static_no_contracts.cpp | 69 ++++ test/public_function/static_old_throw.cpp | 66 ++++ 75 files changed, 5596 insertions(+), 3214 deletions(-) create mode 100644 test/constructor/no_contracts.cpp create mode 100644 test/destructor/no_contracts.cpp create mode 100644 test/function/no_contracts.cpp create mode 100644 test/public_function/no_contracts.cpp create mode 100644 test/public_function/static_no_contracts.cpp create mode 100644 test/public_function/static_old_throw.cpp diff --git a/Jamroot b/Jamroot index 97dfc3d..507c69f 100644 --- a/Jamroot +++ b/Jamroot @@ -2,33 +2,214 @@ import testing ; import os ; -# Following `subdir-...` create targets named "subdir_name-file_name". - -rule subdir-run ( subdir : cpp_fname : requirements * ) -{ - run $(subdir)/$(cpp_fname).cpp : : : $(subdir) $(requirements) : - $(subdir)-$(cpp_fname) ; -} - -rule subdir-compile-fail ( subdir : cpp_fname : requirements * ) -{ - compile-fail $(subdir)/$(cpp_fname).cpp : - $(subdir) $(requirements) : $(subdir)-$(cpp_fname) ; -} - if ! [ os.environ BOOST_ROOT ] { - exit "Error: Set BOOST_ROOT environment variable to Boost root directory" ; + exit "error: set BOOST_ROOT environment variable to Boost root directory" ; } local BOOST_ROOT = [ os.environ BOOST_ROOT ] ; -echo "Using Boost libraries from (see $BOOST_ROOT): $(BOOST_ROOT)" ; +echo "using: Boost libraries from \"$(BOOST_ROOT)\" (see $BOOST_ROOT)" ; use-project boost : $(BOOST_ROOT) ; project - : requirements - gcc:-std=c++11 - clang:-std=c++11 - "./include" - $(BOOST_ROOT) - $(BOOST_ROOT)/stage/lib - ; +: + requirements + gcc:-std=c++11 + clang:-std=c++11 + "./include" + $(BOOST_ROOT) + $(BOOST_ROOT)/stage/lib +; + +rule subdir-usage ( ) { + echo ; + echo "usage: [time] bjam [-aq toolset=msvc,gcc,clang] DIR_NAME[-FILE_NAME[-no_...]] [--clean] [; echo $?]" ; + echo "where: -no_... = -no[_entryinv][_pre][_exitinv][_post] | -no_all | n/a" ; + echo ; +} + +rule subdir-compile-fail ( subdir : cpp_fname : requirements * ) { + compile-fail $(subdir)/$(cpp_fname).cpp + : + $(subdir) + $(requirements) + : + $(subdir)-$(cpp_fname) + ; +} + +rule subdir-run ( subdir : cpp_fname : requirements * ) { + run $(subdir)/$(cpp_fname).cpp : : + : + $(subdir) + $(requirements) + : + $(subdir)-$(cpp_fname) + ; +} + +rule subdir-run-withno ( subdir : cpp_fname : requirements * ) { + subdir-run $(subdir) : $(cpp_fname) : $(requirements) ; + # Compilation of 1 contract off. + run $(subdir)/$(cpp_fname).cpp : : + : + BOOST_CONTRACT_CONFIG_NO_ENTRY_INVARIANTS + $(subdir) + $(requirements) + : + $(subdir)-$(cpp_fname)-no_entryinv + ; + run $(subdir)/$(cpp_fname).cpp : : + : + BOOST_CONTRACT_CONFIG_NO_PRECONDITIONS + $(subdir) + $(requirements) + : + $(subdir)-$(cpp_fname)-no_pre + ; + run $(subdir)/$(cpp_fname).cpp : : + : + BOOST_CONTRACT_CONFIG_NO_EXIT_INVARIANTS + $(subdir) + $(requirements) + : + $(subdir)-$(cpp_fname)-no_exitinv + ; + run $(subdir)/$(cpp_fname).cpp : : + : + BOOST_CONTRACT_CONFIG_NO_POSTCONDITIONS + $(subdir) + $(requirements) + : + $(subdir)-$(cpp_fname)-no_post + ; + # Compilation of 2 contracts off. + run $(subdir)/$(cpp_fname).cpp : : + : + BOOST_CONTRACT_CONFIG_NO_ENTRY_INVARIANTS + BOOST_CONTRACT_CONFIG_NO_PRECONDITIONS + $(subdir) + $(requirements) + : + $(subdir)-$(cpp_fname)-no_entryinv_pre + ; + run $(subdir)/$(cpp_fname).cpp : : + : + BOOST_CONTRACT_CONFIG_NO_ENTRY_INVARIANTS + BOOST_CONTRACT_CONFIG_NO_EXIT_INVARIANTS + $(subdir) + $(requirements) + : + $(subdir)-$(cpp_fname)-no_entryinv_exitinv + ; + run $(subdir)/$(cpp_fname).cpp : : + : + BOOST_CONTRACT_CONFIG_NO_ENTRY_INVARIANTS + BOOST_CONTRACT_CONFIG_NO_POSTCONDITIONS + $(subdir) + $(requirements) + : + $(subdir)-$(cpp_fname)-no_entryinv_post + ; + run $(subdir)/$(cpp_fname).cpp : : + : + BOOST_CONTRACT_CONFIG_NO_PRECONDITIONS + BOOST_CONTRACT_CONFIG_NO_EXIT_INVARIANTS + $(subdir) + $(requirements) + : + $(subdir)-$(cpp_fname)-no_pre_exitinv + ; + run $(subdir)/$(cpp_fname).cpp : : + : + BOOST_CONTRACT_CONFIG_NO_PRECONDITIONS + BOOST_CONTRACT_CONFIG_NO_POSTCONDITIONS + $(subdir) + $(requirements) + : + $(subdir)-$(cpp_fname)-no_pre_post + ; + run $(subdir)/$(cpp_fname).cpp : : + : + BOOST_CONTRACT_CONFIG_NO_EXIT_INVARIANTS + BOOST_CONTRACT_CONFIG_NO_POSTCONDITIONS + $(subdir) + $(requirements) + : + $(subdir)-$(cpp_fname)-no_exitinv_post + ; + # Compilation of 3 contracts off. + run $(subdir)/$(cpp_fname).cpp : : + : + BOOST_CONTRACT_CONFIG_NO_PRECONDITIONS + BOOST_CONTRACT_CONFIG_NO_EXIT_INVARIANTS + BOOST_CONTRACT_CONFIG_NO_POSTCONDITIONS + $(subdir) + $(requirements) + : + $(subdir)-$(cpp_fname)-no_pre_exitinv_post + ; + run $(subdir)/$(cpp_fname).cpp : : + : + BOOST_CONTRACT_CONFIG_NO_ENTRY_INVARIANTS + BOOST_CONTRACT_CONFIG_NO_EXIT_INVARIANTS + BOOST_CONTRACT_CONFIG_NO_POSTCONDITIONS + $(subdir) + $(requirements) + : + $(subdir)-$(cpp_fname)-no_entryinv_exitinv_post + ; + run $(subdir)/$(cpp_fname).cpp : : + : + BOOST_CONTRACT_CONFIG_NO_ENTRY_INVARIANTS + BOOST_CONTRACT_CONFIG_NO_PRECONDITIONS + BOOST_CONTRACT_CONFIG_NO_POSTCONDITIONS + $(subdir) + $(requirements) + : + $(subdir)-$(cpp_fname)-no_entryinv_pre_post + ; + run $(subdir)/$(cpp_fname).cpp : : + : + BOOST_CONTRACT_CONFIG_NO_ENTRY_INVARIANTS + BOOST_CONTRACT_CONFIG_NO_PRECONDITIONS + BOOST_CONTRACT_CONFIG_NO_EXIT_INVARIANTS + $(subdir) + $(requirements) + : + $(subdir)-$(cpp_fname)-no_entryinv_pre_exitinv + ; + # Compilation of all 4 contracts off. + run $(subdir)/$(cpp_fname).cpp : : + : + BOOST_CONTRACT_CONFIG_NO_ENTRY_INVARIANTS + BOOST_CONTRACT_CONFIG_NO_PRECONDITIONS + BOOST_CONTRACT_CONFIG_NO_EXIT_INVARIANTS + BOOST_CONTRACT_CONFIG_NO_POSTCONDITIONS + $(subdir) + $(requirements) + : + $(subdir)-$(cpp_fname)-no_entryinv_pre_exitinv_post + ; + # Group all compilation off targets. + test-suite $(subdir)-$(cpp_fname)-no_all + : + $(subdir)-$(cpp_fname)-no_entryinv + $(subdir)-$(cpp_fname)-no_pre + $(subdir)-$(cpp_fname)-no_exitinv + $(subdir)-$(cpp_fname)-no_post + + $(subdir)-$(cpp_fname)-no_entryinv_pre + $(subdir)-$(cpp_fname)-no_entryinv_exitinv + $(subdir)-$(cpp_fname)-no_entryinv_post + $(subdir)-$(cpp_fname)-no_pre_exitinv + $(subdir)-$(cpp_fname)-no_pre_post + $(subdir)-$(cpp_fname)-no_exitinv_post + + $(subdir)-$(cpp_fname)-no_pre_exitinv_post + $(subdir)-$(cpp_fname)-no_entryinv_exitinv_post + $(subdir)-$(cpp_fname)-no_entryinv_pre_post + $(subdir)-$(cpp_fname)-no_entryinv_pre_exitinv + + $(subdir)-$(cpp_fname)-no_entryinv_pre_exitinv_post + ; +} diff --git a/include/boost/contract/assert.hpp b/include/boost/contract/assert.hpp index a9ddc02..498ef7e 100644 --- a/include/boost/contract/assert.hpp +++ b/include/boost/contract/assert.hpp @@ -4,18 +4,22 @@ /** @file */ -#include -/** @cond */ -#include -/** @endcond */ +#include /* PUBLIC */ // Must use ternary operator expr here (instead of if-statement) so this macro // can always be used with if-statements and all other C++ constructs. -#define BOOST_CONTRACT_ASSERT(condition) \ - ((condition) ? (void*)0 : throw boost::contract::assertion_failure( \ - __FILE__, __LINE__, BOOST_PP_STRINGIZE(condition))) +#if BOOST_CONTRACT_PRECONDITIONS || BOOST_CONTRACT_POSTCONDITIONS || \ + BOOST_CONTRACT_INVARIANTS +# include +# include +# define BOOST_CONTRACT_ASSERT(condition) \ + ((condition) ? (void*)0 : throw boost::contract::assertion_failure( \ + __FILE__, __LINE__, BOOST_PP_STRINGIZE(condition))) +#else +# define BOOST_CONTRACT_ASSERT(condition) /* nothing */ +#endif #endif // #include guard diff --git a/include/boost/contract/aux_/condition/check_base.hpp b/include/boost/contract/aux_/condition/check_base.hpp index 7d4b33a..0d8dff3 100644 --- a/include/boost/contract/aux_/condition/check_base.hpp +++ b/include/boost/contract/aux_/condition/check_base.hpp @@ -5,7 +5,9 @@ #include #include /** @cond */ -#include +#if BOOST_CONTRACT_PRECONDITIONS || BOOST_CONTRACT_POSTCONDITIONS +# include +#endif #include #include #ifndef BOOST_CONTRACT_CONFIG_ON_MISSING_GUARD @@ -34,13 +36,13 @@ public: void assert_guarded() { // Derived dtors must assert this at entry. guard_asserted_ = true; -#ifdef BOOST_CONTRACT_CONFIG_ON_MISSING_GUARD - if(!BOOST_CONTRACT_ERROR_missing_guard_declaration) { - BOOST_CONTRACT_CONFIG_ON_MISSING_GUARD; - } -#else - assert(BOOST_CONTRACT_ERROR_missing_guard_declaration); -#endif + #ifdef BOOST_CONTRACT_CONFIG_ON_MISSING_GUARD + if(!BOOST_CONTRACT_ERROR_missing_guard_declaration) { + BOOST_CONTRACT_CONFIG_ON_MISSING_GUARD; + } + #else + assert(BOOST_CONTRACT_ERROR_missing_guard_declaration); + #endif } void guard() { // Must be called by contract guard ctor. @@ -49,32 +51,45 @@ public: } template - void set_pre(F const& f) { pre_ = f; } + void set_pre(F const& f) { + #if BOOST_CONTRACT_PRECONDITIONS + pre_ = f; + #endif + } template - void set_old(F const& f) { old_ = f; } + void set_old(F const& f) { + #if BOOST_CONTRACT_POSTCONDITIONS + old_ = f; + #endif + } protected: virtual void init() = 0; + // Return true if actually checked calling user ftor. bool check_pre(bool throw_on_failure = false) { - if(!pre_) return false; - if(failed()) return true; - try { pre_(); } - catch(...) { - // Subcontracted pre must throw on failure (instead of - // calling failure handler) so to be checked in logic-or. - if(throw_on_failure) throw; - fail(&boost::contract::precondition_failure); - } + #if BOOST_CONTRACT_PRECONDITIONS + if(!pre_) return false; + if(failed()) return true; + try { pre_(); } + catch(...) { + // Subcontracted pre must throw on failure (instead of + // calling failure handler) so to be checked in logic-or. + if(throw_on_failure) throw; + fail(&boost::contract::precondition_failure); + } + #endif return true; } void copy_old() { - if(failed()) return; - // TODO: Document that when old copies throw, using .old() calls post failure handler (more correct), while using = OLDOF makes enclosing user function throw (less correct). Plus of course using .old() makes old copies after inv and pre are checked, while using = OLDOF makes old copies before inv and pre checking (this is less correct in theory, but it should not really matter in most practical cases unless the old copy are programmed assuming inv and pre are satisfied). - try { if(old_) old_(); } - catch(...) { fail(&boost::contract::postcondition_failure); } + #if BOOST_CONTRACT_POSTCONDITIONS + if(failed()) return; + // TODO: Document that when old copies throw, using .old() calls post failure handler (more correct), while using = OLDOF makes enclosing user function throw (less correct). Plus of course using .old() makes old copies after inv and pre are checked, while using = OLDOF makes old copies before inv and pre checking (this is less correct in theory, but it should not really matter in most practical cases unless the old copy are programmed assuming inv and pre are satisfied). + try { if(old_) old_(); } + catch(...) { fail(&boost::contract::postcondition_failure); } + #endif } void fail(void (*h)(boost::contract::from)) { @@ -89,8 +104,12 @@ protected: private: bool BOOST_CONTRACT_ERROR_missing_guard_declaration; boost::contract::from from_; - boost::function pre_; // Use Boost.Function to handle also - boost::function old_; // lambdas, binds, etc. + #if BOOST_CONTRACT_PRECONDITIONS + boost::function pre_; // Use Boost.Function to handle also + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + boost::function old_; // lambdas, binds, etc. + #endif bool failed_; bool guard_asserted_; // Avoid throwing twice from dtors (undef behavior). }; diff --git a/include/boost/contract/aux_/condition/check_pre_post.hpp b/include/boost/contract/aux_/condition/check_pre_post.hpp index 07ab6e0..b685973 100644 --- a/include/boost/contract/aux_/condition/check_pre_post.hpp +++ b/include/boost/contract/aux_/condition/check_pre_post.hpp @@ -2,17 +2,51 @@ #ifndef BOOST_CONTRACT_AUX_CHECK_PRE_POST_HPP_ #define BOOST_CONTRACT_AUX_CHECK_PRE_POST_HPP_ -#include +#include +#if BOOST_CONTRACT_POSTCONDITIONS +# include +#endif #include #include -#include #include -/** @cond */ #include -#include +#if BOOST_CONTRACT_POSTCONDITIONS +# include +#endif #include #include -/** @endcond */ +#include + +/* PRIVATE */ + +#define BOOST_CONTRACT_AUX_CHECK_PRE_POST_IMPL_(ftor_var, ftor_call, f_type) \ + public: \ + explicit check_pre_post(boost::contract::from from) : \ + check_base(from) {} \ + \ + template \ + void set_post(F const& f) { \ + BOOST_PP_EXPR_IIF(BOOST_CONTRACT_POSTCONDITIONS, \ + ftor_var = f; \ + ) \ + } \ + \ + protected: \ + void check_post(r_type const& r) { \ + BOOST_PP_EXPR_IIF(BOOST_CONTRACT_POSTCONDITIONS, \ + if(failed()) return; \ + try { if(ftor_var) { ftor_call; } } \ + catch(...) { fail(&boost::contract::postcondition_failure); } \ + ) \ + } \ + \ + private: \ + BOOST_PP_EXPR_IIF(BOOST_CONTRACT_POSTCONDITIONS, \ + /* use Boost.Function for lambdas, etc. */ \ + boost::function ftor_var; \ + ) + +/* CODE */ namespace boost { namespace contract { namespace aux { @@ -23,57 +57,27 @@ class check_pre_post : public check_base { // Non-copyable base. typename optional_value_type::type>::type const&> const& , R const& - >::type r_cref; + >::type r_type; -public: - explicit check_pre_post(boost::contract::from from) : check_base(from) {} - - template - void set_post(F const& f) { - BOOST_CONTRACT_ERROR_postcondition_result_parameter_required = f; - } - -protected: - void check_post(r_cref const& r) { - if(failed()) return; - try { - if(BOOST_CONTRACT_ERROR_postcondition_result_parameter_required) { - BOOST_CONTRACT_ERROR_postcondition_result_parameter_required(r); - } - } catch(...) { fail(&boost::contract::postcondition_failure); } - } - -private: - boost::function // Use Boost.Function for lambdas, etc. - BOOST_CONTRACT_ERROR_postcondition_result_parameter_required; + BOOST_CONTRACT_AUX_CHECK_PRE_POST_IMPL_( + BOOST_CONTRACT_ERROR_postcondition_result_parameter_required, + BOOST_CONTRACT_ERROR_postcondition_result_parameter_required(r), + void (r_type) + ) }; template<> class check_pre_post : public check_base { // Non-copyable base. -public: - explicit check_pre_post(boost::contract::from from) : check_base(from) {} - - template - void set_post(F const& f) { - BOOST_CONTRACT_ERROR_postcondition_result_parameter_not_allowed = f; - } - -protected: - void check_post(none const&) { - if(failed()) return; - try { - if(BOOST_CONTRACT_ERROR_postcondition_result_parameter_not_allowed){ - BOOST_CONTRACT_ERROR_postcondition_result_parameter_not_allowed(); - } - } catch(...) { fail(&boost::contract::postcondition_failure); } - } + typedef none r_type; -private: - boost::function // Use Boost.Function for lambdas, etc. - BOOST_CONTRACT_ERROR_postcondition_result_parameter_not_allowed; + BOOST_CONTRACT_AUX_CHECK_PRE_POST_IMPL_( + BOOST_CONTRACT_ERROR_postcondition_result_parameter_not_allowed, + BOOST_CONTRACT_ERROR_postcondition_result_parameter_not_allowed(), + void () + ) }; -} } } +} } } // namespace #endif // #include guard diff --git a/include/boost/contract/aux_/condition/check_pre_post_inv.hpp b/include/boost/contract/aux_/condition/check_pre_post_inv.hpp index e1c91f8..494c3eb 100644 --- a/include/boost/contract/aux_/condition/check_pre_post_inv.hpp +++ b/include/boost/contract/aux_/condition/check_pre_post_inv.hpp @@ -2,9 +2,9 @@ #ifndef BOOST_CONTRACT_AUX_CHECK_PRE_POST_INV_HPP_ #define BOOST_CONTRACT_AUX_CHECK_PRE_POST_INV_HPP_ +#include #include #include -#include #include /** @cond */ #include @@ -26,167 +26,200 @@ namespace boost { namespace contract { namespace aux { template class check_pre_post_inv : public check_pre_post { // Non-copyable base. public: -#ifndef BOOST_CONTRACT_CONFIG_PERMISSIVE - BOOST_STATIC_ASSERT_MSG( - !boost::contract::access::has_static_invariant_f >::value, - "static invariant member function cannot be mutable " - "(it must be static instead)" - ); - BOOST_STATIC_ASSERT_MSG( - !boost::contract::access::has_static_invariant_f, boost::function_types::const_non_volatile>::value, - "static invariant member function cannot be const qualified " - "(it must be static instead)" - ); - BOOST_STATIC_ASSERT_MSG( - !boost::contract::access::has_static_invariant_f, boost::function_types::volatile_non_const>::value, - "static invariant member function cannot be volatile qualified " - "(it must be static instead)" - ); - BOOST_STATIC_ASSERT_MSG( - !boost::contract::access::has_static_invariant_f, boost::function_types::cv_qualified>::value, - "static invariant member function cannot be const volatile qualified " - "(it must be static instead)" - ); + #ifndef BOOST_CONTRACT_CONFIG_PERMISSIVE + BOOST_STATIC_ASSERT_MSG( + !boost::contract::access::has_static_invariant_f< + C, void, boost::mpl:: vector<> + >::value, + "static invariant member function cannot be mutable " + "(it must be static instead)" + ); + BOOST_STATIC_ASSERT_MSG( + !boost::contract::access::has_static_invariant_f< + C, void, boost::mpl::vector<>, + boost::function_types::const_non_volatile + >::value, + "static invariant member function cannot be const qualified " + "(it must be static instead)" + ); + BOOST_STATIC_ASSERT_MSG( + !boost::contract::access::has_static_invariant_f< + C, void, boost::mpl::vector<>, + boost::function_types::volatile_non_const + >::value, + "static invariant member function cannot be volatile qualified " + "(it must be static instead)" + ); + BOOST_STATIC_ASSERT_MSG( + !boost::contract::access::has_static_invariant_f< + C, void, boost::mpl::vector<>, + boost::function_types::cv_qualified + >::value, + "static invariant member function cannot be const volatile " + "qualified (it must be static instead)" + ); - BOOST_STATIC_ASSERT_MSG( - !boost::contract::access::has_invariant_s >::value, - "non-static invariant member function cannot be static " - "(it must be either const or const volatile qualified instead)" - ); - BOOST_STATIC_ASSERT_MSG( - !boost::contract::access::has_invariant_f, boost::function_types::non_cv>::value, - "non-static invariant member function cannot be mutable " - "(it must be either const or const volatile qualified instead)" - ); - BOOST_STATIC_ASSERT_MSG( - !boost::contract::access::has_invariant_f, boost::function_types::volatile_non_const>::value, - "non-static invariant member function cannot be volatile qualified " - "(it must be const or const volatile qualified instead)" - ); -#endif + BOOST_STATIC_ASSERT_MSG( + !boost::contract::access::has_invariant_s< + C, void, boost::mpl::vector<> + >::value, + "non-static invariant member function cannot be static " + "(it must be either const or const volatile qualified instead)" + ); + BOOST_STATIC_ASSERT_MSG( + !boost::contract::access::has_invariant_f< + C, void, boost::mpl::vector<>, + boost::function_types::non_cv + >::value, + "non-static invariant member function cannot be mutable " + "(it must be either const or const volatile qualified instead)" + ); + BOOST_STATIC_ASSERT_MSG( + !boost::contract::access::has_invariant_f< + C, void, boost::mpl::vector<>, + boost::function_types::volatile_non_const + >::value, + "non-static invariant member function cannot be volatile qualified " + "(it must be const or const volatile qualified instead)" + ); + #endif // obj can be 0 for static member functions. explicit check_pre_post_inv(boost::contract::from from, C* obj) : check_pre_post(from), obj_(obj) {} protected: - void check_exit_inv() { check_inv(false, false); } - void check_entry_inv() { check_inv(true, false); } + void check_entry_inv() { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + check_inv(true, false); + #endif + } + + void check_exit_inv() { + #if BOOST_CONTRACT_EXIT_INVARIANTS + check_inv(false, false); + #endif + } - void check_entry_static_inv() { check_inv(true, true); } - void check_exit_static_inv() { check_inv(false, true); } + void check_entry_static_inv() { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + check_inv(true, true); + #endif + } + + void check_exit_static_inv() { + #if BOOST_CONTRACT_EXIT_INVARIANTS + check_inv(false, true); + #endif + } C* object() { return obj_; } private: - void check_inv(bool on_entry, bool static_inv_only) { - if(this->failed()) return; - try { - // Static members only check static inv. - check_static_inv(); - if(!static_inv_only) { - // Volatile (const or not) members check static and cv inv. - check_cv_inv(); - // Other members (const or not) check static, cv, and const. - check_const_inv(); - } - } catch(...) { - if(on_entry) this->fail(&boost::contract::entry_invariant_failure); - else this->fail(&boost::contract::exit_invariant_failure); - } - } - - template - typename boost::enable_if< - boost::contract::access::has_static_invariant >::type - check_static_inv() { - // SFINAE HAS_STATIC_... returns true even when member is inherited so - // need extra run-time check here (that's not the case for non static). - if(!inherited::apply()) { - boost::contract::access::static_invariant(); - } - } - - template - typename boost::disable_if< - boost::contract::access::has_static_invariant >::type - check_static_inv() {} - - template - typename boost::enable_if< - boost::contract::access::has_cv_invariant >::type - check_cv_inv() { boost::contract::access::cv_invariant(obj_); } - - template - typename boost::disable_if< - boost::contract::access::has_cv_invariant >::type - check_cv_inv() {} - - template - struct call_const_inv : - boost::mpl::and_< - boost::contract::access::has_const_invariant, - // Volatile (like const) cannot be stripped so [const] volatile - // members only check cv invariant, and cannot check const inv. - boost::mpl::not_ > - > - {}; - - template - typename boost::enable_if >::type - check_const_inv() { boost::contract::access::const_invariant(obj_); } - - template - typename boost::disable_if >::type - check_const_inv() {} - - // Check is class's func is inherited from its base types or not. - template class HasFunc, template class FuncAddr> - struct inherited { - static bool apply() { + #if BOOST_CONTRACT_INVARIANTS + void check_inv(bool on_entry, bool static_inv_only) { + if(this->failed()) return; try { - boost::mpl::for_each< - // For now, no reason to deeply search inheritance tree (as - // SFINAE HAS_STATIC_... already fails in that case). - typename boost::mpl::transform< - typename boost::mpl::copy_if< - typename boost::mpl::eval_if, - typename boost::contract::access:: - base_types_of - , - boost::mpl::vector<> - >::type, - HasFunc - >::type, - boost::add_pointer - >::type - >(compare_func_addr()); - } catch(signal_equal const&) { return true; } - return false; + // Static members only check static inv. + check_static_inv(); + if(!static_inv_only) { + // Volatile (const or not) members check static and cv inv. + check_cv_inv(); + // Other members (const or not) check static, cv, and const. + check_const_inv(); + } + } catch(...) { + if(on_entry) { + this->fail(&boost::contract::entry_invariant_failure); + } else this->fail(&boost::contract::exit_invariant_failure); + } } - private: - class signal_equal {}; // Exception to stop for_each as soon as found. - - struct compare_func_addr { - template - void operator()(B*) { - // Inherited func has same addr as in its base. - if(FuncAddr::apply() == FuncAddr::apply()) { - throw signal_equal(); - } + template + typename boost::enable_if< + boost::contract::access::has_static_invariant >::type + check_static_inv() { + // SFINAE HAS_STATIC_... returns true even when member is inherited + // so extra run-time check here (not the same for non static). + if(!inherited::apply()) { + boost::contract::access::static_invariant(); } + } + + template + typename boost::disable_if< + boost::contract::access::has_static_invariant >::type + check_static_inv() {} + + template + typename boost::enable_if< + boost::contract::access::has_cv_invariant >::type + check_cv_inv() { boost::contract::access::cv_invariant(obj_); } + + template + typename boost::disable_if< + boost::contract::access::has_cv_invariant >::type + check_cv_inv() {} + + template + struct call_const_inv : + boost::mpl::and_< + boost::contract::access::has_const_invariant, + // Volatile (like const) cannot be stripped so [const] volatile + // members only check cv invariant, and cannot check const inv. + boost::mpl::not_ > + > + {}; + + template + typename boost::enable_if >::type + check_const_inv() { boost::contract::access::const_invariant(obj_); } + + template + typename boost::disable_if >::type + check_const_inv() {} + + // Check is class's func is inherited from its base types or not. + template class HasFunc, template class FuncAddr> + struct inherited { + static bool apply() { + try { + boost::mpl::for_each< + // For now, no reason to deeply search inheritance tree + // (SFINAE HAS_STATIC_... already fails in that case). + typename boost::mpl::transform< + typename boost::mpl::copy_if< + typename boost::mpl::eval_if, + typename boost::contract::access:: + base_types_of + , + boost::mpl::vector<> + >::type, + HasFunc + >::type, + boost::add_pointer + >::type + >(compare_func_addr()); + } catch(signal_equal const&) { return true; } + return false; + } + + private: + class signal_equal {}; // Except. to stop for_each as soon as found. + + struct compare_func_addr { + template + void operator()(B*) { + // Inherited func has same addr as in its base. + if(FuncAddr::apply() == FuncAddr::apply()) { + throw signal_equal(); + } + } + }; }; - }; + #endif C* obj_; }; diff --git a/include/boost/contract/aux_/condition/check_subcontracted_pre_post_inv.hpp b/include/boost/contract/aux_/condition/check_subcontracted_pre_post_inv.hpp index 63e5ec6..93e4820 100644 --- a/include/boost/contract/aux_/condition/check_subcontracted_pre_post_inv.hpp +++ b/include/boost/contract/aux_/condition/check_subcontracted_pre_post_inv.hpp @@ -2,9 +2,9 @@ #ifndef BOOST_CONTRACT_AUX_CHECK_SUBCONTRACTED_PRE_POST_INV_HPP_ #define BOOST_CONTRACT_AUX_CHECK_SUBCONTRACTED_PRE_POST_INV_HPP_ +#include #include #include -#include #include #include #include @@ -52,66 +52,71 @@ namespace check_subcontracted_pre_post_inv_ { template class check_subcontracted_pre_post_inv : public check_pre_post_inv { // Non-copyable base. - template > - class overridden_bases_of { - struct search_bases { - typedef typename boost::mpl::fold< - typename boost::contract::access::base_types_of::type, - Result, - // Fold: _1 = result, _2 = current base type from base_types. - boost::mpl::eval_if >, - boost::mpl::_1 // Base already in result, do not add again. - , - boost::mpl::eval_if< - typename O::template BOOST_CONTRACT_AUX_NAME1( - has_member_function)< - boost::mpl::_2, - typename member_function_types:: - result_type, - typename member_function_types:: - virtual_argument_types, - typename member_function_types:: - property_tag - > + #if BOOST_CONTRACT_PUBLIC_FUNCTIONS + template > + class overridden_bases_of { + struct search_bases { + typedef typename boost::mpl::fold< + typename boost::contract::access::base_types_of:: + type, + Result, + // Fold: _1 = result, _2 = current base from base_types. + boost::mpl::eval_if >, + boost::mpl::_1 // Base in result, do not add it again. , - boost::mpl::push_back< - overridden_bases_of, - // Bases as * since for_each later constructs them. - boost::add_pointer + boost::mpl::eval_if< + typename O::template BOOST_CONTRACT_AUX_NAME1( + has_member_function)< + boost::mpl::_2, + typename member_function_types:: + result_type, + typename member_function_types:: + virtual_argument_types, + typename member_function_types:: + property_tag + > + , + boost::mpl::push_back< + overridden_bases_of, + // Bases as * since for_each constructs them. + boost::add_pointer + > + , + overridden_bases_of > - , - overridden_bases_of > - > + >::type type; + }; + public: + typedef typename boost::mpl::eval_if< + boost::contract::access::has_base_types, + search_bases + , + boost::mpl::identity // Return result (stop recursion). >::type type; }; - public: - typedef typename boost::mpl::eval_if< - boost::contract::access::has_base_types, - search_bases + + typedef typename boost::mpl::eval_if, + boost::mpl::vector<> , - boost::mpl::identity // Return result (stop recursion). - >::type type; - }; - - typedef typename boost::mpl::eval_if, - boost::mpl::vector<> - , - overridden_bases_of - >::type overridden_bases; + overridden_bases_of + >::type overridden_bases; + #else + typedef boost::mpl::vector<> overridden_bases; + #endif -#ifndef BOOST_CONTRACT_CONFIG_PERMISSIVE - BOOST_STATIC_ASSERT_MSG( - boost::mpl::or_< - boost::is_same, - boost::mpl::not_ > - >::value, - "subcontracting function specified as 'override' but does not " - "override any contracted member function" - ); -#endif + #ifndef BOOST_CONTRACT_CONFIG_PERMISSIVE + BOOST_STATIC_ASSERT_MSG( + boost::mpl::or_< + boost::is_same, + boost::mpl::not_ > + >::value, + "subcontracting function specified as 'override' but does not " + "override any contracted member function" + ); + #endif public: explicit check_subcontracted_pre_post_inv(boost::contract::from from, @@ -121,54 +126,69 @@ public: if(v) { base_call_ = true; v_ = v; // Invariant: v_ never null if base_call_. + BOOST_CONTRACT_AUX_DEBUG(v_); } else { base_call_ = false; if(!boost::mpl::empty::value) { v_ = new boost::contract::virtual_( boost::contract::virtual_::no_action); - v_->result_ptr_ = &r_; - v_->result_type_name_ = typeid(R).name(); - v_->result_optional_ = is_optional::value; + #if BOOST_CONTRACT_POSTCONDITIONS + v_->result_ptr_ = &r_; + v_->result_type_name_ = typeid(R).name(); + v_->result_optional_ = is_optional::value; + #endif } else v_ = 0; } } virtual ~check_subcontracted_pre_post_inv() BOOST_NOEXCEPT_IF(false) { - if(!base_call_ && v_) delete v_; + if(!base_call_) delete v_; } protected: void init_subcontracted_old() { - exec_and(boost::contract::virtual_::push_old_init - /* old values of overloaded func on stack (so no `f` here) */); + #if BOOST_CONTRACT_POSTCONDITIONS + // Old values of overloaded func on stack (so no `f` param here). + exec_and(boost::contract::virtual_::push_old_init); + #endif } void check_subcontracted_entry_inv() { - exec_and(boost::contract::virtual_::check_entry_inv, - &check_subcontracted_pre_post_inv::check_entry_inv); + #if BOOST_CONTRACT_ENTRY_INVARIANTS + exec_and(boost::contract::virtual_::check_entry_inv, + &check_subcontracted_pre_post_inv::check_entry_inv); + #endif } void check_subcontracted_pre() { - exec_or( - boost::contract::virtual_::check_pre, - &check_subcontracted_pre_post_inv::check_pre, - &boost::contract::precondition_failure - ); + #if BOOST_CONTRACT_PRECONDITIONS + exec_or( + boost::contract::virtual_::check_pre, + &check_subcontracted_pre_post_inv::check_pre, + &boost::contract::precondition_failure + ); + #endif } void copy_subcontracted_old() { - exec_and(boost::contract::virtual_::call_old_copy, - &check_subcontracted_pre_post_inv::copy_old_v); + #if BOOST_CONTRACT_POSTCONDITIONS + exec_and(boost::contract::virtual_::call_old_copy, + &check_subcontracted_pre_post_inv::copy_old_v); + #endif } void check_subcontracted_exit_inv() { - exec_and(boost::contract::virtual_::check_exit_inv, - &check_subcontracted_pre_post_inv::check_exit_inv); + #if BOOST_CONTRACT_EXIT_INVARIANTS + exec_and(boost::contract::virtual_::check_exit_inv, + &check_subcontracted_pre_post_inv::check_exit_inv); + #endif } void check_subcontracted_post() { - exec_and(boost::contract::virtual_::check_post, - &check_subcontracted_pre_post_inv::check_post_v); + #if BOOST_CONTRACT_POSTCONDITIONS + exec_and(boost::contract::virtual_::check_post, + &check_subcontracted_pre_post_inv::check_post_v); + #endif } bool base_call() const { return base_call_; } @@ -184,38 +204,51 @@ protected: } private: - void copy_old_v() { - boost::contract::virtual_::action_enum a; - if(base_call_) { - a = v_->action_; - v_->action_ = boost::contract::virtual_::push_old_copy; - } - this->copy_old(); - if(base_call_) v_->action_ = a; - } - - void check_post_v() { - if(base_call_) { - boost::contract::virtual_::action_enum a = v_->action_; - v_->action_ = boost::contract::virtual_::pop_old_copy; + #if BOOST_CONTRACT_POSTCONDITIONS + void copy_old_v() { + boost::contract::virtual_::action_enum a; + if(base_call_) { + a = v_->action_; + v_->action_ = boost::contract::virtual_::push_old_copy; + } this->copy_old(); - v_->action_ = a; + if(base_call_) v_->action_ = a; } + + void check_post_v() { + if(base_call_) { + boost::contract::virtual_::action_enum a = v_->action_; + v_->action_ = boost::contract::virtual_::pop_old_copy; + this->copy_old(); + v_->action_ = a; + } - typedef typename boost::remove_reference::type>::type r_type; - boost::optional r; // No result copy in following code. - if(!base_call_) r = r_; - else if(v_->result_optional_) { - try { - r = **boost::any_cast*>( - v_->result_ptr_); - } catch(boost::bad_any_cast const&) { - try { // Handle optional<...&>. - r = **boost::any_cast*>( + typedef typename boost::remove_reference::type>::type r_type; + boost::optional r; // No result copy in this code. + if(!base_call_) r = r_; + else if(v_->result_optional_) { + try { + r = **boost::any_cast*>( v_->result_ptr_); } catch(boost::bad_any_cast const&) { - try { // No type names in bad_any_cast so use custom except. + try { // Handle optional<...&>. + r = **boost::any_cast*>( + v_->result_ptr_); + } catch(boost::bad_any_cast const&) { + try { + throw boost::contract::bad_virtual_result_cast(v_-> + result_type_name_, typeid(r_type).name()); + } catch(...) { + this->fail(&boost::contract::postcondition_failure); + } + } + } + } else { + try { + r = *boost::any_cast(v_->result_ptr_); + } catch(boost::bad_any_cast const&) { + try { throw boost::contract::bad_virtual_result_cast( v_->result_type_name_, typeid(r_type).name()); } catch(...) { @@ -223,31 +256,20 @@ private: } } } - } else { - try { - r = *boost::any_cast(v_->result_ptr_); - } catch(boost::bad_any_cast const&) { - try { - throw boost::contract::bad_virtual_result_cast( - v_->result_type_name_, typeid(r_type).name()); - } catch(...) { - this->fail(&boost::contract::postcondition_failure); - } - } + check_post_r(r); } - check_post_r(r); - } - template - typename boost::enable_if >::type - check_post_r(Result const& r) { this->check_post(r); } - - template - typename boost::disable_if >::type - check_post_r(Result const& r) { - BOOST_CONTRACT_AUX_DEBUG(r); - this->check_post(*r); - } + template + typename boost::enable_if >::type + check_post_r(Result const& r) { this->check_post(r); } + + template + typename boost::disable_if >::type + check_post_r(Result const& r) { + BOOST_CONTRACT_AUX_DEBUG(r); + this->check_post(*r); + } + #endif void exec_and( // Execute action in short-circuit logic-and with bases. boost::contract::virtual_::action_enum a, @@ -257,7 +279,7 @@ private: if(!base_call_ || v_->action_ == a) { if(!base_call_ && v_) { v_->action_ = a; - boost::mpl::for_each(call_base(this)); + boost::mpl::for_each(call_base(*this)); } if(f) (this->*f)(); if(base_call_) { @@ -309,7 +331,7 @@ private: exec_or_bases() { if(boost::mpl::empty::value) return false; try { - call_base(this)(typename boost::mpl::front::type()); + call_base(*this)(typename boost::mpl::front::type()); } catch(check_subcontracted_pre_post_inv_::signal_not_checked const&) { return exec_or_bases< typename boost::mpl::pop_front::type>(); @@ -324,29 +346,26 @@ private: return true; } - class call_base { // Copyable (as *). + class call_base { // Copyable (as &). public: - explicit call_base(check_subcontracted_pre_post_inv* outer) : - outer_(outer) { - BOOST_CONTRACT_AUX_DEBUG(outer_); - } + explicit call_base(check_subcontracted_pre_post_inv& me) : me_(me) {} template void operator()(B*) { - BOOST_CONTRACT_AUX_DEBUG(outer_->object()); - BOOST_CONTRACT_AUX_DEBUG(outer_->v_); - BOOST_CONTRACT_AUX_DEBUG(outer_->v_->action_ != + BOOST_CONTRACT_AUX_DEBUG(me_.object()); + BOOST_CONTRACT_AUX_DEBUG(me_.v_); + BOOST_CONTRACT_AUX_DEBUG(me_.v_->action_ != boost::contract::virtual_::no_action); try { O::template BOOST_CONTRACT_AUX_NAME1(call_base)( - outer_->object(), outer_->a0_, outer_->a1_, outer_->v_); + me_.object(), me_.a0_, me_.a1_, me_.v_); } catch(check_subcontracted_pre_post_inv_::signal_no_error const&) { // No error (do not throw). } } private: - check_subcontracted_pre_post_inv* outer_; + check_subcontracted_pre_post_inv& me_; }; boost::contract::virtual_* v_; diff --git a/include/boost/contract/aux_/operation/constructor.hpp b/include/boost/contract/aux_/operation/constructor.hpp index b6a69cc..efc5e57 100644 --- a/include/boost/contract/aux_/operation/constructor.hpp +++ b/include/boost/contract/aux_/operation/constructor.hpp @@ -2,14 +2,15 @@ #ifndef BOOST_CONTRACT_AUX_CONSTRUCTOR_HPP_ #define BOOST_CONTRACT_AUX_CONSTRUCTOR_HPP_ +#include +#if BOOST_CONTRACT_INVARIANTS || BOOST_CONTRACT_POSTCONDITIONS +# include +# include +#endif #include #include -#include #include -/** @cond */ #include -#include -/** @endcond */ namespace boost { namespace contract { namespace aux { @@ -19,35 +20,47 @@ class constructor : public check_pre_post_inv { // Non-copyable base. public: explicit constructor(C* obj) : - check_pre_post_inv(boost::contract::from_constructor, - obj) + check_pre_post_inv( + boost::contract::from_constructor, obj) {} private: void init() /* override */ { - if(check_guard::checking()) return; - { - check_guard checking; - this->check_entry_static_inv(); - // No object before ctor body so check only static inv at entry. - // Ctor pre checked by constructor_precondition. - } - this->copy_old(); + #if BOOST_CONTRACT_ENTRY_INVARIANTS || BOOST_CONTRACT_POSTCONDITIONS + if(check_guard::checking()) return; + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + { + check_guard checking; + this->check_entry_static_inv(); + // No object before ctor body so check only static inv at + // entry. Ctor pre checked by constructor_precondition. + } + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + this->copy_old(); + #endif + #endif } public: ~constructor() BOOST_NOEXCEPT_IF(false) { this->assert_guarded(); - if(check_guard::checking()) return; - check_guard checking; - // If ctor body threw, no obj so check only static inv. Otherwise, obj - // constructed so check static inv, non-static inv, and post. - if(std::uncaught_exception()) { - this->check_exit_static_inv(); - } else { - this->check_exit_inv(); - this->check_post(none()); - } + #if BOOST_CONTRACT_EXIT_INVARIANTS || BOOST_CONTRACT_POSTCONDITIONS + if(check_guard::checking()) return; + check_guard checking; + // If ctor body threw, no obj so check only static inv. Otherwise, + // obj constructed so check static inv, non-static inv, and post. + bool body_threw = std::uncaught_exception(); + + #if BOOST_CONTRACT_EXIT_INVARIANTS + if(body_threw) this->check_exit_static_inv(); + else this->check_exit_inv(); + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + if(!body_threw) this->check_post(none()); + #endif + #endif } }; diff --git a/include/boost/contract/aux_/operation/destructor.hpp b/include/boost/contract/aux_/operation/destructor.hpp index ac9696a..40eb06f 100644 --- a/include/boost/contract/aux_/operation/destructor.hpp +++ b/include/boost/contract/aux_/operation/destructor.hpp @@ -2,14 +2,13 @@ #ifndef BOOST_CONTRACT_AUX_DESTRUCTOR_HPP_ #define BOOST_CONTRACT_AUX_DESTRUCTOR_HPP_ +#include #include #include #include #include -/** @cond */ #include #include -/** @endcond */ namespace boost { namespace contract { namespace aux { @@ -25,34 +24,46 @@ public: private: void init() /* override */ { - if(check_guard::checking()) return; - { - check_guard checking; - // Obj exists (before dtor body) so check static and non-static inv. - this->check_entry_inv(); - // Dtor cannot have pre because it has no parameters. - } - this->copy_old(); + #if BOOST_CONTRACT_ENTRY_INVARIANTS || BOOST_CONTRACT_POSTCONDITIONS + if(check_guard::checking()) return; + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + { + check_guard checking; + // Obj exists (before dtor body), check static and non- inv. + this->check_entry_inv(); + // Dtor cannot have pre because it has no parameters. + } + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + this->copy_old(); + #endif + #endif } public: ~destructor() BOOST_NOEXCEPT_IF(false) { this->assert_guarded(); - if(check_guard::checking()) return; - check_guard checking; - // If dtor body threw, obj still exists so check subcontracted static - // and non-static inv (but no post because of throw). Otherwise, obj - // destructed so check static inv and post (even if there is no obj - // after dtor body, this library allows dtor post, for example to check - // static members for an instance counter class). - // NOTE: In theory C++ destructors should not throw, but the language - // allows for that so this library must handle such a case. - if(std::uncaught_exception()) { - this->check_exit_inv(); - } else { - this->check_exit_static_inv(); - this->check_post(none()); - } + #if BOOST_CONTRACT_EXIT_INVARIANTS || BOOST_CONTRACT_POSTCONDITIONS + if(check_guard::checking()) return; + check_guard checking; + // If dtor body threw, obj still exists so check subcontracted + // static and non- inv (but no post because of throw). Otherwise, + // obj destructed so check static inv and post (even if there is no + // obj after dtor body, this library allows dtor post, for example + // to check static members for an instance counter class). + // NOTE: In theory C++ destructors should not throw, but the + // language allows for that so this library must handle such a case. + bool body_threw = std::uncaught_exception(); + + #if BOOST_CONTRACT_EXIT_INVARIANTS + if(body_threw) this->check_exit_inv(); + else this->check_exit_static_inv(); + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + if(!body_threw) this->check_post(none()); + #endif + #endif } }; diff --git a/include/boost/contract/aux_/operation/function.hpp b/include/boost/contract/aux_/operation/function.hpp index a19bfcd..7e995ce 100644 --- a/include/boost/contract/aux_/operation/function.hpp +++ b/include/boost/contract/aux_/operation/function.hpp @@ -2,13 +2,12 @@ #ifndef BOOST_CONTRACT_AUX_FUNCTION_HPP_ #define BOOST_CONTRACT_AUX_FUNCTION_HPP_ +#include #include #include #include -/** @cond */ #include #include -/** @endcond */ namespace boost { namespace contract { namespace aux { @@ -17,25 +16,34 @@ class function : public check_pre_post { // Non-copyable base. public: explicit function() : - check_pre_post(boost::contract::from_function) - {} + check_pre_post(boost::contract::from_function) {} private: void init() /* override */ { - if(check_guard::checking()) return; - { - check_guard checking; - this->check_pre(); - } - this->copy_old(); + #if BOOST_CONTRACT_PRECONDITIONS || BOOST_CONTRACT_POSTCONDITIONS + if(check_guard::checking()) return; + + #if BOOST_CONTRACT_PRECONDITIONS + { + check_guard checking; + this->check_pre(); + } + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + this->copy_old(); + #endif + #endif } public: ~function() BOOST_NOEXCEPT_IF(false) { this->assert_guarded(); - if(check_guard::checking()) return; - check_guard checking; - if(!std::uncaught_exception()) this->check_post(none()); + #if BOOST_CONTRACT_POSTCONDITIONS + if(check_guard::checking()) return; + check_guard checking; + + if(!std::uncaught_exception()) this->check_post(none()); + #endif } }; diff --git a/include/boost/contract/aux_/operation/public_function.hpp b/include/boost/contract/aux_/operation/public_function.hpp index 0fe3274..27e7baa 100644 --- a/include/boost/contract/aux_/operation/public_function.hpp +++ b/include/boost/contract/aux_/operation/public_function.hpp @@ -2,14 +2,13 @@ #ifndef BOOST_CONTRACT_AUX_PUBLIC_FUNCTION_HPP_ #define BOOST_CONTRACT_AUX_PUBLIC_FUNCTION_HPP_ +#include #include #include #include #include -/** @cond */ #include #include -/** @endcond */ namespace boost { namespace contract { namespace aux { @@ -27,33 +26,68 @@ public: private: void init() /* override */ { - this->init_subcontracted_old(); + #if BOOST_CONTRACT_POSTCONDITIONS + this->init_subcontracted_old(); + #endif if(!this->base_call()) { - if(check_guard::checking()) return; - { - check_guard checking; - this->check_subcontracted_entry_inv(); - this->check_subcontracted_pre(); - } - this->copy_subcontracted_old(); + #if BOOST_CONTRACT_ENTRY_INVARIANTS || BOOST_CONTRACT_PRECONDITIONS\ + || BOOST_CONTRACT_POSTCONDITIONS + if(check_guard::checking()) return; + { + check_guard checking; + #if BOOST_CONTRACT_ENTRY_INVARIANTS + this->check_subcontracted_entry_inv(); + #endif + #if BOOST_CONTRACT_PRECONDITIONS + this->check_subcontracted_pre(); + #endif + } + #if BOOST_CONTRACT_POSTCONDITIONS + this->copy_subcontracted_old(); + #endif + #endif } else { - this->check_subcontracted_entry_inv(); - this->check_subcontracted_pre(); - this->copy_subcontracted_old(); - this->check_subcontracted_exit_inv(); - if(!std::uncaught_exception()) this->check_subcontracted_post(); + #if BOOST_CONTRACT_INVARIANTS || BOOST_CONTRACT_PRECONDITIONS || \ + BOOST_CONTRACT_POSTCONDITIONS + #if BOOST_CONTRACT_ENTRY_INVARIANTS + this->check_subcontracted_entry_inv(); + #endif + #if BOOST_CONTRACT_PRECONDITIONS + this->check_subcontracted_pre(); + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + this->copy_subcontracted_old(); + #endif + #if BOOST_CONTRACT_EXIT_INVARIANTS + this->check_subcontracted_exit_inv(); + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + if(!std::uncaught_exception()) { + this->check_subcontracted_post(); + } + #endif + #endif } } public: ~public_function() BOOST_NOEXCEPT_IF(false) { this->assert_guarded(); - if(!this->base_call()) { - if(check_guard::checking()) return; - check_guard checking; - this->check_subcontracted_exit_inv(); - if(!std::uncaught_exception()) this->check_subcontracted_post(); - } + #if BOOST_CONTRACT_EXIT_INVARIANTS || BOOST_CONTRACT_POSTCONDITIONS + if(!this->base_call()) { + if(check_guard::checking()) return; + check_guard checking; + + #if BOOST_CONTRACT_EXIT_INVARIANTS + this->check_subcontracted_exit_inv(); + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + if(!std::uncaught_exception()) { + this->check_subcontracted_post(); + } + #endif + } + #endif } }; diff --git a/include/boost/contract/aux_/operation/public_static_function.hpp b/include/boost/contract/aux_/operation/public_static_function.hpp index 0a1c7b4..3579da2 100644 --- a/include/boost/contract/aux_/operation/public_static_function.hpp +++ b/include/boost/contract/aux_/operation/public_static_function.hpp @@ -2,15 +2,14 @@ #ifndef BOOST_CONTRACT_AUX_PUBLIC_STATIC_FUNCTION_HPP_ #define BOOST_CONTRACT_AUX_PUBLIC_STATIC_FUNCTION_HPP_ +#include #include #include #include #include #include -/** @cond */ #include #include -/** @endcond */ namespace boost { namespace contract { namespace aux { @@ -26,22 +25,40 @@ public: private: void init() /* override */ { - if(check_guard::checking()) return; - { - check_guard checking; - this->check_entry_static_inv(); - this->check_pre(); - } - this->copy_old(); + #if BOOST_CONTRACT_ENTRY_INVARIANTS || BOOST_CONTRACT_PRECONDITIONS || \ + BOOST_CONTRACT_POSTCONDITIONS + if(check_guard::checking()) return; + #if BOOST_CONTRACT_ENTRY_INVARIANTS || BOOST_CONTRACT_PRECONDITIONS + { + check_guard checking; + #if BOOST_CONTRACT_ENTRY_INVARIANTS + this->check_entry_static_inv(); + #endif + #if BOOST_CONTRACT_PRECONDITIONS + this->check_pre(); + #endif + } + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + this->copy_old(); + #endif + #endif } public: ~public_static_function() BOOST_NOEXCEPT_IF(false) { this->assert_guarded(); - if(check_guard::checking()) return; - check_guard checking; - this->check_exit_static_inv(); - if(!std::uncaught_exception()) this->check_post(none()); + #if BOOST_CONTRACT_EXIT_INVARIANTS || BOOST_CONTRACT_POSTCONDITIONS + if(check_guard::checking()) return; + check_guard checking; + + #if BOOST_CONTRACT_EXIT_INVARIANTS + this->check_exit_static_inv(); + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + if(!std::uncaught_exception()) this->check_post(none()); + #endif + #endif } }; diff --git a/include/boost/contract/base_types.hpp b/include/boost/contract/base_types.hpp index e4bc0bb..088940a 100644 --- a/include/boost/contract/base_types.hpp +++ b/include/boost/contract/base_types.hpp @@ -4,12 +4,13 @@ /** @file */ -/** @cond */ +#include #include -/** @endcond */ #if !BOOST_PP_VARIADICS # define BOOST_CONTRACT_BASE_TYPES \ BOOST_CONTRACT_ERROR_macro_BASE_TYPES_requires_variadic_macros_otherwise_manually_program_base_types +#elif !BOOST_CONTRACT_PUBLIC_FUNCTIONS +# define BOOST_CONTRACT_BASE_TYPES(...) void /* dummy type for typedef */ #else #include @@ -141,7 +142,7 @@ BOOST_CONTRACT_ERROR_macro_BASE_TYPES_requires_variadic_macros_otherwise_manuall 0 \ ))) -#endif // BOOST_PP_VARIADICS +#endif #endif // #include guard diff --git a/include/boost/contract/constructor.hpp b/include/boost/contract/constructor.hpp index 33e046e..c97d5ec 100644 --- a/include/boost/contract/constructor.hpp +++ b/include/boost/contract/constructor.hpp @@ -4,8 +4,11 @@ /** @file */ +#include +#if BOOST_CONTRACT_PRECONDITIONS +# include +#endif #include -#include #include namespace boost { namespace contract { @@ -16,19 +19,20 @@ set_old_postcondition<> constructor(C* obj) { new boost::contract::aux::constructor(obj)); } -// Uses C tparam to avoid multiple inheritance from same type. -template +template // tparam avoids multiple instance of same base in user code. class constructor_precondition { // Copyable (no data). public: constructor_precondition() {} // For user ctor overloads with no pre. template explicit constructor_precondition(F const& f) { - try { f(); } - catch(...) { precondition_failure(from_constructor); } + #if BOOST_CONTRACT_PRECONDITIONS + try { f(); } + catch(...) { precondition_failure(from_constructor); } + #endif } - // Default copy operations (so user's derived classes can also be copyable). + // Default copy operations (so user's derived classes can be copied, etc.). }; } } // namespace diff --git a/include/boost/contract/core/access.hpp b/include/boost/contract/core/access.hpp index f5bbe26..3b0f5f4 100644 --- a/include/boost/contract/core/access.hpp +++ b/include/boost/contract/core/access.hpp @@ -38,63 +38,67 @@ namespace boost { namespace contract { // at run-time. Therefore programmers must make sure to either declare contract // members public or to make this class a friend. class access { // Copyable (as shell with no data member). - BOOST_CONTRACT_AUX_INTROSPECTION_HAS_TYPE(has_base_types, - BOOST_CONTRACT_CONFIG_BASE_TYPES) + #if BOOST_CONTRACT_PUBLIC_FUNCTIONS + BOOST_CONTRACT_AUX_INTROSPECTION_HAS_TYPE(has_base_types, + BOOST_CONTRACT_CONFIG_BASE_TYPES) - template - struct base_types_of { - typedef typename C::BOOST_CONTRACT_CONFIG_BASE_TYPES type; - }; + template + struct base_types_of { + typedef typename C::BOOST_CONTRACT_CONFIG_BASE_TYPES type; + }; + #endif - BOOST_CONTRACT_AUX_INTROSPECTION_HAS_MEMBER_FUNCTION( - has_static_invariant_f, BOOST_CONTRACT_CONFIG_STATIC_INVARIANT) - - BOOST_CONTRACT_AUX_INTROSPECTION_HAS_STATIC_MEMBER_FUNCTION( - has_static_invariant_s, BOOST_CONTRACT_CONFIG_STATIC_INVARIANT) + #if BOOST_CONTRACT_INVARIANTS + BOOST_CONTRACT_AUX_INTROSPECTION_HAS_MEMBER_FUNCTION( + has_static_invariant_f, BOOST_CONTRACT_CONFIG_STATIC_INVARIANT) + + BOOST_CONTRACT_AUX_INTROSPECTION_HAS_STATIC_MEMBER_FUNCTION( + has_static_invariant_s, BOOST_CONTRACT_CONFIG_STATIC_INVARIANT) - template - struct has_static_invariant : has_static_invariant_s > {}; + template + struct has_static_invariant : has_static_invariant_s > {}; - template - static void static_invariant() { - C::BOOST_CONTRACT_CONFIG_STATIC_INVARIANT(); - } - - template - class static_invariant_addr { // Tpl instead of func to pass it as tparam. - typedef void (*func_ptr)(); - public: - static func_ptr apply() { - return &C::BOOST_CONTRACT_CONFIG_STATIC_INVARIANT; + template + static void static_invariant() { + C::BOOST_CONTRACT_CONFIG_STATIC_INVARIANT(); } - }; - BOOST_CONTRACT_AUX_INTROSPECTION_HAS_MEMBER_FUNCTION( - has_invariant_f, BOOST_CONTRACT_CONFIG_INVARIANT) - - BOOST_CONTRACT_AUX_INTROSPECTION_HAS_STATIC_MEMBER_FUNCTION( - has_invariant_s, BOOST_CONTRACT_CONFIG_INVARIANT) + template + class static_invariant_addr { // Class so to pass it as tparam. + typedef void (*func_ptr)(); + public: + static func_ptr apply() { + return &C::BOOST_CONTRACT_CONFIG_STATIC_INVARIANT; + } + }; - template - struct has_cv_invariant : has_invariant_f, - boost::function_types::cv_qualified> {}; - - template - struct has_const_invariant : has_invariant_f, - boost::function_types::const_qualified> {}; + BOOST_CONTRACT_AUX_INTROSPECTION_HAS_MEMBER_FUNCTION( + has_invariant_f, BOOST_CONTRACT_CONFIG_INVARIANT) + + BOOST_CONTRACT_AUX_INTROSPECTION_HAS_STATIC_MEMBER_FUNCTION( + has_invariant_s, BOOST_CONTRACT_CONFIG_INVARIANT) - template - static void cv_invariant(C const volatile* obj) { - BOOST_CONTRACT_AUX_DEBUG(obj); - obj->BOOST_CONTRACT_CONFIG_INVARIANT(); - } - - template - static void const_invariant(C const* obj) { - BOOST_CONTRACT_AUX_DEBUG(obj); - obj->BOOST_CONTRACT_CONFIG_INVARIANT(); - } + template + struct has_cv_invariant : has_invariant_f, + boost::function_types::cv_qualified> {}; + + template + struct has_const_invariant : has_invariant_f, boost::function_types::const_qualified> {}; + + template + static void cv_invariant(C const volatile* obj) { + BOOST_CONTRACT_AUX_DEBUG(obj); + obj->BOOST_CONTRACT_CONFIG_INVARIANT(); + } + + template + static void const_invariant(C const* obj) { + BOOST_CONTRACT_AUX_DEBUG(obj); + obj->BOOST_CONTRACT_CONFIG_INVARIANT(); + } + #endif // Friendship used to limit library's public API. diff --git a/include/boost/contract/core/config.hpp b/include/boost/contract/core/config.hpp index 6c43713..390ea86 100644 --- a/include/boost/contract/core/config.hpp +++ b/include/boost/contract/core/config.hpp @@ -4,22 +4,26 @@ /** @file */ +// IMPORTANT: This header MUST NOT #include any other header. That way users +// can #include this header and not #include any of this lib headers after that +// depending on the contract 0/1 macros below ensuring no compilation overhead. + // TODO: Disable pre, post, and/or entry/exit inv (all combinations). Can I compile lib1 with some contract enabled/disable settings, lib2 with other settings and then link the two together? // TODO: Add a config macro PRECONDITIONS_DISABLE_NOTHING to avoid disabling contract assertions within assertions checking for preconditions (to avoid passing unchecked arguments to function body...). This is what N1962 does... but this macro should be #undef by default. #ifndef BOOST_CONTRACT_CONFIG_BASE_TYPES -# define BOOST_CONTRACT_CONFIG_BASE_TYPES base_types + #define BOOST_CONTRACT_CONFIG_BASE_TYPES base_types #endif #ifndef BOOST_CONTRACT_CONFIG_INVARIANT -# define BOOST_CONTRACT_CONFIG_INVARIANT invariant + #define BOOST_CONTRACT_CONFIG_INVARIANT invariant #endif // C++ does not allow to overload member functions based on static classifier, // so a name different from the non-static class invariant member must be used. #ifndef BOOST_CONTRACT_CONFIG_STATIC_INVARIANT -# define BOOST_CONTRACT_CONFIG_STATIC_INVARIANT static_invariant + #define BOOST_CONTRACT_CONFIG_STATIC_INVARIANT static_invariant #endif // BOOST_CONTRACT_CONFIG_PERMISSIVE (#undef by default). @@ -47,43 +51,91 @@ // BOOST_CONTRACT_CONFIG_NO_EXIT_INVARIANTS // BOOST_CONTRACT_CONFIG_NO_INVARIANTS -#ifdef BOOST_CONTRACT_CONFIG_NO_PRECONDITIONS -# define BOOST_CONTRACT_NO_PRECONDITIONS 1 +// Following are NOT configuration macros. + +#if defined(BOOST_CONTRACT_PRECONDITIONS) + #error "define/undef ..._CONFIG_NO_PRECONDITIONS instead" +#elif defined(BOOST_CONTRACT_CONFIG_NO_PRECONDITIONS) + #define BOOST_CONTRACT_PRECONDITIONS 0 #else -# define BOOST_CONTRACT_NO_PRECONDITIONS 0 + #define BOOST_CONTRACT_PRECONDITIONS 1 #endif -#ifdef BOOST_CONTRACT_CONFIG_NO_POSTCONDITIONS -# define BOOST_CONTRACT_NO_POSTCONDITIONS 1 +#if defined(BOOST_CONTRACT_POSTCONDITIONS) + #error "define/undef ..._CONFIG_NO_POSTCONDITIONS instead" +#elif defined(BOOST_CONTRACT_CONFIG_NO_POSTCONDITIONS) + #define BOOST_CONTRACT_POSTCONDITIONS 0 #else -# define BOOST_CONTRACT_NO_POSTCONDITIONS 0 + #define BOOST_CONTRACT_POSTCONDITIONS 1 #endif -#if defined(BOOST_CONTRACT_CONFIG_NO_ENTRY_INVARIANTS) || \ +#if defined(BOOST_CONTRACT_ENTRY_INVARIANTS) + #error "define/undef ..._CONFIG_NO[_ENTRY]_INVARIANTS instead" +#elif defined(BOOST_CONTRACT_CONFIG_NO_ENTRY_INVARIANTS) || \ defined (BOOST_CONTRACT_CONFIG_NO_INVARIANTS) -# define BOOST_CONTRACT_NO_ENTRY_INVARIANTS 1 + #define BOOST_CONTRACT_ENTRY_INVARIANTS 0 #else -# define BOOST_CONTRACT_NO_ENTRY_INVARIANTS 0 + #define BOOST_CONTRACT_ENTRY_INVARIANTS 1 #endif -#if defined(BOOST_CONTRACT_CONFIG_NO_EXIT_INVARIANTS) || \ +#if defined(BOOST_CONTRACT_EXIT_INVARIANTS) + #error "define/undef ..._CONFIG_NO[_EXIT]_INVARIANTS instead" +#elif defined(BOOST_CONTRACT_CONFIG_NO_EXIT_INVARIANTS) || \ defined (BOOST_CONTRACT_CONFIG_NO_INVARIANTS) -# define BOOST_CONTRACT_NO_EXIT_INVARIANTS 1 + #define BOOST_CONTRACT_EXIT_INVARIANTS 0 #else -# define BOOST_CONTRACT_NO_EXIT_INVARIANTS 0 + #define BOOST_CONTRACT_EXIT_INVARIANTS 1 #endif -#if BOOST_CONTRACT_NO_ENTRY_INVARIANTS && BOOST_CONTRACT_NO_EXIT_INVARIANTS -# define BOOST_CONTRACT_NO_INVARIANTS 1 +#if defined(BOOST_CONTRACT_INVARIANTS) + #error "define/undef ..._CONFIG_NO[_ENTRY/_EXIT]_INVARIANTS instead" +#elif BOOST_CONTRACT_NO_ENTRY_INVARIANTS && BOOST_CONTRACT_NO_EXIT_INVARIANTS + #define BOOST_CONTRACT_INVARIANTS 0 #else -# define BOOST_CONTRACT_NO_INVARIANTS 1 + #define BOOST_CONTRACT_INVARIANTS 1 #endif -#if BOOST_CONTRACT_NO_PRECONDITONS && BOOST_CONTRACT_NO_POSTCONDITIONS && \ - BOOST_CONTRACT_NO_INVARIANTS -# define BOOST_CONTRACT_NO_CONTRACTS 1 +#if defined(BOOST_CONTRACT_FUNCTIONS) + #error "define/undef ..._CONFIG_NO_... instead" +#elif !BOOST_CONTRACT_PRECONDITIONS && !BOOST_CONTRACT_POSTCONDITIONS + #define BOOST_CONTRACT_FUNCTIONS 0 #else -# define BOOST_CONTRACT_NO_CONTRACTS 0 + #define BOOST_CONTRACT_FUNCTIONS 1 +#endif + +#if defined(BOOST_CONTRACT_CONSTRUCTORS) + #error "define/undef ..._CONFIG_NO_... instead" +// Ctor pre checked separately and outside guard so not part of this if cond. +#elif !BOOST_CONTRACT_POSTCONDITIONS && !BOOST_CONTRACT_INVARIANTS + #define BOOST_CONTRACT_CONSTRUCTORS 0 +#else + #define BOOST_CONTRACT_CONSTRUCTORS 1 +#endif + +#if defined(BOOST_CONTRACT_DESTRUCTORS) + #error "define/undef ..._CONFIG_NO_... instead" +#elif !BOOST_CONTRACT_POSTCONDITIONS && !BOOST_CONTRACT_INVARIANTS + #define BOOST_CONTRACT_DESTRUCTORS 0 +#else + #define BOOST_CONTRACT_DESTRUCTORS 1 +#endif + +#if defined(BOOST_CONTRACT_PUBLIC_FUNCTIONS) + #error "define/undef ..._CONFIG_NO_... instead" +#elif !BOOST_CONTRACT_PRECONDITONS && !BOOST_CONTRACT_POSTCONDITIONS && \ + !BOOST_CONTRACT_INVARIANTS + #define BOOST_CONTRACT_PUBLIC_FUNCTIONS 0 +#else + #define BOOST_CONTRACT_PUBLIC_FUNCTIONS 1 +#endif + +#if defined(BOOST_CONTRACT_CLASSES) + #error "define/undef ..._CONFIG_NO_... instead" +#elif !BOOST_CONTRACT_CONSTRUCTORS && !BOOST_CONTRACT_DESTRUCTORS && \ + !BOOST_CONTRACT_PUBLIC_FUNCTIONS + #define BOOST_CONTRACT_CLASSES 0 +#else + #define BOOST_CONTRACT_CLASSES 1 #endif #endif // #include guard diff --git a/include/boost/contract/core/exception.hpp b/include/boost/contract/core/exception.hpp index bab61ae..29ae24f 100644 --- a/include/boost/contract/core/exception.hpp +++ b/include/boost/contract/core/exception.hpp @@ -4,6 +4,7 @@ /** @file */ +#include /** @cond */ #include #include @@ -17,7 +18,7 @@ /* PRIVATE */ #define BOOST_CONTRACT_EXCEPTION_HANDLER_SCOPED_LOCK_(_mutex) \ - /*boost::mutex::scoped_lock lock(_mutex);*/ \ + /*boost::mutex::scoped_lock lock(_mutex);*/ #define BOOST_CONTRACT_EXCEPTION_HANDLER_SET_(_mutex, handler, f) \ BOOST_CONTRACT_EXCEPTION_HANDLER_SCOPED_LOCK_(_mutex); \ @@ -138,6 +139,7 @@ namespace exception_ { } // TODO: These (and some of the related def code) should be moved in a .cpp. + //boost::mutex pre_failure_mutex; assertion_failure_handler pre_failure_handler = &default_handler; @@ -155,6 +157,8 @@ namespace exception_ { &default_handler; } +// Contract compilation on/off cannot change following set/get. + assertion_failure_handler set_precondition_failure( assertion_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW { BOOST_CONTRACT_EXCEPTION_HANDLER_SET_(exception_::pre_failure_mutex, @@ -168,8 +172,10 @@ assertion_failure_handler get_precondition_failure() } void precondition_failure(from where) /* can throw */ { - BOOST_CONTRACT_EXCEPTION_HANDLER_(exception_::pre_failure_mutex, - exception_::pre_failure_handler, where) + #if BOOST_CONTRACT_PRECONDITIONS + BOOST_CONTRACT_EXCEPTION_HANDLER_(exception_::pre_failure_mutex, + exception_::pre_failure_handler, where) + #endif } assertion_failure_handler set_postcondition_failure( @@ -185,14 +191,16 @@ assertion_failure_handler get_postcondition_failure() } void postcondition_failure(from where) /* can throw */ { - BOOST_CONTRACT_EXCEPTION_HANDLER_(exception_::post_failure_mutex, - exception_::post_failure_handler, where); + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_CONTRACT_EXCEPTION_HANDLER_(exception_::post_failure_mutex, + exception_::post_failure_handler, where); + #endif } assertion_failure_handler set_entry_invariant_failure( assertion_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW { BOOST_CONTRACT_EXCEPTION_HANDLER_SET_(exception_::entry_inv_failure_mutex, - exception_::entry_inv_failure_handler, f); + exception_::entry_inv_failure_handler, f); } assertion_failure_handler get_entry_invariant_failure() @@ -202,14 +210,16 @@ assertion_failure_handler get_entry_invariant_failure() } void entry_invariant_failure(from where) /* can throw */ { - BOOST_CONTRACT_EXCEPTION_HANDLER_(exception_::entry_inv_failure_mutex, - exception_::entry_inv_failure_handler, where); + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_CONTRACT_EXCEPTION_HANDLER_(exception_::entry_inv_failure_mutex, + exception_::entry_inv_failure_handler, where); + #endif } assertion_failure_handler set_exit_invariant_failure( assertion_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW { BOOST_CONTRACT_EXCEPTION_HANDLER_SET_(exception_::exit_inv_failure_mutex, - exception_::exit_inv_failure_handler, f); + exception_::exit_inv_failure_handler, f); } assertion_failure_handler get_exit_invariant_failure() @@ -219,12 +229,14 @@ assertion_failure_handler get_exit_invariant_failure() } void exit_invariant_failure(from where) /* can throw */ { - BOOST_CONTRACT_EXCEPTION_HANDLER_(exception_::exit_inv_failure_mutex, - exception_::exit_inv_failure_handler, where); + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_CONTRACT_EXCEPTION_HANDLER_(exception_::exit_inv_failure_mutex, + exception_::exit_inv_failure_handler, where); + #endif } -void set_invariant_failure( - assertion_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW { +void set_invariant_failure(assertion_failure_handler const& f) + BOOST_NOEXCEPT_OR_NOTHROW { set_entry_invariant_failure(f); set_exit_invariant_failure(f); } diff --git a/include/boost/contract/core/set_nothing.hpp b/include/boost/contract/core/set_nothing.hpp index 15d17e8..5b7533f 100644 --- a/include/boost/contract/core/set_nothing.hpp +++ b/include/boost/contract/core/set_nothing.hpp @@ -6,7 +6,6 @@ #include #include -#include /** @cond */ #include /** @endcond */ diff --git a/include/boost/contract/core/set_old_postcondition.hpp b/include/boost/contract/core/set_old_postcondition.hpp index 7427f4e..43e49f9 100644 --- a/include/boost/contract/core/set_old_postcondition.hpp +++ b/include/boost/contract/core/set_old_postcondition.hpp @@ -4,12 +4,15 @@ /** @file */ +#include #include #include #include #include #include -#include +#if BOOST_CONTRACT_POSTCONDITIONS +# include +#endif /** @cond */ #include /** @endcond */ @@ -30,15 +33,19 @@ public: template set_postcondition_only old(F const& f) { - BOOST_CONTRACT_AUX_DEBUG(check_); - check_->set_old(f); + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_CONTRACT_AUX_DEBUG(check_); + check_->set_old(f); + #endif return set_postcondition_only(check_.release()); } template set_nothing postcondition(F const& f) { - BOOST_CONTRACT_AUX_DEBUG(check_); - check_->set_post(f); + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_CONTRACT_AUX_DEBUG(check_); + check_->set_post(f); + #endif return set_nothing(check_.release()); } diff --git a/include/boost/contract/core/set_postcondition_only.hpp b/include/boost/contract/core/set_postcondition_only.hpp index 7ae4c7b..184f924 100644 --- a/include/boost/contract/core/set_postcondition_only.hpp +++ b/include/boost/contract/core/set_postcondition_only.hpp @@ -4,11 +4,14 @@ /** @file */ +#include #include #include #include #include -#include +#if BOOST_CONTRACT_POSTCONDITIONS +# include +#endif /** @cond */ #include /** @endcond */ @@ -32,8 +35,10 @@ public: template set_nothing postcondition(F const& f) { - BOOST_CONTRACT_AUX_DEBUG(check_); - check_->set_post(f); + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_CONTRACT_AUX_DEBUG(check_); + check_->set_post(f); + #endif return set_nothing(check_.release()); } diff --git a/include/boost/contract/core/set_precondition_old_postcondition.hpp b/include/boost/contract/core/set_precondition_old_postcondition.hpp index 8aaa83e..c223727 100644 --- a/include/boost/contract/core/set_precondition_old_postcondition.hpp +++ b/include/boost/contract/core/set_precondition_old_postcondition.hpp @@ -4,13 +4,16 @@ /** @file */ +#include #include #include #include #include #include #include -#include +#if BOOST_CONTRACT_PRECONDITIONS || BOOST_CONTRACT_POSTCONDITIONS +# include +#endif /** @cond */ #include /** @endcond */ @@ -30,22 +33,28 @@ public: template set_old_postcondition precondition(F const& f) { - BOOST_CONTRACT_AUX_DEBUG(check_); - check_->set_pre(f); + #if BOOST_CONTRACT_PRECONDITIONS + BOOST_CONTRACT_AUX_DEBUG(check_); + check_->set_pre(f); + #endif return set_old_postcondition(check_.release()); } template set_postcondition_only old(F const& f) { - BOOST_CONTRACT_AUX_DEBUG(check_); - check_->set_old(f); + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_CONTRACT_AUX_DEBUG(check_); + check_->set_old(f); + #endif return set_postcondition_only(check_.release()); } template set_nothing postcondition(F const& f) { - BOOST_CONTRACT_AUX_DEBUG(check_); - check_->set_post(f); + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_CONTRACT_AUX_DEBUG(check_); + check_->set_post(f); + #endif return set_nothing(check_.release()); } diff --git a/include/boost/contract/core/virtual.hpp b/include/boost/contract/core/virtual.hpp index 9ad6128..a6b091b 100644 --- a/include/boost/contract/core/virtual.hpp +++ b/include/boost/contract/core/virtual.hpp @@ -2,6 +2,7 @@ #ifndef BOOST_CONTRACT_VIRTUAL_HPP_ #define BOOST_CONTRACT_VIRTUAL_HPP_ +#include /** @cond */ #include #include @@ -29,28 +30,48 @@ private: enum action_enum { // virtual_ always hold/passed by ptr so null ptr used for user call. no_action, - push_old_init, - check_entry_inv, - check_pre, - call_old_copy, - push_old_copy, - check_exit_inv, - pop_old_copy, - check_post, - pop_old_init = check_post // These must be the same value. + #if BOOST_CONTRACT_POSTCONDITIONS + push_old_init, + #endif + #if BOOST_CONTRACT_ENTRY_INVARIANTS + check_entry_inv, + #endif + #if BOOST_CONTRACT_PRECONDITIONS + check_pre, + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + call_old_copy, + push_old_copy, + #endif + #if BOOST_CONTRACT_EXIT_INVARIANTS + check_exit_inv, + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + pop_old_copy, + check_post, + pop_old_init = check_post // These must be the same value. + #endif }; - explicit virtual_(action_enum a) : action_(a), result_type_name_(), - result_optional_(), failed_(false) {} + explicit virtual_(action_enum a) : + action_(a), + #if BOOST_CONTRACT_POSTCONDITIONS + result_type_name_(), + result_optional_(), + #endif + failed_(false) + {} action_enum action_; - std::queue > old_inits_; - std::stack > old_copies_; + #if BOOST_CONTRACT_POSTCONDITIONS + std::queue > old_inits_; + std::stack > old_copies_; - boost::any result_ptr_; - char const* result_type_name_; - bool result_optional_; + boost::any result_ptr_; + char const* result_type_name_; + bool result_optional_; + #endif bool failed_; diff --git a/include/boost/contract/guard.hpp b/include/boost/contract/guard.hpp index ffe99c3..cdf1a88 100644 --- a/include/boost/contract/guard.hpp +++ b/include/boost/contract/guard.hpp @@ -33,7 +33,7 @@ class guard { // Non-copyable (but copy ctor ~= move via ptr release). public: // Following copy and implicit type conversion ctors to allow `guard = ...`. - guard(guard const& other) : + guard(guard const& other) : // Copy ctor moves check_ pointer to dest. check_(const_cast(other).check_.release()) {} template diff --git a/include/boost/contract/old.hpp b/include/boost/contract/old.hpp index 8a6994a..9e1b29f 100644 --- a/include/boost/contract/old.hpp +++ b/include/boost/contract/old.hpp @@ -33,6 +33,8 @@ BOOST_CONTRACT_ERROR_macro_OLDOF_requires_variadic_macros_otherwise_manually_pro /* PUBLIC */ +// NOTE: Leave this #defined the same regardless of +// BOOST_CONTRACT_POSTCONDITIONS (impl of expanded func will change instead). #define BOOST_CONTRACT_OLDOF(...) \ BOOST_PP_CAT( /* CAT(..., EMTPY()) required on MSVC */ \ BOOST_PP_OVERLOAD( \ @@ -89,8 +91,10 @@ template class old_ptr { // Copyable (as *). public: explicit old_ptr() {} + + // Only const access (because contracts should not change program state). - T const& operator*() const { return ptr_.operator*(); } + T const& operator*() const { BOOST_CONTRACT_AUX_DEBUG(ptr_); return *ptr_; } T const* operator->() const { return ptr_.operator->(); } @@ -112,13 +116,17 @@ public: /* implicit */ unconvertible_old( T const& old_value, typename boost::enable_if >::type* = 0 - ) : ptr_(boost::make_shared(old_value)) {} // The one single copy of T. + ) + #if BOOST_CONTRACT_POSTCONDITIONS + : ptr_(boost::make_shared(old_value)) // The one single copy of T. + #endif // Else, null ptr_ (so not copy of T). + {} template /* implicit */ unconvertible_old( T const&, typename boost::disable_if >::type* = 0 - ) : ptr_() {} // Null ptr, no copy of T. + ) {} // Null ptr_ (so no copy of T). private: explicit unconvertible_old() {} @@ -134,53 +142,58 @@ public: // Implicitly called by constructor init `old_ptr old_x = ...`. template /* implicit */ operator old_ptr() { - if(!boost::is_copy_constructible::value) { - BOOST_CONTRACT_AUX_DEBUG(!ptr_); // Non-copyable so no old... - return old_ptr(); // ...and return null. - } else if(!v_ && boost::contract::aux::check_guard::checking()) { - // Return null shared ptr (see after if statement). - } else if(!v_) { - BOOST_CONTRACT_AUX_DEBUG(ptr_); - boost::shared_ptr old = - boost::static_pointer_cast(ptr_); - BOOST_CONTRACT_AUX_DEBUG(old); - return old_ptr(old); - } else if(v_->action_ == boost::contract::virtual_::push_old_init || - v_->action_ == boost::contract::virtual_::push_old_copy) { - BOOST_CONTRACT_AUX_DEBUG(ptr_); - if(v_->action_ == boost::contract::virtual_::push_old_init) { - v_->old_inits_.push(ptr_); - } else { - v_->old_copies_.push(ptr_); + #if BOOST_CONTRACT_POSTCONDITIONS + if(!boost::is_copy_constructible::value) { + BOOST_CONTRACT_AUX_DEBUG(!ptr_); // Non-copyable so no old... + return old_ptr(); // ...and return null. + } else if(!v_ && boost::contract::aux::check_guard::checking()) { + // Return null shared ptr (see after if statement). + } else if(!v_) { + BOOST_CONTRACT_AUX_DEBUG(ptr_); + boost::shared_ptr old = + boost::static_pointer_cast(ptr_); + BOOST_CONTRACT_AUX_DEBUG(old); + return old_ptr(old); + } else if(v_->action_ == boost::contract::virtual_::push_old_init || + v_->action_ == boost::contract::virtual_::push_old_copy) { + BOOST_CONTRACT_AUX_DEBUG(ptr_); + if(v_->action_ == boost::contract::virtual_::push_old_init) { + v_->old_inits_.push(ptr_); + } else { + v_->old_copies_.push(ptr_); + } + return old_ptr(); + } else if(v_->action_ == boost::contract::virtual_::pop_old_init || + v_->action_ == boost::contract::virtual_::pop_old_copy) { + BOOST_CONTRACT_AUX_DEBUG(!ptr_); + boost::shared_ptr ptr; + if(v_->action_ == boost::contract::virtual_::pop_old_init) { + ptr = v_->old_inits_.front(); + } else { + ptr = v_->old_copies_.top(); + } + BOOST_CONTRACT_AUX_DEBUG(ptr); + if(v_->action_ == boost::contract::virtual_::pop_old_init) { + v_->old_inits_.pop(); + } else { + v_->old_copies_.pop(); + } + boost::shared_ptr old = + boost::static_pointer_cast(ptr); + BOOST_CONTRACT_AUX_DEBUG(old); + return old_ptr(old); } - return old_ptr(); - } else if(v_->action_ == boost::contract::virtual_::pop_old_init || - v_->action_ == boost::contract::virtual_::pop_old_copy) { - BOOST_CONTRACT_AUX_DEBUG(!ptr_); - boost::shared_ptr ptr; - if(v_->action_ == boost::contract::virtual_::pop_old_init) { - ptr = v_->old_inits_.front(); - } else { - ptr = v_->old_copies_.top(); - } - BOOST_CONTRACT_AUX_DEBUG(ptr); - if(v_->action_ == boost::contract::virtual_::pop_old_init) { - v_->old_inits_.pop(); - } else { - v_->old_copies_.pop(); - } - boost::shared_ptr old = - boost::static_pointer_cast(ptr); - BOOST_CONTRACT_AUX_DEBUG(old); - return old_ptr(old); - } + #endif BOOST_CONTRACT_AUX_DEBUG(!ptr_); return old_ptr(); } private: - explicit convertible_old(virtual_* v, unconvertible_old const& old) : - v_(v), ptr_(old.ptr_) {} + explicit convertible_old(virtual_* v, unconvertible_old const& old) + #if BOOST_CONTRACT_POSTCONDITIONS + : v_(v), ptr_(old.ptr_) + #endif + {} virtual_* v_; boost::shared_ptr ptr_; @@ -200,21 +213,21 @@ convertible_old make_old(virtual_* v, unconvertible_old const& old) { } bool copy_old() { -#if BOOST_CONTRACT_CONFIG_NO_POSTCONDITIONS - return false; // Post checking disabled, so never copy old values. -#else - return !boost::contract::aux::check_guard::checking(); -#endif + #if BOOST_CONTRACT_POSTCONDITIONS + return !boost::contract::aux::check_guard::checking(); + #else + return false; // Post checking disabled, so never copy old values. + #endif } bool copy_old(virtual_* v) { -#if BOOST_CONTRACT_CONFIG_NO_POSTCONDITIONS - return false; // Post checking disabled, so never copy old values. -#else - if(!v) return !boost::contract::aux::check_guard::checking(); - return v->action_ == boost::contract::virtual_::push_old_init || - v->action_ == boost::contract::virtual_::push_old_copy; -#endif + #if BOOST_CONTRACT_POSTCONDITIONS + if(!v) return !boost::contract::aux::check_guard::checking(); + return v->action_ == boost::contract::virtual_::push_old_init || + v->action_ == boost::contract::virtual_::push_old_copy; + #else + return false; // Post checking disabled, so never copy old values. + #endif } } } // namespace diff --git a/include/boost/contract/override.hpp b/include/boost/contract/override.hpp index a87fdc3..f89e136 100644 --- a/include/boost/contract/override.hpp +++ b/include/boost/contract/override.hpp @@ -4,75 +4,77 @@ /** @file */ -#include -#include -#include -#include -/** @cond */ -#include -/** @endcond */ - /* PUBLIC */ +#include #define BOOST_CONTRACT_OVERRIDE(f) \ BOOST_CONTRACT_OVERRIDE_TRAIT(BOOST_PP_CAT(override_, f), f) -#define BOOST_CONTRACT_OVERRIDE_TRAIT(trait, f) \ - struct trait { \ - BOOST_CONTRACT_AUX_INTROSPECTION_HAS_MEMBER_FUNCTION( \ - BOOST_CONTRACT_AUX_NAME1(has_member_function), f) \ - /* arity = 0 */ \ - template< \ - class BOOST_CONTRACT_AUX_NAME1(B), \ - class BOOST_CONTRACT_AUX_NAME1(C) \ - > \ - static void BOOST_CONTRACT_AUX_NAME1(call_base)( \ - BOOST_CONTRACT_AUX_NAME1(C)* BOOST_CONTRACT_AUX_NAME1(obj), \ - boost::contract::aux::none&, \ - boost::contract::aux::none&, \ - boost::contract::virtual_* BOOST_CONTRACT_AUX_NAME1(v) \ - ) { \ - BOOST_CONTRACT_AUX_NAME1(obj)->BOOST_CONTRACT_AUX_NAME1(B)::f( \ - BOOST_CONTRACT_AUX_NAME1(v) \ - ); \ - } \ - /* arity = 1 */ \ - template< \ - class BOOST_CONTRACT_AUX_NAME1(B), \ - class BOOST_CONTRACT_AUX_NAME1(C), \ - typename BOOST_CONTRACT_AUX_NAME1(A0) \ - > \ - static void BOOST_CONTRACT_AUX_NAME1(call_base)( \ - BOOST_CONTRACT_AUX_NAME1(C)* BOOST_CONTRACT_AUX_NAME1(obj), \ - BOOST_CONTRACT_AUX_NAME1(A0)& BOOST_CONTRACT_AUX_NAME1(a0), \ - boost::contract::aux::none&, \ - boost::contract::virtual_* BOOST_CONTRACT_AUX_NAME1(v) \ - ) { \ - BOOST_CONTRACT_AUX_NAME1(obj)->BOOST_CONTRACT_AUX_NAME1(B)::f( \ - BOOST_CONTRACT_AUX_NAME1(a0), \ - BOOST_CONTRACT_AUX_NAME1(v) \ - ); \ - } \ - /* arity = 2 */ \ - template< \ - class BOOST_CONTRACT_AUX_NAME1(B), \ - class BOOST_CONTRACT_AUX_NAME1(C), \ - typename BOOST_CONTRACT_AUX_NAME1(A0), \ - typename BOOST_CONTRACT_AUX_NAME1(A1) \ - > \ - static void BOOST_CONTRACT_AUX_NAME1(call_base)( \ - BOOST_CONTRACT_AUX_NAME1(C)* BOOST_CONTRACT_AUX_NAME1(obj), \ - BOOST_CONTRACT_AUX_NAME1(A0)& BOOST_CONTRACT_AUX_NAME1(a0), \ - BOOST_CONTRACT_AUX_NAME1(A1)& BOOST_CONTRACT_AUX_NAME1(a1), \ - boost::contract::virtual_* BOOST_CONTRACT_AUX_NAME1(v) \ - ) { \ - BOOST_CONTRACT_AUX_NAME1(obj)->BOOST_CONTRACT_AUX_NAME1(B)::f( \ - BOOST_CONTRACT_AUX_NAME1(a0), \ - BOOST_CONTRACT_AUX_NAME1(a1), \ - BOOST_CONTRACT_AUX_NAME1(v) \ - ); \ - } \ - }; +#if BOOST_CONTRACT_PUBLIC_FUNCTIONS +# include +# include +# include +# include +# define BOOST_CONTRACT_OVERRIDE_TRAIT(trait, f) \ + struct trait { \ + BOOST_CONTRACT_AUX_INTROSPECTION_HAS_MEMBER_FUNCTION( \ + BOOST_CONTRACT_AUX_NAME1(has_member_function), f) \ + /* arity = 0 */ \ + template< \ + class BOOST_CONTRACT_AUX_NAME1(B), \ + class BOOST_CONTRACT_AUX_NAME1(C) \ + > \ + static void BOOST_CONTRACT_AUX_NAME1(call_base)( \ + BOOST_CONTRACT_AUX_NAME1(C)* BOOST_CONTRACT_AUX_NAME1(obj), \ + boost::contract::aux::none&, \ + boost::contract::aux::none&, \ + boost::contract::virtual_* BOOST_CONTRACT_AUX_NAME1(v) \ + ) { \ + BOOST_CONTRACT_AUX_NAME1(obj)->BOOST_CONTRACT_AUX_NAME1(B)::f( \ + BOOST_CONTRACT_AUX_NAME1(v) \ + ); \ + } \ + /* arity = 1 */ \ + template< \ + class BOOST_CONTRACT_AUX_NAME1(B), \ + class BOOST_CONTRACT_AUX_NAME1(C), \ + typename BOOST_CONTRACT_AUX_NAME1(A0) \ + > \ + static void BOOST_CONTRACT_AUX_NAME1(call_base)( \ + BOOST_CONTRACT_AUX_NAME1(C)* BOOST_CONTRACT_AUX_NAME1(obj), \ + BOOST_CONTRACT_AUX_NAME1(A0)& BOOST_CONTRACT_AUX_NAME1(a0), \ + boost::contract::aux::none&, \ + boost::contract::virtual_* BOOST_CONTRACT_AUX_NAME1(v) \ + ) { \ + BOOST_CONTRACT_AUX_NAME1(obj)->BOOST_CONTRACT_AUX_NAME1(B)::f( \ + BOOST_CONTRACT_AUX_NAME1(a0), \ + BOOST_CONTRACT_AUX_NAME1(v) \ + ); \ + } \ + /* arity = 2 */ \ + template< \ + class BOOST_CONTRACT_AUX_NAME1(B), \ + class BOOST_CONTRACT_AUX_NAME1(C), \ + typename BOOST_CONTRACT_AUX_NAME1(A0), \ + typename BOOST_CONTRACT_AUX_NAME1(A1) \ + > \ + static void BOOST_CONTRACT_AUX_NAME1(call_base)( \ + BOOST_CONTRACT_AUX_NAME1(C)* BOOST_CONTRACT_AUX_NAME1(obj), \ + BOOST_CONTRACT_AUX_NAME1(A0)& BOOST_CONTRACT_AUX_NAME1(a0), \ + BOOST_CONTRACT_AUX_NAME1(A1)& BOOST_CONTRACT_AUX_NAME1(a1), \ + boost::contract::virtual_* BOOST_CONTRACT_AUX_NAME1(v) \ + ) { \ + BOOST_CONTRACT_AUX_NAME1(obj)->BOOST_CONTRACT_AUX_NAME1(B)::f( \ + BOOST_CONTRACT_AUX_NAME1(a0), \ + BOOST_CONTRACT_AUX_NAME1(a1), \ + BOOST_CONTRACT_AUX_NAME1(v) \ + ); \ + } \ + }; +#else +# define BOOST_CONTRACT_OVERRIDE_TRAIT(trait, f) \ + struct trait { /* empty */ }; +#endif #endif // #include guard diff --git a/include/boost/contract/public_function.hpp b/include/boost/contract/public_function.hpp index 4dc57bd..ca2477a 100644 --- a/include/boost/contract/public_function.hpp +++ b/include/boost/contract/public_function.hpp @@ -21,9 +21,9 @@ /* PRIVATE */ -// This check is strictly not necessary because compilation will fail anyways, +// This check is not strictly necessary because compilation will fail anyways, // but it helps limiting cryptic compiler's errors. -#define BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_ARITY(F, arity) \ +#define BOOST_CONTRACT_PUBLIC_FUNCTION_ASSERT_ARITY_(F, arity) \ BOOST_STATIC_ASSERT_MSG( \ /* -2 for both `this` and `virtual_*` extra parameters */ \ boost::function_types::function_arity::value - 2 == arity, \ @@ -32,16 +32,16 @@ // Always enforce this so base contracts can always specify postconditions with // result, without need to change derived contracts. -#define BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_VOID_RESULT_(F) \ +#define BOOST_CONTRACT_PUBLIC_FUNCTION_ASSERT_NO_RESULT_(F) \ BOOST_STATIC_ASSERT_MSG( \ boost::is_same< \ typename boost::function_types::result_type::type, \ void \ >::value, \ - "missing result argument for non-void function" \ + "missing 'result' argument for non-void function" \ ); -#define BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_RESULT_(F, R) \ +#define BOOST_CONTRACT_PUBLIC_FUNCTION_ASSERT_RESULT_(F, R) \ BOOST_STATIC_ASSERT_MSG( \ boost::is_same< \ typename boost::remove_reference::value, \ - "enclosing class missing 'base types' typedef" \ + "enclosing class missing 'base-types' typedef" \ ); /* CODE */ @@ -146,9 +146,9 @@ set_precondition_old_postcondition public_function( // For virtual, overriding, void member functions. template set_precondition_old_postcondition<> public_function(virtual_* v, F, C* obj) { - BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_ARITY(F, 0) - BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_VOID_RESULT_(F) - BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_BASE_TYPES_(C) + BOOST_CONTRACT_PUBLIC_FUNCTION_ASSERT_ARITY_(F, 0) + BOOST_CONTRACT_PUBLIC_FUNCTION_ASSERT_NO_RESULT_(F) + BOOST_CONTRACT_PUBLIC_FUNCTION_ASSERT_BASE_TYPES_(C) boost::contract::aux::none n; return set_precondition_old_postcondition<>( new boost::contract::aux::public_function< @@ -165,9 +165,9 @@ set_precondition_old_postcondition<> public_function(virtual_* v, F, C* obj) { template set_precondition_old_postcondition public_function( virtual_* v, R& r, F, C* obj) { - BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_ARITY(F, 0) - BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_RESULT_(F, R) - BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_BASE_TYPES_(C) + BOOST_CONTRACT_PUBLIC_FUNCTION_ASSERT_ARITY_(F, 0) + BOOST_CONTRACT_PUBLIC_FUNCTION_ASSERT_RESULT_(F, R) + BOOST_CONTRACT_PUBLIC_FUNCTION_ASSERT_BASE_TYPES_(C) boost::contract::aux::none n; return set_precondition_old_postcondition( new boost::contract::aux::public_function< @@ -185,9 +185,9 @@ set_precondition_old_postcondition public_function( template set_precondition_old_postcondition<> public_function( virtual_* v, F, C* obj, A0& a0) { - BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_ARITY(F, 1) - BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_VOID_RESULT_(F) - BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_BASE_TYPES_(C) + BOOST_CONTRACT_PUBLIC_FUNCTION_ASSERT_ARITY_(F, 1) + BOOST_CONTRACT_PUBLIC_FUNCTION_ASSERT_NO_RESULT_(F) + BOOST_CONTRACT_PUBLIC_FUNCTION_ASSERT_BASE_TYPES_(C) boost::contract::aux::none n; return set_precondition_old_postcondition<>( new boost::contract::aux::public_function< @@ -203,9 +203,9 @@ set_precondition_old_postcondition<> public_function( template set_precondition_old_postcondition public_function( virtual_* v, R& r, F, C* obj, A0& a0) { - BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_ARITY(F, 1) - BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_RESULT_(F, R) - BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_BASE_TYPES_(C) + BOOST_CONTRACT_PUBLIC_FUNCTION_ASSERT_ARITY_(F, 1) + BOOST_CONTRACT_PUBLIC_FUNCTION_ASSERT_RESULT_(F, R) + BOOST_CONTRACT_PUBLIC_FUNCTION_ASSERT_BASE_TYPES_(C) boost::contract::aux::none n; return set_precondition_old_postcondition( new boost::contract::aux::public_function< @@ -223,9 +223,9 @@ set_precondition_old_postcondition public_function( template set_precondition_old_postcondition<> public_function( virtual_* v, F, C* obj, A0& a0, A1& a1) { - BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_ARITY(F, 2) - BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_VOID_RESULT_(F) - BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_BASE_TYPES_(C) + BOOST_CONTRACT_PUBLIC_FUNCTION_ASSERT_ARITY_(F, 2) + BOOST_CONTRACT_PUBLIC_FUNCTION_ASSERT_NO_RESULT_(F) + BOOST_CONTRACT_PUBLIC_FUNCTION_ASSERT_BASE_TYPES_(C) boost::contract::aux::none n; return set_precondition_old_postcondition<>( new boost::contract::aux::public_function< @@ -241,9 +241,9 @@ set_precondition_old_postcondition<> public_function( template set_precondition_old_postcondition public_function( virtual_* v, R& r, F, C* obj, A0& a0, A1& a1) { - BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_ARITY(F, 2) - BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_RESULT_(F, R) - BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_BASE_TYPES_(C) + BOOST_CONTRACT_PUBLIC_FUNCTION_ASSERT_ARITY_(F, 2) + BOOST_CONTRACT_PUBLIC_FUNCTION_ASSERT_RESULT_(F, R) + BOOST_CONTRACT_PUBLIC_FUNCTION_ASSERT_BASE_TYPES_(C) return set_precondition_old_postcondition( new boost::contract::aux::public_function< O, diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 72d4149..9eb5fea 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -1,205 +1,223 @@ -test-suite constructor : - [ subdir-run constructor : decl_pre_all ] - [ subdir-run constructor : decl_pre_ends ] - [ subdir-run constructor : decl_pre_mid ] - [ subdir-run constructor : decl_pre_none ] +subdir-usage ; + +test-suite constructor +: + [ subdir-run-withno constructor : decl_pre_all ] + [ subdir-run-withno constructor : decl_pre_ends ] + [ subdir-run-withno constructor : decl_pre_mid ] + [ subdir-run-withno constructor : decl_pre_none ] - [ subdir-run constructor : decl_post_all ] - [ subdir-run constructor : decl_post_ends ] - [ subdir-run constructor : decl_post_mid ] - [ subdir-run constructor : decl_post_none ] + [ subdir-run-withno constructor : decl_post_all ] + [ subdir-run-withno constructor : decl_post_ends ] + [ subdir-run-withno constructor : decl_post_mid ] + [ subdir-run-withno constructor : decl_post_none ] - [ subdir-run constructor : decl_entry_static_inv_all ] - [ subdir-run constructor : decl_entry_static_inv_ends ] - [ subdir-run constructor : decl_entry_static_inv_mid ] - [ subdir-run constructor : decl_entry_static_inv_none ] + [ subdir-run-withno constructor : decl_entry_static_inv_all ] + [ subdir-run-withno constructor : decl_entry_static_inv_ends ] + [ subdir-run-withno constructor : decl_entry_static_inv_mid ] + [ subdir-run-withno constructor : decl_entry_static_inv_none ] - [ subdir-run constructor : decl_exit_static_inv_all ] - [ subdir-run constructor : decl_exit_static_inv_ends ] - [ subdir-run constructor : decl_exit_static_inv_mid ] - [ subdir-run constructor : decl_exit_static_inv_none ] + [ subdir-run-withno constructor : decl_exit_static_inv_all ] + [ subdir-run-withno constructor : decl_exit_static_inv_ends ] + [ subdir-run-withno constructor : decl_exit_static_inv_mid ] + [ subdir-run-withno constructor : decl_exit_static_inv_none ] # No decl_entry_static_inv_... for constructors. - [ subdir-run constructor : decl_exit_inv_all ] - [ subdir-run constructor : decl_exit_inv_ends ] - [ subdir-run constructor : decl_exit_inv_mid ] - [ subdir-run constructor : decl_exit_inv_none ] + [ subdir-run-withno constructor : decl_exit_inv_all ] + [ subdir-run-withno constructor : decl_exit_inv_ends ] + [ subdir-run-withno constructor : decl_exit_inv_mid ] + [ subdir-run-withno constructor : decl_exit_inv_none ] - [ subdir-run constructor : bases ] - [ subdir-run constructor : access ] + [ subdir-run-withno constructor : bases ] + [ subdir-run-withno constructor : access ] + [ subdir-run-withno constructor : no_contracts ] - [ subdir-run constructor : body_throw ] - [ subdir-run constructor : old_throw ] + [ subdir-run-withno constructor : body_throw ] + [ subdir-run-withno constructor : old_throw ] [ subdir-compile-fail constructor : pre_error ] ; -test-suite destructor : +test-suite destructor +: # No decl_pre_... for destructors. - [ subdir-run destructor : decl_post_all ] - [ subdir-run destructor : decl_post_ends ] - [ subdir-run destructor : decl_post_mid ] - [ subdir-run destructor : decl_post_none ] + [ subdir-run-withno destructor : decl_post_all ] + [ subdir-run-withno destructor : decl_post_ends ] + [ subdir-run-withno destructor : decl_post_mid ] + [ subdir-run-withno destructor : decl_post_none ] - [ subdir-run destructor : decl_entry_static_inv_all ] - [ subdir-run destructor : decl_entry_static_inv_ends ] - [ subdir-run destructor : decl_entry_static_inv_mid ] - [ subdir-run destructor : decl_entry_static_inv_none ] + [ subdir-run-withno destructor : decl_entry_static_inv_all ] + [ subdir-run-withno destructor : decl_entry_static_inv_ends ] + [ subdir-run-withno destructor : decl_entry_static_inv_mid ] + [ subdir-run-withno destructor : decl_entry_static_inv_none ] - [ subdir-run destructor : decl_exit_static_inv_all ] - [ subdir-run destructor : decl_exit_static_inv_ends ] - [ subdir-run destructor : decl_exit_static_inv_mid ] - [ subdir-run destructor : decl_exit_static_inv_none ] + [ subdir-run-withno destructor : decl_exit_static_inv_all ] + [ subdir-run-withno destructor : decl_exit_static_inv_ends ] + [ subdir-run-withno destructor : decl_exit_static_inv_mid ] + [ subdir-run-withno destructor : decl_exit_static_inv_none ] - [ subdir-run destructor : decl_entry_inv_all ] - [ subdir-run destructor : decl_entry_inv_ends ] - [ subdir-run destructor : decl_entry_inv_mid ] - [ subdir-run destructor : decl_entry_inv_none ] + [ subdir-run-withno destructor : decl_entry_inv_all ] + [ subdir-run-withno destructor : decl_entry_inv_ends ] + [ subdir-run-withno destructor : decl_entry_inv_mid ] + [ subdir-run-withno destructor : decl_entry_inv_none ] # No decl_exit_inv_... for destructors. - [ subdir-run destructor : bases ] - [ subdir-run destructor : access ] + [ subdir-run-withno destructor : bases ] + [ subdir-run-withno destructor : access ] + [ subdir-run-withno destructor : no_contracts ] - [ subdir-run destructor : body_throw ] - [ subdir-run destructor : old_throw ] + [ subdir-run-withno destructor : body_throw ] + [ subdir-run-withno destructor : old_throw ] [ subdir-compile-fail destructor : pre_error ] ; -test-suite public_function : - [ subdir-run public_function : decl_pre_all ] - [ subdir-run public_function : decl_pre_ends ] - [ subdir-run public_function : decl_pre_mid ] - [ subdir-run public_function : decl_pre_none ] +test-suite public_function +: + [ subdir-run-withno public_function : decl_pre_all ] + [ subdir-run-withno public_function : decl_pre_ends ] + [ subdir-run-withno public_function : decl_pre_mid ] + [ subdir-run-withno public_function : decl_pre_none ] - [ subdir-run public_function : decl_post_all ] - [ subdir-run public_function : decl_post_ends ] - [ subdir-run public_function : decl_post_mid ] - [ subdir-run public_function : decl_post_none ] + [ subdir-run-withno public_function : decl_post_all ] + [ subdir-run-withno public_function : decl_post_ends ] + [ subdir-run-withno public_function : decl_post_mid ] + [ subdir-run-withno public_function : decl_post_none ] - [ subdir-run public_function : decl_entry_static_inv_all ] - [ subdir-run public_function : decl_entry_static_inv_ends ] - [ subdir-run public_function : decl_entry_static_inv_mid ] - [ subdir-run public_function : decl_entry_static_inv_none ] + [ subdir-run-withno public_function : decl_entry_static_inv_all ] + [ subdir-run-withno public_function : decl_entry_static_inv_ends ] + [ subdir-run-withno public_function : decl_entry_static_inv_mid ] + [ subdir-run-withno public_function : decl_entry_static_inv_none ] - [ subdir-run public_function : decl_exit_static_inv_all ] - [ subdir-run public_function : decl_exit_static_inv_ends ] - [ subdir-run public_function : decl_exit_static_inv_mid ] - [ subdir-run public_function : decl_exit_static_inv_none ] + [ subdir-run-withno public_function : decl_exit_static_inv_all ] + [ subdir-run-withno public_function : decl_exit_static_inv_ends ] + [ subdir-run-withno public_function : decl_exit_static_inv_mid ] + [ subdir-run-withno public_function : decl_exit_static_inv_none ] - [ subdir-run public_function : decl_entry_inv_all ] - [ subdir-run public_function : decl_entry_inv_ends ] - [ subdir-run public_function : decl_entry_inv_mid ] - [ subdir-run public_function : decl_entry_inv_none ] + [ subdir-run-withno public_function : decl_entry_inv_all ] + [ subdir-run-withno public_function : decl_entry_inv_ends ] + [ subdir-run-withno public_function : decl_entry_inv_mid ] + [ subdir-run-withno public_function : decl_entry_inv_none ] - [ subdir-run public_function : decl_exit_inv_all ] - [ subdir-run public_function : decl_exit_inv_ends ] - [ subdir-run public_function : decl_exit_inv_mid ] - [ subdir-run public_function : decl_exit_inv_none ] + [ subdir-run-withno public_function : decl_exit_inv_all ] + [ subdir-run-withno public_function : decl_exit_inv_ends ] + [ subdir-run-withno public_function : decl_exit_inv_mid ] + [ subdir-run-withno public_function : decl_exit_inv_none ] - [ subdir-run public_function : bases ] - [ subdir-run public_function : bases_virtual ] - [ subdir-run public_function : bases_branch ] - [ subdir-run public_function : bases_sparse ] + [ subdir-run-withno public_function : bases ] + [ subdir-run-withno public_function : bases_virtual ] + [ subdir-run-withno public_function : bases_branch ] + [ subdir-run-withno public_function : bases_sparse ] - [ subdir-run public_function : access ] + [ subdir-run-withno public_function : access ] + [ subdir-run-withno public_function : no_contracts ] - [ subdir-run public_function : body_throw ] - [ subdir-run public_function : old_throw ] + [ subdir-run-withno public_function : body_throw ] + [ subdir-run-withno public_function : old_throw ] - [ subdir-run public_function : static ] - [ subdir-run public_function : static_body_throw ] + [ subdir-run-withno public_function : static ] + [ subdir-run-withno public_function : static_body_throw ] + [ subdir-run-withno public_function : static_old_throw ] + [ subdir-run-withno public_function : static_no_contracts ] [ subdir-compile-fail public_function : override_error ] - [ subdir-run public_function : override_permissive ] + [ subdir-run-withno public_function : override_permissive ] ; -test-suite function : - [ subdir-run function : decl_pre_all ] - [ subdir-run function : decl_pre_none ] +test-suite function +: + [ subdir-run-withno function : decl_pre_all ] + [ subdir-run-withno function : decl_pre_none ] - [ subdir-run function : decl_post_all ] - [ subdir-run function : decl_post_none ] + [ subdir-run-withno function : decl_post_all ] + [ subdir-run-withno function : decl_post_none ] - [ subdir-run function : func ] + [ subdir-run-withno function : func ] + [ subdir-run-withno function : no_contracts ] - [ subdir-run function : body_throw ] - [ subdir-run function : old_throw ] + [ subdir-run-withno function : body_throw ] + [ subdir-run-withno function : old_throw ] ; -test-suite invariant : - [ subdir-run invariant : all_static_cv_const ] - [ subdir-run invariant : both_static_cv ] - [ subdir-run invariant : both_cv_const ] - [ subdir-run invariant : both_static_const ] - [ subdir-run invariant : only_static ] - [ subdir-run invariant : only_cv ] - [ subdir-run invariant : only_const ] - [ subdir-run invariant : no_inv ] +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-compile-fail invariant : static_inv_mutable_error ] - [ subdir-run invariant : static_inv_mutable_permissive ] + [ subdir-run-withno invariant : static_inv_mutable_permissive ] [ subdir-compile-fail invariant : static_inv_const_error ] - [ subdir-run invariant : static_inv_const_permissive ] + [ subdir-run-withno invariant : static_inv_const_permissive ] [ subdir-compile-fail invariant : static_inv_volatile_error ] - [ subdir-run invariant : static_inv_volatile_permissive ] + [ subdir-run-withno invariant : static_inv_volatile_permissive ] [ subdir-compile-fail invariant : static_inv_cv_error ] - [ subdir-run invariant : static_inv_cv_permissive ] + [ subdir-run-withno invariant : static_inv_cv_permissive ] [ subdir-compile-fail invariant : inv_static_error ] - [ subdir-run invariant : inv_static_permissive ] + [ subdir-run-withno invariant : inv_static_permissive ] [ subdir-compile-fail invariant : inv_mutable_error ] - [ subdir-run invariant : inv_mutable_permissive ] + [ subdir-run-withno invariant : inv_mutable_permissive ] [ subdir-compile-fail invariant : inv_volatile_error ] - [ subdir-run invariant : inv_volatile_permissive ] + [ subdir-run-withno invariant : inv_volatile_permissive ] ; -test-suite result : - [ subdir-run result : mixed_optional ] - [ subdir-run result : mixed_optional_ref ] +test-suite result +: + [ subdir-run-withno result : mixed_optional ] + [ subdir-run-withno result : mixed_optional_ref ] [ subdir-compile-fail result : type_mismatch_error ] ; -test-suite old : - [ subdir-run old : auto ] +test-suite old +: + [ subdir-run-withno old : auto ] - [ subdir-run old : no_macros ] + [ subdir-run-withno old : no_macros ] [ subdir-compile-fail old : no_make_old_error ] - [ subdir-run old : noncopyable ] + [ subdir-run-withno old : noncopyable ] [ subdir-compile-fail old : noncopyable_error ] - [ subdir-run old : no_equal ] + [ subdir-run-withno old : no_equal ] [ subdir-compile-fail old : no_equal_error ] ; -test-suite disable : - [ subdir-run disable : checking ] +test-suite disable +: + [ subdir-run-withno disable : checking ] ; -test-suite set : - [ subdir-run set : all_pre_old_post ] - [ subdir-run set : both_pre_old ] - [ subdir-run set : both_old_post ] - [ subdir-run set : both_pre_post ] - [ subdir-run set : only_pre ] - [ subdir-run set : only_old ] - [ subdir-run set : only_post ] - [ subdir-run set : nothing ] +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 : nothing ] - [ subdir-run set : no_guard ] + [ subdir-run-withno set : no_guard ] [ subdir-compile-fail set : old_pre_error ] [ subdir-compile-fail set : post_old_error ] [ subdir-compile-fail set : post_pre_error ] ; -test-suite call_if : +test-suite call_if +: [ subdir-run call_if : true_ ] [ subdir-run call_if : false_ ] @@ -210,7 +228,8 @@ test-suite call_if : ; # C++14 supported only by Clang... so in its own suite and explicit. -test-suite cxx14 : +test-suite cxx14 +: [ subdir-run call_if : equal_to_cxx14 : clang:-std=c++1y ] [ subdir-run call_if : advance_cxx14 : diff --git a/test/aux_/oteststream.hpp b/test/aux_/oteststream.hpp index 0125d89..4d19420 100644 --- a/test/aux_/oteststream.hpp +++ b/test/aux_/oteststream.hpp @@ -46,9 +46,19 @@ struct oteststream : ", because '" << r[i] << "' != '" << s[i] << "':" << std::endl ; std::cout << std::endl; - std::cout << r.substr(0, std::min(i + 1, r.size())) << std::endl; + std::cout + << r.substr(0, i) + << "(((" << r[i] << ")))" + << r.substr(std::min(i + 1, r.size()), r.size()) + << std::endl + ; std::cout << std::endl; - std::cout << s.substr(0, std::min(i + 1, s.size())) << std::endl; + std::cout + << s.substr(0, i) + << "(((" << s[i] << ")))" + << s.substr(std::min(i + 1, s.size()), s.size()) + << std::endl + ; std::cout << std::endl; return false; } diff --git a/test/constructor/no_contracts.cpp b/test/constructor/no_contracts.cpp new file mode 100644 index 0000000..73653f9 --- /dev/null +++ b/test/constructor/no_contracts.cpp @@ -0,0 +1,125 @@ + +// Test contract compilation on/off. + +#include "../aux_/oteststream.hpp" +#include +#if BOOST_CONTRACT_CONSTRUCTORS + #include + #include + #include +#endif +#include +#include + +boost::contract::aux::test::oteststream out; + +struct b + #if BOOST_CONTRACT_PRECONDITIONS + : private boost::contract::constructor_precondition + #endif +{ + #if BOOST_CONTRACT_INVARIANTS + static void static_invariant() { out << "b::static_inv" << std::endl; } + void invariant() const { out << "b::inv" << std::endl; } + #endif + + explicit b(int x) + #if BOOST_CONTRACT_PRECONDITIONS + : boost::contract::constructor_precondition( + [] { out << "b::ctor::pre" << std::endl; } + ) + #endif + { + #if BOOST_CONTRACT_POSTCONDITIONS + boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(x); + #endif + #if BOOST_CONTRACT_CONSTRUCTORS + boost::contract::guard c = boost::contract::constructor(this) + #if BOOST_CONTRACT_POSTCONDITIONS + .old([] { out << "b::f::old" << std::endl; }) + .postcondition([] { out << "b::ctor::post" << std::endl; }) + #endif + ; + #endif + out << "b::ctor::body" << std::endl; + } +}; + +struct a : + #if BOOST_CONTRACT_PRECONDITIONS + private boost::contract::constructor_precondition, + #endif + public b +{ + #if BOOST_CONTRACT_INVARIANTS + static void static_invariant() { out << "a::static_inv" << std::endl; } + void invariant() const { out << "a::inv" << std::endl; } + #endif + + explicit a(int x) : + #if BOOST_CONTRACT_PRECONDITIONS + boost::contract::constructor_precondition( + [] { out << "a::ctor::pre" << std::endl; } + ), + #endif + b(x) + { + #if BOOST_CONTRACT_POSTCONDITIONS + boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(x); + #endif + #if BOOST_CONTRACT_CONSTRUCTORS + boost::contract::guard c = boost::contract::constructor(this) + #if BOOST_CONTRACT_POSTCONDITIONS + .old([] { out << "a::f::old" << std::endl; }) + .postcondition([] { out << "a::ctor::post" << std::endl; }) + #endif + ; + #endif + out << "a::ctor::body" << std::endl; + } +}; + +int main() { + std::ostringstream ok; + out.str(""); + a aa(123); + ok.str(""); ok + #if BOOST_CONTRACT_PRECONDITIONS + << "a::ctor::pre" << std::endl + << "b::ctor::pre" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::f::old" << std::endl + #endif + << "b::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::ctor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::f::old" << std::endl + #endif + << "a::ctor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::ctor::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + return boost::report_errors(); +} + diff --git a/test/destructor/no_contracts.cpp b/test/destructor/no_contracts.cpp new file mode 100644 index 0000000..24149cc --- /dev/null +++ b/test/destructor/no_contracts.cpp @@ -0,0 +1,106 @@ + +// Test contract compilation on/off. + +#include "../aux_/oteststream.hpp" +#include +#if BOOST_CONTRACT_DESTRUCTORS + #include + #include + #include +#endif +#include +#include + +boost::contract::aux::test::oteststream out; + +struct b { + #if BOOST_CONTRACT_INVARIANTS + static void static_invariant() { out << "b::static_inv" << std::endl; } + void invariant() const { out << "b::inv" << std::endl; } + #endif + + virtual ~b() { + #if BOOST_CONTRACT_POSTCONDITIONS + boost::contract::old_ptr old_y = BOOST_CONTRACT_OLDOF(y); + #endif + #if BOOST_CONTRACT_DESTRUCTORS + boost::contract::guard c = boost::contract::destructor(this) + #if BOOST_CONTRACT_POSTCONDITIONS + .old([] { out << "b::dtor::old" << std::endl; }) + .postcondition([] { out << "b::dtor::post" << std::endl; }) + #endif + ; + #endif + out << "b::dtor::body" << std::endl; + } + + static int y; +}; +int b::y = 0; + +struct a : public b { + #if BOOST_CONTRACT_INVARIANTS + static void static_invariant() { out << "a::static_inv" << std::endl; } + void invariant() const { out << "a::inv" << std::endl; } + #endif + + virtual ~a() { + #if BOOST_CONTRACT_POSTCONDITIONS + boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(x); + #endif + #if BOOST_CONTRACT_DESTRUCTORS + boost::contract::guard c = boost::contract::destructor(this) + #if BOOST_CONTRACT_POSTCONDITIONS + .old([] { out << "a::dtor::old" << std::endl; }) + .postcondition([] { out << "a::dtor::post" << std::endl; }) + #endif + ; + #endif + out << "a::dtor::body" << std::endl; + } + + static int x; +}; +int a::x = 0; + +int main() { + std::ostringstream ok; + { + a aa; + out.str(""); + } + ok.str(""); ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::old" << std::endl + #endif + << "a::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::dtor::post" << std::endl + #endif + + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::old" << std::endl + #endif + << "b::dtor::body" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::dtor::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + return boost::report_errors(); +} + diff --git a/test/function/body_throw.cpp b/test/function/body_throw.cpp index 0924644..0ddd2a8 100644 --- a/test/function/body_throw.cpp +++ b/test/function/body_throw.cpp @@ -30,8 +30,12 @@ int main() { BOOST_TEST(false); } catch(err const&) { 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 // Test this threw. ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/function/decl.hpp b/test/function/decl.hpp index 987f726..00bb7e0 100644 --- a/test/function/decl.hpp +++ b/test/function/decl.hpp @@ -14,19 +14,19 @@ boost::contract::aux::test::oteststream out; bool f_pre = true, f_post = true; void f() { boost::contract::guard c = boost::contract::function() -#ifndef BOOST_CONTRACT_AUX_TEST_NO_F_PRE - .precondition([&] { - out << "f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(f_pre); - }) -#endif + #ifndef BOOST_CONTRACT_AUX_TEST_NO_F_PRE + .precondition([&] { + out << "f::pre" << std::endl; + BOOST_CONTRACT_ASSERT(f_pre); + }) + #endif .old([] { out << "f::old" << std::endl; }) -#ifndef BOOST_CONTRACT_AUX_TEST_NO_F_POST - .postcondition([] { - out << "f::post" << std::endl; - BOOST_CONTRACT_ASSERT(f_post); - }) -#endif + #ifndef BOOST_CONTRACT_AUX_TEST_NO_F_POST + .postcondition([] { + out << "f::post" << std::endl; + BOOST_CONTRACT_ASSERT(f_post); + }) + #endif ; out << "f::body" << std::endl; } diff --git a/test/function/decl_post_all.cpp b/test/function/decl_post_all.cpp index 00afe07..57926d2 100644 --- a/test/function/decl_post_all.cpp +++ b/test/function/decl_post_all.cpp @@ -14,10 +14,16 @@ int main() { out.str(""); 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 // Test no failure here. + #if BOOST_CONTRACT_POSTCONDITIONS + << "f::post" << std::endl // Test no failure here. + #endif ; BOOST_TEST(out.eq(ok.str())); @@ -29,13 +35,21 @@ int main() { out.str(""); try { f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif 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 // Test this failed. + #if BOOST_CONTRACT_POSTCONDITIONS + << "f::post" << std::endl // Test this failed. + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/function/decl_post_none.cpp b/test/function/decl_post_none.cpp index e25d55d..437a4e1 100644 --- a/test/function/decl_post_none.cpp +++ b/test/function/decl_post_none.cpp @@ -9,8 +9,12 @@ int main() { std::ostringstream ok; ok // Test nothing fails. - << "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 ; diff --git a/test/function/decl_pre_all.cpp b/test/function/decl_pre_all.cpp index b277885..f3f637b 100644 --- a/test/function/decl_pre_all.cpp +++ b/test/function/decl_pre_all.cpp @@ -14,10 +14,16 @@ int main() { out.str(""); f(); ok.str(""); ok - << "f::pre" << std::endl // Test no failure here. - << "f::old" << std::endl + #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 - << "f::post" << std::endl + #if BOOST_CONTRACT_POSTCONDITIONS + << "f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); @@ -29,10 +35,14 @@ int main() { out.str(""); try { f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_PRECONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok + #if BOOST_CONTRACT_PRECONDITIONS << "f::pre" << std::endl // Test this failed. + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/function/decl_pre_none.cpp b/test/function/decl_pre_none.cpp index 28c0b7d..ae620e6 100644 --- a/test/function/decl_pre_none.cpp +++ b/test/function/decl_pre_none.cpp @@ -9,9 +9,13 @@ int main() { std::ostringstream ok; ok // Test nothing fails. - << "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 ; f_pre = true; diff --git a/test/function/func.cpp b/test/function/func.cpp index 8f00bbd..82124ac 100644 --- a/test/function/func.cpp +++ b/test/function/func.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -55,10 +56,16 @@ int main() { out.str(""); bool r = 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())); @@ -67,12 +74,16 @@ int main() { BOOST_TEST_EQ(y.value, 123); } - BOOST_TEST_EQ(x_type::copies(), 1); - BOOST_TEST_EQ(x_type::evals(), 1); + BOOST_TEST_EQ(x_type::copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); + BOOST_TEST_EQ(x_type::evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); BOOST_TEST_EQ(x_type::ctors(), x_type::dtors()); // No leak. - BOOST_TEST_EQ(y_type::copies(), 1); - BOOST_TEST_EQ(y_type::evals(), 1); + BOOST_TEST_EQ(y_type::copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); + BOOST_TEST_EQ(y_type::evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); BOOST_TEST_EQ(y_type::ctors(), y_type::dtors()); // No leak. return boost::report_errors(); diff --git a/test/function/no_contracts.cpp b/test/function/no_contracts.cpp new file mode 100644 index 0000000..3e88683 --- /dev/null +++ b/test/function/no_contracts.cpp @@ -0,0 +1,53 @@ + +// Test contract compilation on/off. + +#include "../aux_/oteststream.hpp" +#include +#if BOOST_CONTRACT_FUNCTIONS + #include + #include + #include +#endif +#include +#include + +boost::contract::aux::test::oteststream out; + +void f(int x) { + #if BOOST_CONTRACT_POSTCONDITIONS + boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(x); + #endif + #if BOOST_CONTRACT_FUNCTIONS + boost::contract::guard c = boost::contract::function() + #if BOOST_CONTRACT_PRECONDITIONS + .precondition([] { out << "f::pre" << std::endl; }) + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + .old([] { out << "f::old" << std::endl; }) + .postcondition([] { out << "f::post" << std::endl; }) + #endif + ; + #endif + out << "f::body" << std::endl; +} + +int main() { + std::ostringstream ok; + out.str(""); + f(123); + 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 + #endif + ; + BOOST_TEST(out.eq(ok.str())); + return boost::report_errors(); +} + diff --git a/test/function/old_throw.cpp b/test/function/old_throw.cpp index c340d52..8a2a232 100644 --- a/test/function/old_throw.cpp +++ b/test/function/old_throw.cpp @@ -32,11 +32,17 @@ int main() { try { out.str(""); f(); - BOOST_TEST(false); + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + #endif } catch(err const&) { ok.str(""); ok - << "f::pre" << std::endl - << "f::old" << std::endl // Test this threw. + #if BOOST_CONTRACT_PRECONDITIONS + << "f::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "f::old" << std::endl // Test this threw. + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/public_function/access.cpp b/test/public_function/access.cpp index 1ed0de4..39b56c9 100644 --- a/test/public_function/access.cpp +++ b/test/public_function/access.cpp @@ -71,28 +71,33 @@ int main() { out.str(""); aa.f('a'); ok.str(""); ok - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - - << "b::f::pre" << std::endl - << "a::f::pre" << std::endl - - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #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 - - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << 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 + << "b::static_inv" << std::endl + << "b::inv" << std::endl + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::f::old" << std::endl + << "b::f::post" << std::endl + // No old call here because not a base object. + << "a::f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); @@ -100,14 +105,24 @@ int main() { out.str(""); bb.f('b'); ok.str(""); ok - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::f::pre" << std::endl - << "b::f::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #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 - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "b::f::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "b::f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/public_function/bases.cpp b/test/public_function/bases.cpp index 4c9ce39..aebe31c 100644 --- a/test/public_function/bases.cpp +++ b/test/public_function/bases.cpp @@ -1,5 +1,8 @@ +// Test public member function subcontracting. + #include "bases.hpp" +#include #include #include @@ -12,67 +15,82 @@ int main() { result_type& r = aa.f(s); ok.str(""); ok - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - - << "d::f::pre" << std::endl - << "e::f::pre" << std::endl - << "c::f::pre" << std::endl - << "a::f::pre" << std::endl - - << "d::f::old" << std::endl - << "e::f::old" << std::endl - << "c::f::old" << std::endl - << "a::f::old" << std::endl - + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "d::static_inv" << std::endl + << "d::inv" << std::endl + << "e::static_inv" << std::endl + << "e::inv" << std::endl + << "c::static_inv" << std::endl + << "c::inv" << std::endl + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_PRECONDITIONS + << "d::f::pre" << std::endl + << "e::f::pre" << std::endl + << "c::f::pre" << std::endl + << "a::f::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "d::f::old" << std::endl + << "e::f::old" << std::endl + << "c::f::old" << std::endl + << "a::f::old" << std::endl + #endif << "a::f::body" << std::endl - - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - - << "d::f::old" << std::endl - << "d::f::post" << std::endl - << "e::f::old" << std::endl - << "e::f::post" << std::endl - << "c::f::old" << std::endl - << "c::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 + << "e::static_inv" << std::endl + << "e::inv" << std::endl + << "c::static_inv" << std::endl + << "c::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 + << "e::f::old" << std::endl + << "e::f::post" << std::endl + << "c::f::old" << std::endl + << "c::f::post" << std::endl + // No old call here because not a base object. + << "a::f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); BOOST_TEST_EQ(r.value, "A"); BOOST_TEST_EQ(s.value, "acde"); - BOOST_TEST_EQ(s.copies(), 4); - BOOST_TEST_EQ(s.evals(), 4); + BOOST_TEST_EQ(s.copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 4, 0)); + BOOST_TEST_EQ(s.evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 4, 0)); BOOST_TEST_EQ(aa.x.value, "aA"); - BOOST_TEST_EQ(aa.x.copies(), 1); - BOOST_TEST_EQ(aa.x.evals(), 1); + BOOST_TEST_EQ(aa.x.copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); + BOOST_TEST_EQ(aa.x.evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); BOOST_TEST_EQ(aa.y.value, "cA"); - BOOST_TEST_EQ(aa.y.copies(), 1); - BOOST_TEST_EQ(aa.y.evals(), 1); + BOOST_TEST_EQ(aa.y.copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); + BOOST_TEST_EQ(aa.y.evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); BOOST_TEST_EQ(aa.t<'d'>::z.value, "dA"); - BOOST_TEST_EQ(aa.t<'d'>::z.copies(), 1); - BOOST_TEST_EQ(aa.t<'d'>::z.evals(), 1); + BOOST_TEST_EQ(aa.t<'d'>::z.copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); + BOOST_TEST_EQ(aa.t<'d'>::z.evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); BOOST_TEST_EQ(aa.t<'e'>::z.value, "eA"); - BOOST_TEST_EQ(aa.t<'e'>::z.copies(), 1); - BOOST_TEST_EQ(aa.t<'e'>::z.evals(), 1); + BOOST_TEST_EQ(aa.t<'e'>::z.copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); + BOOST_TEST_EQ(aa.t<'e'>::z.evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); return boost::report_errors(); } diff --git a/test/public_function/bases_branch.cpp b/test/public_function/bases_branch.cpp index 4a54c9b..2976343 100644 --- a/test/public_function/bases_branch.cpp +++ b/test/public_function/bases_branch.cpp @@ -1,4 +1,6 @@ +// Test public function subcontracting from middle branch of inheritance tree. + #include "bases.hpp" #include #include @@ -12,55 +14,68 @@ int main() { result_type& r = cc.f(s); ok.str(""); ok - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - - << "d::f::pre" << std::endl - << "e::f::pre" << std::endl - << "c::f::pre" << std::endl - - << "d::f::old" << std::endl - << "e::f::old" << std::endl - << "c::f::old" << std::endl - + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "d::static_inv" << std::endl + << "d::inv" << std::endl + << "e::static_inv" << std::endl + << "e::inv" << std::endl + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_PRECONDITIONS + << "d::f::pre" << std::endl + << "e::f::pre" << std::endl + << "c::f::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "d::f::old" << std::endl + << "e::f::old" << std::endl + << "c::f::old" << std::endl + #endif << "c::f::body" << std::endl - - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - - << "d::f::old" << std::endl - << "d::f::post" << std::endl - << "e::f::old" << std::endl - << "e::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 + << "e::static_inv" << std::endl + << "e::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 + << "e::f::old" << std::endl + << "e::f::post" << std::endl + // No old call here because not a base object. + << "c::f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); BOOST_TEST_EQ(r.value, "C"); BOOST_TEST_EQ(s.value, "cde"); - BOOST_TEST_EQ(s.copies(), 3); - BOOST_TEST_EQ(s.evals(), 3); + BOOST_TEST_EQ(s.copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 3, 0)); + BOOST_TEST_EQ(s.evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 3, 0)); BOOST_TEST_EQ(cc.y.value, "cC"); - BOOST_TEST_EQ(cc.y.copies(), 1); - BOOST_TEST_EQ(cc.y.evals(), 1); + BOOST_TEST_EQ(cc.y.copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); + BOOST_TEST_EQ(cc.y.evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); BOOST_TEST_EQ(cc.t<'d'>::z.value, "dC"); - BOOST_TEST_EQ(cc.t<'d'>::z.copies(), 1); - BOOST_TEST_EQ(cc.t<'d'>::z.evals(), 1); + BOOST_TEST_EQ(cc.t<'d'>::z.copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); + BOOST_TEST_EQ(cc.t<'d'>::z.evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); BOOST_TEST_EQ(cc.t<'e'>::z.value, "eC"); - BOOST_TEST_EQ(cc.t<'e'>::z.copies(), 1); - BOOST_TEST_EQ(cc.t<'e'>::z.evals(), 1); + BOOST_TEST_EQ(cc.t<'e'>::z.copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); + BOOST_TEST_EQ(cc.t<'e'>::z.evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); return boost::report_errors(); } diff --git a/test/public_function/bases_sparse.cpp b/test/public_function/bases_sparse.cpp index d1d2f51..846877d 100644 --- a/test/public_function/bases_sparse.cpp +++ b/test/public_function/bases_sparse.cpp @@ -174,60 +174,65 @@ int main() { out.str(""); aa.f('a'); ok.str(""); ok - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "i::static_inv" << std::endl - << "i::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - << "j::static_inv" << std::endl - << "j::inv" << std::endl - << "h::static_inv" << std::endl - << "h::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - - << "c::f::pre" << std::endl - << "i::f::pre" << std::endl - << "e::f::pre" << std::endl - << "j::f::pre" << std::endl - << "h::f::pre" << std::endl - << "a::f::pre" << std::endl - - << "c::f::old" << std::endl - << "i::f::old" << std::endl - << "e::f::old" << std::endl - << "j::f::old" << std::endl - << "h::f::old" << std::endl - << "a::f::old" << std::endl - + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + << "i::static_inv" << std::endl + << "i::inv" << std::endl + << "e::static_inv" << std::endl + << "e::inv" << std::endl + << "j::static_inv" << std::endl + << "j::inv" << std::endl + << "h::static_inv" << std::endl + << "h::inv" << std::endl + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_PRECONDITIONS + << "c::f::pre" << std::endl + << "i::f::pre" << std::endl + << "e::f::pre" << std::endl + << "j::f::pre" << std::endl + << "h::f::pre" << std::endl + << "a::f::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::f::old" << std::endl + << "i::f::old" << std::endl + << "e::f::old" << std::endl + << "j::f::old" << std::endl + << "h::f::old" << std::endl + << "a::f::old" << std::endl + #endif << "a::f::body" << std::endl - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "i::static_inv" << std::endl - << "i::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - << "j::static_inv" << std::endl - << "j::inv" << std::endl - << "h::static_inv" << std::endl - << "h::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "i::f::old" << std::endl - << "i::f::post" << std::endl - << "e::f::old" << std::endl - << "e::f::post" << std::endl - << "j::f::old" << std::endl - << "j::f::post" << std::endl - << "h::f::old" << std::endl - << "h::f::post" << std::endl - // No old call here because not a base object. - << "a::f::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + << "i::static_inv" << std::endl + << "i::inv" << std::endl + << "e::static_inv" << std::endl + << "e::inv" << std::endl + << "j::static_inv" << std::endl + << "j::inv" << std::endl + << "h::static_inv" << std::endl + << "h::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 + << "i::f::old" << std::endl + << "i::f::post" << std::endl + << "e::f::old" << std::endl + << "e::f::post" << std::endl + << "j::f::old" << std::endl + << "j::f::post" << std::endl + << "h::f::old" << std::endl + << "h::f::post" << std::endl + // No old call here because not a base object. + << "a::f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); @@ -235,15 +240,25 @@ int main() { out.str(""); cc.f('c'); ok.str(""); ok - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "c::f::pre" << std::endl - << "c::f::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_PRECONDITIONS + << "c::f::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::f::old" << std::endl + #endif << "c::f::body" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - // No old call here because not a base object. - << "c::f::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + // No old call here because not a base object. + << "c::f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); @@ -251,15 +266,25 @@ int main() { out.str(""); dd.f('i'); // d's f inherited from i. ok.str(""); ok - << "i::static_inv" << std::endl - << "i::inv" << std::endl - << "i::f::pre" << std::endl - << "i::f::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "i::static_inv" << std::endl + << "i::inv" << std::endl + #endif + #if BOOST_CONTRACT_PRECONDITIONS + << "i::f::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "i::f::old" << std::endl + #endif << "i::f::body" << std::endl - << "i::static_inv" << std::endl - << "i::inv" << std::endl - // No old call here because not a base object. - << "i::f::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "i::static_inv" << std::endl + << "i::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + // No old call here because not a base object. + << "i::f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); @@ -267,28 +292,33 @@ int main() { out.str(""); ee.f('e'); ok.str(""); ok - << "i::static_inv" << std::endl - << "i::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - - << "i::f::pre" << std::endl - << "e::f::pre" << std::endl - - << "i::f::old" << std::endl - << "e::f::old" << std::endl - + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "i::static_inv" << std::endl + << "i::inv" << std::endl + << "e::static_inv" << std::endl + << "e::inv" << std::endl + #endif + #if BOOST_CONTRACT_PRECONDITIONS + << "i::f::pre" << std::endl + << "e::f::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "i::f::old" << std::endl + << "e::f::old" << std::endl + #endif << "e::f::body" << std::endl - - << "i::static_inv" << std::endl - << "i::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - - << "i::f::old" << std::endl - << "i::f::post" << std::endl - // No old call here because not a base object. - << "e::f::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "i::static_inv" << std::endl + << "i::inv" << std::endl + << "e::static_inv" << std::endl + << "e::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "i::f::old" << std::endl + << "i::f::post" << std::endl + // No old call here because not a base object. + << "e::f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); @@ -296,15 +326,25 @@ int main() { out.str(""); ii.f('i'); ok.str(""); ok - << "i::static_inv" << std::endl - << "i::inv" << std::endl - << "i::f::pre" << std::endl - << "i::f::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "i::static_inv" << std::endl + << "i::inv" << std::endl + #endif + #if BOOST_CONTRACT_PRECONDITIONS + << "i::f::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "i::f::old" << std::endl + #endif << "i::f::body" << std::endl - << "i::static_inv" << std::endl - << "i::inv" << std::endl - // No old call here because not a base object. - << "i::f::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "i::static_inv" << std::endl + << "i::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + // No old call here because not a base object. + << "i::f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); @@ -312,28 +352,33 @@ int main() { out.str(""); hh.f('h'); ok.str(""); ok - << "j::static_inv" << std::endl - << "j::inv" << std::endl - << "h::static_inv" << std::endl - << "h::inv" << std::endl - - << "j::f::pre" << std::endl - << "h::f::pre" << std::endl - - << "j::f::old" << std::endl - << "h::f::old" << std::endl - + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "j::static_inv" << std::endl + << "j::inv" << std::endl + << "h::static_inv" << std::endl + << "h::inv" << std::endl + #endif + #if BOOST_CONTRACT_PRECONDITIONS + << "j::f::pre" << std::endl + << "h::f::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "j::f::old" << std::endl + << "h::f::old" << std::endl + #endif << "h::f::body" << std::endl - - << "j::static_inv" << std::endl - << "j::inv" << std::endl - << "h::static_inv" << std::endl - << "h::inv" << std::endl - - << "j::f::old" << std::endl - << "j::f::post" << std::endl - // No old call here because not a base object. - << "h::f::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "j::static_inv" << std::endl + << "j::inv" << std::endl + << "h::static_inv" << std::endl + << "h::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "j::f::old" << std::endl + << "j::f::post" << std::endl + // No old call here because not a base object. + << "h::f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); @@ -341,15 +386,25 @@ int main() { out.str(""); jj.f('j'); ok.str(""); ok - << "j::static_inv" << std::endl - << "j::inv" << std::endl - << "j::f::pre" << std::endl - << "j::f::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "j::static_inv" << std::endl + << "j::inv" << std::endl + #endif + #if BOOST_CONTRACT_PRECONDITIONS + << "j::f::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "j::f::old" << std::endl + #endif << "j::f::body" << std::endl - << "j::static_inv" << std::endl - << "j::inv" << std::endl - // No old call here because not a base object. - << "j::f::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "j::static_inv" << std::endl + << "j::inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + // No old call here because not a base object. + << "j::f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/public_function/bases_virtual.cpp b/test/public_function/bases_virtual.cpp index 702b0a9..58f482c 100644 --- a/test/public_function/bases_virtual.cpp +++ b/test/public_function/bases_virtual.cpp @@ -1,5 +1,8 @@ +// Test public function subcontracting via virtual functions. + #include "bases.hpp" +#include #include #include @@ -13,68 +16,83 @@ int main() { result_type& r = ca.f(s); ok.str(""); ok - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - - << "d::f::pre" << std::endl - << "e::f::pre" << std::endl - << "c::f::pre" << std::endl - << "a::f::pre" << std::endl - - << "d::f::old" << std::endl - << "e::f::old" << std::endl - << "c::f::old" << std::endl - << "a::f::old" << std::endl - + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "d::static_inv" << std::endl + << "d::inv" << std::endl + << "e::static_inv" << std::endl + << "e::inv" << std::endl + << "c::static_inv" << std::endl + << "c::inv" << std::endl + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_PRECONDITIONS + << "d::f::pre" << std::endl + << "e::f::pre" << std::endl + << "c::f::pre" << std::endl + << "a::f::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "d::f::old" << std::endl + << "e::f::old" << std::endl + << "c::f::old" << std::endl + << "a::f::old" << std::endl + #endif << "a::f::body" << std::endl - - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - - << "d::f::old" << std::endl - << "d::f::post" << std::endl - << "e::f::old" << std::endl - << "e::f::post" << std::endl - << "c::f::old" << std::endl - << "c::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 + << "e::static_inv" << std::endl + << "e::inv" << std::endl + << "c::static_inv" << std::endl + << "c::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 + << "e::f::old" << std::endl + << "e::f::post" << std::endl + << "c::f::old" << std::endl + << "c::f::post" << std::endl + // No old call here because not a base object. + << "a::f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); BOOST_TEST_EQ(r.value, "A"); BOOST_TEST_EQ(s.value, "acde"); - BOOST_TEST_EQ(s.copies(), 4); - BOOST_TEST_EQ(s.evals(), 4); + BOOST_TEST_EQ(s.copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 4, 0)); + BOOST_TEST_EQ(s.evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 4, 0)); // Cannot access x via ca, but only via aa. BOOST_TEST_EQ(aa.x.value, "aA"); - BOOST_TEST_EQ(aa.x.copies(), 1); - BOOST_TEST_EQ(aa.x.evals(), 1); + BOOST_TEST_EQ(aa.x.copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); + BOOST_TEST_EQ(aa.x.evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); BOOST_TEST_EQ(ca.y.value, "cA"); - BOOST_TEST_EQ(ca.y.copies(), 1); - BOOST_TEST_EQ(ca.y.evals(), 1); + BOOST_TEST_EQ(ca.y.copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); + BOOST_TEST_EQ(ca.y.evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); BOOST_TEST_EQ(ca.t<'d'>::z.value, "dA"); - BOOST_TEST_EQ(ca.t<'d'>::z.copies(), 1); - BOOST_TEST_EQ(ca.t<'d'>::z.evals(), 1); + BOOST_TEST_EQ(ca.t<'d'>::z.copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); + BOOST_TEST_EQ(ca.t<'d'>::z.evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); BOOST_TEST_EQ(ca.t<'e'>::z.value, "eA"); - BOOST_TEST_EQ(ca.t<'e'>::z.copies(), 1); - BOOST_TEST_EQ(ca.t<'e'>::z.evals(), 1); + BOOST_TEST_EQ(ca.t<'e'>::z.copies(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); + BOOST_TEST_EQ(ca.t<'e'>::z.evals(), + BOOST_PP_IIF(BOOST_CONTRACT_POSTCONDITIONS, 1, 0)); return boost::report_errors(); } diff --git a/test/public_function/body_throw.cpp b/test/public_function/body_throw.cpp index 9e625b8..5229fba 100644 --- a/test/public_function/body_throw.cpp +++ b/test/public_function/body_throw.cpp @@ -96,30 +96,34 @@ int main() { BOOST_TEST(false); } catch(a::err const&) { ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - << "b::f::pre" << std::endl - << "a::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 + << "b::f::pre" << std::endl + << "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 // Test this threw. - - // Test no post (but still subcontracted inv) because body threw. - << "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 + #if BOOST_CONTRACT_EXIT_INVARIANTS + // Test no post (but still subcontracted inv) as body threw. + << "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 ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/public_function/decl.hpp b/test/public_function/decl.hpp index ca1f744..79c9c54 100644 --- a/test/public_function/decl.hpp +++ b/test/public_function/decl.hpp @@ -18,38 +18,38 @@ bool c_entering_static_inv = true, c_entry_static_inv = true, c_exit_static_inv = true; bool c_entering_inv = true, c_entry_inv = true, c_exit_inv = true; struct c { -#ifndef BOOST_CONTRACT_AUX_TEST_NO_C_STATIC_INV - static void static_invariant() { - out << "c::static_inv" << std::endl; - if(c_entering_static_inv) BOOST_CONTRACT_ASSERT(c_entry_static_inv); - else BOOST_CONTRACT_ASSERT(c_exit_static_inv); - c_entering_static_inv = false; - } -#endif -#ifndef BOOST_CONTRACT_AUX_TEST_NO_C_INV - void invariant() const { - out << "c::inv" << std::endl; - if(c_entering_inv) BOOST_CONTRACT_ASSERT(c_entry_inv); - else BOOST_CONTRACT_ASSERT(c_exit_inv); - c_entering_inv = false; - } -#endif + #ifndef BOOST_CONTRACT_AUX_TEST_NO_C_STATIC_INV + static void static_invariant() { + out << "c::static_inv" << std::endl; + if(c_entering_static_inv) BOOST_CONTRACT_ASSERT(c_entry_static_inv); + else BOOST_CONTRACT_ASSERT(c_exit_static_inv); + c_entering_static_inv = false; + } + #endif + #ifndef BOOST_CONTRACT_AUX_TEST_NO_C_INV + void invariant() const { + out << "c::inv" << std::endl; + if(c_entering_inv) BOOST_CONTRACT_ASSERT(c_entry_inv); + else BOOST_CONTRACT_ASSERT(c_exit_inv); + c_entering_inv = false; + } + #endif virtual void f(boost::contract::virtual_* v = 0) { boost::contract::guard c = boost::contract::public_function(v, this) -#ifndef BOOST_CONTRACT_AUX_TEST_NO_C_PRE - .precondition([&] { - out << "c::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(c_pre); - }) -#endif + #ifndef BOOST_CONTRACT_AUX_TEST_NO_C_PRE + .precondition([&] { + out << "c::f::pre" << std::endl; + BOOST_CONTRACT_ASSERT(c_pre); + }) + #endif .old([] { out << "c::f::old" << std::endl; }) -#ifndef BOOST_CONTRACT_AUX_TEST_NO_C_POST - .postcondition([] { - out << "c::f::post" << std::endl; - BOOST_CONTRACT_ASSERT(c_post); - }) -#endif + #ifndef BOOST_CONTRACT_AUX_TEST_NO_C_POST + .postcondition([] { + out << "c::f::post" << std::endl; + BOOST_CONTRACT_ASSERT(c_post); + }) + #endif ; out << "c::f::body" << std::endl; } @@ -66,38 +66,38 @@ struct b typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; #undef BASES -#ifndef BOOST_CONTRACT_AUX_TEST_NO_B_STATIC_INV - static void static_invariant() { - out << "b::static_inv" << std::endl; - if(b_entering_static_inv) BOOST_CONTRACT_ASSERT(b_entry_static_inv); - else BOOST_CONTRACT_ASSERT(b_exit_static_inv); - b_entering_static_inv = false; - } -#endif -#ifndef BOOST_CONTRACT_AUX_TEST_NO_B_INV - void invariant() const { - out << "b::inv" << std::endl; - if(b_entering_inv) BOOST_CONTRACT_ASSERT(b_entry_inv); - else BOOST_CONTRACT_ASSERT(b_exit_inv); - b_entering_inv = false; - } -#endif + #ifndef BOOST_CONTRACT_AUX_TEST_NO_B_STATIC_INV + static void static_invariant() { + out << "b::static_inv" << std::endl; + if(b_entering_static_inv) BOOST_CONTRACT_ASSERT(b_entry_static_inv); + else BOOST_CONTRACT_ASSERT(b_exit_static_inv); + b_entering_static_inv = false; + } + #endif + #ifndef BOOST_CONTRACT_AUX_TEST_NO_B_INV + void invariant() const { + out << "b::inv" << std::endl; + if(b_entering_inv) BOOST_CONTRACT_ASSERT(b_entry_inv); + else BOOST_CONTRACT_ASSERT(b_exit_inv); + b_entering_inv = false; + } + #endif virtual void f(boost::contract::virtual_* v = 0) { boost::contract::guard c = boost::contract::public_function(v, this) -#ifndef BOOST_CONTRACT_AUX_TEST_NO_B_PRE - .precondition([&] { - out << "b::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(b_pre); - }) -#endif + #ifndef BOOST_CONTRACT_AUX_TEST_NO_B_PRE + .precondition([&] { + out << "b::f::pre" << std::endl; + BOOST_CONTRACT_ASSERT(b_pre); + }) + #endif .old([] { out << "b::f::old" << std::endl; }) -#ifndef BOOST_CONTRACT_AUX_TEST_NO_B_POST - .postcondition([] { - out << "b::f::post" << std::endl; - BOOST_CONTRACT_ASSERT(b_post); - }) -#endif + #ifndef BOOST_CONTRACT_AUX_TEST_NO_B_POST + .postcondition([] { + out << "b::f::post" << std::endl; + BOOST_CONTRACT_ASSERT(b_post); + }) + #endif ; out << "a::f::body" << std::endl; } @@ -114,39 +114,39 @@ struct a typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; #undef BASES -#ifndef BOOST_CONTRACT_AUX_TEST_NO_A_STATIC_INV - static void static_invariant() { - out << "a::static_inv" << std::endl; - if(a_entering_static_inv) BOOST_CONTRACT_ASSERT(a_entry_static_inv); - else BOOST_CONTRACT_ASSERT(a_exit_static_inv); - a_entering_static_inv = false; - } -#endif -#ifndef BOOST_CONTRACT_AUX_TEST_NO_A_INV - void invariant() const { - out << "a::inv" << std::endl; - if(a_entering_inv) BOOST_CONTRACT_ASSERT(a_entry_inv); - else BOOST_CONTRACT_ASSERT(a_exit_inv); - a_entering_inv = false; - } -#endif + #ifndef BOOST_CONTRACT_AUX_TEST_NO_A_STATIC_INV + static void static_invariant() { + out << "a::static_inv" << std::endl; + if(a_entering_static_inv) BOOST_CONTRACT_ASSERT(a_entry_static_inv); + else BOOST_CONTRACT_ASSERT(a_exit_static_inv); + a_entering_static_inv = false; + } + #endif + #ifndef BOOST_CONTRACT_AUX_TEST_NO_A_INV + void invariant() const { + out << "a::inv" << std::endl; + if(a_entering_inv) BOOST_CONTRACT_ASSERT(a_entry_inv); + else BOOST_CONTRACT_ASSERT(a_exit_inv); + a_entering_inv = false; + } + #endif virtual void f(boost::contract::virtual_* v = 0) /* override */ { boost::contract::guard c = boost::contract::public_function( v, &a::f, this) -#ifndef BOOST_CONTRACT_AUX_TEST_NO_A_PRE - .precondition([&] { - out << "a::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(a_pre); - }) -#endif + #ifndef BOOST_CONTRACT_AUX_TEST_NO_A_PRE + .precondition([&] { + out << "a::f::pre" << std::endl; + BOOST_CONTRACT_ASSERT(a_pre); + }) + #endif .old([] { out << "a::f::old" << std::endl; }) -#ifndef BOOST_CONTRACT_AUX_TEST_NO_A_POST - .postcondition([] { - out << "a::f::post" << std::endl; - BOOST_CONTRACT_ASSERT(a_post); - }) -#endif + #ifndef BOOST_CONTRACT_AUX_TEST_NO_A_POST + .postcondition([] { + out << "a::f::post" << std::endl; + BOOST_CONTRACT_ASSERT(a_post); + }) + #endif ; out << "a::f::body" << std::endl; } diff --git a/test/public_function/decl_entry_inv_all.cpp b/test/public_function/decl_entry_inv_all.cpp index 6c8e5ae..3c7f52b 100644 --- a/test/public_function/decl_entry_inv_all.cpp +++ b/test/public_function/decl_entry_inv_all.cpp @@ -6,6 +6,7 @@ #undef BOOST_CONTRACT_AUX_TEST_NO_C_INV #include "decl.hpp" +#include #include #include @@ -17,37 +18,43 @@ int main() { a_entry_inv = true; b_entry_inv = true; c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_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. - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "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 - - << "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 + #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 ; BOOST_TEST(out.eq(ok.str())); @@ -58,19 +65,49 @@ int main() { a_entry_inv = false; b_entry_inv = true; c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "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 // Test this 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 // 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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -78,17 +115,47 @@ int main() { a_entry_inv = true; b_entry_inv = false; c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl // Test this failed. + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + << "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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -96,15 +163,45 @@ int main() { a_entry_inv = true; b_entry_inv = true; c_entry_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::static_inv" << std::endl - << "c::inv" << std::endl // Test this failed. + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -112,15 +209,45 @@ int main() { a_entry_inv = false; b_entry_inv = false; c_entry_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::static_inv" << std::endl - << "c::inv" << std::endl // Test this failed (as all did). + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/public_function/decl_entry_inv_ends.cpp b/test/public_function/decl_entry_inv_ends.cpp index fb04c42..69e7469 100644 --- a/test/public_function/decl_entry_inv_ends.cpp +++ b/test/public_function/decl_entry_inv_ends.cpp @@ -6,6 +6,7 @@ #undef BOOST_CONTRACT_AUX_TEST_NO_C_INV #include "decl.hpp" +#include #include #include @@ -17,35 +18,41 @@ int main() { a_entry_inv = true; b_entry_inv = true; c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_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. - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << 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 + #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 ; BOOST_TEST(out.eq(ok.str())); @@ -56,18 +63,47 @@ int main() { a_entry_inv = false; b_entry_inv = true; c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl // Test this 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 // 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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -75,36 +111,42 @@ int main() { a_entry_inv = true; b_entry_inv = false; c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); ok.str(""); ok - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << 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 + #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 ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -112,15 +154,44 @@ int main() { a_entry_inv = true; b_entry_inv = true; c_entry_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::static_inv" << std::endl - << "c::inv" << std::endl // Test this failed. + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -128,15 +199,44 @@ int main() { a_entry_inv = false; b_entry_inv = false; c_entry_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::static_inv" << std::endl - << "c::inv" << std::endl // Test this failed (as all did). + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/public_function/decl_entry_inv_mid.cpp b/test/public_function/decl_entry_inv_mid.cpp index df80d5b..3349df3 100644 --- a/test/public_function/decl_entry_inv_mid.cpp +++ b/test/public_function/decl_entry_inv_mid.cpp @@ -6,6 +6,7 @@ #define BOOST_CONTRACT_AUX_TEST_NO_C_INV #include "decl.hpp" +#include #include #include @@ -17,33 +18,39 @@ int main() { a_entry_inv = true; b_entry_inv = true; c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_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. - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << 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 + #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 ; BOOST_TEST(out.eq(ok.str())); @@ -54,34 +61,40 @@ int main() { a_entry_inv = false; b_entry_inv = true; c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); ok.str(""); ok - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << 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 + #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 ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -89,16 +102,44 @@ int main() { a_entry_inv = true; b_entry_inv = false; c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl // Test this fail. + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -106,34 +147,40 @@ int main() { a_entry_inv = true; b_entry_inv = true; c_entry_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); ok.str(""); ok - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << 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 + #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 ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -141,16 +188,44 @@ int main() { a_entry_inv = false; b_entry_inv = false; c_entry_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl // Test this failed (as all did). + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/public_function/decl_entry_inv_none.cpp b/test/public_function/decl_entry_inv_none.cpp index dddd47a..29beae8 100644 --- a/test/public_function/decl_entry_inv_none.cpp +++ b/test/public_function/decl_entry_inv_none.cpp @@ -6,33 +6,39 @@ #define BOOST_CONTRACT_AUX_TEST_NO_C_INV #include "decl.hpp" +#include #include #include int main() { std::ostringstream ok; ok.str(""); ok // Test nothing fails. - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "b::static_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 - - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << 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 + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "b::static_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 ; a aa; @@ -40,7 +46,8 @@ int main() { a_entry_inv = true; b_entry_inv = true; c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); aa.f(); BOOST_TEST(out.eq(ok.str())); @@ -48,7 +55,8 @@ int main() { a_entry_inv = false; b_entry_inv = true; c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); aa.f(); BOOST_TEST(out.eq(ok.str())); @@ -56,7 +64,8 @@ int main() { a_entry_inv = true; b_entry_inv = false; c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); aa.f(); BOOST_TEST(out.eq(ok.str())); @@ -64,7 +73,8 @@ int main() { a_entry_inv = true; b_entry_inv = true; c_entry_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); aa.f(); BOOST_TEST(out.eq(ok.str())); @@ -72,7 +82,8 @@ int main() { a_entry_inv = false; b_entry_inv = false; c_entry_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); aa.f(); 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 d02b520..7cc28b9 100644 --- a/test/public_function/decl_entry_static_inv_all.cpp +++ b/test/public_function/decl_entry_static_inv_all.cpp @@ -6,6 +6,7 @@ #undef BOOST_CONTRACT_AUX_TEST_NO_C_STATIC_INV #include "decl.hpp" +#include #include #include @@ -17,37 +18,44 @@ int main() { a_entry_static_inv = true; b_entry_static_inv = true; c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); + std::clog << "---" << std::endl; aa.f(); ok.str(""); ok // Test nothing failed. - << "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 - - << "c::f::pre" << std::endl // Test only c pre checked. - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 // 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 - - << "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 - - << "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 + #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 ; BOOST_TEST(out.eq(ok.str())); @@ -58,18 +66,49 @@ int main() { a_entry_static_inv = false; b_entry_static_inv = true; c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { + std::clog << "---" << std::endl; aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl // Test this 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 // 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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -77,16 +116,47 @@ int main() { a_entry_static_inv = true; b_entry_static_inv = false; c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { + std::clog << "---" << std::endl; aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl // Test this failed. + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -94,14 +164,45 @@ int main() { a_entry_static_inv = true; b_entry_static_inv = true; c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { + std::clog << "---" << std::endl; aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::static_inv" << std::endl // Test this failed. + #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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -109,14 +210,46 @@ int main() { a_entry_static_inv = false; b_entry_static_inv = false; c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { + std::clog << "---" << std::endl; aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::static_inv" << std::endl // Test this failed (as all did). + #if BOOST_CONTRACT_ENTRY_INVARIANTS + // 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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/public_function/decl_entry_static_inv_ends.cpp b/test/public_function/decl_entry_static_inv_ends.cpp index 7e098ba..44a0328 100644 --- a/test/public_function/decl_entry_static_inv_ends.cpp +++ b/test/public_function/decl_entry_static_inv_ends.cpp @@ -6,6 +6,7 @@ #undef BOOST_CONTRACT_AUX_TEST_NO_C_STATIC_INV #include "decl.hpp" +#include #include #include @@ -17,35 +18,41 @@ int main() { a_entry_static_inv = true; b_entry_static_inv = true; c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); aa.f(); ok.str(""); ok - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << 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 + #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 ; BOOST_TEST(out.eq(ok.str())); @@ -56,17 +63,46 @@ int main() { a_entry_static_inv = false; b_entry_static_inv = true; c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl // Test this failed. + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + << "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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -79,31 +115,36 @@ int main() { try { aa.f(); ok.str(""); ok - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << 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 + #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 ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -111,14 +152,43 @@ int main() { a_entry_static_inv = true; b_entry_static_inv = true; c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::static_inv" << std::endl // Test this failed. + #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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -126,14 +196,44 @@ int main() { a_entry_static_inv = false; b_entry_static_inv = false; c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::static_inv" << std::endl // Test this failed (as all did). + #if BOOST_CONTRACT_ENTRY_INVARIANTS + // 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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/public_function/decl_entry_static_inv_mid.cpp b/test/public_function/decl_entry_static_inv_mid.cpp index c87778f..433c6b4 100644 --- a/test/public_function/decl_entry_static_inv_mid.cpp +++ b/test/public_function/decl_entry_static_inv_mid.cpp @@ -6,6 +6,7 @@ #define BOOST_CONTRACT_AUX_TEST_NO_C_STATIC_INV #include "decl.hpp" +#include #include #include @@ -17,33 +18,39 @@ int main() { a_entry_static_inv = true; b_entry_static_inv = true; c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); aa.f(); ok.str(""); ok // Test nothing failed. - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << 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 + #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 ; BOOST_TEST(out.eq(ok.str())); @@ -59,29 +66,34 @@ int main() { try { aa.f(); ok.str(""); ok - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << 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 + #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 ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -89,15 +101,43 @@ int main() { a_entry_static_inv = true; b_entry_static_inv = false; c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::inv" << std::endl - << "b::static_inv" << std::endl // Test this fail. + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -110,29 +150,34 @@ int main() { try { aa.f(); ok.str(""); ok - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << 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 + #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 ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -140,15 +185,44 @@ int main() { a_entry_static_inv = false; b_entry_static_inv = false; c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_ENTRY_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::inv" << std::endl - << "b::static_inv" << std::endl // Test this failed (as all did). + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::inv" << std::endl + // 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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/public_function/decl_entry_static_inv_none.cpp b/test/public_function/decl_entry_static_inv_none.cpp index 4ef19b9..25127cd 100644 --- a/test/public_function/decl_entry_static_inv_none.cpp +++ b/test/public_function/decl_entry_static_inv_none.cpp @@ -6,32 +6,38 @@ #define BOOST_CONTRACT_AUX_TEST_NO_C_STATIC_INV #include "decl.hpp" +#include #include #include int main() { std::ostringstream ok; ok // Test nothing fails. - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "c::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 - - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << 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 + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::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 ; a aa; @@ -39,7 +45,8 @@ int main() { a_entry_static_inv = true; b_entry_static_inv = true; c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); aa.f(); BOOST_TEST(out.eq(ok.str())); @@ -47,7 +54,8 @@ int main() { a_entry_static_inv = false; b_entry_static_inv = true; c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); aa.f(); BOOST_TEST(out.eq(ok.str())); @@ -55,7 +63,8 @@ int main() { a_entry_static_inv = true; b_entry_static_inv = false; c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); aa.f(); BOOST_TEST(out.eq(ok.str())); @@ -63,7 +72,8 @@ int main() { a_entry_static_inv = true; b_entry_static_inv = true; c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); aa.f(); BOOST_TEST(out.eq(ok.str())); @@ -71,7 +81,8 @@ int main() { a_entry_static_inv = false; b_entry_static_inv = false; c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); aa.f(); 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 3dc6ad9..5b051c2 100644 --- a/test/public_function/decl_exit_inv_all.cpp +++ b/test/public_function/decl_exit_inv_all.cpp @@ -6,6 +6,7 @@ #undef BOOST_CONTRACT_AUX_TEST_NO_C_INV #include "decl.hpp" +#include #include #include @@ -17,37 +18,43 @@ int main() { a_exit_inv = true; b_exit_inv = true; c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_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. - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "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 - - << "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 + #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 ; BOOST_TEST(out.eq(ok.str())); @@ -58,34 +65,47 @@ int main() { a_exit_inv = false; b_exit_inv = true; c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "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 // Test this failed. + #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 // 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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -93,32 +113,45 @@ int main() { a_exit_inv = true; b_exit_inv = false; c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl // Test this failed. + #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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -126,30 +159,43 @@ int main() { a_exit_inv = true; b_exit_inv = true; c_exit_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl - << "c::inv" << std::endl // Test this failed. + #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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -157,30 +203,43 @@ int main() { a_exit_inv = false; b_exit_inv = false; c_exit_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl - << "c::inv" << std::endl // Test this failed (as all did). + #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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/public_function/decl_exit_inv_ends.cpp b/test/public_function/decl_exit_inv_ends.cpp index 54d8d60..951495f 100644 --- a/test/public_function/decl_exit_inv_ends.cpp +++ b/test/public_function/decl_exit_inv_ends.cpp @@ -6,6 +6,7 @@ #undef BOOST_CONTRACT_AUX_TEST_NO_C_INV #include "decl.hpp" +#include #include #include @@ -17,35 +18,41 @@ int main() { a_exit_inv = true; b_exit_inv = true; c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_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. - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << 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 + #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 ; BOOST_TEST(out.eq(ok.str())); @@ -56,32 +63,45 @@ int main() { a_exit_inv = false; b_exit_inv = true; c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl // Test this failed. + #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 // 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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -89,36 +109,42 @@ int main() { a_exit_inv = true; b_exit_inv = false; c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); ok.str(""); ok - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << 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 + #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 ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -126,29 +152,42 @@ int main() { a_exit_inv = true; b_exit_inv = true; c_exit_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl - << "c::inv" << std::endl // Test this failed. + #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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -156,29 +195,42 @@ int main() { a_exit_inv = false; b_exit_inv = false; c_exit_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl - << "c::inv" << std::endl // Test this failed (as all did). + #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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/public_function/decl_exit_inv_mid.cpp b/test/public_function/decl_exit_inv_mid.cpp index 74a3438..a8a6963 100644 --- a/test/public_function/decl_exit_inv_mid.cpp +++ b/test/public_function/decl_exit_inv_mid.cpp @@ -6,6 +6,7 @@ #define BOOST_CONTRACT_AUX_TEST_NO_C_INV #include "decl.hpp" +#include #include #include @@ -17,33 +18,39 @@ int main() { a_exit_inv = true; b_exit_inv = true; c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_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. - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << 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 + #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 ; BOOST_TEST(out.eq(ok.str())); @@ -54,35 +61,41 @@ int main() { a_exit_inv = false; b_exit_inv = true; c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); ok.str(""); ok - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - // Test no failure here. - - << "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 + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "b::static_inv" << std::endl + << "b::inv" << std::endl + << "a::static_inv" << std::endl + // 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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -90,29 +103,42 @@ int main() { a_exit_inv = true; b_exit_inv = false; c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl // Test this failed. + #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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -120,34 +146,40 @@ int main() { a_exit_inv = true; b_exit_inv = true; c_exit_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); ok.str(""); ok - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << 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 + #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 ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -155,29 +187,42 @@ int main() { a_exit_inv = false; b_exit_inv = false; c_exit_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl // Test this failed (as all did). + #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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/public_function/decl_exit_inv_none.cpp b/test/public_function/decl_exit_inv_none.cpp index ae7ecc5..b3969f1 100644 --- a/test/public_function/decl_exit_inv_none.cpp +++ b/test/public_function/decl_exit_inv_none.cpp @@ -6,34 +6,40 @@ #define BOOST_CONTRACT_AUX_TEST_NO_C_INV #include "decl.hpp" +#include #include #include int main() { std::ostringstream ok; ok.str(""); ok // Test nothing fails. - // No invariants. - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #if BOOST_CONTRACT_ENTRY_INVARIANTS + // No invariants. + << "c::static_inv" << std::endl + << "b::static_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 - - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << 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 + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "b::static_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 ; struct err {}; @@ -45,7 +51,8 @@ int main() { a_exit_inv = true; b_exit_inv = true; c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); aa.f(); BOOST_TEST(out.eq(ok.str())); @@ -53,15 +60,15 @@ int main() { a_exit_inv = false; b_exit_inv = true; c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); aa.f(); BOOST_TEST(out.eq(ok.str())); a_exit_inv = true; b_exit_inv = false; - c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = true; + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); aa.f(); BOOST_TEST(out.eq(ok.str())); @@ -69,7 +76,8 @@ int main() { a_exit_inv = true; b_exit_inv = true; c_exit_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); aa.f(); BOOST_TEST(out.eq(ok.str())); @@ -77,7 +85,8 @@ int main() { a_exit_inv = false; b_exit_inv = false; c_exit_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = true; + a_entering_inv = b_entering_inv = c_entering_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); aa.f(); 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 0b50bdc..f57ee63 100644 --- a/test/public_function/decl_exit_static_inv_all.cpp +++ b/test/public_function/decl_exit_static_inv_all.cpp @@ -6,6 +6,7 @@ #undef BOOST_CONTRACT_AUX_TEST_NO_C_STATIC_INV #include "decl.hpp" +#include #include #include @@ -17,37 +18,43 @@ int main() { a_exit_static_inv = true; b_exit_static_inv = true; c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); aa.f(); ok.str(""); ok // Test nothing failed. - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "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 - - << "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 + #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 ; BOOST_TEST(out.eq(ok.str())); @@ -58,65 +65,91 @@ int main() { a_exit_static_inv = false; b_exit_static_inv = true; c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl // Test this failed. + #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 // 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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } - + a_exit_static_inv = true; b_exit_static_inv = false; c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl // Test this failed. + #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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -124,29 +157,42 @@ int main() { a_exit_static_inv = true; b_exit_static_inv = true; c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl // Test this failed. + #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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -154,29 +200,43 @@ int main() { a_exit_static_inv = false; b_exit_static_inv = false; c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl // Test this failed (as all did). + #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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/public_function/decl_exit_static_inv_ends.cpp b/test/public_function/decl_exit_static_inv_ends.cpp index 7292e6b..6d9f272 100644 --- a/test/public_function/decl_exit_static_inv_ends.cpp +++ b/test/public_function/decl_exit_static_inv_ends.cpp @@ -6,6 +6,7 @@ #undef BOOST_CONTRACT_AUX_TEST_NO_C_STATIC_INV #include "decl.hpp" +#include #include #include @@ -17,35 +18,41 @@ int main() { a_exit_static_inv = true; b_exit_static_inv = true; c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); aa.f(); ok.str(""); ok // Test nothing failed. - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << 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 + #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 ; BOOST_TEST(out.eq(ok.str())); @@ -56,31 +63,44 @@ int main() { a_exit_static_inv = false; b_exit_static_inv = true; c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl // Test this failed. + #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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -88,37 +108,43 @@ int main() { a_exit_static_inv = true; b_exit_static_inv = false; c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); ok.str(""); ok - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl - << "c::inv" << std::endl - // Test no failure here. - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << 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 + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::static_inv" << std::endl + << "c::inv" << std::endl + // Test no failure here. + << "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 ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -126,28 +152,41 @@ int main() { a_exit_static_inv = true; b_exit_static_inv = true; c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl // Test this failed. + #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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -155,28 +194,42 @@ int main() { a_exit_static_inv = false; b_exit_static_inv = false; c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::static_inv" << std::endl // Test this failed (as all did). + #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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/public_function/decl_exit_static_inv_mid.cpp b/test/public_function/decl_exit_static_inv_mid.cpp index f5b1a64..3278f43 100644 --- a/test/public_function/decl_exit_static_inv_mid.cpp +++ b/test/public_function/decl_exit_static_inv_mid.cpp @@ -6,6 +6,7 @@ #define BOOST_CONTRACT_AUX_TEST_NO_C_STATIC_INV #include "decl.hpp" +#include #include #include @@ -17,33 +18,39 @@ int main() { a_exit_static_inv = true; b_exit_static_inv = true; c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); aa.f(); ok.str(""); ok // Test nothing failed. - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << 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 + #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 ; BOOST_TEST(out.eq(ok.str())); @@ -54,35 +61,41 @@ int main() { a_exit_static_inv = false; b_exit_static_inv = true; c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); ok.str(""); ok - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - // Test no failure here. - << "a::inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #if BOOST_CONTRACT_ENTRY_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 - - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << 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 + #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 ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -90,28 +103,41 @@ int main() { a_exit_static_inv = true; b_exit_static_inv = false; c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::inv" << std::endl - << "b::static_inv" << std::endl // Test this failed. + #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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -119,35 +145,41 @@ int main() { a_exit_static_inv = true; b_exit_static_inv = true; c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); ok.str(""); ok - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::inv" << std::endl - // Test no failure here. - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << 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 + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::inv" << std::endl + // Test no failure here. + << "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 ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -155,28 +187,42 @@ int main() { a_exit_static_inv = false; b_exit_static_inv = false; c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_EXIT_INVARIANTS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "c::inv" << std::endl - << "b::static_inv" << std::endl // Test this failed (as all did). + #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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/public_function/decl_exit_static_inv_none.cpp b/test/public_function/decl_exit_static_inv_none.cpp index e7c1272..f0a23b5 100644 --- a/test/public_function/decl_exit_static_inv_none.cpp +++ b/test/public_function/decl_exit_static_inv_none.cpp @@ -6,33 +6,39 @@ #define BOOST_CONTRACT_AUX_TEST_NO_C_STATIC_INV #include "decl.hpp" +#include #include #include int main() { std::ostringstream ok; ok // Test nothing fails. - // No static invariants. - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #if BOOST_CONTRACT_ENTRY_INVARIANTS + // No static invariants. + << "c::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 - - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << 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 + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "c::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 ; struct err {}; @@ -44,7 +50,8 @@ int main() { a_exit_static_inv = true; b_exit_static_inv = true; c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); aa.f(); BOOST_TEST(out.eq(ok.str())); @@ -52,7 +59,8 @@ int main() { a_exit_static_inv = false; b_exit_static_inv = true; c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); aa.f(); BOOST_TEST(out.eq(ok.str())); @@ -60,7 +68,8 @@ int main() { a_exit_static_inv = true; b_exit_static_inv = false; c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); aa.f(); BOOST_TEST(out.eq(ok.str())); @@ -68,7 +77,8 @@ int main() { a_exit_static_inv = true; b_exit_static_inv = true; c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); aa.f(); BOOST_TEST(out.eq(ok.str())); @@ -76,7 +86,8 @@ int main() { a_exit_static_inv = false; b_exit_static_inv = false; c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; + a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = + BOOST_PP_IIF(BOOST_CONTRACT_ENTRY_INVARIANTS, true, false); out.str(""); aa.f(); 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 82a4d0a..c49e96d 100644 --- a/test/public_function/decl_post_all.cpp +++ b/test/public_function/decl_post_all.cpp @@ -20,33 +20,38 @@ int main() { out.str(""); aa.f(); ok.str(""); ok // Test nothing failed. - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "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 - - << "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 + #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 ; BOOST_TEST(out.eq(ok.str())); @@ -60,36 +65,43 @@ int main() { out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "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 - - << "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 // Test this failed. + #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 // Test this failed. + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -100,35 +112,42 @@ int main() { out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "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 - - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl // Test this failed. + #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 // Test this failed. + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -139,33 +158,40 @@ int main() { out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "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 - - << "c::f::old" << std::endl - << "c::f::post" << std::endl // Test this failed. + #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 // Test this failed. + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -176,33 +202,40 @@ int main() { out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "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 - - << "c::f::old" << std::endl - << "c::f::post" << std::endl // Test this failed (as all did). + #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 // Test this failed (as all did). + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/public_function/decl_post_ends.cpp b/test/public_function/decl_post_ends.cpp index 034622f..b237acf 100644 --- a/test/public_function/decl_post_ends.cpp +++ b/test/public_function/decl_post_ends.cpp @@ -20,32 +20,37 @@ int main() { out.str(""); aa.f(); ok.str(""); ok // Test nothing failed. - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "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 - - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "a::f::post" << 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 + << "a::f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); @@ -59,35 +64,42 @@ int main() { out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "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 - - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "a::f::post" << std::endl // Test this failed. + #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 + << "a::f::post" << std::endl // Test this failed. + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -99,33 +111,38 @@ int main() { try { aa.f(); ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "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 - - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - // Test no failure here. - << "a::f::post" << 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 + // Test no failure here. + << "a::f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -136,33 +153,40 @@ int main() { out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "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 - - << "c::f::old" << std::endl - << "c::f::post" << std::endl // Test this failed. + #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 // Test this failed. + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -173,33 +197,40 @@ int main() { out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "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 - - << "c::f::old" << std::endl - << "c::f::post" << std::endl // Test this failed (as all did). + #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 // Test this failed (as all did). + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/public_function/decl_post_mid.cpp b/test/public_function/decl_post_mid.cpp index e1c1959..31fcd3e 100644 --- a/test/public_function/decl_post_mid.cpp +++ b/test/public_function/decl_post_mid.cpp @@ -20,31 +20,36 @@ int main() { out.str(""); aa.f(); ok.str(""); ok // Test nothing failed. - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "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 - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << 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 + << "b::f::old" << std::endl + << "b::f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); @@ -59,32 +64,37 @@ int main() { try { aa.f(); ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "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 - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - // Test no failure here. + #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 + << "b::f::old" << std::endl + << "b::f::post" << std::endl + // Test no failure here. + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -95,34 +105,41 @@ int main() { out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "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 - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl // Test this failed. + #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 + << "b::f::old" << std::endl + << "b::f::post" << std::endl // Test this failed. + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -134,32 +151,37 @@ int main() { try { aa.f(); ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "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 - - << "c::f::old" << std::endl - // Test no failure here. - << "b::f::old" << std::endl - << "b::f::post" << 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 + // Test no failure here. + << "b::f::old" << std::endl + << "b::f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -170,34 +192,41 @@ int main() { out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "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 - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl // Test this failed (as all did). + #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 + << "b::f::old" << std::endl + << "b::f::post" << std::endl // Test this failed (as all did). + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/public_function/decl_post_none.cpp b/test/public_function/decl_post_none.cpp index 4f5f668..b91e894 100644 --- a/test/public_function/decl_post_none.cpp +++ b/test/public_function/decl_post_none.cpp @@ -11,31 +11,36 @@ int main() { std::ostringstream ok; ok // Test nothing fails. - << "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 - - << "c::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "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 - - // No postconditions. - << "c::f::old" << std::endl - << "b::f::old" << 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 + // No postconditions. + << "c::f::old" << std::endl + << "b::f::old" << std::endl + #endif ; a aa; diff --git a/test/public_function/decl_pre_all.cpp b/test/public_function/decl_pre_all.cpp index 12a3963..e77f09f 100644 --- a/test/public_function/decl_pre_all.cpp +++ b/test/public_function/decl_pre_all.cpp @@ -20,33 +20,38 @@ int main() { out.str(""); aa.f(); ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl // Test only c::f::pre checked. - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 // 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 - - << "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 - - << "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 + #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 ; BOOST_TEST(out.eq(ok.str())); @@ -56,35 +61,40 @@ int main() { out.str(""); aa.f(); ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - << "b::f::pre" << std::endl - << "a::f::pre" << std::endl // Test all pre checked. - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 + << "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 - - << "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 - - << "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 + #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 ; BOOST_TEST(out.eq(ok.str())); @@ -94,35 +104,40 @@ int main() { out.str(""); aa.f(); ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - << "b::f::pre" << std::endl - // Test only a::f::pre not checked. - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 + << "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 - - << "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 - - << "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 + #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 ; BOOST_TEST(out.eq(ok.str())); @@ -132,33 +147,38 @@ int main() { out.str(""); aa.f(); ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl // Test only c::f::pre checked. - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 // 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 - - << "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 - - << "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 + #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 ; BOOST_TEST(out.eq(ok.str())); @@ -172,20 +192,23 @@ int main() { out.str(""); try { aa.f(); - BOOST_TEST(false); +#if BOOST_CONTRACT_PRECONDITIONS + BOOST_TEST(false); } catch(err const&) { ok.str(""); ok - << "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 - + #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 << "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 9a50689..9cbe642 100644 --- a/test/public_function/decl_pre_ends.cpp +++ b/test/public_function/decl_pre_ends.cpp @@ -20,33 +20,38 @@ int main() { out.str(""); aa.f(); ok.str(""); ok // Test nothing failed. - << "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 - - << "c::f::pre" << std::endl // Test only c pre checked. - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 // 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 - - << "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 - - << "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 + #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 ; BOOST_TEST(out.eq(ok.str())); @@ -56,35 +61,40 @@ int main() { out.str(""); aa.f(); ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - // Test b's pre not checked. - << "a::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 + // 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 - - << "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 - - << "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 + #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 ; BOOST_TEST(out.eq(ok.str())); @@ -94,33 +104,38 @@ int main() { out.str(""); aa.f(); ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl // Test only c pre checked. - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 // 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 - - << "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 - - << "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 + #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 ; BOOST_TEST(out.eq(ok.str())); @@ -128,17 +143,20 @@ int main() { boost::contract::set_precondition_failure( [] (boost::contract::from) { throw err(); }); - ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - << "a::f::pre" << std::endl // Only first/last pre checked and failed. - ; + #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; @@ -146,8 +164,10 @@ int main() { out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_PRECONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -157,8 +177,10 @@ int main() { out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_PRECONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #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 8329958..e37c52e 100644 --- a/test/public_function/decl_pre_mid.cpp +++ b/test/public_function/decl_pre_mid.cpp @@ -20,33 +20,38 @@ int main() { out.str(""); aa.f(); ok.str(""); ok // Test nothing failed. - << "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 - - << "b::f::pre" << std::endl - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 + << "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 - - << "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 - - << "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 + #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 ; BOOST_TEST(out.eq(ok.str())); @@ -56,33 +61,39 @@ int main() { out.str(""); aa.f(); ok.str(""); ok - << "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 - - << "b::f::pre" << std::endl // Test only middle pre checked and no fail. - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 + // 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 - - << "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 - - << "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 + #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 ; BOOST_TEST(out.eq(ok.str())); @@ -90,16 +101,20 @@ int main() { boost::contract::set_precondition_failure( [] (boost::contract::from) { throw err(); }); - ok.str(""); ok - << "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 - - << "b::f::pre" << std::endl // Test only middle pre checked and failed. - ; + #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; @@ -107,8 +122,10 @@ int main() { out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_PRECONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -118,8 +135,10 @@ int main() { out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_PRECONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -129,8 +148,10 @@ int main() { out.str(""); try { aa.f(); - BOOST_TEST(false); - } catch(err const&) { + #if BOOST_CONTRACT_PRECONDITIONS + BOOST_TEST(false); + } catch(err const&) { + #endif BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/public_function/decl_pre_none.cpp b/test/public_function/decl_pre_none.cpp index 68ff764..60e6deb 100644 --- a/test/public_function/decl_pre_none.cpp +++ b/test/public_function/decl_pre_none.cpp @@ -11,33 +11,36 @@ int main() { std::ostringstream ok; ok // Test nothing fails. - << "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 - + #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 // No preconditions here. - - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - + #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 - - << "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 - - << "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 + #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 ; a aa; diff --git a/test/public_function/no_contracts.cpp b/test/public_function/no_contracts.cpp new file mode 100644 index 0000000..836a8e1 --- /dev/null +++ b/test/public_function/no_contracts.cpp @@ -0,0 +1,116 @@ + +// Test contract compilation on/off. + +#include "../aux_/oteststream.hpp" +#include +#if BOOST_CONTRACT_PUBLIC_FUNCTIONS + #include + #include + #include + #include + #include +#endif +#include +#include + +boost::contract::aux::test::oteststream out; + +struct b { + #if BOOST_CONTRACT_INVARIANTS + static void static_invariant() { out << "b::static_inv" << std::endl; } + void invariant() const { out << "b::inv" << std::endl; } + #endif + + virtual void f(int x, boost::contract::virtual_* v = 0) = 0; +}; + +void b::f(int x, boost::contract::virtual_* v) { + #if BOOST_CONTRACT_POSTCONDITIONS + boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(v, x); + #endif + #if BOOST_CONTRACT_PUBLIC_FUNCTIONS + boost::contract::guard c = boost::contract::public_function(v, this) + #if BOOST_CONTRACT_PRECONDITIONS + .precondition([] { out << "b::f::pre" << std::endl; }) + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + .old([] { out << "b::f::old" << std::endl; }) + .postcondition([] { out << "b::f::post" << std::endl; }) + #endif + ; + #endif + out << "b::f::body" << std::endl; +} + +struct a + #define BASES public b + : BASES +{ + #if BOOST_CONTRACT_PUBLIC_FUNCTIONS + typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; + BOOST_CONTRACT_OVERRIDE(f) + #endif + + #if BOOST_CONTRACT_INVARIANTS + static void static_invariant() { out << "a::static_inv" << std::endl; } + void invariant() const { out << "a::inv" << std::endl; } + #endif + + virtual void f(int x, boost::contract::virtual_* v = 0) { + #if BOOST_CONTRACT_POSTCONDITIONS + boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(v, x); + #endif + #if BOOST_CONTRACT_PUBLIC_FUNCTIONS + boost::contract::guard c = boost::contract::public_function< + override_f>(v, &a::f, this, x) + #if BOOST_CONTRACT_PRECONDITIONS + .precondition([] { out << "a::f::pre" << std::endl; }) + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + .old([] { out << "a::f::old" << std::endl; }) + .postcondition([] { out << "a::f::post" << std::endl; }) + #endif + ; + #endif + out << "a::f::body" << std::endl; + } +}; + +int main() { + std::ostringstream ok; + + a aa; + out.str(""); + aa.f(123); + ok.str(); ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "b::static_inv" << std::endl + << "b::inv" << std::endl + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #endif + #if BOOST_CONTRACT_PRECONDITIONS + << "b::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 + << "b::static_inv" << std::endl + << "b::inv" << std::endl + << "a::static_inv" << std::endl + << "a::inv" << std::endl + #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())); + + return boost::report_errors(); +} + diff --git a/test/public_function/old_throw.cpp b/test/public_function/old_throw.cpp index 020f661..fbe8aae 100644 --- a/test/public_function/old_throw.cpp +++ b/test/public_function/old_throw.cpp @@ -1,5 +1,5 @@ -// Test from public function (derived and bases) .old(). +// Test throw from public function (derived and bases) .old(). #include "../aux_/oteststream.hpp" #include @@ -20,15 +20,15 @@ struct c { virtual void f(boost::contract::virtual_* v = 0) { boost::contract::guard c = boost::contract::public_function(v, this) - .precondition([&] { + .precondition([] { out << "c::f::pre" << std::endl; BOOST_CONTRACT_ASSERT(false); // To check derived pre. }) - .old([&] { + .old([] { out << "c::f::old" << std::endl; throw c::err(); // Test .old() throws. }) - .postcondition([&] { out << "c::f::post" << std::endl; }) + .postcondition([] { out << "c::f::post" << std::endl; }) ; out << "c::f::body" << std::endl; } @@ -49,15 +49,15 @@ struct b virtual void f(boost::contract::virtual_* v = 0) /* override */ { boost::contract::guard c = boost::contract::public_function( v, &b::f, this) - .precondition([&] { + .precondition([] { out << "b::f::pre" << std::endl; BOOST_CONTRACT_ASSERT(false); // To check derived pre. }) - .old([&] { + .old([] { out << "b::f::old" << std::endl; throw b::err(); // Test .old() throws. }) - .postcondition([&] { out << "b::f::post" << std::endl; }) + .postcondition([] { out << "b::f::post" << std::endl; }) ; out << "b::f::body" << std::endl; } @@ -79,12 +79,12 @@ struct a void f(boost::contract::virtual_* v = 0) /* override */ { boost::contract::guard c = boost::contract::public_function( v, &a::f, this) - .precondition([&] { out << "a::f::pre" << std::endl; }) - .old([&] { + .precondition([] { out << "a::f::pre" << std::endl; }) + .old([] { out << "a::f::old" << std::endl; throw a::err(); // Test .old() throws. }) - .postcondition([&] { out << "a::f::post" << std::endl; }) + .postcondition([] { out << "a::f::post" << std::endl; }) ; out << "a::f::body" << std::endl; } @@ -102,21 +102,37 @@ int main() { try { out.str(""); ba.f(); - BOOST_TEST(false); - } catch(c::err const&) { + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(c::err const&) { + #endif ok.str(""); ok - << "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 - - << "c::f::pre" << std::endl - << "b::f::pre" << std::endl - << "a::f::pre" << std::endl - - << "c::f::old" << std::endl // Test this threw. + #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 + << "b::f::pre" << std::endl + << "a::f::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "c::f::old" << std::endl // Test this threw. + #else + << "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 + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/public_function/static.cpp b/test/public_function/static.cpp index 2829df2..e5b547c 100644 --- a/test/public_function/static.cpp +++ b/test/public_function/static.cpp @@ -16,9 +16,9 @@ struct b { static void f() { boost::contract::guard c = boost::contract::public_function() - .precondition([&] { out << "b::f::pre" << std::endl; }) - .old([&] { out << "b::f::old" << std::endl; }) - .postcondition([&] { out << "b::f::post" << std::endl; }) + .precondition([] { out << "b::f::pre" << std::endl; }) + .old([] { out << "b::f::old" << std::endl; }) + .postcondition([] { out << "b::f::post" << std::endl; }) ; out << "b::f::body" << std::endl; } @@ -36,9 +36,9 @@ struct a static void f() { boost::contract::guard c = boost::contract::public_function() - .precondition([&] { out << "a::f::pre" << std::endl; }) - .old([&] { out << "a::f::old" << std::endl; }) - .postcondition([&] { out << "a::f::post" << std::endl; }) + .precondition([] { out << "a::f::pre" << std::endl; }) + .old([] { out << "a::f::old" << std::endl; }) + .postcondition([] { out << "a::f::post" << std::endl; }) ; out << "a::f::body" << std::endl; } @@ -52,13 +52,23 @@ int main() { ok.str(""); ok // Static so no object thus only static inv, plus never virtual so subst // principle does not apply and no subcontracting. - << "a::static_inv" << std::endl - << "a::f::pre" << std::endl - << "a::f::old" << std::endl + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_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 - // No old call here because not base object. - << "a::f::post" << std::endl + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + // No old call here because not base object. + << "a::f::post" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/public_function/static_body_throw.cpp b/test/public_function/static_body_throw.cpp index f4629c4..6729855 100644 --- a/test/public_function/static_body_throw.cpp +++ b/test/public_function/static_body_throw.cpp @@ -13,36 +13,45 @@ struct a { static void static_invariant() { out << "a::static_inv" << std::endl; } void invariant() const { out << "a::inv" << std::endl; } - struct e {}; + struct err {}; static void f() { boost::contract::guard c = boost::contract::public_function() - .precondition([&] { out << "a::f::pre" << std::endl; }) - .old([&] { out << "a::f::old" << std::endl; }) - .postcondition([&] { out << "a::f::post" << std::endl; }) + .precondition([] { out << "a::f::pre" << std::endl; }) + .old([] { out << "a::f::old" << std::endl; }) + .postcondition([] { out << "a::f::post" << std::endl; }) ; out << "a::f::body" << std::endl; - throw a::e(); + throw a::err(); } }; int main() { std::ostringstream ok; - bool threw = false; - out.str(""); - try { a::f(); } - catch(a::e const&) { threw = true; } - BOOST_TEST(threw); - ok.str(""); ok - << "a::static_inv" << std::endl - << "a::f::pre" << std::endl - << "a::f::old" << std::endl - << "a::f::body" << std::endl - << "a::static_inv" << std::endl - // Test no post (but still static inv) because body threw. - ; - BOOST_TEST(out.eq(ok.str())); + try { + out.str(""); + a::f(); + BOOST_TEST(false); + } catch(a::err const&) { + ok.str(""); ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_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 + // Test no post (but still static inv) because body threw. + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } return boost::report_errors(); } diff --git a/test/public_function/static_no_contracts.cpp b/test/public_function/static_no_contracts.cpp new file mode 100644 index 0000000..9bc1529 --- /dev/null +++ b/test/public_function/static_no_contracts.cpp @@ -0,0 +1,69 @@ + +// Test public static member function contract compilation on/off. + +#include "../aux_/oteststream.hpp" +#include +#if BOOST_CONTRACT_PUBLIC_FUNCTIONS + #include + #include + #include +#endif +#include +#include + +boost::contract::aux::test::oteststream out; + +struct a { + #if BOOST_CONTRACT_INVARIANTS + static void static_invariant() { out << "a::static_inv" << std::endl; } + void invariant() const { out << "a::inv" << std::endl; } + #endif + + static void f(int x) { + #if BOOST_CONTRACT_POSTCONDITIONS + boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(x); + #endif + #if BOOST_CONTRACT_PUBLIC_FUNCTIONS + boost::contract::guard c = boost::contract::public_function() + #if BOOST_CONTRACT_PRECONDITIONS + .precondition([] { out << "a::f::pre" << std::endl; }) + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + .old([] { out << "a::f::old" << std::endl; }) + .postcondition([] { out << "a::f::post" << std::endl; }) + #endif + ; + #endif + out << "a::f::body" << std::endl; + } +}; + +int main() { + std::ostringstream ok; + + out.str(""); + a::f(123); + ok.str(""); ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_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 + // Test no post (but still static inv) because body threw. + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::f::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + return boost::report_errors(); +} + diff --git a/test/public_function/static_old_throw.cpp b/test/public_function/static_old_throw.cpp new file mode 100644 index 0000000..97a16f8 --- /dev/null +++ b/test/public_function/static_old_throw.cpp @@ -0,0 +1,66 @@ + +// Test throw from public static member function .old(). + +#include "../aux_/oteststream.hpp" +#include +#include +#include +#include + +boost::contract::aux::test::oteststream out; + +struct a { + static void static_invariant() { out << "a::static_inv" << std::endl; } + void invariant() const { out << "a::inv" << std::endl; } + + struct err {}; + + static void f() { + boost::contract::guard c = boost::contract::public_function() + .precondition([] { out << "a::f::pre" << std::endl; }) + .old([] { + out << "a::f::old" << std::endl; + throw a::err(); + }) + .postcondition([] { out << "a::f::post" << std::endl; }) + ; + out << "a::f::body" << std::endl; + } +}; + +int main() { + std::ostringstream ok; + + boost::contract::set_postcondition_failure( + [] (boost::contract::from) { throw; }); + + try { + out.str(""); + a::f(); + #if BOOST_CONTRACT_POSTCONDITIONS + BOOST_TEST(false); + } catch(a::err const&) { + #endif + ok.str(""); ok + #if BOOST_CONTRACT_ENTRY_INVARIANTS + << "a::static_inv" << std::endl + #endif + #if BOOST_CONTRACT_PRECONDITIONS + << "a::f::pre" << std::endl + #endif + #if BOOST_CONTRACT_POSTCONDITIONS + << "a::f::old" << std::endl // Test this threw. + #else + << "a::f::body" << std::endl + // Test no post (but still static inv) because .old() threw. + #if BOOST_CONTRACT_EXIT_INVARIANTS + << "a::static_inv" << std::endl + #endif + #endif + ; + BOOST_TEST(out.eq(ok.str())); + } catch(...) { BOOST_TEST(false); } + + return boost::report_errors(); +} +