diff --git a/src/libraries/turtle/expectation.hpp b/src/libraries/turtle/expectation.hpp index f15cadf..90f893f 100644 --- a/src/libraries/turtle/expectation.hpp +++ b/src/libraries/turtle/expectation.hpp @@ -28,15 +28,15 @@ namespace mock { namespace detail { - class matcher_base : private orderable + class expectation_base : private orderable { public: - matcher_base() + expectation_base() : i_( new detail::unlimited() ) , file_( "unknown location" ) , line_( 0 ) {} - virtual ~matcher_base() + virtual ~expectation_base() { for( sequences_cit it = sequences_.begin(); it != sequences_.end(); ++it ) @@ -149,7 +149,7 @@ namespace detail template< typename Result, typename Signature > class expectation< Result, Signature, 0 > - : public matcher_base, public action< Result, Signature > + : public expectation_base, public action< Result, Signature > { public: bool is_valid() const @@ -182,7 +182,7 @@ namespace detail #define MOCK_EXPECTATION(z, n, d) \ template< typename Result, typename Signature > \ class expectation< Result, Signature, n > \ - : public matcher_base, public action< Result, Signature > \ + : public expectation_base, public action< Result, Signature > \ { \ BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_EXPECTATION_TYPEDEF, BOOST_PP_EMPTY) \ public: \ diff --git a/src/libraries/turtle/function.hpp b/src/libraries/turtle/function.hpp index fce8752..d410ed9 100644 --- a/src/libraries/turtle/function.hpp +++ b/src/libraries/turtle/function.hpp @@ -51,7 +51,8 @@ namespace mock }; private: - typedef detail::expectation< result_type, Signature, arity::value > matcher_type; + typedef detail::expectation< result_type, Signature, arity::value > + expectation_type; public: struct expectation_tag @@ -84,11 +85,11 @@ namespace mock impl_->reset(); } - matcher_type& expect( const std::string& file, int line ) + expectation_type& expect( const std::string& file, int line ) { return impl_->expect( file, line ); } - matcher_type& expect() + expectation_type& expect() { return impl_->expect(); } @@ -131,8 +132,8 @@ namespace mock { parent_->remove( *this ); if( ! std::uncaught_exception() ) - for( matchers_cit it = matchers_.begin(); - it != matchers_.end(); ++it ) + for( expectations_cit it = expectations_.begin(); + it != expectations_.end(); ++it ) if( valid_ && ! it->verify() ) ErrorPolicy::untriggered_expectation( context(), it->file(), it->line() ); @@ -155,8 +156,8 @@ namespace mock virtual bool verify() const { - for( matchers_cit it = matchers_.begin(); - it != matchers_.end(); ++it ) + for( expectations_cit it = expectations_.begin(); + it != expectations_.end(); ++it ) if( !it->verify() ) { valid_ = false; @@ -168,21 +169,21 @@ namespace mock virtual void reset() { valid_ = true; - matchers_.clear(); + expectations_.clear(); } - matcher_type& expect( const std::string& file, int line ) + expectation_type& expect( const std::string& file, int line ) { - matchers_.push_back( matcher_type() ); - matchers_.back().set_location( file, line ); + expectations_.push_back( expectation_type() ); + expectations_.back().set_location( file, line ); valid_ = true; - return matchers_.back(); + return expectations_.back(); } - matcher_type& expect() + expectation_type& expect() { - matchers_.push_back( matcher_type() ); + expectations_.push_back( expectation_type() ); valid_ = true; - return matchers_.back(); + return expectations_.back(); } struct no_throw_abort @@ -199,33 +200,34 @@ namespace mock return invoke< ErrorPolicy >(); } -#define MOCK_EXPECTATION_FORMAT(z, n, d) BOOST_PP_IF(n, + ", " +,) format( p##n ) +#define MOCK_EXPECTATION_FORMAT(z, n, d) \ + BOOST_PP_IF(n, + ", " +,) format( p##n ) #define MOCK_EXPECTATION_CONTEXT(n) \ context( BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_EXPECTATION_FORMAT, BOOST_PP_EMPTY) ) #define MOCK_EXPECTATION_OPERATOR(z, n, d) \ - MOCK_DECL(operator(), n, Signature, const, BOOST_DEDUCED_TYPENAME) \ - { \ - for( matchers_cit it = matchers_.begin(); it != matchers_.end(); ++it ) \ - if( it->is_valid( BOOST_PP_ENUM_PARAMS(n, p) ) ) \ + MOCK_DECL(operator(), n, Signature, const, BOOST_DEDUCED_TYPENAME) \ + { \ + for( expectations_cit it = expectations_.begin(); it != expectations_.end(); ++it ) \ + if( it->is_valid( BOOST_PP_ENUM_PARAMS(n, p) ) ) \ + { \ + if( ! it->invoke() ) \ { \ - if( ! it->invoke() ) \ - { \ - valid_ = false; \ - ErrorPolicy::sequence_failed( MOCK_EXPECTATION_CONTEXT(n), it->file(), it->line() ); \ - return ErrorPolicy::abort(); \ - } \ - if( ! it->functor() ) \ - { \ - ErrorPolicy::missing_action( MOCK_EXPECTATION_CONTEXT(n), it->file(), it->line() ); \ - return ErrorPolicy::abort(); \ - } \ - return it->functor()( BOOST_PP_ENUM_PARAMS(n, p) ); \ + valid_ = false; \ + ErrorPolicy::sequence_failed( MOCK_EXPECTATION_CONTEXT(n), it->file(), it->line() ); \ + return ErrorPolicy::abort(); \ } \ - valid_ = false; \ - ErrorPolicy::no_match( MOCK_EXPECTATION_CONTEXT(n) ); \ - return ErrorPolicy::abort(); \ - } - BOOST_PP_REPEAT_FROM_TO(1, MOCK_NUM_ARGS, MOCK_EXPECTATION_OPERATOR, BOOST_PP_EMPTY) + if( ! it->functor() ) \ + { \ + ErrorPolicy::missing_action( MOCK_EXPECTATION_CONTEXT(n), it->file(), it->line() ); \ + return ErrorPolicy::abort(); \ + } \ + return it->functor()( BOOST_PP_ENUM_PARAMS(n, p) ); \ + } \ + valid_ = false; \ + ErrorPolicy::no_match( MOCK_EXPECTATION_CONTEXT(n) ); \ + return ErrorPolicy::abort(); \ + } + BOOST_PP_REPEAT_FROM_TO(1, MOCK_NUM_ARGS, MOCK_EXPECTATION_OPERATOR, BOOST_PP_EMPTY) #undef MOCK_EXPECTATION_CONTEXT #undef MOCK_EXPECTATION_FORMAT #undef MOCK_EXPECTATION_OPERATOR @@ -239,8 +241,8 @@ namespace mock template< typename T > result_type invoke() const { - for( matchers_cit it = matchers_.begin(); - it != matchers_.end(); ++it ) + for( expectations_cit it = expectations_.begin(); + it != expectations_.end(); ++it ) if( it->is_valid() ) { if( ! it->invoke() ) @@ -264,14 +266,14 @@ namespace mock } private: - typedef std::list< matcher_type > matchers_type; + typedef std::list< expectation_type > expectations_type; typedef BOOST_DEDUCED_TYPENAME - matchers_type::const_iterator matchers_cit; + expectations_type::const_iterator expectations_cit; void serialize( std::ostream& s ) const { - for( matchers_cit it = matchers_.begin(); - it != matchers_.end(); ++it ) + for( expectations_cit it = expectations_.begin(); + it != expectations_.end(); ++it ) s << std::endl << *it; } @@ -297,7 +299,7 @@ namespace mock std::string name_; node* parent_; mutable bool valid_; - matchers_type matchers_; + expectations_type expectations_; }; private: diff --git a/src/tests/turtle_test/function_test.cpp b/src/tests/turtle_test/function_test.cpp index 8b1e3c5..8e694b0 100644 --- a/src/tests/turtle_test/function_test.cpp +++ b/src/tests/turtle_test/function_test.cpp @@ -530,7 +530,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_throws_the_set_exception, err BOOST_FAIL( "should have thrown" ); } -// multiple matchers +// multiple expectations BOOST_FIXTURE_TEST_CASE( expecting_twice_a_single_expectation_makes_it_callable_twice, error_fixture ) { @@ -552,7 +552,7 @@ BOOST_FIXTURE_TEST_CASE( expecting_twice_a_single_expectation_makes_it_callable_ } } -BOOST_FIXTURE_TEST_CASE( best_matcher_is_selected_first, error_fixture ) +BOOST_FIXTURE_TEST_CASE( best_expectation_is_selected_first, error_fixture ) { { mock::function< void( int ) > e; @@ -704,7 +704,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_no_match_call_disables_the_automatic_verific CHECK_ERROR( e(), no_match ); } -BOOST_FIXTURE_TEST_CASE( adding_a_matcher_reactivates_the_verification_upon_destruction, error_fixture ) +BOOST_FIXTURE_TEST_CASE( adding_a_expectation_reactivates_the_verification_upon_destruction, error_fixture ) { std::auto_ptr< mock::function< void() > > e( new mock::function< void() > ); CHECK_ERROR( (*e)(), no_match );