mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Merge from refactoring branch
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@53 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
be0af3d224
commit
3f118a8164
14 changed files with 498 additions and 257 deletions
|
|
@ -14,9 +14,6 @@
|
|||
|
||||
BOOST_AUTO_TEST_CASE( all_comparison_constraints_can_be_instanciated )
|
||||
{
|
||||
mock::any;
|
||||
mock::negate;
|
||||
mock::evaluate;
|
||||
mock::equal( 0 );
|
||||
mock::less( 0 );
|
||||
mock::greater( 0 );
|
||||
|
|
|
|||
|
|
@ -580,6 +580,17 @@ BOOST_AUTO_TEST_CASE( best_matcher_is_selected_first )
|
|||
|
||||
// error report
|
||||
|
||||
namespace
|
||||
{
|
||||
template< typename T >
|
||||
std::string to_string( const T& t )
|
||||
{
|
||||
std::stringstream s;
|
||||
s << t;
|
||||
return s.str();
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( expectation_can_be_serialized_to_be_human_readable )
|
||||
{
|
||||
{
|
||||
|
|
@ -587,22 +598,18 @@ BOOST_AUTO_TEST_CASE( expectation_can_be_serialized_to_be_human_readable )
|
|||
e.expect().once().with( 1 );
|
||||
e.expect().once().with( 2 );
|
||||
BOOST_CHECK_NO_THROW( e( 2 ) );
|
||||
std::stringstream s;
|
||||
s << e;
|
||||
const std::string expected = "my expectation\n"
|
||||
". expect( once() ).with( 1 )\n"
|
||||
"v expect( once() ).with( 2 )";
|
||||
BOOST_CHECK_EQUAL( expected, s.str() );
|
||||
BOOST_CHECK_EQUAL( expected, to_string( e ) );
|
||||
e.reset();
|
||||
}
|
||||
{
|
||||
mock::expectation< void( int ) > e( "my expectation" );
|
||||
e.expect().never().with( 1 );
|
||||
std::stringstream s;
|
||||
s << e;
|
||||
const std::string expected = "my expectation\n"
|
||||
"v expect( never() ).with( 1 )";
|
||||
BOOST_CHECK_EQUAL( expected, s.str() );
|
||||
BOOST_CHECK_EQUAL( expected, to_string( e ) );
|
||||
e.reset();
|
||||
}
|
||||
{
|
||||
|
|
@ -611,82 +618,66 @@ BOOST_AUTO_TEST_CASE( expectation_can_be_serialized_to_be_human_readable )
|
|||
e.expect().exactly( 2 ).with( "second" );
|
||||
BOOST_CHECK_NO_THROW( e( "second" ) );
|
||||
{
|
||||
std::stringstream s;
|
||||
s << e;
|
||||
const std::string expected = "?\n"
|
||||
"v expect( never() ).with( less( \"first\" ) )\n"
|
||||
". expect( exactly( 1/2 ) ).with( \"second\" )";
|
||||
BOOST_CHECK_EQUAL( expected, s.str() );
|
||||
BOOST_CHECK_EQUAL( expected, to_string( e ) );
|
||||
}
|
||||
BOOST_CHECK_NO_THROW( e( "second" ) );
|
||||
{
|
||||
std::stringstream s;
|
||||
s << e;
|
||||
const std::string expected = "?\n"
|
||||
"v expect( never() ).with( less( \"first\" ) )\n"
|
||||
"v expect( exactly( 2/2 ) ).with( \"second\" )";
|
||||
BOOST_CHECK_EQUAL( expected, s.str() );
|
||||
BOOST_CHECK_EQUAL( expected, to_string( e ) );
|
||||
}
|
||||
e.reset();
|
||||
}
|
||||
{
|
||||
mock::expectation< void( int ) > e( "my expectation" );
|
||||
e.expect().once();
|
||||
std::stringstream s;
|
||||
s << e;
|
||||
const std::string expected = "my expectation\n"
|
||||
". expect( once() ).with( any )";
|
||||
BOOST_CHECK_EQUAL( expected, s.str() );
|
||||
BOOST_CHECK_EQUAL( expected, to_string( e ) );
|
||||
e.reset();
|
||||
}
|
||||
{
|
||||
mock::expectation< void( int ) > e( "my expectation" );
|
||||
e.expect().once().with( mock::any );
|
||||
std::stringstream s;
|
||||
s << e;
|
||||
const std::string expected = "my expectation\n"
|
||||
". expect( once() ).with( any )";
|
||||
BOOST_CHECK_EQUAL( expected, s.str() );
|
||||
BOOST_CHECK_EQUAL( expected, to_string( e ) );
|
||||
e.reset();
|
||||
}
|
||||
{
|
||||
mock::expectation< void( int ) > e( "my expectation" );
|
||||
e.expect().once();
|
||||
std::stringstream s;
|
||||
s << e;
|
||||
const std::string expected = "my expectation\n"
|
||||
". expect( once() ).with( any )";
|
||||
BOOST_CHECK_EQUAL( expected, s.str() );
|
||||
BOOST_CHECK_EQUAL( expected, to_string( e ) );
|
||||
e.reset();
|
||||
}
|
||||
{
|
||||
mock::expectation< void( int ) > e( "my expectation" );
|
||||
e.expect().once().with( &custom_constraint );
|
||||
std::stringstream s;
|
||||
s << e;
|
||||
const std::string expected = "my expectation\n"
|
||||
". expect( once() ).with( ? )";
|
||||
BOOST_CHECK_EQUAL( expected, s.str() );
|
||||
BOOST_CHECK_EQUAL( expected, to_string( e ) );
|
||||
e.reset();
|
||||
}
|
||||
{
|
||||
mock::expectation< void( int ) > e( "my expectation" );
|
||||
e.expect().once().with( mock::constraint( &custom_constraint, "custom constraint" ) );
|
||||
std::stringstream s;
|
||||
s << e;
|
||||
const std::string expected = "my expectation\n"
|
||||
". expect( once() ).with( custom constraint )";
|
||||
BOOST_CHECK_EQUAL( expected, s.str() );
|
||||
BOOST_CHECK_EQUAL( expected, to_string( e ) );
|
||||
e.reset();
|
||||
}
|
||||
{
|
||||
mock::expectation< void( int ) > e( "my expectation" );
|
||||
e.expect().once().with( mock::constraint( &custom_constraint, true ) );
|
||||
std::stringstream s;
|
||||
s << e;
|
||||
const std::string expected = "my expectation\n"
|
||||
". expect( once() ).with( true )";
|
||||
BOOST_CHECK_EQUAL( expected, s.str() );
|
||||
BOOST_CHECK_EQUAL( expected, to_string( e ) );
|
||||
e.reset();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,21 @@
|
|||
# pragma warning( disable : 4355 4505 )
|
||||
#endif
|
||||
|
||||
namespace
|
||||
{
|
||||
struct my_custom_mock
|
||||
{
|
||||
MOCK_METHOD_EXT( my_method, 0, void(), my_method )
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( custom_mock_object_without_macros_and_without_inheriting_from_object )
|
||||
{
|
||||
my_custom_mock m;
|
||||
MOCK_EXPECT( m, my_method ).once();
|
||||
m.my_method();
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
struct my_custom_mock_object : mock::object
|
||||
|
|
@ -32,9 +47,9 @@ namespace
|
|||
|
||||
BOOST_AUTO_TEST_CASE( custom_mock_object_without_macros )
|
||||
{
|
||||
my_custom_mock_object mock;
|
||||
MOCK_EXPECT( mock, my_method );
|
||||
mock.my_method();
|
||||
my_custom_mock_object m;
|
||||
MOCK_EXPECT( m, my_method ).once();
|
||||
m.my_method();
|
||||
}
|
||||
|
||||
namespace
|
||||
|
|
@ -51,7 +66,7 @@ BOOST_AUTO_TEST_CASE( basic_mock_object_usage )
|
|||
MOCK_EXPECT( m, my_method ).once().returns( 0 );
|
||||
BOOST_CHECK_EQUAL( 0, m.my_method( 13 ) );
|
||||
mock::verify();
|
||||
mock::reset(); // $$$$ MAT : shouldn't reset implicitly call verify ?
|
||||
mock::reset();
|
||||
MOCK_EXPECT( m, my_method ).once().with( 42 ).returns( 7 );
|
||||
BOOST_CHECK_EQUAL( 7, m.my_method( 42 ) );
|
||||
mock::verify();
|
||||
|
|
@ -60,73 +75,6 @@ BOOST_AUTO_TEST_CASE( basic_mock_object_usage )
|
|||
BOOST_CHECK_EQUAL( 51, m.my_method( 27 ) );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
class my_observer : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
virtual ~my_observer() {}
|
||||
|
||||
virtual void notify( int value ) = 0;
|
||||
};
|
||||
|
||||
class my_manager : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
virtual ~my_manager() {}
|
||||
|
||||
virtual my_observer& get_observer() const = 0;
|
||||
};
|
||||
|
||||
class my_subject : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
explicit my_subject( my_manager& f )
|
||||
: o_( f.get_observer() )
|
||||
, value_( 0 )
|
||||
{}
|
||||
void increment()
|
||||
{
|
||||
o_.notify( ++value_ );
|
||||
}
|
||||
private:
|
||||
my_observer& o_;
|
||||
int value_;
|
||||
};
|
||||
|
||||
MOCK_BASE_CLASS( my_mock_observer, my_observer )
|
||||
{
|
||||
MOCK_METHOD( notify, 1 )
|
||||
};
|
||||
|
||||
MOCK_BASE_CLASS( my_mock_manager, my_manager )
|
||||
{
|
||||
MOCK_METHOD( get_observer, 0 )
|
||||
};
|
||||
|
||||
class fixture
|
||||
{
|
||||
public:
|
||||
fixture()
|
||||
: manager( "(the only one)" )
|
||||
{}
|
||||
my_mock_manager manager;
|
||||
my_mock_observer observer;
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE( basic_mock_object_collaboration_usage, fixture )
|
||||
{
|
||||
MOCK_EXPECT( manager, get_observer ).returns( boost::ref( observer ) );
|
||||
my_subject subject( manager );
|
||||
MOCK_EXPECT( observer, notify ).once().with( 1 );
|
||||
subject.increment();
|
||||
MOCK_EXPECT( observer, notify ).once().with( 2 );
|
||||
subject.increment();
|
||||
MOCK_EXPECT( observer, notify ).once().with( 3 );
|
||||
subject.increment();
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
class my_ambiguited_interface : boost::noncopyable
|
||||
|
|
@ -179,3 +127,148 @@ BOOST_AUTO_TEST_CASE( mock_object_method_const_disambiguation )
|
|||
const my_const_ambiguited_mock const_mock;
|
||||
BOOST_CHECK_THROW( const_mock.my_method(), mock::exception );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( mock_functor_in_function_is_supported )
|
||||
{
|
||||
boost::function< int( float, const std::string& ) > func;
|
||||
{
|
||||
MOCK_FUNCTOR( int( float, const std::string& ) ) f;
|
||||
MOCK_EXPECT(f, operator).once().with( 3, "op" ).returns( 42 );
|
||||
func = f;
|
||||
}
|
||||
BOOST_CHECK_EQUAL( 42, func( 3, "op" ) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( mock_functor_name_can_be_customised )
|
||||
{
|
||||
MOCK_FUNCTOR( int( float, const std::string& ) ) f( "my functor" );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
struct functor_fixture
|
||||
{
|
||||
MOCK_FUNCTOR( int( float, const std::string& ) ) f;
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE( mock_functor_in_fixture_is_supported, functor_fixture )
|
||||
{
|
||||
MOCK_EXPECT(f, operator).once().with( 3, "op" ).returns( 42 );
|
||||
BOOST_CHECK_EQUAL( 42, f( 3.f, "op" ) );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
template< typename T >
|
||||
struct my_template_mock
|
||||
{
|
||||
MOCK_METHOD_EXT( my_method, 0, void(), my_method )
|
||||
MOCK_METHOD_EXT_TPL( my_method, 2, void( T, std::string ), my_method_t )
|
||||
MOCK_METHOD_EXT_TPL( my_other_method, 0, void(), my_other_method )
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( mocking_a_template_class_method_is_supported )
|
||||
{
|
||||
my_template_mock< int > m;
|
||||
MOCK_EXPECT( m, my_method_t ).with( 3, "" );
|
||||
m.my_method( 3, "" );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
template< typename T >
|
||||
struct my_template_base_class
|
||||
{
|
||||
virtual ~my_template_base_class()
|
||||
{}
|
||||
virtual void my_method( T ) = 0;
|
||||
virtual void my_other_method() = 0;
|
||||
};
|
||||
template< typename T >
|
||||
MOCK_BASE_CLASS( my_template_base_class_mock, my_template_base_class< T > )
|
||||
{
|
||||
#if (defined __CYGWIN__) && (__GNUC__ == 3)
|
||||
MOCK_METHOD_EXT_TPL( my_method, 1, void( T ), my_method )
|
||||
MOCK_METHOD_EXT_TPL( my_other_method, 0, void(), my_other_method )
|
||||
#else
|
||||
MOCK_METHOD_TPL( my_method, 1 )
|
||||
MOCK_METHOD_TPL( my_other_method, 0 )
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( mocking_a_template_base_class_method_is_supported )
|
||||
{
|
||||
my_template_base_class_mock< int > m;
|
||||
MOCK_EXPECT( m, my_method ).once().with( 3 );
|
||||
m.my_method( 3 );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
class my_observer : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
virtual ~my_observer() {}
|
||||
|
||||
virtual void notify( int value ) = 0;
|
||||
};
|
||||
|
||||
class my_manager : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
virtual ~my_manager() {}
|
||||
|
||||
virtual my_observer& get_observer() const = 0;
|
||||
};
|
||||
|
||||
class my_subject : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
explicit my_subject( my_manager& f )
|
||||
: o_( f.get_observer() )
|
||||
, value_( 0 )
|
||||
{}
|
||||
void increment()
|
||||
{
|
||||
o_.notify( ++value_ );
|
||||
}
|
||||
private:
|
||||
my_observer& o_;
|
||||
int value_;
|
||||
};
|
||||
|
||||
MOCK_BASE_CLASS( my_mock_observer, my_observer )
|
||||
{
|
||||
MOCK_METHOD( notify, 1 )
|
||||
};
|
||||
|
||||
MOCK_BASE_CLASS( my_mock_manager, my_manager )
|
||||
{
|
||||
MOCK_METHOD( get_observer, 0 )
|
||||
};
|
||||
|
||||
struct fixture
|
||||
{
|
||||
fixture()
|
||||
{
|
||||
manager.tag( "(the only one)" );
|
||||
}
|
||||
my_mock_manager manager;
|
||||
my_mock_observer observer;
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE( basic_mock_object_collaboration_usage, fixture )
|
||||
{
|
||||
MOCK_EXPECT( manager, get_observer ).returns( boost::ref( observer ) );
|
||||
my_subject subject( manager );
|
||||
MOCK_EXPECT( observer, notify ).once().with( 1 );
|
||||
subject.increment();
|
||||
MOCK_EXPECT( observer, notify ).once().with( 2 );
|
||||
subject.increment();
|
||||
MOCK_EXPECT( observer, notify ).once().with( 3 );
|
||||
subject.increment();
|
||||
}
|
||||
|
|
@ -141,3 +141,55 @@ BOOST_AUTO_TEST_CASE( MOCK_EXPECT_macro )
|
|||
MOCK_EXPECT( m, my_method ).once().with( 42 );
|
||||
m.my_method( 42 );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
template< typename T >
|
||||
std::string to_string( const T& t )
|
||||
{
|
||||
std::stringstream s;
|
||||
s << t;
|
||||
return s.str();
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( mock_object_is_named )
|
||||
{
|
||||
my_mock m;
|
||||
BOOST_CHECK_EQUAL( "my_mock::my_method", to_string( MOCK_MOCKER( m, my_method ) ) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( mock_object_with_tag_is_named )
|
||||
{
|
||||
my_mock m;
|
||||
m.tag( "(my tag)" );
|
||||
BOOST_CHECK_EQUAL( "my_mock(my tag)::my_method", to_string( MOCK_MOCKER( m, my_method ) ) );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
struct my_custom_mock
|
||||
{
|
||||
MOCK_METHOD_EXT( my_method, 0, void(), my_method )
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( custom_mock_object_without_macros_and_without_inheriting_from_object_is_named )
|
||||
{
|
||||
my_custom_mock m;
|
||||
BOOST_CHECK_EQUAL( "my_custom_mock::my_method", to_string( MOCK_MOCKER( m, my_method ) ) );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
struct my_custom_mock_object : mock::object
|
||||
{
|
||||
MOCK_METHOD_EXT( my_method, 0, void(), my_method )
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( custom_mock_object_without_macros_is_named )
|
||||
{
|
||||
my_custom_mock_object m;
|
||||
BOOST_CHECK_EQUAL( "my_custom_mock_object::my_method", to_string( MOCK_MOCKER( m, my_method ) ) );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@ namespace
|
|||
BOOST_AUTO_TEST_CASE( verifying_an_object_containing_a_failing_expectation_fails )
|
||||
{
|
||||
mock::object o;
|
||||
mock::expectation< void(), silent_error > e( o );
|
||||
mock::expectation< void(), silent_error > e;
|
||||
o.set_parent( e );
|
||||
e.expect().once();
|
||||
BOOST_CHECK( ! o.verify() );
|
||||
}
|
||||
|
|
@ -43,30 +44,37 @@ BOOST_AUTO_TEST_CASE( verifying_an_object_containing_a_failing_expectation_fails
|
|||
BOOST_AUTO_TEST_CASE( resetting_an_object_containing_a_failing_expectation_and_verifying_it_succeeds )
|
||||
{
|
||||
mock::object o;
|
||||
mock::expectation< void() > e( o );
|
||||
mock::expectation< void() > e;
|
||||
o.set_parent( e );
|
||||
e.expect().once();
|
||||
o.reset();
|
||||
BOOST_CHECK( o.verify() );
|
||||
BOOST_CHECK( e.verify() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( verifying_an_object_containing_another_object_with_a_failing_expectation_fails )
|
||||
BOOST_AUTO_TEST_CASE( an_object_is_assignable_by_sharing_its_state )
|
||||
{
|
||||
mock::object o1;
|
||||
mock::object o2( o1 );
|
||||
mock::expectation< void(), silent_error > e( o2 );
|
||||
e.expect().once();
|
||||
mock::expectation< void(), silent_error > e;
|
||||
{
|
||||
mock::object o2;
|
||||
o2.set_parent( e );
|
||||
e.expect().once();
|
||||
o1 = o2;
|
||||
BOOST_CHECK( ! o2.verify() );
|
||||
BOOST_CHECK( ! o1.verify() );
|
||||
}
|
||||
BOOST_CHECK( ! o1.verify() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( resetting_an_object_containing_another_object_with_a_failing_expectation_and_verifying_it_succeeds )
|
||||
BOOST_AUTO_TEST_CASE( an_object_is_copiable_by_sharing_its_state )
|
||||
{
|
||||
mock::object o1;
|
||||
mock::object o2( o1 );
|
||||
mock::expectation< void() > e( o2 );
|
||||
std::auto_ptr< mock::object > o2( new mock::object );
|
||||
const mock::object o1( *o2 );
|
||||
mock::expectation< void(), silent_error > e;
|
||||
o2->set_parent( e );
|
||||
e.expect().once();
|
||||
o1.reset();
|
||||
BOOST_CHECK( o1.verify() );
|
||||
BOOST_CHECK( o2.verify() );
|
||||
BOOST_CHECK( e.verify() );
|
||||
BOOST_CHECK( ! o2->verify() );
|
||||
BOOST_CHECK( ! o1.verify() );
|
||||
o2.reset();
|
||||
BOOST_CHECK( ! o1.verify() );
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue