Reverted 220

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@221 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2011-01-30 08:42:23 +00:00
parent f7be6ea503
commit 4450ea0330
12 changed files with 314 additions and 517 deletions

View file

@ -20,12 +20,11 @@
#define CHECK_CALLS( calls ) \
BOOST_CHECK_EQUAL( calls, expected_call_count ); \
expected_call_count = 0;
#define CHECK_ERROR( expr, error, calls, context ) \
#define CHECK_ERROR( expr, error, calls ) \
BOOST_CHECK( verify() ); \
expr; \
BOOST_CHECK_EQUAL( 1, error##_count ); \
CHECK_CALLS( calls ); \
BOOST_CHECK_EQUAL( context, last_context ); \
reset();
namespace
@ -49,7 +48,6 @@ namespace
sequence_failed_count = 0;
verification_failed_count = 0;
untriggered_expectation_count = 0;
last_context.clear();
}
bool verify() const
{
@ -89,11 +87,11 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_unconfigured_function_calls_unexpected_ca
{
{
mock::function< void() > f;
CHECK_ERROR( f(), unexpected_call, 0, "?()" );
CHECK_ERROR( f(), unexpected_call, 0 );
}
{
mock::function< int( int, const std::string& ) > f;
CHECK_ERROR( f( 1, "s" ), unexpected_call, 0, "?( 1, \"s\" )" );
CHECK_ERROR( f( 1, "s" ), unexpected_call, 0 );
}
}
@ -102,12 +100,12 @@ BOOST_FIXTURE_TEST_CASE( triggering_a_never_expectation_calls_unexpected_call_er
{
mock::function< void() > f;
f.expect().never();
CHECK_ERROR( f(), unexpected_call, 0, "?()\nv never()" );
CHECK_ERROR( f(), unexpected_call, 0 );
}
{
mock::function< int( int, const std::string& ) > f;
f.expect().never();
CHECK_ERROR( f( 1, "s" ), unexpected_call, 0, "?( 1, \"s\" )\nv never().with( any, any )" );
CHECK_ERROR( f( 1, "s" ), unexpected_call, 0 );
}
}
@ -135,13 +133,13 @@ BOOST_FIXTURE_TEST_CASE( triggering_a_once_expectation_calls_unexpected_call_err
mock::function< void() > f;
f.expect().once();
f();
CHECK_ERROR( f(), unexpected_call, 1, "?()\nv once()" );
CHECK_ERROR( f(), unexpected_call, 1 );
}
{
mock::function< void( int, const std::string& ) > f;
f.expect().once();
f( 1, "s" );
CHECK_ERROR( f( 1, "s" ), unexpected_call, 1, "?( 1, \"s\" )\nv once().with( any, any )" );
CHECK_ERROR( f( 1, "s" ), unexpected_call, 1 );
}
}
@ -208,12 +206,12 @@ BOOST_FIXTURE_TEST_CASE( verifying_a_once_expectation_before_the_call_fails, err
{
mock::function< void() > f;
f.expect().once();
CHECK_ERROR( BOOST_CHECK( ! f.verify() ), verification_failed, 0, "?\n. once()" );
CHECK_ERROR( BOOST_CHECK( ! f.verify() ), verification_failed, 0 );
}
{
mock::function< int( int, const std::string& ) > f;
f.expect().once();
CHECK_ERROR( BOOST_CHECK( ! f.verify() ), verification_failed, 0, "?\n. once().with( any, any )" );
CHECK_ERROR( BOOST_CHECK( ! f.verify() ), verification_failed, 0 );
}
}
@ -225,13 +223,13 @@ BOOST_FIXTURE_TEST_CASE( triggering_a_reset_function_calls_unexpected_call_error
mock::function< void() > f;
f.expect();
f.reset();
CHECK_ERROR( f(), unexpected_call, 0, "?()" );
CHECK_ERROR( f(), unexpected_call, 0 );
}
{
mock::function< int( int, const std::string& ) > f;
f.expect();
f.reset();
CHECK_ERROR( f( 1, "s" ), unexpected_call, 0, "?( 1, \"s\" )" );
CHECK_ERROR( f( 1, "s" ), unexpected_call, 0 );
}
}
@ -258,12 +256,12 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_wrong_parameter_value_in
{
mock::function< void( int ) > f;
f.expect().with( 42 );
CHECK_ERROR( f( 43 ), unexpected_call, 0, "?( 43 )\n. unlimited().with( 42 )" );
CHECK_ERROR( f( 43 ), unexpected_call, 0 );
}
{
mock::function< int( int, const std::string& ) > f;
f.expect().with( 42, "expected" );
CHECK_ERROR( f( 42, "actual" ), unexpected_call, 0, "?( 42, \"actual\" )\n. unlimited().with( 42, \"expected\" )" );
CHECK_ERROR( f( 42, "actual" ), unexpected_call, 0 );
}
}
@ -273,7 +271,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_wrong_parameter_value_in
f.expect().with( mock::equal( 42 ) || mock::less( 42 ) );
f( 41 );
f( 42 );
CHECK_ERROR( f( 43 ), unexpected_call, 2, "?( 43 )\n. unlimited().with( ( equal( 42 ) || less( 42 ) ) )" );
CHECK_ERROR( f( 43 ), unexpected_call, 2 );
}
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_wrong_parameter_value_in_equal_and_not_less_constraint_calls_unexpected_call_error, error_fixture )
@ -281,7 +279,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_wrong_parameter_value_in
mock::function< void( int ) > f;
f.expect().with( mock::equal( 42 ) && ! mock::less( 41 ) );
f( 42 );
CHECK_ERROR( f( 43 ), unexpected_call, 1, "?( 43 )\n. unlimited().with( ( equal( 42 ) && ! less( 41 ) ) )" );
CHECK_ERROR( f( 43 ), unexpected_call, 1 );
}
namespace
@ -330,12 +328,12 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_failing_custom_constrain
{
mock::function< void( int ) > f;
f.expect().with( &custom_constraint );
CHECK_ERROR( f( 42 ), unexpected_call, 0, "?( 42 )\n. unlimited().with( ? )" );
CHECK_ERROR( f( 42 ), unexpected_call, 0 );
}
{
mock::function< int( int, const std::string& ) > f;
f.expect().with( &custom_constraint, "actual" );
CHECK_ERROR( f( 42, "actual" ), unexpected_call, 0, "?( 42, \"actual\" )\n. unlimited().with( ?, \"actual\" )" );
CHECK_ERROR( f( 42, "actual" ), unexpected_call, 0 );
}
}
@ -356,17 +354,17 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_no_return_set_calls_miss
{
mock::function< int() > f;
f.expect();
CHECK_ERROR( f(), missing_action, 0, "?()\n. unlimited()" );
CHECK_ERROR( f(), missing_action, 0 );
}
{
mock::function< int&() > f;
f.expect();
CHECK_ERROR( f(), missing_action, 0, "?()\n. unlimited()" );
CHECK_ERROR( f(), missing_action, 0 );
}
{
mock::function< const std::string&() > f;
f.expect();
CHECK_ERROR( f(), missing_action, 0, "?()\n. unlimited()" );
CHECK_ERROR( f(), missing_action, 0 );
}
}
@ -584,7 +582,7 @@ BOOST_FIXTURE_TEST_CASE( expecting_twice_a_single_expectation_makes_it_callable_
f.expect().once();
f();
f();
CHECK_ERROR( f(), unexpected_call, 2, "?()\nv once()\nv once()" );
CHECK_ERROR( f(), unexpected_call, 2 );
}
{
mock::function< void( const std::string& ) > f;
@ -592,7 +590,7 @@ BOOST_FIXTURE_TEST_CASE( expecting_twice_a_single_expectation_makes_it_callable_
f.expect().once().with( "second" );
f( "first" );
f( "second" );
CHECK_ERROR( f( "third"), unexpected_call, 2, "?( \"third\" )\nv once().with( \"first\" )\nv once().with( \"second\" )" );
CHECK_ERROR( f( "third"), unexpected_call, 2 );
}
}
@ -604,7 +602,7 @@ BOOST_FIXTURE_TEST_CASE( best_expectation_is_selected_first, error_fixture )
f.expect().once().with( 2 );
f( 2 );
f( 1 );
CHECK_ERROR( f( 3 ), unexpected_call, 2, "?( 3 )\nv once().with( 1 )\nv once().with( 2 )" );
CHECK_ERROR( f( 3 ), unexpected_call, 2 );
}
{
mock::function< void( const std::string& ) > f;
@ -612,7 +610,7 @@ BOOST_FIXTURE_TEST_CASE( best_expectation_is_selected_first, error_fixture )
f.expect().once().with( "second" );
f( "second" );
f( "first" );
CHECK_ERROR( f( "third"), unexpected_call, 2, "?( \"third\" )\nv once().with( \"first\" )\nv once().with( \"second\" )" );
CHECK_ERROR( f( "third"), unexpected_call, 2 );
}
}
@ -716,28 +714,28 @@ BOOST_FIXTURE_TEST_CASE( expectation_with_remaining_untriggered_matches_upon_des
{
std::auto_ptr< mock::function< void() > > f( new mock::function< void() > );
f->expect().once();
CHECK_ERROR( f.reset(), untriggered_expectation, 0, "?\n. once()" );
CHECK_ERROR( f.reset(), untriggered_expectation, 0 );
}
BOOST_FIXTURE_TEST_CASE( verifying_expectation_with_remaining_matches_disables_the_automatic_verification_upon_destruction, error_fixture )
{
mock::function< void() > f;
f.expect().once();
CHECK_ERROR( f.verify(), verification_failed, 0, "?\n. once()" );
CHECK_ERROR( f.verify(), verification_failed, 0 );
}
BOOST_FIXTURE_TEST_CASE( triggering_unexpected_call_call_disables_the_automatic_verification_upon_destruction, error_fixture )
{
mock::function< void() > f;
CHECK_ERROR( f(), unexpected_call, 0, "?()" );
CHECK_ERROR( f(), unexpected_call, 0 );
}
BOOST_FIXTURE_TEST_CASE( adding_a_expectation_reactivates_the_verification_upon_destruction, error_fixture )
{
std::auto_ptr< mock::function< void() > > f( new mock::function< void() > );
CHECK_ERROR( (*f)(), unexpected_call, 0, "?()" );
CHECK_ERROR( (*f)(), unexpected_call, 0 );
f->expect().once();
CHECK_ERROR( f.reset(), untriggered_expectation, 0, "?\n. once()" );
CHECK_ERROR( f.reset(), untriggered_expectation, 0 );
}
BOOST_FIXTURE_TEST_CASE( throwing_an_exception_disables_the_automatic_verification_upon_destruction, error_fixture )