mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Generalized to MOCK_CONSTRAINT
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@660 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
8a6edd531e
commit
400aaddf9a
7 changed files with 108 additions and 123 deletions
|
|
@ -5,7 +5,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 MOCK_CONSTRAINT helper macro
|
||||
* Added support for several sequences in 'in'
|
||||
* Added support for nullptr as constraint
|
||||
* Added mock::close, mock::close_fraction, mock::small and mock::near constraints
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ Simple enough, however this constraint isn't serializable and thus yields a rath
|
|||
|
||||
Just like a parameter, a constraint can be displayed in a readable form using its serialization operator, see [link turtle.customization.logging logging].
|
||||
|
||||
Thus a widely used constraint (for instance one shipped with the code of a library) is likely better to be defined like this :
|
||||
Thus a widely used constraint (for instance one shipped with the code of a library) is likely better defined like this :
|
||||
|
||||
[custom_constraint_functor]
|
||||
|
||||
|
|
@ -99,7 +99,7 @@ See [link turtle.reference.expectation.constraints constraints] for an explanati
|
|||
|
||||
For more information about the serialization operator and the use of mock::format, refer to [link turtle.customization.logging loggin].
|
||||
|
||||
[note The [link turtle.reference.helpers.mock_unary_constraint MOCK_UNARY_CONSTRAINT] and [link turtle.reference.helpers.mock_binary_constraint MOCK_BINARY_CONSTRAINT] macros replace the need to write the constraints explicitly for the most trivial cases.]
|
||||
[note The [link turtle.reference.helpers.mock_constraint MOCK_CONSTRAINT] macro takes care of everything for simple cases.]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
|
|
|||
|
|
@ -759,22 +759,42 @@ BOOST_AUTO_TEST_CASE( demonstrates_resetting_a_static_mock_method )
|
|||
namespace helpers_example_1
|
||||
{
|
||||
//[ helpers_example_1
|
||||
MOCK_UNARY_CONSTRAINT( any, true ) // this is (almost) how mock::any is defined
|
||||
MOCK_UNARY_CONSTRAINT( forty_two, actual == 42 ) // this defines a 'forty_two' constraint
|
||||
MOCK_CONSTRAINT( 0, any, true ) // this is (almost) how mock::any is defined
|
||||
MOCK_CONSTRAINT( 0, forty_two, actual == 42 ) // this defines a 'forty_two' constraint
|
||||
|
||||
BOOST_AUTO_TEST_CASE( mock_constraint_0_arity )
|
||||
{
|
||||
MOCK_FUNCTOR( f, void( int ) );
|
||||
MOCK_EXPECT( f ).with( forty_two );
|
||||
MOCK_EXPECT( f ).with( any );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace helpers_example_2
|
||||
{
|
||||
//[ helpers_example_2
|
||||
MOCK_BINARY_CONSTRAINT( equal, actual == expected ) // this is how mock::equal is defined
|
||||
MOCK_BINARY_CONSTRAINT( near, std::abs( actual - expected ) < 0.01 ) // this defines a 'near' constraint which can be used as 'near( 42 )'
|
||||
MOCK_CONSTRAINT( 1, equal, actual == expected_0 ) // this is how mock::equal is defined
|
||||
MOCK_CONSTRAINT( 1, near, std::abs( actual - expected_0 ) < 0.01 ) // this defines a 'near' constraint which can be used as 'near( 42 )'
|
||||
|
||||
BOOST_AUTO_TEST_CASE( mock_constraint_1_arity )
|
||||
{
|
||||
MOCK_FUNCTOR( f, void( int ) );
|
||||
MOCK_EXPECT( f ).with( near( 42 ) );
|
||||
MOCK_EXPECT( f ).with( equal( 42 ) );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace helpers_example_3
|
||||
{
|
||||
//[ helpers_example_3
|
||||
MOCK_TERNARY_CONSTRAINT( near, std::abs( actual - expected ) < arg ) // this defines a 'near' constraint which can be used as 'near( 42, 0.01 )'
|
||||
MOCK_CONSTRAINT( 2, near, std::abs( actual - expected_0 ) < expected_1 ) // this is how mock::near is defined
|
||||
|
||||
BOOST_AUTO_TEST_CASE( mock_constraint_2_arity )
|
||||
{
|
||||
MOCK_FUNCTOR( f, void( int ) );
|
||||
MOCK_EXPECT( f ).with( near( 42, 0.001 ) );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -323,10 +323,10 @@ Constraints :
|
|||
[[mock::greater( ['expected] )] [['actual] > ['expected]] [compares ['actual] to ['expected] using operator >]]
|
||||
[[mock::less_equal( ['expected] )] [['actual] <= ['expected]] [compares ['actual] to ['expected] using operator <=]]
|
||||
[[mock::greater_equal( ['expected] )] [['actual] >= ['expected]] [compares ['actual] to ['expected] using operator >=]]
|
||||
[[mock::near] [std::abs( ['actual] - ['expected] ) < ['arg]] [checks whether ['actual] is near ['expected]]]
|
||||
[[mock::close] [boost::test_tools::check_is_close( ['actual], ['expected], boost::test_tools::percent_tolerance( ['arg] ) )] [checks whether ['actual] is close to ['expected], see [@http://www.boost.org/libs/test/doc/html/utf/testing-tools/floating_point_comparison.html Floating-point comparison algorithms] ]]
|
||||
[[mock::close_fraction] [boost::test_tools::check_is_close( ['actual], ['expected], boost::test_tools::fraction_tolerance( ['arg] ) )] [checks whether ['actual] is close to ['expected], see [@http://www.boost.org/libs/test/doc/html/utf/testing-tools/floating_point_comparison.html Floating-point comparison algorithms] ]]
|
||||
[[mock::small] [boost::test_tools::check_is_small( ['actual], ['expected] ) )] [checks whether ['actual] is small with a tolerance of ['expected], see [@http://www.boost.org/libs/test/doc/html/utf/testing-tools/floating_point_comparison.html Floating-point comparison algorithms] ]]
|
||||
[[mock::near( ['expected], ['tolerance] )] [std::abs( ['actual] - ['expected] ) < ['tolerance]] [checks whether ['actual] is near ['expected] within ['tolerance]]]
|
||||
[[mock::close( ['expected], ['tolerance] )] [boost::test_tools::check_is_close( ['actual], ['expected], boost::test_tools::percent_tolerance( ['arg] ) )] [checks whether ['actual] is close to ['expected], see [@http://www.boost.org/libs/test/doc/html/utf/testing-tools/floating_point_comparison.html Floating-point comparison algorithms] ]]
|
||||
[[mock::close_fraction( ['expected], ['tolerance] )] [boost::test_tools::check_is_close( ['actual], ['expected], boost::test_tools::fraction_tolerance( ['arg] ) )] [checks whether ['actual] is close to ['expected], see [@http://www.boost.org/libs/test/doc/html/utf/testing-tools/floating_point_comparison.html Floating-point comparison algorithms] ]]
|
||||
[[mock::small( ['tolerance] )] [boost::test_tools::check_is_small( ['actual], ['expected] ) )] [checks whether ['actual] is small within ['tolerance], see [@http://www.boost.org/libs/test/doc/html/utf/testing-tools/floating_point_comparison.html Floating-point comparison algorithms] ]]
|
||||
[[mock::call( ['expected] )] [['expected]( ['actual] )] [calls ['expected] as a functor returning a ['bool] and accepting ['actual] as parameter]]
|
||||
[[mock::same( ['expected] )] [&['actual] == &['expected]] [compares ['actual] to ['expected] by comparing their pointers]]
|
||||
[[mock::assign( ['expected] )] [['actual] = ['expected], true
|
||||
|
|
@ -490,49 +490,27 @@ Example :
|
|||
|
||||
[section Helpers]
|
||||
|
||||
This section presents macros used to help with defining custom constraints.
|
||||
This section presents various useful tools.
|
||||
|
||||
[section MOCK_UNARY_CONSTRAINT]
|
||||
[section MOCK_CONSTRAINT]
|
||||
|
||||
Synopsis :
|
||||
|
||||
MOCK_UNARY_CONSTRAINT( name, expression ) // defines a constraint 'name' based on the given 'expression'
|
||||
MOCK_CONSTRAINT( arity, name, expression ) // defines a constraint 'name' based on the given 'expression'
|
||||
|
||||
The expression manipulates the received parameter 'actual' in order to implement the constraint.
|
||||
The expression manipulates the received parameter ['actual] in order to implement the constraint, as well as ['arity] extra expected arguments ['expected_0], ['expected_1], etc...
|
||||
|
||||
Example :
|
||||
[note The type of all expected arguments must be copy-constructible and assignable.]
|
||||
|
||||
Example without any extra argument :
|
||||
|
||||
[helpers_example_1]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section MOCK_BINARY_CONSTRAINT]
|
||||
|
||||
Synopsis :
|
||||
|
||||
MOCK_BINARY_CONSTRAINT( name, expression ) // defines a constraint 'name' based on the given 'expression'
|
||||
|
||||
The expression manipulates the received parameter 'actual' as well as the passed argument 'expected' in order to implement the constraint.
|
||||
|
||||
[note The type of expected must be copy-constructible and assignable.]
|
||||
|
||||
Example :
|
||||
Example with one extra argument :
|
||||
|
||||
[helpers_example_2]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section MOCK_TERNARY_CONSTRAINT]
|
||||
|
||||
Synopsis :
|
||||
|
||||
MOCK_TERNARY_CONSTRAINT( name, expression ) // defines a constraint 'name' based on the given 'expression'
|
||||
|
||||
The expression manipulates the received parameter 'actual' as well as the passed arguments 'expected' and 'arg' in order to implement the constraint.
|
||||
|
||||
[note The types of expected and arg must be copy-constructible and assignable.]
|
||||
|
||||
Example :
|
||||
Example with two extra arguments :
|
||||
|
||||
[helpers_example_3]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue