mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Added support for several sequences in 'in'
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@635 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
4ee2837dcd
commit
8d2fb9c94c
6 changed files with 34 additions and 15 deletions
|
|
@ -6,6 +6,7 @@ Not yet released
|
|||
* Added support for C++11 lambdas as constraints
|
||||
* Return actions now accept by copy types derived from abstract base types
|
||||
* Officially documented MOCK_UNARY_CONSTRAINT and MOCK_BINARY_CONSTRAINT
|
||||
* Added support for several sequences in 'in'
|
||||
|
||||
[endsect]
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
|||
calculator c( v );
|
||||
mock::sequence s;
|
||||
MOCK_EXPECT( v.display ).once().with( 0 ).in( s ); // add this expectation to the sequence
|
||||
MOCK_EXPECT( v.display ).with( 1 ).in( s ); // add this expectation to the sequence after the previous one
|
||||
MOCK_EXPECT( v.display ).with( 1 ).in( s ); // add this expectation to the sequence after the previous call
|
||||
c.add( 0, 0 );
|
||||
c.add( 1, 0 );
|
||||
}
|
||||
|
|
@ -78,7 +78,7 @@ BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
|||
mock::sequence s1, s2;
|
||||
MOCK_EXPECT( v.display ).once().with( 0 ).in( s1 );
|
||||
MOCK_EXPECT( v.display ).once().with( 1 ).in( s2 );
|
||||
MOCK_EXPECT( v.display ).with( 2 ).in( s1 ).in( s2 ); // add this expectation to both sequences after the previous ones
|
||||
MOCK_EXPECT( v.display ).with( 2 ).in( s1, s2 ); // add this expectation to both sequences after the previous calls
|
||||
c.add( 0, 0 );
|
||||
c.add( 1, 0 );
|
||||
c.add( 1, 1 );
|
||||
|
|
|
|||
|
|
@ -393,7 +393,7 @@ An expectation is a statement of configuration for a mock object.
|
|||
|
||||
Synopsis :
|
||||
|
||||
MOCK_EXPECT( identifier ).``[link turtle.reference.expectation.invocation invocation]``( arguments ).with( ``[link turtle.reference.expectation.constraints constraints]`` ).in( ``[link turtle.reference.expectation.sequence sequence]`` ).``[link turtle.reference.expectation.actions action]``( value );
|
||||
MOCK_EXPECT( identifier ).``[link turtle.reference.expectation.invocation invocation]``( arguments ).with( ``[link turtle.reference.expectation.constraints constraints]`` ).in( ``[link turtle.reference.expectation.sequence sequences]`` ).``[link turtle.reference.expectation.actions action]``( value );
|
||||
|
||||
[note The identifier refers to the one specified when [link turtle.reference.creation creating] a mock object]
|
||||
|
||||
|
|
@ -612,9 +612,9 @@ Example using &&, || and ! :
|
|||
|
||||
Synopsis :
|
||||
|
||||
mock::sequence s;
|
||||
MOCK_EXPECT( identifier_1 ).in( s );
|
||||
MOCK_EXPECT( identifier_2 ).in( s );
|
||||
mock::sequence s_1, s_2;
|
||||
MOCK_EXPECT( identifier_1 ).in( s_1 );
|
||||
MOCK_EXPECT( identifier_2 ).in( s_1, s_2 );
|
||||
|
||||
Example :
|
||||
|
||||
|
|
@ -636,20 +636,25 @@ Example :
|
|||
MOCK_EXPECT( c_2.method_2 ).in( s );
|
||||
}
|
||||
|
||||
Example of setting several sequences by chaining calls to ['in] :
|
||||
Example of setting several sequences :
|
||||
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_METHOD( method, 0, void() )
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_enforcing_several_expectations_orders )
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_enforcing_several_expectation_orders )
|
||||
{
|
||||
mock_class c;
|
||||
mock::sequence s_1, s_2;
|
||||
MOCK_EXPECT( c.method ).in( s_1 ).in( s_2 );
|
||||
MOCK_EXPECT( c.method ).in( s_1, s_2 );
|
||||
}
|
||||
|
||||
The maximum number of sequences that can be passed to ['in] is MOCK_MAX_SEQUENCES which defaults to 5. If needed the value can be increased before including the library :
|
||||
|
||||
#define MOCK_MAX_SEQUENCES 7
|
||||
#include <mock/turtle.hpp>
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Actions]
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ BOOST_AUTO_TEST_CASE( an_expectation_can_be_used_in_several_sequences )
|
|||
{
|
||||
mock::sequence s1, s2;
|
||||
mock::detail::function< void() > e;
|
||||
e.expect().once().in( s1 ).in( s2 );
|
||||
e.expect().once().in( s1, s2 );
|
||||
BOOST_CHECK_NO_THROW( e() );
|
||||
BOOST_CHECK( e.verify() );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,10 @@
|
|||
# define MOCK_USE_BOOST_PHOENIX
|
||||
#endif
|
||||
|
||||
#ifndef MOCK_MAX_SEQUENCES
|
||||
# define MOCK_MAX_SEQUENCES 10
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_FUNCTION_MAX_ARGS
|
||||
# define BOOST_FUNCTION_MAX_ARGS MOCK_MAX_ARGS
|
||||
#elif BOOST_PP_LESS(BOOST_FUNCTION_MAX_ARGS, MOCK_MAX_ARGS)
|
||||
|
|
|
|||
|
|
@ -30,6 +30,15 @@
|
|||
#define MOCK_EXPECTATION_SERIALIZE(z, n, d) \
|
||||
BOOST_PP_IF(n, << ", " <<,) *m.c##n##_
|
||||
|
||||
#define MOCK_EXPECTATION_IN_ADD(z, n, d ) \
|
||||
add( s##n.impl_ );
|
||||
#define MOCK_EXPECTATION_IN(z, n, d) \
|
||||
expectation& in( BOOST_PP_ENUM_PARAMS(n, sequence& s) ) \
|
||||
{ \
|
||||
BOOST_PP_REPEAT(n, MOCK_EXPECTATION_IN_ADD, _ ) \
|
||||
return *this; \
|
||||
}
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
|
|
@ -68,11 +77,9 @@ namespace detail
|
|||
MOCK_EXPECTATION_IS_VALID, BOOST_PP_EMPTY);
|
||||
}
|
||||
|
||||
expectation& in( sequence& s )
|
||||
{
|
||||
add( s.impl_ );
|
||||
return *this;
|
||||
}
|
||||
BOOST_PP_REPEAT(MOCK_MAX_SEQUENCES,
|
||||
MOCK_EXPECTATION_IN, BOOST_PP_EMPTY)
|
||||
|
||||
expectation& once()
|
||||
{
|
||||
i_ = boost::make_shared< detail::once >();
|
||||
|
|
@ -131,3 +138,5 @@ namespace detail
|
|||
#undef MOCK_EXPECTATION_ARGS
|
||||
#undef MOCK_EXPECTATION_IS_VALID
|
||||
#undef MOCK_EXPECTATION_SERIALIZE
|
||||
#undef MOCK_EXPECTATION_IN
|
||||
#undef MOCK_EXPECTATION_IN_ADD
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue