Changed MOCK_DESTRUCTOR and MOCK_*CONVERSION_OPERATOR to support different calling conventions

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@707 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2014-02-07 14:26:21 +00:00
parent a6c6b5dd82
commit 53e67c0a81
5 changed files with 300 additions and 87 deletions

View file

@ -157,7 +157,7 @@ struct base_class
MOCK_BASE_CLASS( mock_class, base_class )
{
MOCK_METHOD( method, 1, void( float ), method ) // this generates both const and non-const versions
MOCK_METHOD( method, 1, void( float ) ) // this generates both const and non-const versions
};
//]
}
@ -231,6 +231,28 @@ MOCK_CLASS( mock_class )
//]
}
#ifdef BOOST_MSVC
namespace member_function_example_9
{
//[ member_function_example_9
MOCK_CLASS( mock_class )
{
MOCK_METHOD( __stdcall method, 0, void(), method ) // all parameters must be provided when specifying a different calling convention
};
//]
}
#elif defined( BOOST_GCC )
namespace member_function_example_10
{
//[ member_function_example_10
MOCK_CLASS( mock_class )
{
MOCK_METHOD( __attribute((stdcall)) method, 0, void(), method ) // all parameters must be provided when specifying a different calling convention
};
//]
}
#endif
namespace static_member_function_example_1
{
//[ static_member_function_example_1
@ -252,6 +274,28 @@ MOCK_CLASS( mock_class )
//]
}
#ifdef BOOST_MSVC
namespace static_member_function_example_3
{
//[ static_member_function_example_3
MOCK_CLASS( mock_class )
{
MOCK_STATIC_METHOD( __stdcall method, 0, void(), method ) // all parameters must be provided when specifying a different calling convention
};
//]
}
#elif defined( BOOST_GCC )
namespace static_member_function_example_4
{
//[ static_member_function_example_4
MOCK_CLASS( mock_class )
{
MOCK_STATIC_METHOD( __attribute((stdcall)) method, 0, void(), method ) // all parameters must be provided when specifying a different calling convention
};
//]
}
#endif
namespace constructor_example_1
{
//[ constructor_example_1
@ -274,23 +318,67 @@ MOCK_CLASS( mock_class )
//]
}
#ifdef BOOST_MSVC
namespace constructor_example_3
{
//[ constructor_example_3
MOCK_CLASS( mock_class )
{
MOCK_CONSTRUCTOR( __stdcall mock_class, 0, (), constructor )
};
//]
}
#elif defined( BOOST_GCC )
namespace constructor_example_4
{
//[ constructor_example_4
MOCK_CLASS( mock_class )
{
MOCK_CONSTRUCTOR( __attribute((stdcall)) mock_class, 0, (), constructor )
};
//]
}
#endif
namespace destructor_example_1
{
//[ destructor_example_1
MOCK_CLASS( mock_class )
{
MOCK_DESTRUCTOR( mock_class, destructor )
MOCK_DESTRUCTOR( ~mock_class, destructor )
};
//]
}
#ifdef BOOST_MSVC
namespace destructor_example_2
{
//[ destructor_example_2
MOCK_CLASS( mock_class )
{
MOCK_DESTRUCTOR( __stdcall ~mock_class, destructor )
};
//]
}
#elif defined( BOOST_GCC )
namespace destructor_example_3
{
//[ destructor_example_3
MOCK_CLASS( mock_class )
{
MOCK_DESTRUCTOR( __attribute((stdcall)) ~mock_class, destructor )
};
//]
}
#endif
namespace conversion_operator_example_1
{
//[ conversion_operator_example_1
MOCK_CLASS( mock_class )
{
MOCK_CONVERSION_OPERATOR( int, conversion_to_int )
MOCK_CONST_CONVERSION_OPERATOR( const std::string&, conversion_to_string )
MOCK_CONVERSION_OPERATOR( operator, int, conversion_to_int )
MOCK_CONST_CONVERSION_OPERATOR( operator, const std::string&, conversion_to_string )
};
//]
}
@ -301,13 +389,66 @@ namespace conversion_operator_example_2
template< typename T >
MOCK_CLASS( mock_class )
{
MOCK_CONVERSION_OPERATOR_TPL( T, conversion_to_T ) // the _TPL variants must be used if the signature includes a template parameter of the class
MOCK_CONST_CONVERSION_OPERATOR( const std::string&, const_conversion_to_string )
MOCK_NON_CONST_CONVERSION_OPERATOR( const std::string&, non_const_conversion_to_string )
MOCK_CONVERSION_OPERATOR_TPL( operator, T, conversion_to_T ) // the _TPL variants must be used if the signature includes a template parameter of the class
MOCK_CONST_CONVERSION_OPERATOR( operator, const std::string&, const_conversion_to_string )
MOCK_NON_CONST_CONVERSION_OPERATOR( operator, const std::string&, non_const_conversion_to_string )
};
//]
}
#ifdef BOOST_MSVC
namespace conversion_operator_example_3
{
//[ conversion_operator_example_3
MOCK_CLASS( mock_class )
{
MOCK_CONVERSION_OPERATOR( __stdcall operator, int, conversion_to_int )
};
//]
}
#elif defined( BOOST_GCC )
namespace conversion_operator_example_4
{
//[ conversion_operator_example_4
MOCK_CLASS( mock_class )
{
MOCK_CONVERSION_OPERATOR( __attribute((stdcall)) operator, int, conversion_to_int )
};
//]
}
#endif
namespace function_example_1
{
//[ function_example_1
MOCK_FUNCTION( f, 1, float( int ) )
BOOST_AUTO_TEST_CASE( demonstrates_instantiating_a_mock_function )
{
f( 3 );
}
//]
}
#ifdef BOOST_MSVC
namespace function_example_2
{
//[ function_example_2
MOCK_FUNCTION( __stdcall f, 0, void(), f ) // all parameters must be provided when specifying a different calling convention
//]
}
#elif defined( BOOST_GCC )
namespace function_example_3
{
//[ function_example_3
MOCK_CLASS( mock_class )
{
MOCK_FUNCTION( __attribute((stdcall)) f, 0, void() )
};
//]
}
#endif
namespace functor_example_1
{
//[ functor_example_1
@ -336,18 +477,6 @@ BOOST_AUTO_TEST_CASE( demonstrates_instantiating_a_mock_functor )
//]
}
namespace function_example_1
{
//[ function_example_1
MOCK_FUNCTION( f, 1, float( int ) )
BOOST_AUTO_TEST_CASE( demonstrates_instantiating_a_mock_function )
{
f( 3 );
}
//]
}
namespace expectation_example_1
{
//[ expectation_example_1

View file

@ -80,13 +80,13 @@ Deriving from mock::object is optional but provides the additional following ben
Synopsis :
MOCK_METHOD( name, arity[, signature[, identifier]] ) // generates both const and non-const methods
MOCK_CONST_METHOD( name, arity[, signature[, identifier]] ) // generates only the const version of the method
MOCK_NON_CONST_METHOD( name, arity[, signature[, identifier]] ) // generates only the non-const version of the method
MOCK_METHOD( [calling convention] name, arity[, signature[, identifier]] ) // generates both const and non-const methods
MOCK_CONST_METHOD( [calling convention] name, arity[, signature[, identifier]] ) // generates only the const version of the method
MOCK_NON_CONST_METHOD( [calling convention] name, arity[, signature[, identifier]] ) // generates only the non-const version of the method
MOCK_METHOD_TPL( name, arity[, signature[, identifier]] ) // must be used if the signature uses a template parameter of the class, generates both const and non-const methods
MOCK_CONST_METHOD_TPL( name, arity[, signature[, identifier]] ) // must be used if the signature uses a template parameter of the class, generates only the const version of the method
MOCK_NON_CONST_METHOD_TPL( name, arity[, signature[, identifier]] ) // must be used if the signature uses a template parameter of the class, generates only the non-const version of the method
MOCK_METHOD_TPL( [calling convention] name, arity[, signature[, identifier]] ) // must be used if the signature uses a template parameter of the class, generates both const and non-const methods
MOCK_CONST_METHOD_TPL( [calling convention] name, arity[, signature[, identifier]] ) // must be used if the signature uses a template parameter of the class, generates only the const version of the method
MOCK_NON_CONST_METHOD_TPL( [calling convention] name, arity[, signature[, identifier]] ) // must be used if the signature uses a template parameter of the class, generates only the non-const version of the method
[note If the identifier is omitted it will default to the method name.]
@ -96,19 +96,19 @@ Synopsis :
[note [link turtle.reference.creation.constructor Constructors], [link turtle.reference.creation.destructor destructors] and [link turtle.reference.creation.conversion_operator conversion operators] require special care.]
For compilers without support for variadic macros the signature and the identifier cannot be specified, thus in case of ambiguity another set of macros must be used.
[note In case of a calling convention specified, all four parameters must be provided.]
[warning For compilers without support for variadic macros the MOCK_METHOD_EXT familly set of macros must be used.]
Synopsis :
MOCK_METHOD_EXT( name, arity, signature, identifier ) // generates both const and non-const methods
MOCK_CONST_METHOD_EXT( name, arity, signature, identifier ) // generates only the const version of the method
MOCK_NON_CONST_METHOD_EXT( name, arity, signature, identifier ) // generates only the non-const version of the method
MOCK_METHOD_EXT( [calling convention] name, arity, signature, identifier ) // generates both const and non-const methods
MOCK_CONST_METHOD_EXT( [calling convention] name, arity, signature, identifier ) // generates only the const version of the method
MOCK_NON_CONST_METHOD_EXT( [calling convention] name, arity, signature, identifier ) // generates only the non-const version of the method
MOCK_METHOD_EXT_TPL( name, arity, signature, identifier ) // must be used if the signature uses a template parameter of the class, generates both const and non-const methods
MOCK_CONST_METHOD_EXT_TPL( name, arity, signature, identifier ) // must be used if the signature uses a template parameter of the class, generates only the const version of the method
MOCK_NON_CONST_METHOD_EXT_TPL( name, arity, signature, identifier ) // must be used if the signature uses a template parameter of the class, generates only the non-const version of the method
Of course those macros are also available for compilers which support variadic macros.
MOCK_METHOD_EXT_TPL( [calling convention] name, arity, signature, identifier ) // must be used if the signature uses a template parameter of the class, generates both const and non-const methods
MOCK_CONST_METHOD_EXT_TPL( [calling convention] name, arity, signature, identifier ) // must be used if the signature uses a template parameter of the class, generates only the const version of the method
MOCK_NON_CONST_METHOD_EXT_TPL( [calling convention] name, arity, signature, identifier ) // must be used if the signature uses a template parameter of the class, generates only the non-const version of the method
Example :
@ -138,18 +138,28 @@ Example :
[member_function_example_8]
Example for msvc :
[member_function_example_9]
Example for gcc :
[member_function_example_10]
[endsect]
[section Static member function]
Synopsis :
MOCK_STATIC_METHOD( name, arity, signature[, identifier] ) // if 'identifier' is omitted it will default to 'name'
MOCK_STATIC_METHOD( [calling convention] name, arity, signature[, identifier] ) // if 'identifier' is omitted it will default to 'name'
MOCK_STATIC_METHOD_TPL( name, arity, signature[, identifier] ) // must be used if the signature uses a template parameter of the class, if 'identifier' is omitted it will default to 'name'
MOCK_STATIC_METHOD_TPL( [calling convention] name, arity, signature[, identifier] ) // must be used if the signature uses a template parameter of the class, if 'identifier' is omitted it will default to 'name'
[note A static object is used behind the scene in order to keep track of the expectations of a mock static method, therefore to ensure all tests run in isolation it is strongly suggested to manually [link turtle.reference.verification verify] and [link turtle.reference.reset reset] the static method at the end of each test.]
[note In case of a calling convention specified, all four parameters must be provided.]
[warning For compilers without support for variadic macros the identifier cannot be omitted and must be given explicitly.]
Example :
@ -160,15 +170,23 @@ Example :
[static_member_function_example_2]
Example for msvc :
[static_member_function_example_3]
Example for gcc :
[static_member_function_example_4]
[endsect]
[section Constructor]
Synopsis :
MOCK_CONSTRUCTOR( name, arity, parameters, identifier )
MOCK_CONSTRUCTOR( [calling convention] name, arity, parameters, identifier )
MOCK_CONSTRUCTOR_TPL( name, arity, parameters, identifier ) // must be used if the signature uses a template parameter of the class
MOCK_CONSTRUCTOR_TPL( [calling convention] name, arity, parameters, identifier ) // must be used if the signature uses a template parameter of the class
[note As constructors do not have a return type, the usual signature gets restricted here to just the parameters.]
@ -180,13 +198,21 @@ Example :
[constructor_example_2]
Example for msvc :
[constructor_example_3]
Example for gcc :
[constructor_example_4]
[endsect]
[section Destructor]
Synopsis :
MOCK_DESTRUCTOR( name, identifier )
MOCK_DESTRUCTOR( [calling convention] ~name, identifier )
[note When mocking a destructor it is strongly suggested to manually [link turtle.reference.verification verify] the expectation at the end of the test, because the automatic verification will not be triggered if the mock object is not destroyed.]
@ -194,19 +220,27 @@ Example :
[destructor_example_1]
Example for msvc :
[destructor_example_2]
Example for gcc :
[destructor_example_3]
[endsect]
[section Conversion operator]
Synopsis :
MOCK_CONVERSION_OPERATOR( type, identifier ) // generates both const and non-const operators
MOCK_CONST_CONVERSION_OPERATOR( type, identifier ) // generates only a const operator
MOCK_NON_CONST_CONVERSION_OPERATOR( type, identifier ) // generates only a non-const operator
MOCK_CONVERSION_OPERATOR( [calling convention] name, type, identifier ) // generates both const and non-const operators
MOCK_CONST_CONVERSION_OPERATOR( [calling convention] name, type, identifier ) // generates only a const operator
MOCK_NON_CONST_CONVERSION_OPERATOR( [calling convention] name, type, identifier ) // generates only a non-const operator
MOCK_CONVERSION_OPERATOR_TPL( type, identifier ) // must be used if the signature uses a template parameter of the class
MOCK_CONST_CONVERSION_OPERATOR_TPL( type, identifier ) // must be used if the signature uses a template parameter of the class
MOCK_NON_CONST_CONVERSION_OPERATOR_TPL( type, identifier ) // must be used if the signature uses a template parameter of the class
MOCK_CONVERSION_OPERATOR_TPL( [calling convention] name, type, identifier ) // must be used if the signature uses a template parameter of the class
MOCK_CONST_CONVERSION_OPERATOR_TPL( [calling convention] name, type, identifier ) // must be used if the signature uses a template parameter of the class
MOCK_NON_CONST_CONVERSION_OPERATOR_TPL( [calling convention] name, type, identifier ) // must be used if the signature uses a template parameter of the class
Example :
@ -216,15 +250,49 @@ Example :
[conversion_operator_example_2]
Example for msvc :
[conversion_operator_example_3]
Example for gcc :
[conversion_operator_example_4]
[endsect]
[section Function]
Synopsis :
MOCK_FUNCTION( [calling convention] name, arity, signature[, identifier] ) // if 'identifier' is omitted it will default to 'name'
[note A static object is used behind the scene in order to keep track of the expectations of a mock function, therefore to ensure all tests run in isolation it is strongly suggested to manually [link turtle.reference.verification verify] and [link turtle.reference.reset reset] the mock function at the end of each test.]
[note In case of a calling convention specified, all four parameters must be provided.]
[warning For compilers without support for variadic macros the identifier cannot be omitted and must be given explicitly.]
Example :
[function_example_1]
Example for msvc :
[function_example_2]
Example for gcc :
[function_example_3]
[endsect]
[section Functor]
Synopsis :
MOCK_FUNCTOR( name, signature );
MOCK_FUNCTOR( [calling convention] name, signature );
MOCK_FUNCTOR_TPL( name, signature ); // must be used if the signature uses a template parameter
MOCK_FUNCTOR_TPL( [calling convention] name, signature ); // must be used if the signature uses a template parameter
Example :
@ -236,22 +304,6 @@ Example :
[endsect]
[section Function]
Synopsis :
MOCK_FUNCTION( name, arity, signature[, identifier] ) // if 'identifier' is omitted it will default to 'name'
[note A static object is used behind the scene in order to keep track of the expectations of a mock function, therefore to ensure all tests run in isolation it is strongly suggested to manually [link turtle.reference.verification verify] and [link turtle.reference.reset reset] the mock function at the end of each test.]
[warning For compilers without support for variadic macros the identifier cannot be omitted and must be given explicitly.]
Example :
[function_example_1]
[endsect]
[endsect]
[section Expectation]