Merged logging branch

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@245 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2011-02-19 22:10:22 +00:00
parent 4450ea0330
commit 171accfe27
30 changed files with 1025 additions and 434 deletions

View file

@ -20,11 +20,12 @@
#define CHECK_CALLS( calls ) \
BOOST_CHECK_EQUAL( calls, expected_call_count ); \
expected_call_count = 0;
#define CHECK_ERROR( expr, error, calls ) \
#define CHECK_ERROR( expr, error, calls, context ) \
BOOST_CHECK( verify() ); \
expr; \
BOOST_CHECK_EQUAL( 1, error##_count ); \
CHECK_CALLS( calls ); \
BOOST_CHECK_EQUAL( context, last_context ); \
reset();
namespace
@ -48,6 +49,7 @@ namespace
sequence_failed_count = 0;
verification_failed_count = 0;
untriggered_expectation_count = 0;
last_context.clear();
}
bool verify() const
{
@ -87,11 +89,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 );
CHECK_ERROR( f( 1, "s" ), unexpected_call, 0, "?( 1, \"s\" )" );
}
}
@ -100,12 +102,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 );
CHECK_ERROR( f(), unexpected_call, 0, "?()\nv never()" );
}
{
mock::function< int( int, const std::string& ) > f;
f.expect().never();
CHECK_ERROR( f( 1, "s" ), unexpected_call, 0 );
CHECK_ERROR( f( 1, "s" ), unexpected_call, 0, "?( 1, \"s\" )\nv never().with( any, any )" );
}
}
@ -133,13 +135,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 );
CHECK_ERROR( f(), unexpected_call, 1, "?()\nv once()" );
}
{
mock::function< void( int, const std::string& ) > f;
f.expect().once();
f( 1, "s" );
CHECK_ERROR( f( 1, "s" ), unexpected_call, 1 );
CHECK_ERROR( f( 1, "s" ), unexpected_call, 1, "?( 1, \"s\" )\nv once().with( any, any )" );
}
}
@ -206,12 +208,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 );
CHECK_ERROR( BOOST_CHECK( ! f.verify() ), verification_failed, 0, "?\n. once()" );
}
{
mock::function< int( int, const std::string& ) > f;
f.expect().once();
CHECK_ERROR( BOOST_CHECK( ! f.verify() ), verification_failed, 0 );
CHECK_ERROR( BOOST_CHECK( ! f.verify() ), verification_failed, 0, "?\n. once().with( any, any )" );
}
}
@ -223,13 +225,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 );
CHECK_ERROR( f( 1, "s" ), unexpected_call, 0, "?( 1, \"s\" )" );
}
}
@ -256,12 +258,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 );
CHECK_ERROR( f( 43 ), unexpected_call, 0, "?( 43 )\n. unlimited().with( 42 )" );
}
{
mock::function< int( int, const std::string& ) > f;
f.expect().with( 42, "expected" );
CHECK_ERROR( f( 42, "actual" ), unexpected_call, 0 );
CHECK_ERROR( f( 42, "actual" ), unexpected_call, 0, "?( 42, \"actual\" )\n. unlimited().with( 42, \"expected\" )" );
}
}
@ -271,7 +273,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 );
CHECK_ERROR( f( 43 ), unexpected_call, 2, "?( 43 )\n. unlimited().with( ( equal( 42 ) || less( 42 ) ) )" );
}
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_wrong_parameter_value_in_equal_and_not_less_constraint_calls_unexpected_call_error, error_fixture )
@ -279,7 +281,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 );
CHECK_ERROR( f( 43 ), unexpected_call, 1, "?( 43 )\n. unlimited().with( ( equal( 42 ) && ! less( 41 ) ) )" );
}
namespace
@ -328,24 +330,22 @@ 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 );
CHECK_ERROR( f( 42 ), unexpected_call, 0, "?( 42 )\n. unlimited().with( ? )" );
}
{
mock::function< int( int, const std::string& ) > f;
f.expect().with( &custom_constraint, "actual" );
CHECK_ERROR( f( 42, "actual" ), unexpected_call, 0 );
CHECK_ERROR( f( 42, "actual" ), unexpected_call, 0, "?( 42, \"actual\" )\n. unlimited().with( ?, \"actual\" )" );
}
}
/*
BOOST_FIXTURE_TEST_CASE( literal_zero_can_be_used_in_place_of_null_pointers_in_constraints, error_fixture )
{
mock::function< void( int* ) > f;
f.expect().with( 0 );
f.reset();
CHECK_CALLS( 1 );
}
*/
//BOOST_FIXTURE_TEST_CASE( literal_zero_can_be_used_in_place_of_null_pointers_in_constraints, error_fixture )
//{
// mock::function< void( int* ) > f;
// f.expect().with( 0 );
// f.reset();
// CHECK_CALLS( 1 );
//}
// result handling
@ -354,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 );
CHECK_ERROR( f(), missing_action, 0, "?()\n. unlimited()" );
}
{
mock::function< int&() > f;
f.expect();
CHECK_ERROR( f(), missing_action, 0 );
CHECK_ERROR( f(), missing_action, 0, "?()\n. unlimited()" );
}
{
mock::function< const std::string&() > f;
f.expect();
CHECK_ERROR( f(), missing_action, 0 );
CHECK_ERROR( f(), missing_action, 0, "?()\n. unlimited()" );
}
}
@ -582,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 );
CHECK_ERROR( f(), unexpected_call, 2, "?()\nv once()\nv once()" );
}
{
mock::function< void( const std::string& ) > f;
@ -590,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 );
CHECK_ERROR( f( "third"), unexpected_call, 2, "?( \"third\" )\nv once().with( \"first\" )\nv once().with( \"second\" )" );
}
}
@ -602,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 );
CHECK_ERROR( f( 3 ), unexpected_call, 2, "?( 3 )\nv once().with( 1 )\nv once().with( 2 )" );
}
{
mock::function< void( const std::string& ) > f;
@ -610,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 );
CHECK_ERROR( f( "third"), unexpected_call, 2, "?( \"third\" )\nv once().with( \"first\" )\nv once().with( \"second\" )" );
}
}
@ -714,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 );
CHECK_ERROR( f.reset(), untriggered_expectation, 0, "?\n. once()" );
}
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 );
CHECK_ERROR( f.verify(), verification_failed, 0, "?\n. once()" );
}
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 );
CHECK_ERROR( f.reset(), untriggered_expectation, 0, "?\n. once()" );
}
BOOST_FIXTURE_TEST_CASE( throwing_an_exception_disables_the_automatic_verification_upon_destruction, error_fixture )