mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Forced MOCK_ERROR_POLICY to mock_error across all tests to prevent ODR violation
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@697 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
dbf430692d
commit
0609c6c1fa
10 changed files with 312 additions and 247 deletions
|
|
@ -30,7 +30,7 @@
|
||||||
<ClCompile Include="..\..\test\detail\test_type_name.cpp" />
|
<ClCompile Include="..\..\test\detail\test_type_name.cpp" />
|
||||||
<ClCompile Include="..\..\test\test_constraint.cpp" />
|
<ClCompile Include="..\..\test\test_constraint.cpp" />
|
||||||
<ClCompile Include="..\..\test\test_constraints.cpp" />
|
<ClCompile Include="..\..\test\test_constraints.cpp" />
|
||||||
<ClCompile Include="..\..\test\test_error.cpp" />
|
<ClCompile Include="..\..\test\test_exception.cpp" />
|
||||||
<ClCompile Include="..\..\test\test_integration.cpp" />
|
<ClCompile Include="..\..\test\test_integration.cpp" />
|
||||||
<ClCompile Include="..\..\test\test_log.cpp" />
|
<ClCompile Include="..\..\test\test_log.cpp" />
|
||||||
<ClCompile Include="..\..\test\test_matcher.cpp" />
|
<ClCompile Include="..\..\test\test_matcher.cpp" />
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,6 @@
|
||||||
<ClCompile Include="..\..\test\test_constraints.cpp">
|
<ClCompile Include="..\..\test\test_constraints.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\test\test_error.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\test\test_integration.cpp">
|
<ClCompile Include="..\..\test\test_integration.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
@ -66,5 +63,8 @@
|
||||||
<ClCompile Include="..\..\test\test_constraint.cpp">
|
<ClCompile Include="..\..\test\test_constraint.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\test\test_exception.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -17,34 +17,6 @@
|
||||||
#include <boost/function.hpp>
|
#include <boost/function.hpp>
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
struct error_fixture
|
|
||||||
{
|
|
||||||
error_fixture()
|
|
||||||
{
|
|
||||||
data().reset();
|
|
||||||
}
|
|
||||||
~error_fixture()
|
|
||||||
{
|
|
||||||
BOOST_CHECK( data().verify() );
|
|
||||||
BOOST_CHECK_EQUAL( 0, data().call_count );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#define CHECK_CALLS( calls ) \
|
|
||||||
BOOST_CHECK_EQUAL( calls, data().call_count ); \
|
|
||||||
data().call_count = 0;
|
|
||||||
#define CHECK_ERROR( expr, error, calls, context ) \
|
|
||||||
BOOST_CHECK( data().verify() ); \
|
|
||||||
try { expr; } catch( ... ) {} \
|
|
||||||
BOOST_CHECK_EQUAL( 1, data().error_count ); \
|
|
||||||
BOOST_CHECK_EQUAL( error, data().last_message ); \
|
|
||||||
BOOST_CHECK_EQUAL( context, data().last_context ); \
|
|
||||||
CHECK_CALLS( calls ); \
|
|
||||||
data().reset();
|
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -63,13 +35,13 @@ namespace
|
||||||
|
|
||||||
// functor
|
// functor
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( a_function_can_be_passed_as_functor, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( a_function_can_be_passed_as_functor, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::detail::function< void() > f;
|
mock::detail::function< void() > f;
|
||||||
boost::function< void() > functor = f;
|
boost::function< void() > functor = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( a_function_can_be_passed_as_functor_using_boost_bind_and_boost_ref, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( a_function_can_be_passed_as_functor_using_boost_bind_and_boost_ref, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::detail::function< void() > f;
|
mock::detail::function< void() > f;
|
||||||
boost::function< void() > functor = boost::bind( boost::ref( f ) );
|
boost::function< void() > functor = boost::bind( boost::ref( f ) );
|
||||||
|
|
@ -77,7 +49,7 @@ BOOST_FIXTURE_TEST_CASE( a_function_can_be_passed_as_functor_using_boost_bind_an
|
||||||
|
|
||||||
// invocations
|
// invocations
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( triggering_an_unconfigured_function_calls_unexpected_call_error, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( triggering_an_unconfigured_function_calls_unexpected_call_error, mock_error_fixture )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
mock::detail::function< void() > f;
|
mock::detail::function< void() > f;
|
||||||
|
|
@ -89,7 +61,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_unconfigured_function_calls_unexpected_ca
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( triggering_a_never_expectation_calls_unexpected_call_error, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( triggering_a_never_expectation_calls_unexpected_call_error, mock_error_fixture )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
mock::detail::function< void() > f;
|
mock::detail::function< void() > f;
|
||||||
|
|
@ -103,7 +75,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_a_never_expectation_calls_unexpected_call_er
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( triggering_an_unlimited_expectation_is_valid, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( triggering_an_unlimited_expectation_is_valid, mock_error_fixture )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
mock::detail::function< void() > f;
|
mock::detail::function< void() > f;
|
||||||
|
|
@ -121,7 +93,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_unlimited_expectation_is_valid, error_fix
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( triggering_a_once_expectation_calls_unexpected_call_error_after_one_call, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( triggering_a_once_expectation_calls_unexpected_call_error_after_one_call, mock_error_fixture )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
mock::detail::function< void() > f;
|
mock::detail::function< void() > f;
|
||||||
|
|
@ -137,7 +109,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_a_once_expectation_calls_unexpected_call_err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( literal_zero_can_be_used_in_function_call_as_pointers, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( literal_zero_can_be_used_in_function_call_as_pointers, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::detail::function< void( int* ) > f;
|
mock::detail::function< void( int* ) > f;
|
||||||
f.expect().once();
|
f.expect().once();
|
||||||
|
|
@ -147,7 +119,7 @@ BOOST_FIXTURE_TEST_CASE( literal_zero_can_be_used_in_function_call_as_pointers,
|
||||||
|
|
||||||
// verify
|
// verify
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( verifying_an_unconfigured_function_succeeds, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( verifying_an_unconfigured_function_succeeds, mock_error_fixture )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
mock::detail::function< void() > f;
|
mock::detail::function< void() > f;
|
||||||
|
|
@ -159,7 +131,7 @@ BOOST_FIXTURE_TEST_CASE( verifying_an_unconfigured_function_succeeds, error_fixt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( verifying_an_unlimited_expectation_succeeds, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( verifying_an_unlimited_expectation_succeeds, mock_error_fixture )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
mock::detail::function< void() > f;
|
mock::detail::function< void() > f;
|
||||||
|
|
@ -175,7 +147,7 @@ BOOST_FIXTURE_TEST_CASE( verifying_an_unlimited_expectation_succeeds, error_fixt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( verifying_a_once_expectation_after_one_call_succeeds, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( verifying_a_once_expectation_after_one_call_succeeds, mock_error_fixture )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
mock::detail::function< void() > f;
|
mock::detail::function< void() > f;
|
||||||
|
|
@ -193,7 +165,7 @@ BOOST_FIXTURE_TEST_CASE( verifying_a_once_expectation_after_one_call_succeeds, e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( verifying_a_once_expectation_before_the_call_fails, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( verifying_a_once_expectation_before_the_call_fails, mock_error_fixture )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
mock::detail::function< void() > f;
|
mock::detail::function< void() > f;
|
||||||
|
|
@ -207,7 +179,7 @@ BOOST_FIXTURE_TEST_CASE( verifying_a_once_expectation_before_the_call_fails, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( verifying_a_once_expectation_after_a_verify_and_one_call_succeeds, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( verifying_a_once_expectation_after_a_verify_and_one_call_succeeds, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::detail::function< void() > f;
|
mock::detail::function< void() > f;
|
||||||
f.expect().once();
|
f.expect().once();
|
||||||
|
|
@ -219,7 +191,7 @@ BOOST_FIXTURE_TEST_CASE( verifying_a_once_expectation_after_a_verify_and_one_cal
|
||||||
|
|
||||||
// reset
|
// reset
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( triggering_a_reset_function_calls_unexpected_call_error, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( triggering_a_reset_function_calls_unexpected_call_error, mock_error_fixture )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
mock::detail::function< void() > f;
|
mock::detail::function< void() > f;
|
||||||
|
|
@ -235,7 +207,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_a_reset_function_calls_unexpected_call_error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( verifying_a_reset_function_succeeds, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( verifying_a_reset_function_succeeds, mock_error_fixture )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
mock::detail::function< void() > f;
|
mock::detail::function< void() > f;
|
||||||
|
|
@ -253,7 +225,7 @@ BOOST_FIXTURE_TEST_CASE( verifying_a_reset_function_succeeds, error_fixture )
|
||||||
|
|
||||||
// constraints
|
// constraints
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_wrong_parameter_value_in_equal_constraint_calls_unexpected_call_error, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_wrong_parameter_value_in_equal_constraint_calls_unexpected_call_error, mock_error_fixture )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
mock::detail::function< void( int ) > f;
|
mock::detail::function< void( int ) > f;
|
||||||
|
|
@ -267,7 +239,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_wrong_parameter_value_in
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_wrong_parameter_value_in_equal_or_less_constraint_calls_unexpected_call_error, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_wrong_parameter_value_in_equal_or_less_constraint_calls_unexpected_call_error, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::detail::function< void( int ) > f;
|
mock::detail::function< void( int ) > f;
|
||||||
f.expect().with( mock::equal( 42 ) || mock::less( 42 ) );
|
f.expect().with( mock::equal( 42 ) || mock::less( 42 ) );
|
||||||
|
|
@ -276,7 +248,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_wrong_parameter_value_in
|
||||||
CHECK_ERROR( f( 43 ), "unexpected call", 2, "?( 43 )\n. unlimited().with( ( equal( 42 ) || less( 42 ) ) )" );
|
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 )
|
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_wrong_parameter_value_in_equal_and_not_less_constraint_calls_unexpected_call_error, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::detail::function< void( int ) > f;
|
mock::detail::function< void( int ) > f;
|
||||||
f.expect().with( mock::equal( 42 ) && ! mock::less( 41 ) );
|
f.expect().with( mock::equal( 42 ) && ! mock::less( 41 ) );
|
||||||
|
|
@ -299,7 +271,7 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( passing_call_values_by_reference_is_transparent, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( passing_call_values_by_reference_is_transparent, mock_error_fixture )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
mock::detail::function< void( my_interface& ) > f;
|
mock::detail::function< void( my_interface& ) > f;
|
||||||
|
|
@ -325,7 +297,7 @@ namespace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_failing_custom_constraint_calls_unexpected_call_error, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_failing_custom_constraint_calls_unexpected_call_error, mock_error_fixture )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
mock::detail::function< void( int ) > f;
|
mock::detail::function< void( int ) > f;
|
||||||
|
|
@ -339,7 +311,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_failing_custom_constrain
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//BOOST_FIXTURE_TEST_CASE( literal_zero_can_be_used_in_place_of_null_pointers_in_constraints, error_fixture )
|
//BOOST_FIXTURE_TEST_CASE( literal_zero_can_be_used_in_place_of_null_pointers_in_constraints, mock_error_fixture )
|
||||||
//{
|
//{
|
||||||
// mock::detail::function< void( int* ) > f;
|
// mock::detail::function< void( int* ) > f;
|
||||||
// f.expect().with( 0 );
|
// f.expect().with( 0 );
|
||||||
|
|
@ -349,7 +321,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_failing_custom_constrain
|
||||||
|
|
||||||
#ifdef MOCK_NULLPTR
|
#ifdef MOCK_NULLPTR
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( nullptr_can_be_used_in_place_of_null_pointers_in_constraints, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( nullptr_can_be_used_in_place_of_null_pointers_in_constraints, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::detail::function< void( int* ) > f;
|
mock::detail::function< void( int* ) > f;
|
||||||
f.expect().with( nullptr );
|
f.expect().with( nullptr );
|
||||||
|
|
@ -361,7 +333,7 @@ BOOST_FIXTURE_TEST_CASE( nullptr_can_be_used_in_place_of_null_pointers_in_constr
|
||||||
|
|
||||||
#ifdef MOCK_SMART_PTR
|
#ifdef MOCK_SMART_PTR
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( unique_ptr_is_supported_as_parameter, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( unique_ptr_is_supported_as_parameter, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::detail::function< void( std::unique_ptr< int > ) > f;
|
mock::detail::function< void( std::unique_ptr< int > ) > f;
|
||||||
f.expect();
|
f.expect();
|
||||||
|
|
@ -374,7 +346,7 @@ BOOST_FIXTURE_TEST_CASE( unique_ptr_is_supported_as_parameter, error_fixture )
|
||||||
|
|
||||||
// result handling
|
// result handling
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_no_return_set_calls_missing_action, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_no_return_set_calls_missing_action, mock_error_fixture )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
mock::detail::function< int() > f;
|
mock::detail::function< int() > f;
|
||||||
|
|
@ -393,7 +365,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_no_return_set_calls_miss
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_value, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_value, mock_error_fixture )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
mock::detail::function< int() > f;
|
mock::detail::function< int() > f;
|
||||||
|
|
@ -500,7 +472,7 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_auto_ptr_value, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_auto_ptr_value, mock_error_fixture )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
mock::detail::function< std::auto_ptr< int >() > f;
|
mock::detail::function< std::auto_ptr< int >() > f;
|
||||||
|
|
@ -557,7 +529,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_auto_ptr_valu
|
||||||
|
|
||||||
#ifdef MOCK_RVALUE_REFERENCES
|
#ifdef MOCK_RVALUE_REFERENCES
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_moves_the_set_lvalue, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_moves_the_set_lvalue, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::detail::function< int() > f;
|
mock::detail::function< int() > f;
|
||||||
int i = 3;
|
int i = 3;
|
||||||
|
|
@ -566,7 +538,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_moves_the_set_lvalue, error_f
|
||||||
CHECK_CALLS( 1 );
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_moves_the_set_const_lvalue, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_moves_the_set_const_lvalue, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::detail::function< int() > f;
|
mock::detail::function< int() > f;
|
||||||
const int i = 3;
|
const int i = 3;
|
||||||
|
|
@ -575,7 +547,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_moves_the_set_const_lvalue, e
|
||||||
CHECK_CALLS( 1 );
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_moves_the_set_rvalue, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_moves_the_set_rvalue, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::detail::function< int() > f;
|
mock::detail::function< int() > f;
|
||||||
f.expect().moves( 3 );
|
f.expect().moves( 3 );
|
||||||
|
|
@ -587,7 +559,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_moves_the_set_rvalue, error_f
|
||||||
|
|
||||||
#ifdef MOCK_SMART_PTR
|
#ifdef MOCK_SMART_PTR
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_moves_the_set_unique_ptr_lvalue, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_moves_the_set_unique_ptr_lvalue, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::detail::function< std::unique_ptr< int >() > f;
|
mock::detail::function< std::unique_ptr< int >() > f;
|
||||||
std::unique_ptr< int > p( new int );
|
std::unique_ptr< int > p( new int );
|
||||||
|
|
@ -596,7 +568,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_moves_the_set_unique_ptr_lval
|
||||||
CHECK_CALLS( 1 );
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_moves_the_set_unique_ptr_rvalue, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_moves_the_set_unique_ptr_rvalue, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::detail::function< std::unique_ptr< int >() > f;
|
mock::detail::function< std::unique_ptr< int >() > f;
|
||||||
f.expect().moves( std::unique_ptr< int >( new int ) );
|
f.expect().moves( std::unique_ptr< int >( new int ) );
|
||||||
|
|
@ -606,7 +578,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_moves_the_set_unique_ptr_rval
|
||||||
|
|
||||||
#endif // MOCK_SMART_PTR
|
#endif // MOCK_SMART_PTR
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_shared_ptr_value, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_shared_ptr_value, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::detail::function< boost::shared_ptr< base >() > f;
|
mock::detail::function< boost::shared_ptr< base >() > f;
|
||||||
f.expect().returns( new derived );
|
f.expect().returns( new derived );
|
||||||
|
|
@ -614,7 +586,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_shared_ptr_va
|
||||||
CHECK_CALLS( 1 );
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_by_reference, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_by_reference, mock_error_fixture )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
mock::detail::function< base&() > f;
|
mock::detail::function< base&() > f;
|
||||||
|
|
@ -645,7 +617,7 @@ namespace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_calls_the_custom_functor, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_calls_the_custom_functor, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::detail::function< int() > f;
|
mock::detail::function< int() > f;
|
||||||
f.expect().calls( &custom_result );
|
f.expect().calls( &custom_result );
|
||||||
|
|
@ -661,7 +633,7 @@ namespace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_calls_the_custom_functor_with_parameters, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_calls_the_custom_functor_with_parameters, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::detail::function< int( int ) > f;
|
mock::detail::function< int( int ) > f;
|
||||||
f.expect().calls( &custom_result_with_parameter );
|
f.expect().calls( &custom_result_with_parameter );
|
||||||
|
|
@ -669,7 +641,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_calls_the_custom_functor_with
|
||||||
CHECK_CALLS( 1 );
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_calls_the_custom_functor_without_parameters_thanks_to_boost_bind, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_calls_the_custom_functor_without_parameters_thanks_to_boost_bind, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::detail::function< int( int ) > f;
|
mock::detail::function< int( int ) > f;
|
||||||
f.expect().calls( boost::bind( &custom_result ) );
|
f.expect().calls( boost::bind( &custom_result ) );
|
||||||
|
|
@ -677,7 +649,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_calls_the_custom_functor_with
|
||||||
CHECK_CALLS( 1 );
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_throws_the_set_exception, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_throws_the_set_exception, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::detail::function< int() > f;
|
mock::detail::function< int() > f;
|
||||||
f.expect().throws( std::runtime_error( "some exception" ) );
|
f.expect().throws( std::runtime_error( "some exception" ) );
|
||||||
|
|
@ -696,7 +668,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_throws_the_set_exception, err
|
||||||
|
|
||||||
// multiple expectations
|
// multiple expectations
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( expecting_twice_a_single_expectation_makes_it_callable_twice, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( expecting_twice_a_single_expectation_makes_it_callable_twice, mock_error_fixture )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
mock::detail::function< void() > f;
|
mock::detail::function< void() > f;
|
||||||
|
|
@ -716,7 +688,7 @@ BOOST_FIXTURE_TEST_CASE( expecting_twice_a_single_expectation_makes_it_callable_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( best_expectation_is_selected_first, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( best_expectation_is_selected_first, mock_error_fixture )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
mock::detail::function< void( int ) > f;
|
mock::detail::function< void( int ) > f;
|
||||||
|
|
@ -749,7 +721,7 @@ namespace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( expectation_can_be_serialized_to_be_human_readable, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( expectation_can_be_serialized_to_be_human_readable, mock_error_fixture )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
mock::detail::function< void( int ) > f;
|
mock::detail::function< void( int ) > f;
|
||||||
|
|
@ -826,27 +798,27 @@ BOOST_FIXTURE_TEST_CASE( expectation_can_be_serialized_to_be_human_readable, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( expectation_with_remaining_untriggered_matches_upon_destruction_calls_untriggered_expectation, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( expectation_with_remaining_untriggered_matches_upon_destruction_calls_untriggered_expectation, mock_error_fixture )
|
||||||
{
|
{
|
||||||
std::auto_ptr< mock::detail::function< void() > > f( new mock::detail::function< void() > );
|
std::auto_ptr< mock::detail::function< void() > > f( new mock::detail::function< void() > );
|
||||||
f->expect().once();
|
f->expect().once();
|
||||||
CHECK_ERROR( f.reset(), "untriggered expectation", 0, "?\n. once()" );
|
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 )
|
BOOST_FIXTURE_TEST_CASE( verifying_expectation_with_remaining_matches_disables_the_automatic_verification_upon_destruction, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::detail::function< void() > f;
|
mock::detail::function< void() > f;
|
||||||
f.expect().once();
|
f.expect().once();
|
||||||
CHECK_ERROR( f.verify(), "verification failed", 0, "?\n. once()" );
|
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 )
|
BOOST_FIXTURE_TEST_CASE( triggering_unexpected_call_call_disables_the_automatic_verification_upon_destruction, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::detail::function< void() > f;
|
mock::detail::function< void() > f;
|
||||||
CHECK_ERROR( f(), "unexpected call", 0, "?()" );
|
CHECK_ERROR( f(), "unexpected call", 0, "?()" );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( adding_an_expectation_reactivates_the_verification_upon_destruction, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( adding_an_expectation_reactivates_the_verification_upon_destruction, mock_error_fixture )
|
||||||
{
|
{
|
||||||
std::auto_ptr< mock::detail::function< void() > > f( new mock::detail::function< void() > );
|
std::auto_ptr< mock::detail::function< void() > > f( new mock::detail::function< void() > );
|
||||||
CHECK_ERROR( (*f)(), "unexpected call", 0, "?()" );
|
CHECK_ERROR( (*f)(), "unexpected call", 0, "?()" );
|
||||||
|
|
@ -854,7 +826,7 @@ BOOST_FIXTURE_TEST_CASE( adding_an_expectation_reactivates_the_verification_upon
|
||||||
CHECK_ERROR( f.reset(), "untriggered expectation", 0, "?\n. once()" );
|
CHECK_ERROR( f.reset(), "untriggered expectation", 0, "?\n. once()" );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( throwing_an_exception_disables_the_automatic_verification_upon_destruction, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( throwing_an_exception_disables_the_automatic_verification_upon_destruction, mock_error_fixture )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -866,11 +838,11 @@ BOOST_FIXTURE_TEST_CASE( throwing_an_exception_disables_the_automatic_verificati
|
||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( adding_file_and_line_number_information, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( adding_file_and_line_number_information, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::detail::function< void() > f;
|
mock::detail::function< void() > f;
|
||||||
f.expect( "file name", 42 ).once();
|
f.expect( "file name", 42 ).once();
|
||||||
CHECK_ERROR( f.verify(), "verification failed", 0, "?\n. once()" );
|
CHECK_ERROR( f.verify(), "verification failed", 0, "?\n. once()" );
|
||||||
BOOST_CHECK_EQUAL( "file name", data().last_file );
|
BOOST_CHECK_EQUAL( "file name", mock_error_data.last_file );
|
||||||
BOOST_CHECK_EQUAL( 42, data().last_line );
|
BOOST_CHECK_EQUAL( 42, mock_error_data.last_line );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,81 +11,106 @@
|
||||||
|
|
||||||
#define MOCK_ERROR_POLICY mock_error
|
#define MOCK_ERROR_POLICY mock_error
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
#include <boost/test/utils/trivial_singleton.hpp>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
namespace
|
struct mock_error_data_t : boost::unit_test::singleton< mock_error_data_t >
|
||||||
{
|
{
|
||||||
struct mock_error_data
|
~mock_error_data_t()
|
||||||
{
|
{
|
||||||
void reset()
|
assert( verify() );
|
||||||
{
|
}
|
||||||
call_count = 0;
|
void reset()
|
||||||
error_count = 0;
|
|
||||||
last_message.clear();
|
|
||||||
last_context.clear();
|
|
||||||
}
|
|
||||||
bool verify()
|
|
||||||
{
|
|
||||||
return error_count == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void call()
|
|
||||||
{
|
|
||||||
last_context.clear();
|
|
||||||
last_message.clear();
|
|
||||||
++call_count;
|
|
||||||
}
|
|
||||||
void fail( const std::string& message,
|
|
||||||
const std::string& context,
|
|
||||||
const char* file, int line )
|
|
||||||
{
|
|
||||||
last_context = context;
|
|
||||||
last_message = message;
|
|
||||||
last_file = file;
|
|
||||||
last_line = line;
|
|
||||||
++error_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
int error_count;
|
|
||||||
int call_count;
|
|
||||||
std::string last_message;
|
|
||||||
std::string last_context;
|
|
||||||
std::string last_file;
|
|
||||||
int last_line;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline mock_error_data& data()
|
|
||||||
{
|
{
|
||||||
static mock_error_data p;
|
call_count = 0;
|
||||||
return p;
|
error_count = 0;
|
||||||
|
last_message.clear();
|
||||||
|
last_context.clear();
|
||||||
|
}
|
||||||
|
bool verify()
|
||||||
|
{
|
||||||
|
return error_count == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template< typename Result >
|
void call()
|
||||||
struct mock_error
|
|
||||||
{
|
{
|
||||||
static Result abort()
|
last_context.clear();
|
||||||
{
|
last_message.clear();
|
||||||
throw std::runtime_error( "aborted" );
|
++call_count;
|
||||||
}
|
}
|
||||||
|
void fail( const std::string& message,
|
||||||
|
const std::string& context,
|
||||||
|
const char* file, int line )
|
||||||
|
{
|
||||||
|
last_context = context;
|
||||||
|
last_message = message;
|
||||||
|
last_file = file;
|
||||||
|
last_line = line;
|
||||||
|
++error_count;
|
||||||
|
}
|
||||||
|
|
||||||
static void pass( const char* /*file*/, int /*line*/ )
|
int error_count;
|
||||||
{}
|
int call_count;
|
||||||
|
std::string last_message;
|
||||||
|
std::string last_context;
|
||||||
|
std::string last_file;
|
||||||
|
int last_line;
|
||||||
|
private:
|
||||||
|
BOOST_TEST_SINGLETON_CONS( mock_error_data_t );
|
||||||
|
};
|
||||||
|
BOOST_TEST_SINGLETON_INST( mock_error_data )
|
||||||
|
|
||||||
template< typename Context >
|
template< typename Result >
|
||||||
static void call( const Context& /*context*/,
|
struct mock_error
|
||||||
const char* /*file*/, int /*line*/ )
|
{
|
||||||
{
|
static Result abort()
|
||||||
data().call();
|
{
|
||||||
}
|
throw std::runtime_error( "aborted" );
|
||||||
|
}
|
||||||
|
|
||||||
template< typename Context >
|
static void pass( const char* /*file*/, int /*line*/ )
|
||||||
static void fail( const std::string& message, const Context& context,
|
{}
|
||||||
const char* file = "", int line = 0 )
|
|
||||||
{
|
template< typename Context >
|
||||||
data().fail( message,
|
static void call( const Context& /*context*/,
|
||||||
boost::lexical_cast< std::string >( context ), file, line );
|
const char* /*file*/, int /*line*/ )
|
||||||
}
|
{
|
||||||
};
|
mock_error_data.call();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template< typename Context >
|
||||||
|
static void fail( const std::string& message, const Context& context,
|
||||||
|
const char* file = "", int line = 0 )
|
||||||
|
{
|
||||||
|
mock_error_data.fail( message,
|
||||||
|
boost::lexical_cast< std::string >( context ), file, line );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct mock_error_fixture
|
||||||
|
{
|
||||||
|
mock_error_fixture()
|
||||||
|
{
|
||||||
|
mock_error_data.reset();
|
||||||
|
}
|
||||||
|
~mock_error_fixture()
|
||||||
|
{
|
||||||
|
BOOST_CHECK( mock_error_data.verify() );
|
||||||
|
BOOST_CHECK_EQUAL( 0, mock_error_data.call_count );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#define CHECK_CALLS( calls ) \
|
||||||
|
BOOST_CHECK_EQUAL( calls, mock_error_data.call_count ); \
|
||||||
|
mock_error_data.call_count = 0;
|
||||||
|
#define CHECK_ERROR( expr, error, calls, context ) \
|
||||||
|
BOOST_CHECK( mock_error_data.verify() ); \
|
||||||
|
try { expr; } catch( ... ) {} \
|
||||||
|
BOOST_CHECK_EQUAL( 1, mock_error_data.error_count ); \
|
||||||
|
BOOST_CHECK_EQUAL( error, mock_error_data.last_message ); \
|
||||||
|
BOOST_CHECK_EQUAL( context, mock_error_data.last_context ); \
|
||||||
|
CHECK_CALLS( calls ); \
|
||||||
|
mock_error_data.reset();
|
||||||
|
|
||||||
#endif // MOCK_TEST_MOCK_ERROR_HPP_INCLUDED
|
#endif // MOCK_TEST_MOCK_ERROR_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
#include <turtle/error.hpp>
|
#define MOCK_USE_BOOST_TEST
|
||||||
|
#include <turtle/exception.hpp>
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( a_mock_exception_is_not_an_std_exception_to_not_mess_with_user_exceptions )
|
BOOST_AUTO_TEST_CASE( a_mock_exception_is_not_an_std_exception_to_not_mess_with_user_exceptions )
|
||||||
|
|
@ -23,11 +23,12 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( custom_mock_object_without_macros_and_without_inheriting_from_object )
|
BOOST_FIXTURE_TEST_CASE( custom_mock_object_without_macros_and_without_inheriting_from_object, mock_error_fixture )
|
||||||
{
|
{
|
||||||
my_custom_mock m;
|
my_custom_mock m;
|
||||||
MOCK_EXPECT( m.my_tag ).once();
|
MOCK_EXPECT( m.my_tag ).once();
|
||||||
m.my_method();
|
m.my_method();
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -38,11 +39,12 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( custom_mock_object_without_macros )
|
BOOST_FIXTURE_TEST_CASE( custom_mock_object_without_macros, mock_error_fixture )
|
||||||
{
|
{
|
||||||
my_custom_mock_object m;
|
my_custom_mock_object m;
|
||||||
MOCK_EXPECT( m.my_tag ).once();
|
MOCK_EXPECT( m.my_tag ).once();
|
||||||
m.my_method();
|
m.my_method();
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -53,24 +55,27 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( basic_mock_object_usage )
|
BOOST_FIXTURE_TEST_CASE( basic_mock_object_usage, mock_error_fixture )
|
||||||
{
|
{
|
||||||
my_mock m;
|
my_mock m;
|
||||||
{
|
{
|
||||||
MOCK_EXPECT( m.my_tag ).once().returns( 0 );
|
MOCK_EXPECT( m.my_tag ).once().returns( 0 );
|
||||||
BOOST_CHECK_EQUAL( 0, m.my_method( 13 ) );
|
BOOST_CHECK_EQUAL( 0, m.my_method( 13 ) );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
mock::verify();
|
mock::verify();
|
||||||
mock::reset();
|
mock::reset();
|
||||||
{
|
{
|
||||||
MOCK_EXPECT( m.my_tag ).once().with( 42 ).returns( 7 );
|
MOCK_EXPECT( m.my_tag ).once().with( 42 ).returns( 7 );
|
||||||
BOOST_CHECK_EQUAL( 7, m.my_method( 42 ) );
|
BOOST_CHECK_EQUAL( 7, m.my_method( 42 ) );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
mock::verify();
|
mock::verify();
|
||||||
mock::reset();
|
mock::reset();
|
||||||
{
|
{
|
||||||
MOCK_EXPECT( m.my_tag ).once().returns( 51 );
|
MOCK_EXPECT( m.my_tag ).once().returns( 51 );
|
||||||
BOOST_CHECK_EQUAL( 51, m.my_method( 27 ) );
|
BOOST_CHECK_EQUAL( 51, m.my_method( 27 ) );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,12 +97,12 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mock_object_method_disambiguation )
|
BOOST_FIXTURE_TEST_CASE( mock_object_method_disambiguation, mock_error_fixture )
|
||||||
{
|
{
|
||||||
my_ambiguited_mock m;
|
my_ambiguited_mock m;
|
||||||
MOCK_EXPECT( m.my_tag1 );
|
MOCK_EXPECT( m.my_tag1 );
|
||||||
BOOST_CHECK_NO_THROW( m.my_method() );
|
m.my_method();
|
||||||
BOOST_CHECK_THROW( m.my_method( 12 ), std::exception );
|
CHECK_ERROR( m.my_method( 12 ), "unexpected call", 1, "?.my_ambiguited_mock::my_tag_2( 12 )" );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -118,13 +123,13 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mock_object_method_const_disambiguation )
|
BOOST_FIXTURE_TEST_CASE( mock_object_method_const_disambiguation, mock_error_fixture )
|
||||||
{
|
{
|
||||||
my_const_ambiguited_mock mock;
|
my_const_ambiguited_mock mock;
|
||||||
MOCK_EXPECT( mock.tag1 );
|
MOCK_EXPECT( mock.tag1 );
|
||||||
BOOST_CHECK_NO_THROW( mock.my_method() );
|
BOOST_CHECK_NO_THROW( mock.my_method() );
|
||||||
const my_const_ambiguited_mock const_mock;
|
const my_const_ambiguited_mock const_mock;
|
||||||
BOOST_CHECK_THROW( const_mock.my_method(), std::exception );
|
CHECK_ERROR( const_mock.my_method(), "unexpected call", 1, "?.my_const_ambiguited_mock::tag_2()" );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -135,13 +140,13 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mock_object_method_with_declared_but_not_defined_parameter_is_valid )
|
BOOST_FIXTURE_TEST_CASE( mock_object_method_with_declared_but_not_defined_parameter_is_valid, mock_error_fixture )
|
||||||
{
|
{
|
||||||
my_undefined_mock mock;
|
my_undefined_mock mock;
|
||||||
MOCK_EXPECT( mock.t );
|
MOCK_EXPECT( mock.t );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mock_functor_in_function_is_supported )
|
BOOST_FIXTURE_TEST_CASE( mock_functor_in_function_is_supported, mock_error_fixture )
|
||||||
{
|
{
|
||||||
boost::function< int( float, const std::string& ) > func;
|
boost::function< int( float, const std::string& ) > func;
|
||||||
{
|
{
|
||||||
|
|
@ -150,11 +155,12 @@ BOOST_AUTO_TEST_CASE( mock_functor_in_function_is_supported )
|
||||||
func = f;
|
func = f;
|
||||||
}
|
}
|
||||||
BOOST_CHECK_EQUAL( 42, func( 3, "op" ) );
|
BOOST_CHECK_EQUAL( 42, func( 3, "op" ) );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
struct functor_fixture
|
struct functor_fixture : mock_error_fixture
|
||||||
{
|
{
|
||||||
MOCK_FUNCTOR( f, int( float, const std::string& ) );
|
MOCK_FUNCTOR( f, int( float, const std::string& ) );
|
||||||
};
|
};
|
||||||
|
|
@ -164,6 +170,7 @@ BOOST_FIXTURE_TEST_CASE( mock_functor_in_fixture_is_supported, functor_fixture )
|
||||||
{
|
{
|
||||||
MOCK_EXPECT( f ).once().with( 3, "op" ).returns( 42 );
|
MOCK_EXPECT( f ).once().with( 3, "op" ).returns( 42 );
|
||||||
BOOST_CHECK_EQUAL( 42, f( 3.f, "op" ) );
|
BOOST_CHECK_EQUAL( 42, f( 3.f, "op" ) );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -177,12 +184,13 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mocking_a_template_class_method_is_supported )
|
BOOST_FIXTURE_TEST_CASE( mocking_a_template_class_method_is_supported, mock_error_fixture )
|
||||||
{
|
{
|
||||||
my_template_mock< int > m;
|
my_template_mock< int > m;
|
||||||
MOCK_EXPECT( m.my_tpl_tag ).with( 3, "" );
|
MOCK_EXPECT( m.my_tpl_tag ).with( 3, "" );
|
||||||
m.my_method( 3, "" );
|
m.my_method( 3, "" );
|
||||||
BOOST_CHECK( MOCK_VERIFY( m.my_tpl_tag ) );
|
BOOST_CHECK( MOCK_VERIFY( m.my_tpl_tag ) );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -203,12 +211,13 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mocking_a_template_base_class_method_is_supported )
|
BOOST_FIXTURE_TEST_CASE( mocking_a_template_base_class_method_is_supported, mock_error_fixture )
|
||||||
{
|
{
|
||||||
my_template_base_class_mock< int > m;
|
my_template_base_class_mock< int > m;
|
||||||
MOCK_EXPECT( m.my_method ).once().with( 3 );
|
MOCK_EXPECT( m.my_method ).once().with( 3 );
|
||||||
m.my_method( 3 );
|
m.my_method( 3 );
|
||||||
BOOST_CHECK( MOCK_VERIFY( m.my_method ) );
|
BOOST_CHECK( MOCK_VERIFY( m.my_method ) );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -255,7 +264,7 @@ namespace
|
||||||
MOCK_METHOD( get_observer, 0 )
|
MOCK_METHOD( get_observer, 0 )
|
||||||
};
|
};
|
||||||
|
|
||||||
struct fixture
|
struct fixture : mock_error_fixture
|
||||||
{
|
{
|
||||||
my_mock_manager manager;
|
my_mock_manager manager;
|
||||||
my_mock_observer observer;
|
my_mock_observer observer;
|
||||||
|
|
@ -272,6 +281,7 @@ BOOST_FIXTURE_TEST_CASE( basic_mock_object_collaboration_usage, fixture )
|
||||||
subject.increment();
|
subject.increment();
|
||||||
MOCK_EXPECT( observer.notify ).once().with( 3 );
|
MOCK_EXPECT( observer.notify ).once().with( 3 );
|
||||||
subject.increment();
|
subject.increment();
|
||||||
|
CHECK_CALLS( 4 );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -282,11 +292,12 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mocking_a_constructor )
|
BOOST_FIXTURE_TEST_CASE( mocking_a_constructor, mock_error_fixture )
|
||||||
{
|
{
|
||||||
MOCK_EXPECT( my_constructed_class::constructor ).with( 42, "some text" ).once();
|
MOCK_EXPECT( my_constructed_class::constructor ).with( 42, "some text" ).once();
|
||||||
my_constructed_class( 42, "some text" );
|
my_constructed_class( 42, "some text" );
|
||||||
BOOST_CHECK( MOCK_VERIFY( my_constructed_class::constructor ) );
|
BOOST_CHECK( MOCK_VERIFY( my_constructed_class::constructor ) );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -298,11 +309,12 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mocking_a_template_class_constructor )
|
BOOST_FIXTURE_TEST_CASE( mocking_a_template_class_constructor, mock_error_fixture )
|
||||||
{
|
{
|
||||||
MOCK_EXPECT( my_constructed_template_class< int >::constructor ).with( 42, "some text" ).once();
|
MOCK_EXPECT( my_constructed_template_class< int >::constructor ).with( 42, "some text" ).once();
|
||||||
my_constructed_template_class< int >( 42, "some text" );
|
my_constructed_template_class< int >( 42, "some text" );
|
||||||
BOOST_CHECK( MOCK_VERIFY( my_constructed_template_class< int >::constructor ) );
|
BOOST_CHECK( MOCK_VERIFY( my_constructed_template_class< int >::constructor ) );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -313,34 +325,41 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mocking_a_destructor )
|
BOOST_FIXTURE_TEST_CASE( mocking_a_destructor, mock_error_fixture )
|
||||||
{
|
{
|
||||||
my_destroyed_class c;
|
|
||||||
MOCK_EXPECT( c.destructor ).once();
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( failed_expectation_in_mocked_destructor_does_not_throw )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
my_destroyed_class c;
|
my_destroyed_class c;
|
||||||
throw std::runtime_error( "should not crash" );
|
MOCK_EXPECT( c.destructor ).once();
|
||||||
}
|
|
||||||
catch( std::runtime_error& )
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( failed_sequence_in_mocked_destructor_does_not_throw )
|
BOOST_FIXTURE_TEST_CASE( failed_expectation_in_mocked_destructor_does_not_throw, mock_error_fixture )
|
||||||
|
{
|
||||||
|
CHECK_ERROR(
|
||||||
|
try
|
||||||
|
{
|
||||||
|
my_destroyed_class c;
|
||||||
|
throw std::runtime_error( "should not crash" );
|
||||||
|
}
|
||||||
|
catch( std::runtime_error& )
|
||||||
|
{
|
||||||
|
},
|
||||||
|
"unexpected call", 0, "?.my_destroyed_class::destructor()" );
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_FIXTURE_TEST_CASE( failed_sequence_in_mocked_destructor_does_not_throw, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::sequence s;
|
mock::sequence s;
|
||||||
my_custom_mock m;
|
my_custom_mock m;
|
||||||
{
|
CHECK_ERROR(
|
||||||
my_destroyed_class c;
|
{
|
||||||
MOCK_EXPECT( c.destructor ).once().in( s );
|
my_destroyed_class c;
|
||||||
MOCK_EXPECT( m.my_tag ).once().in( s );
|
MOCK_EXPECT( c.destructor ).once().in( s );
|
||||||
m.my_method();
|
MOCK_EXPECT( m.my_tag ).once().in( s );
|
||||||
}
|
m.my_method();
|
||||||
|
},
|
||||||
|
"sequence failed", 1, "c.my_destroyed_class::destructor()\n. once()" );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -351,12 +370,13 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( boost_optional_on_base_class_reference_as_return_type_is_supported )
|
BOOST_FIXTURE_TEST_CASE( boost_optional_on_base_class_reference_as_return_type_is_supported, mock_error_fixture )
|
||||||
{
|
{
|
||||||
boost_optional b;
|
boost_optional b;
|
||||||
my_mock_observer o;
|
my_mock_observer o;
|
||||||
MOCK_EXPECT( b.tag ).once().returns( boost::ref( o ) );
|
MOCK_EXPECT( b.tag ).once().returns( boost::ref( o ) );
|
||||||
b.method();
|
b.method();
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -386,12 +406,13 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( constraints_and_arguments_are_serialized_lazily )
|
BOOST_FIXTURE_TEST_CASE( constraints_and_arguments_are_serialized_lazily, mock_error_fixture )
|
||||||
{
|
{
|
||||||
MOCK_FUNCTOR( f, void( const custom_argument& ) );
|
MOCK_FUNCTOR( f, void( const custom_argument& ) );
|
||||||
MOCK_EXPECT( f ).with( custom_constraint() );
|
MOCK_EXPECT( f ).with( custom_constraint() );
|
||||||
f( custom_argument() );
|
f( custom_argument() );
|
||||||
BOOST_CHECK( ! serialized );
|
BOOST_CHECK( ! serialized );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -406,20 +427,22 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( custom_constraint_function_operator_does_not_need_to_be_const )
|
BOOST_FIXTURE_TEST_CASE( custom_constraint_function_operator_does_not_need_to_be_const, mock_error_fixture )
|
||||||
{
|
{
|
||||||
MOCK_FUNCTOR( f, void( float ) );
|
MOCK_FUNCTOR( f, void( float ) );
|
||||||
MOCK_EXPECT( f ).with( mock::constraint< custom_constraint_with_non_const_operator >( custom_constraint_with_non_const_operator() ) );
|
MOCK_EXPECT( f ).with( mock::constraint< custom_constraint_with_non_const_operator >( custom_constraint_with_non_const_operator() ) );
|
||||||
f( 42 );
|
f( 42 );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( boost_reference_wrapper_is_supported_in_value_constraint )
|
BOOST_FIXTURE_TEST_CASE( boost_reference_wrapper_is_supported_in_value_constraint, mock_error_fixture )
|
||||||
{
|
{
|
||||||
MOCK_FUNCTOR( f, void( const std::string& ) );
|
MOCK_FUNCTOR( f, void( const std::string& ) );
|
||||||
std::string s;
|
std::string s;
|
||||||
MOCK_EXPECT( f ).once().with( boost::cref( s ) );
|
MOCK_EXPECT( f ).once().with( boost::cref( s ) );
|
||||||
s = "string";
|
s = "string";
|
||||||
f( "string" );
|
f( "string" );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -434,7 +457,7 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( member_pointer_on_mock_method_is_valid )
|
BOOST_FIXTURE_TEST_CASE( member_pointer_on_mock_method_is_valid, mock_error_fixture )
|
||||||
{
|
{
|
||||||
nothing( &member_pointer_mock_class::my_method );
|
nothing( &member_pointer_mock_class::my_method );
|
||||||
}
|
}
|
||||||
|
|
@ -444,11 +467,14 @@ namespace
|
||||||
MOCK_FUNCTION( free_function, 1, void( int ), free_function )
|
MOCK_FUNCTION( free_function, 1, void( int ), free_function )
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( a_free_function_can_be_mocked )
|
BOOST_FIXTURE_TEST_CASE( a_free_function_can_be_mocked, mock_error_fixture )
|
||||||
{
|
{
|
||||||
MOCK_EXPECT( free_function ).once();
|
MOCK_EXPECT( free_function ).once();
|
||||||
BOOST_CHECK( ! MOCK_VERIFY( free_function ) );
|
CHECK_ERROR(
|
||||||
|
BOOST_CHECK( ! MOCK_VERIFY( free_function ) ),
|
||||||
|
"verification failed", 0, "free_function\n. once().with( any )" );
|
||||||
free_function( 42 );
|
free_function( 42 );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
BOOST_CHECK( MOCK_VERIFY( free_function ) );
|
BOOST_CHECK( MOCK_VERIFY( free_function ) );
|
||||||
MOCK_RESET( free_function );
|
MOCK_RESET( free_function );
|
||||||
}
|
}
|
||||||
|
|
@ -461,21 +487,26 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( a_static_method_can_be_mocked )
|
BOOST_FIXTURE_TEST_CASE( a_static_method_can_be_mocked, mock_error_fixture )
|
||||||
{
|
{
|
||||||
MOCK_EXPECT( some_class::some_static_method ).once();
|
MOCK_EXPECT( some_class::some_static_method ).once();
|
||||||
BOOST_CHECK( ! MOCK_VERIFY( some_class::some_static_method ) );
|
CHECK_ERROR(
|
||||||
|
BOOST_CHECK( ! MOCK_VERIFY( some_class::some_static_method ) ),
|
||||||
|
"verification failed", 0, "some_class::some_static_method\n. once().with( any )" );
|
||||||
some_class::some_static_method( 42 );
|
some_class::some_static_method( 42 );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
BOOST_CHECK( MOCK_VERIFY( some_class::some_static_method ) );
|
BOOST_CHECK( MOCK_VERIFY( some_class::some_static_method ) );
|
||||||
MOCK_RESET( some_class::some_static_method );
|
MOCK_RESET( some_class::some_static_method );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( a_static_method_is_not_reset_when_resetting_an_instance_of_the_class )
|
BOOST_FIXTURE_TEST_CASE( a_static_method_is_not_reset_when_resetting_an_instance_of_the_class, mock_error_fixture )
|
||||||
{
|
{
|
||||||
MOCK_EXPECT( some_class::some_static_method ).once();
|
MOCK_EXPECT( some_class::some_static_method ).once();
|
||||||
some_class c;
|
some_class c;
|
||||||
mock::reset( c );
|
mock::reset( c );
|
||||||
BOOST_CHECK( ! MOCK_VERIFY( some_class::some_static_method ) );
|
CHECK_ERROR(
|
||||||
|
BOOST_CHECK( ! MOCK_VERIFY( some_class::some_static_method ) ),
|
||||||
|
"verification failed", 0, "some_class::some_static_method\n. once().with( any )" );
|
||||||
MOCK_RESET( some_class::some_static_method );
|
MOCK_RESET( some_class::some_static_method );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -488,14 +519,17 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( a_static_method_in_a_template_class_can_be_mocked )
|
BOOST_FIXTURE_TEST_CASE( a_static_method_in_a_template_class_can_be_mocked, mock_error_fixture )
|
||||||
{
|
{
|
||||||
MOCK_EXPECT( some_template_class< int >::some_static_method ).once();
|
MOCK_EXPECT( some_template_class< int >::some_static_method ).once();
|
||||||
BOOST_CHECK( ! MOCK_VERIFY( some_template_class< int >::some_static_method ) );
|
CHECK_ERROR(
|
||||||
|
BOOST_CHECK( ! MOCK_VERIFY( some_template_class< int >::some_static_method ) ),
|
||||||
|
"verification failed", 0, "some_template_class< int >::some_static_method\n. once().with( any )" );
|
||||||
some_template_class< int >::some_static_method( 42 );
|
some_template_class< int >::some_static_method( 42 );
|
||||||
BOOST_CHECK( mock::verify() );
|
BOOST_CHECK( mock::verify() );
|
||||||
BOOST_CHECK( MOCK_VERIFY( some_template_class< int >::some_static_method ) );
|
BOOST_CHECK( MOCK_VERIFY( some_template_class< int >::some_static_method ) );
|
||||||
MOCK_RESET( some_template_class< int >::some_static_method );
|
MOCK_RESET( some_template_class< int >::some_static_method );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -506,7 +540,7 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( resetting_referenced_mock_class_does_not_crash )
|
BOOST_FIXTURE_TEST_CASE( resetting_referenced_mock_class_does_not_crash, mock_error_fixture )
|
||||||
{
|
{
|
||||||
MOCK_FUNCTOR( f, mock_class() );
|
MOCK_FUNCTOR( f, mock_class() );
|
||||||
{
|
{
|
||||||
|
|
@ -525,7 +559,7 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( resetting_self_referenced_mock_class_does_not_crash )
|
BOOST_FIXTURE_TEST_CASE( resetting_self_referenced_mock_class_does_not_crash, mock_error_fixture )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
mock_class2 c;
|
mock_class2 c;
|
||||||
|
|
|
||||||
|
|
@ -22,16 +22,18 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( call_mock_method_with_max_number_of_args )
|
BOOST_FIXTURE_TEST_CASE( call_mock_method_with_max_number_of_args, mock_error_fixture )
|
||||||
{
|
{
|
||||||
my_custom_mock m;
|
my_custom_mock m;
|
||||||
MOCK_EXPECT( m.tag ).once().with( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0) );
|
MOCK_EXPECT( m.tag ).once().with( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0) );
|
||||||
m.method( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0) );
|
m.method( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0) );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( call_mock_method_with_max_number_of_args_and_a_return_value )
|
BOOST_FIXTURE_TEST_CASE( call_mock_method_with_max_number_of_args_and_a_return_value, mock_error_fixture )
|
||||||
{
|
{
|
||||||
my_custom_mock m;
|
my_custom_mock m;
|
||||||
MOCK_EXPECT( m.tag_2 ).once().with( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0) ).returns( 42 );
|
MOCK_EXPECT( m.tag_2 ).once().with( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0) ).returns( 42 );
|
||||||
BOOST_CHECK_EQUAL( 42, m.method2( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0) ) );
|
BOOST_CHECK_EQUAL( 42, m.method2( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0) ) );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
|
#include "mock_error.hpp"
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
#include <boost/mpl/assert.hpp>
|
#include <boost/mpl/assert.hpp>
|
||||||
|
|
@ -25,11 +26,12 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mock_object_for_static_polymorphism )
|
BOOST_FIXTURE_TEST_CASE( mock_object_for_static_polymorphism, mock_error_fixture )
|
||||||
{
|
{
|
||||||
const mock_class m;
|
const mock_class m;
|
||||||
MOCK_EXPECT( m.my_tag ).once().with( "some parameter" );
|
MOCK_EXPECT( m.my_tag ).once().with( "some parameter" );
|
||||||
my_function( m );
|
my_function( m );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -40,11 +42,12 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mock_addition_operator )
|
BOOST_FIXTURE_TEST_CASE( mock_addition_operator, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock_class_with_operator m;
|
mock_class_with_operator m;
|
||||||
MOCK_EXPECT( m.addition ).once().returns( boost::ref( m ) );
|
MOCK_EXPECT( m.addition ).once().returns( boost::ref( m ) );
|
||||||
m += 1;
|
m += 1;
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -55,11 +58,12 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mock_conversion_operator )
|
BOOST_FIXTURE_TEST_CASE( mock_conversion_operator, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock_class_with_conversion_operator m;
|
mock_class_with_conversion_operator m;
|
||||||
MOCK_EXPECT( m.conversion ).once().returns( 42 );
|
MOCK_EXPECT( m.conversion ).once().returns( 42 );
|
||||||
BOOST_CHECK_EQUAL( 42, static_cast< int >( m ) );
|
BOOST_CHECK_EQUAL( 42, static_cast< int >( m ) );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -71,11 +75,12 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mock_template_conversion_operator )
|
BOOST_FIXTURE_TEST_CASE( mock_template_conversion_operator, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock_template_class_with_conversion_operator< int > m;
|
mock_template_class_with_conversion_operator< int > m;
|
||||||
MOCK_EXPECT( m.conversion ).once().returns( 42 );
|
MOCK_EXPECT( m.conversion ).once().returns( 42 );
|
||||||
BOOST_CHECK_EQUAL( 42, static_cast< int >( m ) );
|
BOOST_CHECK_EQUAL( 42, static_cast< int >( m ) );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -86,12 +91,13 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mock_const_conversion_operator )
|
BOOST_FIXTURE_TEST_CASE( mock_const_conversion_operator, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock_class_with_const_conversion_operator m;
|
mock_class_with_const_conversion_operator m;
|
||||||
MOCK_EXPECT( m.conversion ).once().returns( 42 );
|
MOCK_EXPECT( m.conversion ).once().returns( 42 );
|
||||||
int i = m;
|
int i = m;
|
||||||
BOOST_CHECK_EQUAL( 42, i );
|
BOOST_CHECK_EQUAL( 42, i );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -102,12 +108,13 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mock_non_const_conversion_operator )
|
BOOST_FIXTURE_TEST_CASE( mock_non_const_conversion_operator, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock_class_with_non_const_conversion_operator m;
|
mock_class_with_non_const_conversion_operator m;
|
||||||
MOCK_EXPECT( m.conversion ).once().returns( 42 );
|
MOCK_EXPECT( m.conversion ).once().returns( 42 );
|
||||||
int i = m;
|
int i = m;
|
||||||
BOOST_CHECK_EQUAL( 42, i );
|
BOOST_CHECK_EQUAL( 42, i );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -119,11 +126,12 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mock_template_const_conversion_operator )
|
BOOST_FIXTURE_TEST_CASE( mock_template_const_conversion_operator, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock_template_class_with_const_conversion_operator< int > m;
|
mock_template_class_with_const_conversion_operator< int > m;
|
||||||
MOCK_EXPECT( m.conversion ).once().returns( 42 );
|
MOCK_EXPECT( m.conversion ).once().returns( 42 );
|
||||||
BOOST_CHECK_EQUAL( 42, static_cast< int >( m ) );
|
BOOST_CHECK_EQUAL( 42, static_cast< int >( m ) );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -135,11 +143,12 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mock_template_non_const_conversion_operator )
|
BOOST_FIXTURE_TEST_CASE( mock_template_non_const_conversion_operator, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock_template_class_with_non_const_conversion_operator< int > m;
|
mock_template_class_with_non_const_conversion_operator< int > m;
|
||||||
MOCK_EXPECT( m.conversion ).once().returns( 42 );
|
MOCK_EXPECT( m.conversion ).once().returns( 42 );
|
||||||
BOOST_CHECK_EQUAL( 42, static_cast< int >( m ) );
|
BOOST_CHECK_EQUAL( 42, static_cast< int >( m ) );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -151,29 +160,30 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( MOCK_CONST_METHOD_EXT_macro_defines_a_bindable_method )
|
BOOST_FIXTURE_TEST_CASE( MOCK_CONST_METHOD_EXT_macro_defines_a_bindable_method, mock_error_fixture )
|
||||||
{
|
{
|
||||||
my_mock m;
|
my_mock m;
|
||||||
boost::bind( &my_mock::my_method, &m, 42 );
|
boost::bind( &my_mock::my_method, &m, 42 );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( MOCK_VERIFY_macro )
|
BOOST_FIXTURE_TEST_CASE( MOCK_VERIFY_macro, mock_error_fixture )
|
||||||
{
|
{
|
||||||
my_mock m;
|
my_mock m;
|
||||||
MOCK_VERIFY( m.my_method );
|
MOCK_VERIFY( m.my_method );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( MOCK_RESET_macro )
|
BOOST_FIXTURE_TEST_CASE( MOCK_RESET_macro, mock_error_fixture )
|
||||||
{
|
{
|
||||||
my_mock m;
|
my_mock m;
|
||||||
MOCK_RESET( m.my_method );
|
MOCK_RESET( m.my_method );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( MOCK_EXPECT_macro )
|
BOOST_FIXTURE_TEST_CASE( MOCK_EXPECT_macro, mock_error_fixture )
|
||||||
{
|
{
|
||||||
my_mock m;
|
my_mock m;
|
||||||
MOCK_EXPECT( m.my_method ).once().with( 42 );
|
MOCK_EXPECT( m.my_method ).once().with( 42 );
|
||||||
m.my_method( 42 );
|
m.my_method( 42 );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -187,7 +197,7 @@ namespace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mock_object_is_named )
|
BOOST_FIXTURE_TEST_CASE( mock_object_is_named, mock_error_fixture )
|
||||||
{
|
{
|
||||||
my_mock m;
|
my_mock m;
|
||||||
BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m.my_method ) ) );
|
BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m.my_method ) ) );
|
||||||
|
|
@ -198,7 +208,7 @@ BOOST_AUTO_TEST_CASE( mock_object_is_named )
|
||||||
BOOST_CHECK_EQUAL( "m.my_mock::my_method", to_string( MOCK_HELPER( m.my_method ) ) );
|
BOOST_CHECK_EQUAL( "m.my_mock::my_method", to_string( MOCK_HELPER( m.my_method ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mock_object_auto_pointer_is_named )
|
BOOST_FIXTURE_TEST_CASE( mock_object_auto_pointer_is_named, mock_error_fixture )
|
||||||
{
|
{
|
||||||
std::auto_ptr< my_mock > m( new my_mock );
|
std::auto_ptr< my_mock > m( new my_mock );
|
||||||
BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
|
BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
|
||||||
|
|
@ -207,7 +217,7 @@ BOOST_AUTO_TEST_CASE( mock_object_auto_pointer_is_named )
|
||||||
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
|
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mock_object_const_auto_pointer_is_named )
|
BOOST_FIXTURE_TEST_CASE( mock_object_const_auto_pointer_is_named, mock_error_fixture )
|
||||||
{
|
{
|
||||||
const std::auto_ptr< my_mock > m( new my_mock );
|
const std::auto_ptr< my_mock > m( new my_mock );
|
||||||
BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
|
BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
|
||||||
|
|
@ -216,7 +226,7 @@ BOOST_AUTO_TEST_CASE( mock_object_const_auto_pointer_is_named )
|
||||||
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
|
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mock_object_shared_pointer_is_named )
|
BOOST_FIXTURE_TEST_CASE( mock_object_shared_pointer_is_named, mock_error_fixture )
|
||||||
{
|
{
|
||||||
boost::shared_ptr< my_mock > m( new my_mock );
|
boost::shared_ptr< my_mock > m( new my_mock );
|
||||||
BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
|
BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
|
||||||
|
|
@ -225,7 +235,7 @@ BOOST_AUTO_TEST_CASE( mock_object_shared_pointer_is_named )
|
||||||
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
|
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mock_object_const_shared_pointer_is_named )
|
BOOST_FIXTURE_TEST_CASE( mock_object_const_shared_pointer_is_named, mock_error_fixture )
|
||||||
{
|
{
|
||||||
const boost::shared_ptr< my_mock > m( new my_mock );
|
const boost::shared_ptr< my_mock > m( new my_mock );
|
||||||
BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
|
BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
|
||||||
|
|
@ -243,7 +253,7 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( custom_mock_object_without_macros_and_without_inheriting_from_object_is_named )
|
BOOST_FIXTURE_TEST_CASE( custom_mock_object_without_macros_and_without_inheriting_from_object_is_named, mock_error_fixture )
|
||||||
{
|
{
|
||||||
my_custom_mock m;
|
my_custom_mock m;
|
||||||
BOOST_CHECK_EQUAL( "?.my_custom_mock::my_tag", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag ) ) );
|
BOOST_CHECK_EQUAL( "?.my_custom_mock::my_tag", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag ) ) );
|
||||||
|
|
@ -263,7 +273,7 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( custom_mock_object_without_macros_is_named )
|
BOOST_FIXTURE_TEST_CASE( custom_mock_object_without_macros_is_named, mock_error_fixture )
|
||||||
{
|
{
|
||||||
my_custom_mock_object m;
|
my_custom_mock_object m;
|
||||||
BOOST_CHECK_EQUAL( "?.my_custom_mock_object::my_tag", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag ) ) );
|
BOOST_CHECK_EQUAL( "?.my_custom_mock_object::my_tag", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag ) ) );
|
||||||
|
|
@ -274,7 +284,7 @@ BOOST_AUTO_TEST_CASE( custom_mock_object_without_macros_is_named )
|
||||||
BOOST_CHECK_EQUAL( "m.my_custom_mock_object::my_tag", to_string( MOCK_HELPER( m.my_tag ) ) );
|
BOOST_CHECK_EQUAL( "m.my_custom_mock_object::my_tag", to_string( MOCK_HELPER( m.my_tag ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mock_functor )
|
BOOST_FIXTURE_TEST_CASE( mock_functor, mock_error_fixture )
|
||||||
{
|
{
|
||||||
MOCK_FUNCTOR( f1, void() );
|
MOCK_FUNCTOR( f1, void() );
|
||||||
MOCK_FUNCTOR( f2, int( const std::string& ) );
|
MOCK_FUNCTOR( f2, int( const std::string& ) );
|
||||||
|
|
@ -289,21 +299,21 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mock_functor_reset )
|
BOOST_FIXTURE_TEST_CASE( mock_functor_reset, mock_error_fixture )
|
||||||
{
|
{
|
||||||
MOCK_FUNCTOR( f, void() );
|
MOCK_FUNCTOR( f, void() );
|
||||||
MOCK_RESET( f );
|
MOCK_RESET( f );
|
||||||
mock::reset( f );
|
mock::reset( f );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mock_functor_verify )
|
BOOST_FIXTURE_TEST_CASE( mock_functor_verify, mock_error_fixture )
|
||||||
{
|
{
|
||||||
MOCK_FUNCTOR( f, void() );
|
MOCK_FUNCTOR( f, void() );
|
||||||
MOCK_VERIFY( f );
|
MOCK_VERIFY( f );
|
||||||
mock::verify( f );
|
mock::verify( f );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mock_functor_is_named )
|
BOOST_FIXTURE_TEST_CASE( mock_functor_is_named, mock_error_fixture )
|
||||||
{
|
{
|
||||||
MOCK_FUNCTOR( f, void() );
|
MOCK_FUNCTOR( f, void() );
|
||||||
BOOST_CHECK_EQUAL( "f", to_string( MOCK_HELPER( f ) ) );
|
BOOST_CHECK_EQUAL( "f", to_string( MOCK_HELPER( f ) ) );
|
||||||
|
|
@ -314,7 +324,7 @@ namespace
|
||||||
MOCK_FUNCTION( mock_function, 1, float( int ), mock_function )
|
MOCK_FUNCTION( mock_function, 1, float( int ), mock_function )
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mock_function_is_named )
|
BOOST_FIXTURE_TEST_CASE( mock_function_is_named, mock_error_fixture )
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL( "mock_function", to_string( MOCK_HELPER( mock_function ) ) );
|
BOOST_CHECK_EQUAL( "mock_function", to_string( MOCK_HELPER( mock_function ) ) );
|
||||||
}
|
}
|
||||||
|
|
@ -327,7 +337,7 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( mock_static_function_is_named )
|
BOOST_FIXTURE_TEST_CASE( mock_static_function_is_named, mock_error_fixture )
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL( "static_function_class::f", to_string( MOCK_HELPER( static_function_class::f ) ) );
|
BOOST_CHECK_EQUAL( "static_function_class::f", to_string( MOCK_HELPER( static_function_class::f ) ) );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ namespace
|
||||||
object static_o;
|
object static_o;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( verifying_an_empty_object_succeeds )
|
BOOST_FIXTURE_TEST_CASE( verifying_an_empty_object_succeeds, mock_error_fixture )
|
||||||
{
|
{
|
||||||
object o;
|
object o;
|
||||||
BOOST_CHECK( mock::verify( o ) );
|
BOOST_CHECK( mock::verify( o ) );
|
||||||
|
|
@ -28,7 +28,7 @@ BOOST_AUTO_TEST_CASE( verifying_an_empty_object_succeeds )
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
struct fixture
|
struct fixture : mock_error_fixture
|
||||||
{
|
{
|
||||||
fixture()
|
fixture()
|
||||||
{
|
{
|
||||||
|
|
@ -42,7 +42,9 @@ namespace
|
||||||
BOOST_FIXTURE_TEST_CASE( verifying_an_object_containing_a_failing_expectation_fails, fixture )
|
BOOST_FIXTURE_TEST_CASE( verifying_an_object_containing_a_failing_expectation_fails, fixture )
|
||||||
{
|
{
|
||||||
e.expect().once();
|
e.expect().once();
|
||||||
BOOST_CHECK( ! mock::verify( o ) );
|
CHECK_ERROR(
|
||||||
|
BOOST_CHECK( ! mock::verify( o ) ),
|
||||||
|
"verification failed", 0, "instanceobject::name\n. once()" );
|
||||||
mock::reset( o );
|
mock::reset( o );
|
||||||
BOOST_CHECK( mock::verify( o ) );
|
BOOST_CHECK( mock::verify( o ) );
|
||||||
}
|
}
|
||||||
|
|
@ -50,7 +52,9 @@ BOOST_FIXTURE_TEST_CASE( verifying_an_object_containing_a_failing_expectation_fa
|
||||||
BOOST_FIXTURE_TEST_CASE( verifying_all_objects_with_one_of_them_containing_a_failing_expectation_fails, fixture )
|
BOOST_FIXTURE_TEST_CASE( verifying_all_objects_with_one_of_them_containing_a_failing_expectation_fails, fixture )
|
||||||
{
|
{
|
||||||
e.expect().once();
|
e.expect().once();
|
||||||
BOOST_CHECK( ! mock::verify() );
|
CHECK_ERROR(
|
||||||
|
BOOST_CHECK( ! mock::verify() ),
|
||||||
|
"verification failed", 0, "instanceobject::name\n. once()" );
|
||||||
mock::reset();
|
mock::reset();
|
||||||
BOOST_CHECK( mock::verify() );
|
BOOST_CHECK( mock::verify() );
|
||||||
}
|
}
|
||||||
|
|
@ -62,7 +66,7 @@ BOOST_FIXTURE_TEST_CASE( resetting_an_object_containing_a_failing_expectation_an
|
||||||
BOOST_CHECK( mock::verify( o ) );
|
BOOST_CHECK( mock::verify( o ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( an_object_is_assignable_by_sharing_its_state )
|
BOOST_FIXTURE_TEST_CASE( an_object_is_assignable_by_sharing_its_state, mock_error_fixture )
|
||||||
{
|
{
|
||||||
object o1;
|
object o1;
|
||||||
mock::detail::function< void() > e;
|
mock::detail::function< void() > e;
|
||||||
|
|
@ -71,21 +75,33 @@ BOOST_AUTO_TEST_CASE( an_object_is_assignable_by_sharing_its_state )
|
||||||
mock::detail::configure( o2, e, "instance", mock::detail::type_name( BOOST_SP_TYPEID( o2 ) ), "name" );
|
mock::detail::configure( o2, e, "instance", mock::detail::type_name( BOOST_SP_TYPEID( o2 ) ), "name" );
|
||||||
e.expect().once();
|
e.expect().once();
|
||||||
o1 = o2;
|
o1 = o2;
|
||||||
BOOST_CHECK( ! mock::verify( o2 ) );
|
CHECK_ERROR(
|
||||||
BOOST_CHECK( ! mock::verify( o1 ) );
|
BOOST_CHECK( ! mock::verify( o1 ) ),
|
||||||
|
"verification failed", 0, "instanceobject::name\n. once()" );
|
||||||
|
CHECK_ERROR(
|
||||||
|
BOOST_CHECK( ! mock::verify( o2 ) ),
|
||||||
|
"verification failed", 0, "instanceobject::name\n. once()" );
|
||||||
}
|
}
|
||||||
BOOST_CHECK( ! mock::verify( o1 ) );
|
CHECK_ERROR(
|
||||||
|
BOOST_CHECK( ! mock::verify( o1 ) ),
|
||||||
|
"verification failed", 0, "instanceobject::name\n. once()" );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( an_object_is_copiable_by_sharing_its_state )
|
BOOST_FIXTURE_TEST_CASE( an_object_is_copiable_by_sharing_its_state, mock_error_fixture )
|
||||||
{
|
{
|
||||||
std::auto_ptr< object > o2( new object );
|
std::auto_ptr< object > o2( new object );
|
||||||
const object o1( *o2 );
|
const object o1( *o2 );
|
||||||
mock::detail::function< void() > e;
|
mock::detail::function< void() > e;
|
||||||
mock::detail::configure( *o2, e, "instance", mock::detail::type_name( BOOST_SP_TYPEID( *o2 ) ), "name" );
|
mock::detail::configure( *o2, e, "instance", mock::detail::type_name( BOOST_SP_TYPEID( *o2 ) ), "name" );
|
||||||
e.expect().once();
|
e.expect().once();
|
||||||
BOOST_CHECK( ! mock::verify( *o2 ) );
|
CHECK_ERROR(
|
||||||
BOOST_CHECK( ! mock::verify( o1 ) );
|
BOOST_CHECK( ! mock::verify( *o2 ) ),
|
||||||
|
"verification failed", 0, "instanceobject::name\n. once()" );
|
||||||
|
CHECK_ERROR(
|
||||||
|
BOOST_CHECK( ! mock::verify( o1 ) ),
|
||||||
|
"verification failed", 0, "instanceobject::name\n. once()" );
|
||||||
o2.reset();
|
o2.reset();
|
||||||
BOOST_CHECK( ! mock::verify( o1 ) );
|
CHECK_ERROR(
|
||||||
|
BOOST_CHECK( ! mock::verify( o1 ) ),
|
||||||
|
"verification failed", 0, "instanceobject::name\n. once()" );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,17 +11,17 @@
|
||||||
#include <turtle/detail/function.hpp>
|
#include <turtle/detail/function.hpp>
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( registering_to_a_sequence_and_calling_out_of_order_throws )
|
BOOST_FIXTURE_TEST_CASE( registering_to_a_sequence_and_calling_out_of_order_throws, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::sequence s;
|
mock::sequence s;
|
||||||
mock::detail::function< void( int ) > e;
|
mock::detail::function< void( int ) > e;
|
||||||
e.expect().once().with( 1 ).in( s );
|
e.expect().once().with( 1 ).in( s );
|
||||||
e.expect().once().with( 2 ).in( s );
|
e.expect().once().with( 2 ).in( s );
|
||||||
BOOST_CHECK_NO_THROW( e( 2 ) );
|
BOOST_CHECK_NO_THROW( e( 2 ) );
|
||||||
BOOST_CHECK_THROW( e( 1 ), std::exception );
|
CHECK_ERROR( e( 1 ), "sequence failed", 1, "?( 1 )\n. once().with( 1 )\nv once().with( 2 )" );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( registering_to_a_sequence_and_calling_out_of_order_multiple_invocations_throws )
|
BOOST_FIXTURE_TEST_CASE( registering_to_a_sequence_and_calling_out_of_order_multiple_invocations_throws, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::sequence s;
|
mock::sequence s;
|
||||||
mock::detail::function< void( int ) > e;
|
mock::detail::function< void( int ) > e;
|
||||||
|
|
@ -29,10 +29,10 @@ BOOST_AUTO_TEST_CASE( registering_to_a_sequence_and_calling_out_of_order_multipl
|
||||||
e.expect().once().with( 2 ).in( s );
|
e.expect().once().with( 2 ).in( s );
|
||||||
BOOST_CHECK_NO_THROW( e( 1 ) );
|
BOOST_CHECK_NO_THROW( e( 1 ) );
|
||||||
BOOST_CHECK_NO_THROW( e( 2 ) );
|
BOOST_CHECK_NO_THROW( e( 2 ) );
|
||||||
BOOST_CHECK_THROW( e( 1 ), std::exception );
|
CHECK_ERROR( e( 1 ), "sequence failed", 2, "?( 1 )\n. unlimited().with( 1 )\nv once().with( 2 )" );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( registering_to_a_sequence_and_calling_in_order_is_valid )
|
BOOST_FIXTURE_TEST_CASE( registering_to_a_sequence_and_calling_in_order_is_valid, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::sequence s;
|
mock::sequence s;
|
||||||
mock::detail::function< void( int ) > e;
|
mock::detail::function< void( int ) > e;
|
||||||
|
|
@ -41,9 +41,10 @@ BOOST_AUTO_TEST_CASE( registering_to_a_sequence_and_calling_in_order_is_valid )
|
||||||
BOOST_CHECK_NO_THROW( e( 1 ) );
|
BOOST_CHECK_NO_THROW( e( 1 ) );
|
||||||
BOOST_CHECK_NO_THROW( e( 2 ) );
|
BOOST_CHECK_NO_THROW( e( 2 ) );
|
||||||
BOOST_CHECK( e.verify() );
|
BOOST_CHECK( e.verify() );
|
||||||
|
CHECK_CALLS( 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( registering_to_a_sequence_and_multiply_calling_in_order_is_valid )
|
BOOST_FIXTURE_TEST_CASE( registering_to_a_sequence_and_multiply_calling_in_order_is_valid, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::sequence s;
|
mock::sequence s;
|
||||||
mock::detail::function< void( int ) > e;
|
mock::detail::function< void( int ) > e;
|
||||||
|
|
@ -54,19 +55,20 @@ BOOST_AUTO_TEST_CASE( registering_to_a_sequence_and_multiply_calling_in_order_is
|
||||||
BOOST_CHECK_NO_THROW( e( 2 ) );
|
BOOST_CHECK_NO_THROW( e( 2 ) );
|
||||||
BOOST_CHECK_NO_THROW( e( 2 ) );
|
BOOST_CHECK_NO_THROW( e( 2 ) );
|
||||||
BOOST_CHECK( e.verify() );
|
BOOST_CHECK( e.verify() );
|
||||||
|
CHECK_CALLS( 4 );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( registering_to_a_sequence_enforces_call_order_verification_between_two_different_expectations )
|
BOOST_FIXTURE_TEST_CASE( registering_to_a_sequence_enforces_call_order_verification_between_two_different_expectations, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::sequence s;
|
mock::sequence s;
|
||||||
mock::detail::function< void() > e1, e2;
|
mock::detail::function< void() > e1, e2;
|
||||||
e1.expect().once().in( s );
|
e1.expect().once().in( s );
|
||||||
e2.expect().once().in( s );
|
e2.expect().once().in( s );
|
||||||
BOOST_CHECK_NO_THROW( e2() );
|
BOOST_CHECK_NO_THROW( e2() );
|
||||||
BOOST_CHECK_THROW( e1(), std::exception );
|
CHECK_ERROR( e1(), "sequence failed", 1, "?()\n. once()" );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( destroying_a_sequence_does_not_remove_order_call_enforcement )
|
BOOST_FIXTURE_TEST_CASE( destroying_a_sequence_does_not_remove_order_call_enforcement, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::detail::function< void() > e1, e2;
|
mock::detail::function< void() > e1, e2;
|
||||||
{
|
{
|
||||||
|
|
@ -75,10 +77,10 @@ BOOST_AUTO_TEST_CASE( destroying_a_sequence_does_not_remove_order_call_enforceme
|
||||||
e2.expect().once().in( s );
|
e2.expect().once().in( s );
|
||||||
}
|
}
|
||||||
BOOST_CHECK_NO_THROW( e2() );
|
BOOST_CHECK_NO_THROW( e2() );
|
||||||
BOOST_CHECK_THROW( e1(), std::exception );
|
CHECK_ERROR( e1(), "sequence failed", 1, "?()\n. once()" );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( resetting_an_expectation_removes_it_from_order_call_enforcement )
|
BOOST_FIXTURE_TEST_CASE( resetting_an_expectation_removes_it_from_order_call_enforcement, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::sequence s;
|
mock::sequence s;
|
||||||
mock::detail::function< void() > e1, e2;
|
mock::detail::function< void() > e1, e2;
|
||||||
|
|
@ -88,22 +90,25 @@ BOOST_AUTO_TEST_CASE( resetting_an_expectation_removes_it_from_order_call_enforc
|
||||||
BOOST_CHECK_NO_THROW( e2() );
|
BOOST_CHECK_NO_THROW( e2() );
|
||||||
BOOST_CHECK( e1.verify() );
|
BOOST_CHECK( e1.verify() );
|
||||||
BOOST_CHECK( e2.verify() );
|
BOOST_CHECK( e2.verify() );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( an_expectation_can_be_used_in_several_sequences )
|
BOOST_FIXTURE_TEST_CASE( an_expectation_can_be_used_in_several_sequences, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::sequence s1, s2;
|
mock::sequence s1, s2;
|
||||||
mock::detail::function< void() > e;
|
mock::detail::function< void() > e;
|
||||||
e.expect().once().in( s1, s2 );
|
e.expect().once().in( s1, s2 );
|
||||||
BOOST_CHECK_NO_THROW( e() );
|
BOOST_CHECK_NO_THROW( e() );
|
||||||
BOOST_CHECK( e.verify() );
|
BOOST_CHECK( e.verify() );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( a_result_specification_is_set_after_a_sequence )
|
BOOST_FIXTURE_TEST_CASE( a_result_specification_is_set_after_a_sequence, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::sequence s;
|
mock::sequence s;
|
||||||
mock::detail::function< int() > e;
|
mock::detail::function< int() > e;
|
||||||
e.expect().once().in( s ).returns( 3 );
|
e.expect().once().in( s ).returns( 3 );
|
||||||
BOOST_CHECK_EQUAL( 3, e() );
|
BOOST_CHECK_EQUAL( 3, e() );
|
||||||
BOOST_CHECK( e.verify() );
|
BOOST_CHECK( e.verify() );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue