From 435dadf89d64e13e22b2e7c148822ee4108b9998 Mon Sep 17 00:00:00 2001 From: mat007 Date: Sun, 22 Jul 2012 07:03:26 +0000 Subject: [PATCH] Refactoring git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@488 860be788-9bd5-4423-9f1e-828f051e677b --- turtle/detail/function_template.hpp | 70 +++++++++++++---------------- turtle/mock.hpp | 4 +- 2 files changed, 33 insertions(+), 41 deletions(-) diff --git a/turtle/detail/function_template.hpp b/turtle/detail/function_template.hpp index 2d328cb..24e6250 100644 --- a/turtle/detail/function_template.hpp +++ b/turtle/detail/function_template.hpp @@ -64,11 +64,6 @@ namespace mock return impl_->expect(); } - void test() const - { - impl_->test(); - } - R operator()( BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, T, t) ) const { return (*impl_)( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, t) ); @@ -176,50 +171,47 @@ namespace mock #define MOCK_FORMAT(z, n, N) \ << " " << mock::format( t##n ) \ << BOOST_PP_IF(BOOST_PP_EQUAL(N,n), " ", ",") -#define MOCK_CONTEXT(n) \ +#define MOCK_CONTEXT \ boost::unit_test::lazy_ostream::instance() \ << lazy_context( this ) \ - << "(" BOOST_PP_REPEAT(n, MOCK_FORMAT, BOOST_PP_DEC(n)) \ + << "(" BOOST_PP_REPEAT(MOCK_NUM_ARGS, MOCK_FORMAT, \ + BOOST_PP_DEC(MOCK_NUM_ARGS)) \ << ")" \ << lazy_expectations( this ) -#define MOCK_INVOKE(n, A) \ - { \ - valid_ = false; \ - for( expectations_cit it = expectations_.begin(); \ - it != expectations_.end(); ++it ) \ - if( it->is_valid( BOOST_PP_ENUM_PARAMS(n, t) ) ) \ - { \ - if( ! it->invoke() ) \ - { \ - error_type::sequence_failed( \ - MOCK_CONTEXT(n), it->file(), it->line() ); \ - return A; \ - } \ - if( ! it->functor() ) \ - { \ - error_type::missing_action( \ - MOCK_CONTEXT(n), it->file(), it->line() ); \ - return A; \ - } \ - valid_ = true; \ - error_type::expected_call( \ - MOCK_CONTEXT(n), it->file(), it->line() ); \ - return it->functor()( BOOST_PP_ENUM_PARAMS(n, t) ); \ - } \ - error_type::unexpected_call( MOCK_CONTEXT(n) ); \ - return A; \ - } result_type operator()( BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, T, t) ) const - MOCK_INVOKE(MOCK_NUM_ARGS, error_type::abort()) - - void test() const - MOCK_INVOKE(0,) + { + valid_ = false; + for( expectations_cit it = expectations_.begin(); + it != expectations_.end(); ++it ) + if( it->is_valid( \ + BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, t) ) ) + { + if( ! it->invoke() ) + { + error_type::sequence_failed( + MOCK_CONTEXT, it->file(), it->line() ); + return error_type::abort(); + } + if( ! it->functor() ) + { + error_type::missing_action( + MOCK_CONTEXT, it->file(), it->line() ); + return error_type::abort(); + } + valid_ = true; + error_type::expected_call( + MOCK_CONTEXT, it->file(), it->line() ); + return it->functor()( \ + BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, t) ); + } + error_type::unexpected_call( MOCK_CONTEXT ); + return error_type::abort(); + } #undef MOCK_FORMAT #undef MOCK_OPERATOR -#undef MOCK_INVOKE #undef MOCK_CONTEXT friend std::ostream& operator<<( diff --git a/turtle/mock.hpp b/turtle/mock.hpp index 9ae131e..0418305 100644 --- a/turtle/mock.hpp +++ b/turtle/mock.hpp @@ -141,8 +141,8 @@ namespace detail MOCK_CONSTRUCTOR_AUX(T, n, A, t, BOOST_DEDUCED_TYPENAME) #define MOCK_DESTRUCTOR(T, t) \ - ~T() { MOCK_ANONYMOUS_HELPER(t).test(); } \ - MOCK_METHOD_HELPER(void(), t) + MOCK_METHOD_HELPER(void(), t) \ + ~T() { try { MOCK_ANONYMOUS_HELPER(t)(); } catch( ... ) {} } #define MOCK_FUNCTION_AUX(F, n, S, t, s, tpn) \ MOCK_FUNCTION_HELPER(S, t, s) \