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

@ -8,9 +8,10 @@
#include <turtle/format.hpp>
#include <boost/assign.hpp>
#include <vector>
#include <ostream>
#include <deque>
#include <list>
#include <vector>
#include <map>
#include <set>

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 )

View file

@ -329,41 +329,6 @@ BOOST_AUTO_TEST_CASE( boost_optional_on_base_class_reference_as_return_type_is_s
b.method();
}
namespace
{
bool serialized = false;
struct custom_argument
{
friend std::ostream& operator<<( std::ostream& s, const custom_argument& )
{
serialized = true;
return s;
}
};
struct custom_constraint
{
template< typename Actual >
friend bool operator==( Actual, const custom_constraint& )
{
return true;
}
friend std::ostream& operator<<( std::ostream& s, const custom_constraint& )
{
serialized = true;
return s;
}
};
}
BOOST_AUTO_TEST_CASE( constraints_and_arguments_are_serialized_lazily )
{
MOCK_FUNCTOR( void( custom_argument ) ) f;
MOCK_EXPECT( f, _ ).with( custom_constraint() );
f( custom_argument() );
BOOST_CHECK( ! serialized );
}
namespace
{
template< typename Expected >

View file

@ -10,7 +10,6 @@
#define MOCK_TEST_MOCK_ERROR_HPP_INCLUDED
#include <boost/type_traits/remove_reference.hpp>
#include <boost/lexical_cast.hpp>
#include <string>
namespace
@ -21,8 +20,6 @@ namespace
int sequence_failed_count = 0;
int verification_failed_count = 0;
int untriggered_expectation_count = 0;
std::string last_context;
}
namespace mock
{
@ -35,45 +32,33 @@ namespace mock
return r;
}
template< typename Context >
static void missing_action( const Context& context,
static void missing_action( const std::string& /*context*/,
const std::string& /*file*/, int /*line*/ )
{
last_context = boost::lexical_cast< std::string >( context );
++missing_action_count;
}
template< typename Context >
static void expected_call( const Context& context,
static void expected_call( const std::string& /*context*/,
const std::string& /*file*/, int /*line*/ )
{
last_context = boost::lexical_cast< std::string >( context );
++expected_call_count;
}
template< typename Context >
static void unexpected_call( const Context& context )
static void unexpected_call( const std::string& /*context*/ )
{
last_context = boost::lexical_cast< std::string >( context );
++unexpected_call_count;
}
template< typename Context >
static void sequence_failed( const Context& context,
static void sequence_failed( const std::string& /*context*/,
const std::string& /*file*/, int /*line*/ )
{
last_context = boost::lexical_cast< std::string >( context );
++sequence_failed_count;
}
template< typename Context >
static void verification_failed( const Context& context,
static void verification_failed( const std::string& /*context*/,
const std::string& /*file*/, int /*line*/ )
{
last_context = boost::lexical_cast< std::string >( context );
++verification_failed_count;
}
template< typename Context >
static void untriggered_expectation( const Context& context,
static void untriggered_expectation( const std::string& /*context*/,
const std::string& /*file*/, int /*line*/ )
{
last_context = boost::lexical_cast< std::string >( context );
++untriggered_expectation_count;
}
};
@ -82,45 +67,33 @@ namespace mock
{
static void abort()
{}
template< typename Context >
static void missing_action( const Context& context,
static void missing_action( const std::string& /*context*/,
const std::string& /*file*/, int /*line*/ )
{
last_context = boost::lexical_cast< std::string >( context );
++missing_action_count;
}
template< typename Context >
static void expected_call( const Context& context,
static void expected_call( const std::string& /*context*/,
const std::string& /*file*/, int /*line*/ )
{
last_context = boost::lexical_cast< std::string >( context );
++expected_call_count;
}
template< typename Context >
static void unexpected_call( const Context& context )
static void unexpected_call( const std::string& /*context*/ )
{
last_context = boost::lexical_cast< std::string >( context );
++unexpected_call_count;
}
template< typename Context >
static void sequence_failed( const Context& context,
static void sequence_failed( const std::string& /*context*/,
const std::string& /*file*/, int /*line*/ )
{
last_context = boost::lexical_cast< std::string >( context );
++sequence_failed_count;
}
template< typename Context >
static void verification_failed( const Context& context,
static void verification_failed( const std::string& /*context*/,
const std::string& /*file*/, int /*line*/ )
{
last_context = boost::lexical_cast< std::string >( context );
++verification_failed_count;
}
template< typename Context >
static void untriggered_expectation( const Context& context,
static void untriggered_expectation( const std::string& /*context*/,
const std::string& /*file*/, int /*line*/ )
{
last_context = boost::lexical_cast< std::string >( context );
++untriggered_expectation_count;
}
};

View file

@ -10,6 +10,7 @@
#define MOCK_TEST_SILENT_ERROR_HPP_INCLUDED
#include <string>
#include <sstream>
#include <stdexcept>
namespace mock
@ -21,27 +22,21 @@ namespace mock
{
throw std::runtime_error( "abort" );
}
template< typename Context >
static void expected_call( const Context& /*context*/,
static void expected_call( const std::string& /*context*/,
const std::string& /*file*/, int /*line*/ )
{}
template< typename Context >
static void unexpected_call( const Context& /*context*/ )
static void unexpected_call( const std::string& /*context*/ )
{}
template< typename Context >
static void missing_action( const Context& /*context*/,
static void missing_action( const std::string& /*context*/,
const std::string& /*file*/, int /*line*/ )
{}
template< typename Context >
static void sequence_failed( const Context& /*context*/,
static void sequence_failed( const std::string& /*context*/,
const std::string& /*file*/, int /*line*/ )
{}
template< typename Context >
static void verification_failed( const Context& /*context*/,
static void verification_failed( const std::string& /*context*/,
const std::string& /*file*/, int /*line*/ )
{}
template< typename Context >
static void untriggered_expectation( const Context& /*context*/,
static void untriggered_expectation( const std::string& /*context*/,
const std::string& /*file*/, int /*line*/ )
{}
};