Merge pull request #108 from Flamefire/reduce-interface

Reduce interface, cleanup and docu updates
This commit is contained in:
Alexander Grund 2022-01-28 18:27:57 +01:00 committed by GitHub
commit b9a1a4a4b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 430 additions and 394 deletions

View file

@ -134,27 +134,17 @@ StatementMacros:
- MOCK_BASE_CLASS - MOCK_BASE_CLASS
- MOCK_CLASS - MOCK_CLASS
- MOCK_CONSTRUCTOR - MOCK_CONSTRUCTOR
- MOCK_CONSTRUCTOR_TPL
- MOCK_CONST_CONVERSION_OPERATOR - MOCK_CONST_CONVERSION_OPERATOR
- MOCK_CONST_CONVERSION_OPERATOR_TPL
- MOCK_CONST_METHOD - MOCK_CONST_METHOD
- MOCK_CONST_METHOD_EXT - MOCK_CONST_METHOD_EXT
- MOCK_CONST_METHOD_EXT_TPL
- MOCK_CONST_METHOD_TPL
- MOCK_CONVERSION_OPERATOR - MOCK_CONVERSION_OPERATOR
- MOCK_DESTRUCTOR - MOCK_DESTRUCTOR
- MOCK_METHOD - MOCK_METHOD
- MOCK_METHOD_EXT - MOCK_METHOD_EXT
- MOCK_METHOD_EXT_TPL
- MOCK_METHOD_TPL
- MOCK_NON_CONST_CONVERSION_OPERATOR - MOCK_NON_CONST_CONVERSION_OPERATOR
- MOCK_NON_CONST_CONVERSION_OPERATOR_TPL
- MOCK_NON_CONST_METHOD - MOCK_NON_CONST_METHOD
- MOCK_NON_CONST_METHOD_EXT - MOCK_NON_CONST_METHOD_EXT
- MOCK_NON_CONST_METHOD_EXT_TPL
- MOCK_NON_CONST_METHOD_TPL
- MOCK_STATIC_METHOD - MOCK_STATIC_METHOD
- MOCK_STATIC_METHOD_TPL
TabWidth: 4 TabWidth: 4
UseCRLF: false UseCRLF: false
UseTab: Never UseTab: Never

View file

@ -21,7 +21,8 @@ endif()
find_package(Boost 1.58 REQUIRED) find_package(Boost 1.58 REQUIRED)
set(MOCK_VERSION "\"${PROJECT_VERSION}\"") set(MOCK_VERSION "\"${PROJECT_VERSION}\"")
configure_file(version.hpp.cmake ${CMAKE_CURRENT_BINARY_DIR}/include/turtle/version.hpp @ONLY) set(_turtleVersionFile ${CMAKE_CURRENT_BINARY_DIR}/include/turtle/version.hpp)
configure_file(version.hpp.cmake ${_turtleVersionFile} @ONLY)
add_library(turtle INTERFACE) add_library(turtle INTERFACE)
add_library(turtle::turtle ALIAS turtle) add_library(turtle::turtle ALIAS turtle)
@ -30,6 +31,14 @@ target_compile_features(turtle INTERFACE cxx_std_14)
target_link_libraries(turtle INTERFACE Boost::boost Boost::disable_autolinking) target_link_libraries(turtle INTERFACE Boost::boost Boost::disable_autolinking)
if(NOT CMAKE_VERSION VERSION_LESS 3.19)
file(GLOB _turtleHeaders include/turtle/*.hpp)
file(GLOB _turtleHeadersDetail include/turtle/detail/*.hpp)
source_group(turtle FILES ${_turtleHeaders} ${_turtleVersionFile})
source_group(turtle/detail FILES ${_turtleHeadersDetail})
target_sources(turtle PRIVATE ${_turtleHeaders} ${_turtleVersionFile} ${_turtleHeadersDetail})
endif()
if(BUILD_TESTING) if(BUILD_TESTING)
add_subdirectory(test) add_subdirectory(test)
endif() endif()

View file

@ -12,8 +12,9 @@ Released -
* Allow auto-deducing signature in `MOCK_METHOD_(NON_)CONST` * Allow auto-deducing signature in `MOCK_METHOD_(NON_)CONST`
* Replaced Boost facilities with std:: equivalents where existing in C++14 * Replaced Boost facilities with std:: equivalents where existing in C++14
* Deprecated MOCK_FUNCTOR_TPL as no longer required, use the non _TPL variant even for templates * Removed MOCK_*_TPL as they are no longer required, use the non _TPL variant even for templates
* Added MOCK_PROTECT_FUNCTION_SIG to pass function signatures with commas in the return type * Added MOCK_PROTECT_SIGNATURE to pass function signatures with commas in the return type
* Remove support for protecting function signatures via BOOST_IDENTITY_TYPE, use MOCK_PROTECT_SIGNATURE instead
[endsect] [endsect]

View file

@ -88,8 +88,8 @@ class base
struct name : base, mock::object // equivalent to using MOCK_BASE_CLASS struct name : base, mock::object // equivalent to using MOCK_BASE_CLASS
{ {
typedef base // this is required for the shortest form of MOCK_METHOD to work when not using MOCK_BASE_CLASS
base_type; // this is required for the shortest form of MOCK_METHOD to work when not using MOCK_BASE_CLASS using base_type = base;
}; };
//] //]
} // namespace class_example_7 } // namespace class_example_7
@ -103,7 +103,7 @@ struct base
template<typename T> template<typename T>
struct name : base<T>, mock::object struct name : base<T>, mock::object
{ {
typedef base<T> base_type; using base_type = base<T>;
}; };
//] //]
} // namespace class_example_8 } // namespace class_example_8
@ -134,15 +134,10 @@ struct base_class
MOCK_BASE_CLASS(mock_class, base_class) MOCK_BASE_CLASS(mock_class, base_class)
{ {
MOCK_METHOD( // both the signature and identifier must be specified because of ambiguity due to overloading
method, MOCK_METHOD(method, 2, void(int, const std::string&), identifier_1)
2, // the identifier must differ from the previous one in order to fully disambiguate methods
void(int, const std::string&), MOCK_METHOD(method, 1, void(float), identifier_2)
identifier_1) // both the signature and identifier must be specified because of ambiguity due to overloading
MOCK_METHOD(method,
1,
void(float),
identifier_2) // the identifier must differ from the previous one in order to fully disambiguate methods
}; };
//] //]
} // namespace member_function_example_2 } // namespace member_function_example_2
@ -174,9 +169,10 @@ struct base_class
MOCK_BASE_CLASS(mock_class, base_class) MOCK_BASE_CLASS(mock_class, base_class)
{ {
MOCK_CONST_METHOD(method, 1, void(float), identifier_1) // this generates only the const version // this generates only the const version
MOCK_NON_CONST_METHOD( MOCK_CONST_METHOD(method, 1, void(float), identifier_1)
method, 1, void(float), identifier_2) // this generates only the non-const version, with a different identifier // this generates only the non-const version, with a different identifier
MOCK_NON_CONST_METHOD(method, 1, void(float), identifier_2)
}; };
//] //]
} // namespace member_function_example_4 } // namespace member_function_example_4
@ -191,7 +187,7 @@ struct base_class
struct mock_class : base_class struct mock_class : base_class
{ {
typedef base_class base_type; // this is required for MOCK_METHOD to work when not using MOCK_BASE_CLASS using base_type = base_class; // this is required for MOCK_METHOD to work when not using MOCK_BASE_CLASS
MOCK_METHOD(method, 1) MOCK_METHOD(method, 1)
}; };
@ -215,10 +211,8 @@ namespace member_function_example_7 {
template<typename T> template<typename T>
MOCK_CLASS(mock_class) MOCK_CLASS(mock_class)
{ {
MOCK_METHOD_TPL( // includes a template parameter of the class
method, MOCK_METHOD(method, 1, void(const T&))
1,
void(const T&)) // the _TPL variants must be used if the signature includes a template parameter of the class
}; };
//] //]
} // namespace member_function_example_7 } // namespace member_function_example_7
@ -227,11 +221,14 @@ namespace member_function_example_8 {
//[ member_function_example_8 //[ member_function_example_8
MOCK_CLASS(mock_class) MOCK_CLASS(mock_class)
{ {
MOCK_METHOD( // the signature must be wrapped in MOCK_PROTECT_SIGNATURE if the return type contains a comma
method, 0, BOOST_IDENTITY_TYPE((std::map<int, int>()))) // the signature must be wrapped in BOOST_IDENTITY_TYPE if MOCK_METHOD(method, 0, MOCK_PROTECT_SIGNATURE(std::map<int, int>()))
// the return type contains a comma
}; };
//] //]
static_assert(std::is_same<decltype(std::declval<mock_class>().method()), std::map<int, int>>::value,
"Wrong return value");
} // namespace member_function_example_8 } // namespace member_function_example_8
#ifdef BOOST_MSVC #ifdef BOOST_MSVC
@ -239,10 +236,8 @@ namespace member_function_example_9 {
//[ member_function_example_9 //[ member_function_example_9
MOCK_CLASS(mock_class) MOCK_CLASS(mock_class)
{ {
MOCK_METHOD(__stdcall method, // all parameters must be provided when specifying a different calling convention
0, MOCK_METHOD(__stdcall method, 0, void(), method)
void(),
method) // all parameters must be provided when specifying a different calling convention
}; };
//] //]
} // namespace member_function_example_9 } // namespace member_function_example_9
@ -262,7 +257,7 @@ namespace static_member_function_example_2 {
template<typename T> template<typename T>
MOCK_CLASS(mock_class) MOCK_CLASS(mock_class)
{ {
MOCK_STATIC_METHOD_TPL(method, 1, void(T)) MOCK_STATIC_METHOD(method, 1, void(T)) // includes a template parameter of the class
}; };
//] //]
} // namespace static_member_function_example_2 } // namespace static_member_function_example_2
@ -272,10 +267,8 @@ namespace static_member_function_example_3 {
//[ static_member_function_example_3 //[ static_member_function_example_3
MOCK_CLASS(mock_class) MOCK_CLASS(mock_class)
{ {
MOCK_STATIC_METHOD(__stdcall method, // all parameters must be provided when specifying a different calling convention
0, MOCK_STATIC_METHOD(__stdcall method, 0, void(), method)
void(),
method) // all parameters must be provided when specifying a different calling convention
}; };
//] //]
} // namespace static_member_function_example_3 } // namespace static_member_function_example_3
@ -296,7 +289,7 @@ template<typename T>
MOCK_CLASS(mock_class) MOCK_CLASS(mock_class)
{ {
MOCK_CONSTRUCTOR(mock_class, 2, (int, const std::string&), identifier) MOCK_CONSTRUCTOR(mock_class, 2, (int, const std::string&), identifier)
MOCK_CONSTRUCTOR_TPL(mock_class, 2, (T, const std::string&), identifier_2) MOCK_CONSTRUCTOR(mock_class, 2, (T, const std::string&), identifier_2) // includes a template parameter of the class
}; };
//] //]
} // namespace constructor_example_2 } // namespace constructor_example_2
@ -347,8 +340,7 @@ namespace conversion_operator_example_2 {
template<typename T> template<typename T>
MOCK_CLASS(mock_class) MOCK_CLASS(mock_class)
{ {
MOCK_CONVERSION_OPERATOR_TPL(operator, T, conversion_to_T) // the _TPL variants must be used if the signature MOCK_CONVERSION_OPERATOR(operator, T, conversion_to_T) // includes a template parameter of the class
// includes a template parameter of the class
MOCK_CONST_CONVERSION_OPERATOR(operator, const std::string&, const_conversion_to_string) 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) MOCK_NON_CONST_CONVERSION_OPERATOR(operator, const std::string&, non_const_conversion_to_string)
}; };
@ -381,10 +373,8 @@ BOOST_AUTO_TEST_CASE(demonstrates_instantiating_a_mock_function)
#ifdef BOOST_MSVC #ifdef BOOST_MSVC
namespace function_example_2 { namespace function_example_2 {
//[ function_example_2 //[ function_example_2
MOCK_FUNCTION(__stdcall f, // all parameters must be provided when specifying a different calling convention
0, MOCK_FUNCTION(__stdcall f, 0, void(), f)
void(),
f) // all parameters must be provided when specifying a different calling convention
//] //]
} // namespace function_example_2 } // namespace function_example_2
#endif #endif
@ -898,11 +888,10 @@ BOOST_AUTO_TEST_CASE(mock_constraint_0_arity)
namespace helpers_example_2 { namespace helpers_example_2 {
//[ helpers_example_2 //[ helpers_example_2
MOCK_CONSTRAINT(equal, expected, actual == expected) // this is how mock::equal could be defined // this is how mock::equal could be defined
MOCK_CONSTRAINT(near, MOCK_CONSTRAINT(equal, expected, actual == expected)
expected, // this defines a 'near' constraint which can be used as 'near( 42 )'
std::abs(actual - expected) < MOCK_CONSTRAINT(near, expected, std::abs(actual - expected) < 0.01)
0.01) // this defines a 'near' constraint which can be used as 'near( 42 )'
BOOST_AUTO_TEST_CASE(mock_constraint_1_arity) BOOST_AUTO_TEST_CASE(mock_constraint_1_arity)
{ {
@ -915,10 +904,8 @@ BOOST_AUTO_TEST_CASE(mock_constraint_1_arity)
namespace helpers_example_3 { namespace helpers_example_3 {
//[ helpers_example_3 //[ helpers_example_3
MOCK_CONSTRAINT(near, // this is how mock::near could be defined
expected, MOCK_CONSTRAINT(near, expected, tolerance, std::abs(actual - expected) <= tolerance)
tolerance,
std::abs(actual - expected) < tolerance) // this is how mock::near could be defined
BOOST_AUTO_TEST_CASE(mock_constraint_2_arity) BOOST_AUTO_TEST_CASE(mock_constraint_2_arity)
{ {

View file

@ -90,16 +90,12 @@ Synopsis :
MOCK_METHOD( [calling convention] name, arity[, signature[, identifier]] ) // generates both const and non-const methods 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_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_NON_CONST_METHOD( [calling convention] name, arity[, signature[, identifier]] ) // 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.] [note If the identifier is omitted it will default to the method name.]
[note If the method name is not ambiguous both the signature and the identifier can be omitted in the context of a derived MOCK_BASE_CLASS or base_type typedef.] [note If the method name is not ambiguous both the signature and the identifier can be omitted in the context of a derived MOCK_BASE_CLASS or base_type typedef.]
[note The signature cannot be omitted for the _TPL familly of macros, see the related [link turtle.limitations.template_base_class_methods_cannot_be_mocked_without_specifying_the_signature limitation section].] [note The signature cannot be omitted if it uses a template parameter of the class, see the related [link turtle.limitations.template_base_class_methods_cannot_be_mocked_without_specifying_the_signature limitation section].]
[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.] [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.]
@ -107,13 +103,9 @@ Synopsis :
Synopsis : Synopsis :
MOCK_METHOD_EXT( [calling convention] name, arity, signature, identifier ) // generates both const and non-const methods MOCK_METHOD( [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_CONST_METHOD( [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_NON_CONST_METHOD( [calling convention] name, arity, signature, identifier ) // generates only the non-const version of the method
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 : Example :
@ -158,8 +150,6 @@ Example for gcc :
Synopsis : Synopsis :
MOCK_STATIC_METHOD( [calling convention] 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( [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, see the related [link turtle.patterns.managing_static_mock_objects pattern section].] [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, see the related [link turtle.patterns.managing_static_mock_objects pattern section].]
@ -189,8 +179,6 @@ Synopsis :
MOCK_CONSTRUCTOR( [calling convention] name, arity, parameters, identifier ) MOCK_CONSTRUCTOR( [calling convention] name, arity, parameters, identifier )
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.] [note As constructors do not have a return type, the usual signature gets restricted here to just the parameters.]
Example : Example :
@ -241,10 +229,6 @@ Synopsis :
MOCK_CONST_CONVERSION_OPERATOR( [calling convention] name, type, identifier ) // generates only a const operator 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_NON_CONST_CONVERSION_OPERATOR( [calling convention] name, type, identifier ) // generates only a non-const operator
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 : Example :
[conversion_operator_example_1] [conversion_operator_example_1]
@ -293,8 +277,6 @@ Synopsis :
MOCK_FUNCTOR( [calling convention] name, signature ); MOCK_FUNCTOR( [calling convention] name, signature );
MOCK_FUNCTOR_TPL( [calling convention] name, signature ); // must be used if the signature uses a template parameter
Example : Example :
[functor_example_1] [functor_example_1]

View file

@ -0,0 +1,113 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2008
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef MOCK_MOCK_IMPL_HPP_INCLUDED
#define MOCK_MOCK_IMPL_HPP_INCLUDED
#include "function.hpp"
#include "functor.hpp"
#include "signature.hpp"
#include "signature_traits.hpp"
#include "type_name.hpp"
#include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/preprocessor/stringize.hpp>
#include <type_traits>
namespace mock { namespace detail {
/// Simplified trait to extract the argument type of a function signature with 1 argument
template<typename T>
struct arg_type;
template<typename T, typename U>
struct arg_type<T(U)>
{
using type = U;
};
/// Used in MOCK_PROTECT_SIGNATURE to unwrap the passed function signature
/// T is something like `void(std::map<int, float>)`
template<typename T>
using unwrap_signature_t = std::remove_pointer_t<typename arg_type<T>::type>;
}} // namespace mock::detail
#define MOCK_HELPER(t) t##_mock(mock::detail::root, BOOST_PP_STRINGIZE(t))
#define MOCK_ANONYMOUS_HELPER(t) t##_mock(mock::detail::root, "?.")
#define MOCK_METHOD_HELPER(S, t) \
mutable mock::detail::function<S> t##_mock_; \
mock::detail::function<S>& t##_mock(const mock::detail::context&, const boost::unit_test::const_string& instance) \
const \
{ \
mock::detail::configure(*this, \
t##_mock_, \
instance.substr(0, instance.rfind(BOOST_PP_STRINGIZE(t))), \
mock::detail::make_type_name(*this), \
BOOST_PP_STRINGIZE(t)); \
return t##_mock_; \
}
#define MOCK_PARAM(S) mock::detail::parameter_t < S
#define MOCK_DECL_PARAM(z, n, d) BOOST_PP_COMMA_IF(n) d, n > p##n
#define MOCK_DECL_PARAMS(n, S) BOOST_PP_REPEAT(n, MOCK_DECL_PARAM, MOCK_PARAM(S))
#define MOCK_DECL(M, n, S, c) mock::detail::result_type_t<S> M(MOCK_DECL_PARAMS(n, S)) c
#define MOCK_FORWARD_PARAM(z, n, d) BOOST_PP_COMMA_IF(n) d, n >> (p##n)
#define MOCK_FORWARD_PARAMS(n, S) BOOST_PP_REPEAT(n, MOCK_FORWARD_PARAM, std::forward < MOCK_PARAM(S))
#define MOCK_METHOD_AUX(M, n, S, t, c) \
static_assert(n == mock::detail::function_arity_t<S>::value, "Arity mismatch"); \
MOCK_DECL(M, n, S, c) { return MOCK_ANONYMOUS_HELPER(t)(MOCK_FORWARD_PARAMS(n, S)); }
#define MOCK_METHOD_EXT(M, n, S, t) \
MOCK_METHOD_AUX(M, n, S, t, ) \
MOCK_METHOD_AUX(M, n, S, t, const) \
MOCK_METHOD_HELPER(S, t)
#define MOCK_CONST_METHOD_EXT(M, n, S, t) \
MOCK_METHOD_AUX(M, n, S, t, const) \
MOCK_METHOD_HELPER(S, t)
#define MOCK_NON_CONST_METHOD_EXT(M, n, S, t) \
MOCK_METHOD_AUX(M, n, S, t, ) \
MOCK_METHOD_HELPER(S, t)
#define MOCK_FUNCTION_HELPER(S, t, s) \
s mock::detail::function<S>& t##_mock(mock::detail::context& context, boost::unit_test::const_string instance) \
{ \
static mock::detail::function<S> f; \
return f(context, instance); \
}
#define MOCK_CONSTRUCTOR_AUX(T, n, A, t) \
T(MOCK_DECL_PARAMS(n, void A)) { MOCK_HELPER(t)(MOCK_FORWARD_PARAMS(n, void A)); } \
MOCK_FUNCTION_HELPER(void A, t, static)
#define MOCK_FUNCTION_AUX(F, n, S, t, s) \
MOCK_FUNCTION_HELPER(S, t, s) \
static_assert(n == mock::detail::function_arity_t<S>::value, "Arity mismatch"); \
s MOCK_DECL(F, n, S, ) { return MOCK_HELPER(t)(MOCK_FORWARD_PARAMS(n, S)); }
#define MOCK_VARIADIC_ELEM_0(e0, ...) e0
#define MOCK_VARIADIC_ELEM_1(e0, e1, ...) e1
#define MOCK_VARIADIC_ELEM_2(e0, e1, e2, ...) e2
#define MOCK_REPLACED_MACRO_ERROR(oldName, newName) static_assert(false, #oldName " has been replaced by " #newName)
// Replaced macros
#define MOCK_CONST_CONVERSION_OPERATOR_TPL(...) \
MOCK_REPLACED_MACRO_ERROR(MOCK_CONST_CONVERSION_OPERATOR_TPL, MOCK_CONST_CONVERSION_OPERATOR)
#define MOCK_CONST_METHOD_EXT_TPL(...) MOCK_REPLACED_MACRO_ERROR(MOCK_CONST_METHOD_EXT_TPL, MOCK_CONST_METHOD)
#define MOCK_CONST_METHOD_TPL(...) MOCK_REPLACED_MACRO_ERROR(MOCK_CONST_METHOD_TPL, MOCK_CONST_METHOD)
#define MOCK_CONVERSION_OPERATOR_TPL(...) \
MOCK_REPLACED_MACRO_ERROR(MOCK_CONVERSION_OPERATOR_TPL, MOCK_CONVERSION_OPERATOR)
#define MOCK_FUNCTOR_TPL(...) MOCK_REPLACED_MACRO_ERROR(MOCK_FUNCTOR_TPL, MOCK_FUNCTOR)
#define MOCK_METHOD_EXT_TPL(...) MOCK_REPLACED_MACRO_ERROR(MOCK_METHOD_EXT_TPL, MOCK_METHOD)
#define MOCK_METHOD_TPL(...) MOCK_REPLACED_MACRO_ERROR(MOCK_METHOD_TPL, MOCK_METHOD)
#define MOCK_NON_CONST_CONVERSION_OPERATOR_TPL(...) \
MOCK_REPLACED_MACRO_ERROR(MOCK_NON_CONST_CONVERSION_OPERATOR_TPL, MOCK_NON_CONST_CONVERSION_OPERATOR)
#define MOCK_NON_CONST_METHOD_EXT_TPL(...) \
MOCK_REPLACED_MACRO_ERROR(MOCK_NON_CONST_METHOD_EXT_TPL, MOCK_NON_CONST_METHOD)
#define MOCK_NON_CONST_METHOD_TPL(...) MOCK_REPLACED_MACRO_ERROR(MOCK_NON_CONST_METHOD_TPL, MOCK_NON_CONST_METHOD)
#define MOCK_STATIC_METHOD_TPL(...) MOCK_REPLACED_MACRO_ERROR(MOCK_STATIC_METHOD_TPL, MOCK_STATIC_METHOD)
#define MOCK_CONSTRUCTOR_TPL(...) MOCK_REPLACED_MACRO_ERROR(MOCK_CONSTRUCTOR_TPL, MOCK_CONSTRUCTOR)
#endif // MOCK_MOCK_IMPL_HPP_INCLUDED

View file

@ -1,76 +0,0 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2012
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef MOCK_PARAMETER_HPP_INCLUDED
#define MOCK_PARAMETER_HPP_INCLUDED
#include "../config.hpp"
namespace mock { namespace detail {
template<class...>
struct tuple;
template<std::size_t I, class T>
struct tuple_element;
template<std::size_t I, class H, class... T>
struct tuple_element<I, tuple<H, T...>> : tuple_element<I - 1, tuple<T...>>
{};
template<class H, class... T>
struct tuple_element<0, tuple<H, T...>>
{
using type = H;
};
template<typename Signature>
struct result_type;
template<typename R, typename... Args>
struct result_type<R(Args...)>
{
using type = R;
};
template<typename Signature>
struct function_arity;
template<typename R, typename... Args>
struct function_arity<R(Args...)>
{
static constexpr size_t value = sizeof...(Args);
};
template<typename Signature>
struct parameter_types;
template<typename R, typename... Args>
struct parameter_types<R(Args...)>
{
using type = tuple<Args...>;
};
template<typename Signature, int n>
struct parameter
{
static_assert(n < function_arity<Signature>::value, "Function signature has not that many parameters");
using type = typename tuple_element<n, typename parameter_types<Signature>::type>::type;
};
template<typename T>
struct parameter_type;
template<typename T, typename U>
struct parameter_type<T(U)>
{
using type = U;
};
template<typename T>
using parameter_type_t = typename parameter_type<T>::type;
}} // namespace mock::detail
#endif // MOCK_PARAMETER_HPP_INCLUDED

View file

@ -54,21 +54,24 @@ namespace mock { namespace detail {
struct signature<Sig(C::*)> : signature<typename strip_function_qualifiers<Sig>::type> struct signature<Sig(C::*)> : signature<typename strip_function_qualifiers<Sig>::type>
{}; {};
/// Return the (non-member) function signature out of (any) signature
template<typename M>
using signature_t = typename signature<M>::type;
/// CRTP class to define the base_type typedef
template<typename T> template<typename T>
struct base struct base
{ {
typedef T base_type; using base_type = T;
}; };
// if an error is generated by the line below it means // If an error is generated by the line below it means the method is ambiguous.
// the method is ambiguous : specify its signature to // Specify its signature to disambiguate
// disambiguate
template<typename T> template<typename T>
T& ambiguous_method_requires_to_specify_signature(const T&); T ambiguous_method_requires_to_specify_signature(const T&);
}} // namespace mock::detail }} // namespace mock::detail
#define MOCK_SIGNATURE(M) \ #define MOCK_SIGNATURE(M) \
mock::detail::signature<std::remove_cv_t<std::remove_reference_t<decltype( \ mock::detail::signature_t<decltype(mock::detail::ambiguous_method_requires_to_specify_signature(&base_type::M))>
mock::detail::ambiguous_method_requires_to_specify_signature(&base_type::M))>>>::type
#endif // MOCK_SIGNATURE_HPP_INCLUDED #endif // MOCK_SIGNATURE_HPP_INCLUDED

View file

@ -0,0 +1,62 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2012
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef MOCK_PARAMETER_HPP_INCLUDED
#define MOCK_PARAMETER_HPP_INCLUDED
#include "../config.hpp"
#include <cstddef>
namespace mock { namespace detail {
/// Helper class to store a tuple/list of types
template<class...>
struct tuple;
/// Get the type at the given index in the tuple
template<std::size_t index, class Tuple>
struct tuple_element;
template<std::size_t I, class H, class... T>
struct tuple_element<I, tuple<H, T...>> : tuple_element<I - 1, tuple<T...>>
{};
template<class H, class... T>
struct tuple_element<0, tuple<H, T...>>
{
using type = H;
};
/// Provides information about a given function signature
/// Member types: return_type, args
/// Member constant: arity
template<typename Signature>
struct signature_traits;
template<typename R, typename... Args>
struct signature_traits<R(Args...)>
{
using return_type = R;
static constexpr std::size_t arity = sizeof...(Args);
using args = tuple<Args...>;
};
/// Return the result type of the function signature
template<typename Signature>
using result_type_t = typename signature_traits<Signature>::return_type;
/// Return the arity of the function signature
template<typename Signature>
using function_arity_t = std::integral_constant<std::size_t, signature_traits<Signature>::arity>;
/// Return the type at the given index of the function signature
template<typename Signature, std::size_t idx>
using parameter_t = typename tuple_element<idx, typename signature_traits<Signature>::args>::type;
}} // namespace mock::detail
#endif // MOCK_PARAMETER_HPP_INCLUDED

View file

@ -11,159 +11,64 @@
#include "cleanup.hpp" #include "cleanup.hpp"
#include "config.hpp" #include "config.hpp"
#include "detail/function.hpp" #include "detail/mock_impl.hpp"
#include "detail/functor.hpp"
#include "detail/parameter.hpp"
#include "detail/signature.hpp"
#include "detail/type_name.hpp"
#include "object.hpp" #include "object.hpp"
#include "reset.hpp" #include "reset.hpp"
#include "verify.hpp" #include "verify.hpp"
#include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/preprocessor/stringize.hpp>
/// MOCK_CLASS( name ) /// MOCK_CLASS( name )
/// Define a class /// Define a class
#define MOCK_CLASS(T) struct T : mock::object #define MOCK_CLASS(name) struct name : mock::object
/// MOCK_PROTECT_FUNCTION_SIG( signature )
/// Use this with MOCK_FUNCTION/MOCK_*_METHOD if the return type contains commas
#define MOCK_PROTECT_FUNCTION_SIG(...) mock::detail::parameter_type_t<void(__VA_ARGS__)>
/// Internal compatibility macro if function signature is passed via BOOST_IDENTITY_TYPE
/// TODO: Remove support for doing that and move remove_pointer_t to MOCK_PROTECT_FUNCTION_SIG
#define MOCK_FUNCTION_TYPE(...) std::remove_pointer_t<__VA_ARGS__>
/// MOCK_BASE_CLASS( name, base ) /// MOCK_BASE_CLASS( name, base )
/// Define a class deriving from a base class /// Define a class deriving from a base class
#define MOCK_BASE_CLASS(T, ...) struct T : __VA_ARGS__, mock::object, mock::detail::base<__VA_ARGS__> #define MOCK_BASE_CLASS(name, ...) struct name : __VA_ARGS__, mock::object, mock::detail::base<__VA_ARGS__>
/// MOCK_PROTECT_SIGNATURE( signature )
/// Use this with MOCK_FUNCTION/MOCK_*_METHOD if the return type contains commas
#define MOCK_PROTECT_SIGNATURE(...) mock::detail::unwrap_signature_t<void(__VA_ARGS__)>
/// MOCK_FUNCTOR( name, signature ) /// MOCK_FUNCTOR( name, signature )
/// Define a callable variable/member /// Define a callable variable/member
#define MOCK_FUNCTOR(f, ...) mock::detail::functor<MOCK_FUNCTION_TYPE(__VA_ARGS__)> f, f##_mock #define MOCK_FUNCTOR(name, ...) mock::detail::functor<__VA_ARGS__> name, name##_mock
/// MOCK_FUNCTOR_TPL( name, signature )
#define MOCK_FUNCTOR_TPL(f, ...) static_assert(false, "MOCK_FUNCTOR_TPL has been replaced by MOCK_FUNCTOR")
#define MOCK_HELPER(t) t##_mock(mock::detail::root, BOOST_PP_STRINGIZE(t))
#define MOCK_ANONYMOUS_HELPER(t) t##_mock(mock::detail::root, "?.")
#define MOCK_METHOD_HELPER(S, t) \
mutable mock::detail::function<MOCK_FUNCTION_TYPE(S)> t##_mock_; \
mock::detail::function<MOCK_FUNCTION_TYPE(S)>& t##_mock(const mock::detail::context&, \
const boost::unit_test::const_string& instance) const \
{ \
mock::detail::configure(*this, \
t##_mock_, \
instance.substr(0, instance.rfind(BOOST_PP_STRINGIZE(t))), \
mock::detail::make_type_name(*this), \
BOOST_PP_STRINGIZE(t)); \
return t##_mock_; \
}
#define MOCK_PARAM(S, tpn) tpn mock::detail::parameter < MOCK_FUNCTION_TYPE(S)
#define MOCK_DECL_PARAM(z, n, d) BOOST_PP_COMMA_IF(n) d, n > ::type p##n
#define MOCK_DECL_PARAMS(n, S, tpn) BOOST_PP_REPEAT(n, MOCK_DECL_PARAM, MOCK_PARAM(S, tpn))
#define MOCK_DECL(M, n, S, c, tpn) \
tpn mock::detail::result_type<MOCK_FUNCTION_TYPE(S)>::type M(MOCK_DECL_PARAMS(n, S, tpn)) c
#define MOCK_FORWARD_PARAM(z, n, d) BOOST_PP_COMMA_IF(n) d, n > ::type > (p##n)
#define MOCK_FORWARD_PARAMS(n, S, tpn) BOOST_PP_REPEAT(n, MOCK_FORWARD_PARAM, std::forward < MOCK_PARAM(S, tpn))
#define MOCK_METHOD_AUX(M, n, S, t, c, tpn) \
MOCK_DECL(M, n, S, c, tpn) \
{ \
static_assert(n == mock::detail::function_arity<MOCK_FUNCTION_TYPE(S)>::value, "Arity mismatch"); \
return MOCK_ANONYMOUS_HELPER(t)(MOCK_FORWARD_PARAMS(n, S, tpn)); \
}
#define MOCK_METHOD_EXT(M, n, S, t) \
MOCK_METHOD_AUX(M, n, S, t, , ) \
MOCK_METHOD_AUX(M, n, S, t, const, ) \
MOCK_METHOD_HELPER(S, t)
#define MOCK_CONST_METHOD_EXT(M, n, S, t) \
MOCK_METHOD_AUX(M, n, S, t, const, ) \
MOCK_METHOD_HELPER(S, t)
#define MOCK_NON_CONST_METHOD_EXT(M, n, S, t) \
MOCK_METHOD_AUX(M, n, S, t, , ) \
MOCK_METHOD_HELPER(S, t)
#define MOCK_METHOD_EXT_TPL(M, n, S, t) \
MOCK_METHOD_AUX(M, n, S, t, , typename) \
MOCK_METHOD_AUX(M, n, S, t, const, typename) \
MOCK_METHOD_HELPER(S, t)
#define MOCK_CONST_METHOD_EXT_TPL(M, n, S, t) \
MOCK_METHOD_AUX(M, n, S, t, const, typename) \
MOCK_METHOD_HELPER(S, t)
#define MOCK_NON_CONST_METHOD_EXT_TPL(M, n, S, t) \
MOCK_METHOD_AUX(M, n, S, t, , typename) \
MOCK_METHOD_HELPER(S, t)
/// MOCK_CONVERSION_OPERATOR( [calling convention] name, type, identifier ) /// MOCK_CONVERSION_OPERATOR( [calling convention] name, type, identifier )
/// generates both const and non-const operators /// generates both const and non-const conversion operators
#define MOCK_CONVERSION_OPERATOR(M, T, t) \ #define MOCK_CONVERSION_OPERATOR(M, T, identifier) \
M T() const { return MOCK_ANONYMOUS_HELPER(t)(); } \ M T() const { return MOCK_ANONYMOUS_HELPER(identifier)(); } \
M T() { return MOCK_ANONYMOUS_HELPER(t)(); } \ M T() { return MOCK_ANONYMOUS_HELPER(identifier)(); } \
MOCK_METHOD_HELPER(T(), t) MOCK_METHOD_HELPER(T(), identifier)
/// MOCK_CONST_CONVERSION_OPERATOR( [calling convention] name, type, identifier ) /// MOCK_CONST_CONVERSION_OPERATOR( [calling convention] name, type, identifier )
/// generates only a const operator /// generates only a const conversion operator
#define MOCK_CONST_CONVERSION_OPERATOR(M, T, t) \ #define MOCK_CONST_CONVERSION_OPERATOR(M, T, identifier) \
M T() const { return MOCK_ANONYMOUS_HELPER(t)(); } \ M T() const { return MOCK_ANONYMOUS_HELPER(identifier)(); } \
MOCK_METHOD_HELPER(T(), t) MOCK_METHOD_HELPER(T(), identifier)
/// MOCK_NON_CONST_CONVERSION_OPERATOR( [calling convention] name, type, identifier ) /// MOCK_NON_CONST_CONVERSION_OPERATOR( [calling convention] name, type, identifier )
/// generates only a non-const operator /// generates only a non-const conversion operator
#define MOCK_NON_CONST_CONVERSION_OPERATOR(M, T, t) \ #define MOCK_NON_CONST_CONVERSION_OPERATOR(M, T, identifier) \
M T() { return MOCK_ANONYMOUS_HELPER(t)(); } \ M T() { return MOCK_ANONYMOUS_HELPER(identifier)(); } \
MOCK_METHOD_HELPER(T(), t) MOCK_METHOD_HELPER(T(), identifier)
#define MOCK_CONVERSION_OPERATOR_TPL(M, T, t) MOCK_CONVERSION_OPERATOR(M, T, t)
#define MOCK_CONST_CONVERSION_OPERATOR_TPL(M, T, t) MOCK_CONST_CONVERSION_OPERATOR(M, T, t)
#define MOCK_NON_CONST_CONVERSION_OPERATOR_TPL(M, T, t) MOCK_NON_CONST_CONVERSION_OPERATOR(M, T, t)
#define MOCK_FUNCTION_HELPER(S, t, s, tpn) \
s mock::detail::function<MOCK_FUNCTION_TYPE(S)>& t##_mock(mock::detail::context& context, \
boost::unit_test::const_string instance) \
{ \
static mock::detail::function<MOCK_FUNCTION_TYPE(S)> f; \
return f(context, instance); \
}
#define MOCK_CONSTRUCTOR_AUX(T, n, A, t, tpn) \
T(MOCK_DECL_PARAMS(n, void A, tpn)) { MOCK_HELPER(t)(MOCK_FORWARD_PARAMS(n, void A, tpn)); } \
MOCK_FUNCTION_HELPER(void A, t, static, tpn)
/// MOCK_CONSTRUCTOR( [calling convention] name, arity, parameters, identifier ) /// MOCK_CONSTRUCTOR( [calling convention] name, arity, parameters, identifier )
/// As constructors do not have a return type, the usual signature gets restricted here to just the parameters. /// As constructors do not have a return type, the usual signature gets restricted here to just the parameters.
#define MOCK_CONSTRUCTOR(T, n, A, t) MOCK_CONSTRUCTOR_AUX(T, n, A, t, ) #define MOCK_CONSTRUCTOR(T, arity, parameters, identifier) MOCK_CONSTRUCTOR_AUX(T, arity, parameters, identifier)
/// MOCK_CONSTRUCTOR( [calling convention] name, arity, parameters, identifier )
/// must be used if the signature uses a template parameter of the class
/// As constructors do not have a return type, the usual signature gets restricted here to just the parameters.
#define MOCK_CONSTRUCTOR_TPL(T, n, A, t) MOCK_CONSTRUCTOR_AUX(T, n, A, t, typename)
/// MOCK_DESTRUCTOR( [calling convention] ~name, identifier ) /// MOCK_DESTRUCTOR( [calling convention] ~name, identifier )
#define MOCK_DESTRUCTOR(T, t) \ #define MOCK_DESTRUCTOR(T, identifier) \
T() \ T() \
{ \ { \
try \ try \
{ \ { \
MOCK_ANONYMOUS_HELPER(t)(); \ MOCK_ANONYMOUS_HELPER(identifier)(); \
} catch(...) \ } catch(...) \
{} \ {} \
} \ } \
MOCK_METHOD_HELPER(void(), t) MOCK_METHOD_HELPER(void(), identifier)
#define MOCK_FUNCTION_AUX(F, n, S, t, s, tpn) \
MOCK_FUNCTION_HELPER(S, t, s, tpn) \
s MOCK_DECL(F, n, S, , tpn) \
{ \
static_assert(n == mock::detail::function_arity<MOCK_FUNCTION_TYPE(S)>::value, "Arity mismatch"); \
return MOCK_HELPER(t)(MOCK_FORWARD_PARAMS(n, S, tpn)); \
}
#define MOCK_VARIADIC_ELEM_0(e0, ...) e0
#define MOCK_VARIADIC_ELEM_1(e0, e1, ...) e1
#define MOCK_VARIADIC_ELEM_2(e0, e1, e2, ...) e2
/// MOCK_METHOD( [calling convention] name, arity[, signature[, identifier]] ) /// MOCK_METHOD( [calling convention] name, arity[, signature[, identifier]] )
/// generates both const and non-const methods /// generates both const and non-const methods
/// The 'signature' can be omitted if it can be uniquely identified from the base class
/// if 'identifier' is omitted it will default to 'name'
#define MOCK_METHOD(M, ...) \ #define MOCK_METHOD(M, ...) \
MOCK_METHOD_EXT(M, \ MOCK_METHOD_EXT(M, \
MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \ MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \
@ -171,6 +76,8 @@
MOCK_VARIADIC_ELEM_2(__VA_ARGS__, M, M, )) MOCK_VARIADIC_ELEM_2(__VA_ARGS__, M, M, ))
/// MOCK_CONST_METHOD( [calling convention] name, arity[, signature[, identifier]] ) /// MOCK_CONST_METHOD( [calling convention] name, arity[, signature[, identifier]] )
/// generates only the const version of the method /// generates only the const version of the method
/// The 'signature' can be omitted if it can be uniquely identified from the base class
/// if 'identifier' is omitted it will default to 'name'
#define MOCK_CONST_METHOD(M, ...) \ #define MOCK_CONST_METHOD(M, ...) \
MOCK_CONST_METHOD_EXT(M, \ MOCK_CONST_METHOD_EXT(M, \
MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \ MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \
@ -178,50 +85,32 @@
MOCK_VARIADIC_ELEM_2(__VA_ARGS__, M, M, )) MOCK_VARIADIC_ELEM_2(__VA_ARGS__, M, M, ))
/// MOCK_NON_CONST_METHOD( [calling convention] name, arity[, signature[, identifier]] ) /// MOCK_NON_CONST_METHOD( [calling convention] name, arity[, signature[, identifier]] )
/// generates only the non-const version of the method /// generates only the non-const version of the method
/// The 'signature' can be omitted if it can be uniquely identified from the base class
/// if 'identifier' is omitted it will default to 'name'
#define MOCK_NON_CONST_METHOD(M, ...) \ #define MOCK_NON_CONST_METHOD(M, ...) \
MOCK_NON_CONST_METHOD_EXT(M, \ MOCK_NON_CONST_METHOD_EXT(M, \
MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \ MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, MOCK_SIGNATURE(M), ), \ MOCK_VARIADIC_ELEM_1(__VA_ARGS__, MOCK_SIGNATURE(M), ), \
MOCK_VARIADIC_ELEM_2(__VA_ARGS__, M, M, )) MOCK_VARIADIC_ELEM_2(__VA_ARGS__, M, M, ))
/// 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
#define MOCK_METHOD_TPL(M, n, ...) \
MOCK_METHOD_EXT_TPL(M, n, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), MOCK_VARIADIC_ELEM_1(__VA_ARGS__, M, ))
/// 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
#define MOCK_CONST_METHOD_TPL(M, n, ...) \
MOCK_CONST_METHOD_EXT_TPL(M, n, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), MOCK_VARIADIC_ELEM_1(__VA_ARGS__, M, ))
/// 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
#define MOCK_NON_CONST_METHOD_TPL(M, n, ...) \
MOCK_NON_CONST_METHOD_EXT_TPL(M, n, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), MOCK_VARIADIC_ELEM_1(__VA_ARGS__, M, ))
/// MOCK_FUNCTION( [calling convention] name, arity, signature[, identifier] ) /// MOCK_FUNCTION( [calling convention] name, arity, signature[, identifier] )
/// if 'identifier' is omitted it will default to 'name' /// if 'identifier' is omitted it will default to 'name'
#define MOCK_FUNCTION(F, n, ...) \ #define MOCK_FUNCTION(F, arity, ...) \
MOCK_FUNCTION_AUX(F, n, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F, ), inline, ) MOCK_FUNCTION_AUX(F, arity, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F, ), inline)
/// MOCK_STATIC_METHOD( [calling convention] name, arity, signature[, identifier] ) /// MOCK_STATIC_METHOD( [calling convention] name, arity, signature[, identifier] )
/// if 'identifier' is omitted it will default to 'name' /// if 'identifier' is omitted it will default to 'name'
#define MOCK_STATIC_METHOD(F, n, ...) \ #define MOCK_STATIC_METHOD(F, arity, ...) \
MOCK_FUNCTION_AUX(F, n, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F, ), static, ) MOCK_FUNCTION_AUX(F, arity, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F, ), static)
/// 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'
#define MOCK_STATIC_METHOD_TPL(F, n, ...) \
MOCK_FUNCTION_AUX( \
F, n, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F, ), static, typename)
/// MOCK_EXPECT( identifier ) /// MOCK_EXPECT( identifier )
#define MOCK_EXPECT(t) MOCK_HELPER(t).expect(__FILE__, __LINE__) /// Begin setting up expectation for the identifier
#define MOCK_EXPECT(identifier) MOCK_HELPER(identifier).expect(__FILE__, __LINE__)
/// MOCK_RESET( identifier ) /// MOCK_RESET( identifier )
#define MOCK_RESET(t) MOCK_HELPER(t).reset(__FILE__, __LINE__) /// Reset all pending expectations for the identifier
#define MOCK_RESET(identifier) MOCK_HELPER(identifier).reset(__FILE__, __LINE__)
/// MOCK_VERIFY( identifier ) /// MOCK_VERIFY( identifier )
#define MOCK_VERIFY(t) MOCK_HELPER(t).verify(__FILE__, __LINE__) /// Verify all expectations for the identifier have been met
#define MOCK_VERIFY(identifier) MOCK_HELPER(identifier).verify(__FILE__, __LINE__)
#endif // MOCK_MOCK_HPP_INCLUDED #endif // MOCK_MOCK_HPP_INCLUDED

View file

@ -6,21 +6,87 @@
// (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/detail/signature.hpp> #include <turtle/mock.hpp>
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include <map>
#include <type_traits> #include <type_traits>
namespace { namespace {
struct base struct base
{ {
void method_1(); void method_1();
float method_2(int) const; float method_2(int);
// Using templates in result and argument types
std::map<int, float> method_3(std::map<int, int>, short);
// Qualified methods
float qual_1(int) &;
float qual_2(int) &&;
float qual_3(int) const;
float qual_4(int) const&;
float qual_5(int) const&&;
float qual_6(int) volatile;
float qual_7(int) volatile&;
float qual_8(int) volatile&&;
float qual_9(int) const volatile;
float qual_10(int) const volatile&;
float qual_11(int) const volatile&&;
}; };
typedef base base_type;
} // namespace } // namespace
BOOST_AUTO_TEST_CASE(mock_signature_generates_signature) BOOST_AUTO_TEST_CASE(signature_traits_return_correct_values)
{ {
using function1 = void();
static_assert(std::is_same<mock::detail::result_type_t<function1>, void>::value, "!");
static_assert(mock::detail::function_arity_t<function1>::value == 0, "!");
using function2 = float(int);
static_assert(std::is_same<mock::detail::result_type_t<function2>, float>::value, "!");
static_assert(mock::detail::function_arity_t<function2>::value == 1, "!");
static_assert(std::is_same<mock::detail::parameter_t<function2, 0>, int>::value, "!");
using function3 = unsigned(short&, int, const char*, float, double, char, unsigned char, std::map<int, char>);
static_assert(std::is_same<mock::detail::result_type_t<function3>, unsigned>::value, "!");
static_assert(mock::detail::function_arity_t<function3>::value == 8, "!");
static_assert(std::is_same<mock::detail::parameter_t<function3, 0>, short&>::value, "!");
static_assert(std::is_same<mock::detail::parameter_t<function3, 1>, int>::value, "!");
static_assert(std::is_same<mock::detail::parameter_t<function3, 2>, const char*>::value, "!");
static_assert(std::is_same<mock::detail::parameter_t<function3, 3>, float>::value, "!");
static_assert(std::is_same<mock::detail::parameter_t<function3, 4>, double>::value, "!");
static_assert(std::is_same<mock::detail::parameter_t<function3, 5>, char>::value, "!");
static_assert(std::is_same<mock::detail::parameter_t<function3, 6>, unsigned char>::value, "!");
static_assert(std::is_same<mock::detail::parameter_t<function3, 7>, std::map<int, char>>::value, "!");
}
BOOST_AUTO_TEST_CASE(MOCK_SIGNATURE_generates_signature)
{
using base_type = base; // MOCK_SIGNATURE requires a visible base_type typedef in the current scope
static_assert(std::is_same<void(), MOCK_SIGNATURE(method_1)>::value, "!"); static_assert(std::is_same<void(), MOCK_SIGNATURE(method_1)>::value, "!");
static_assert(std::is_same<float(int), MOCK_SIGNATURE(method_2)>::value, "!"); static_assert(std::is_same<float(int), MOCK_SIGNATURE(method_2)>::value, "!");
static_assert(std::is_same<std::map<int, float>(std::map<int, int>, short), MOCK_SIGNATURE(method_3)>::value, "!");
static_assert(std::is_same<float(int), MOCK_SIGNATURE(qual_1)>::value, "!");
static_assert(std::is_same<float(int), MOCK_SIGNATURE(qual_2)>::value, "!");
static_assert(std::is_same<float(int), MOCK_SIGNATURE(qual_3)>::value, "!");
static_assert(std::is_same<float(int), MOCK_SIGNATURE(qual_4)>::value, "!");
static_assert(std::is_same<float(int), MOCK_SIGNATURE(qual_5)>::value, "!");
static_assert(std::is_same<float(int), MOCK_SIGNATURE(qual_6)>::value, "!");
static_assert(std::is_same<float(int), MOCK_SIGNATURE(qual_7)>::value, "!");
static_assert(std::is_same<float(int), MOCK_SIGNATURE(qual_8)>::value, "!");
static_assert(std::is_same<float(int), MOCK_SIGNATURE(qual_9)>::value, "!");
static_assert(std::is_same<float(int), MOCK_SIGNATURE(qual_10)>::value, "!");
static_assert(std::is_same<float(int), MOCK_SIGNATURE(qual_11)>::value, "!");
}
BOOST_AUTO_TEST_CASE(MOCK_PROTECT_SIGNATURE_keeps_signature)
{
// MOCK_PROTECT_SIGNATURE is basically a no-op regarding its argument
// and only required to get it through a VAR_ARGS macro
// clang-format off
static_assert(std::is_same<void(), MOCK_PROTECT_SIGNATURE(
void())>::value, "!");
static_assert(std::is_same<float*(int*), MOCK_PROTECT_SIGNATURE(
float*(int*))>::value, "!");
static_assert(std::is_same<std::map<int, float>(std::map<int, int>, short), MOCK_PROTECT_SIGNATURE(
std::map<int, float>(std::map<int, int>, short))>::value, "!");
// clang-format on
} }

View file

@ -10,7 +10,7 @@
MOCK_CLASS(my_class) MOCK_CLASS(my_class)
{ {
MOCK_METHOD_EXT(my_method, 1, void(int), my_method) MOCK_METHOD(my_method, 1, void(int), my_method)
}; };
bool constraint(int, int) bool constraint(int, int)
{ {

View file

@ -10,7 +10,7 @@
MOCK_CLASS(my_class) MOCK_CLASS(my_class)
{ {
MOCK_METHOD_EXT(my_method, 1, void(int), my_method) MOCK_METHOD(my_method, 1, void(int), my_method)
}; };
void test_case() void test_case()
{ {

View file

@ -10,7 +10,7 @@
MOCK_CLASS(my_class) MOCK_CLASS(my_class)
{ {
MOCK_METHOD_EXT(my_method, 1, void(int), my_method) MOCK_METHOD(my_method, 1, void(int), my_method)
}; };
void test_case() void test_case()
{ {

View file

@ -10,7 +10,7 @@
MOCK_CLASS(my_class) MOCK_CLASS(my_class)
{ {
MOCK_METHOD_EXT(my_method, 0, int(), my_method) MOCK_METHOD(my_method, 0, int(), my_method)
}; };
void test_case() void test_case()
{ {

View file

@ -10,7 +10,7 @@
MOCK_CLASS(my_class) MOCK_CLASS(my_class)
{ {
MOCK_METHOD_EXT(my_method, 0, std::string(), my_method) MOCK_METHOD(my_method, 0, std::string(), my_method)
}; };
void test_case() void test_case()
{ {

View file

@ -10,7 +10,7 @@
MOCK_CLASS(my_class) MOCK_CLASS(my_class)
{ {
MOCK_METHOD_EXT(my_method, 0, void(), my_method) MOCK_METHOD(my_method, 0, void(), my_method)
}; };
void test_case() void test_case()
{ {

View file

@ -10,7 +10,7 @@
MOCK_CLASS(my_class) MOCK_CLASS(my_class)
{ {
MOCK_METHOD_EXT(my_method, 1, void(int), my_method) MOCK_METHOD(my_method, 1, void(int), my_method)
}; };
void test_case() void test_case()
{ {

View file

@ -15,6 +15,7 @@
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>
/// Container to hold data about mocked function calls (and expectation errors)
struct mock_error_data_t : mock::detail::singleton<mock_error_data_t> struct mock_error_data_t : mock::detail::singleton<mock_error_data_t>
{ {
void reset() void reset()
@ -41,16 +42,15 @@ struct mock_error_data_t : mock::detail::singleton<mock_error_data_t>
++error_count; ++error_count;
} }
int error_count; int call_count = 0;
int call_count; int error_count = 0;
std::string last_message; std::string last_message, last_context, last_file;
std::string last_context; int last_line = 0;
std::string last_file;
int last_line;
MOCK_SINGLETON_CONS(mock_error_data_t); MOCK_SINGLETON_CONS(mock_error_data_t);
}; };
MOCK_SINGLETON_INST(mock_error_data) MOCK_SINGLETON_INST(mock_error_data)
/// Error handler that populates the mock_error_data singleton instead of failing
template<typename Result> template<typename Result>
struct mock_error struct mock_error
{ {
@ -73,6 +73,8 @@ struct mock_error
} }
}; };
/// Fixture to use CHECK_CALLS & CHECK_ERROR: Initializes the mock_error_data singleton
/// Verifies there are no pending verifications on end of the test
struct mock_error_fixture struct mock_error_fixture
{ {
mock_error_fixture() { mock_error_data.reset(); } mock_error_fixture() { mock_error_data.reset(); }
@ -83,9 +85,15 @@ struct mock_error_fixture
} }
}; };
/// Check that the number of calls to mocked function equals the given amount
/// and resets them (for the next check and cleanup)
#define CHECK_CALLS(calls) \ #define CHECK_CALLS(calls) \
BOOST_CHECK_EQUAL(calls, mock_error_data.call_count); \ BOOST_CHECK_EQUAL(calls, mock_error_data.call_count); \
mock_error_data.call_count = 0; mock_error_data.call_count = 0;
/// Similar to BOOST_CHECK_THROW:
/// Checks that running `expr` leads to an error of the set expectations,
/// that the error message equals `error`, with the given `context`
/// and `calls` mocked functions were called.
#define CHECK_ERROR(expr, error, calls, context) \ #define CHECK_ERROR(expr, error, calls, context) \
BOOST_CHECK(mock_error_data.verify()); \ BOOST_CHECK(mock_error_data.verify()); \
try \ try \

View file

@ -17,7 +17,7 @@
namespace { namespace {
struct my_custom_mock struct my_custom_mock
{ {
MOCK_METHOD_EXT(my_method, 0, void(), my_tag) MOCK_METHOD(my_method, 0, void(), my_tag)
}; };
} // namespace } // namespace
@ -32,7 +32,7 @@ BOOST_FIXTURE_TEST_CASE(custom_mock_object_without_macros_and_without_inheriting
namespace { namespace {
struct my_custom_mock_object struct my_custom_mock_object
{ {
MOCK_METHOD_EXT(my_method, 0, void(), my_tag) MOCK_METHOD(my_method, 0, void(), my_tag)
}; };
} // namespace } // namespace
@ -47,7 +47,7 @@ BOOST_FIXTURE_TEST_CASE(custom_mock_object_without_macros, mock_error_fixture)
namespace { namespace {
MOCK_CLASS(my_mock) MOCK_CLASS(my_mock)
{ {
MOCK_METHOD_EXT(my_method, 1, int(int), my_tag) MOCK_METHOD(my_method, 1, int(int), my_tag)
}; };
} // namespace } // namespace
@ -89,8 +89,8 @@ public:
MOCK_BASE_CLASS(my_ambiguited_mock, my_ambiguited_interface) MOCK_BASE_CLASS(my_ambiguited_mock, my_ambiguited_interface)
{ {
MOCK_METHOD_EXT(my_method, 0, void(), my_tag1) MOCK_METHOD(my_method, 0, void(), my_tag1)
MOCK_METHOD_EXT(my_method, 1, void(int), my_tag_2) MOCK_METHOD(my_method, 1, void(int), my_tag_2)
}; };
} // namespace } // namespace
@ -116,8 +116,8 @@ public:
MOCK_BASE_CLASS(my_const_ambiguited_mock, my_const_ambiguited_interface) MOCK_BASE_CLASS(my_const_ambiguited_mock, my_const_ambiguited_interface)
{ {
MOCK_NON_CONST_METHOD_EXT(my_method, 0, void(), tag1) MOCK_NON_CONST_METHOD(my_method, 0, void(), tag1)
MOCK_CONST_METHOD_EXT(my_method, 0, void(), tag_2) MOCK_CONST_METHOD(my_method, 0, void(), tag_2)
}; };
} // namespace } // namespace
@ -133,7 +133,7 @@ BOOST_FIXTURE_TEST_CASE(mock_object_method_const_disambiguation, mock_error_fixt
namespace { namespace {
MOCK_CLASS(my_undefined_mock) MOCK_CLASS(my_undefined_mock)
{ {
MOCK_METHOD_EXT(m, 1, void(undefined&), t) MOCK_METHOD(m, 1, void(undefined&), t)
}; };
} // namespace } // namespace
@ -186,9 +186,9 @@ namespace {
template<typename T> template<typename T>
struct my_template_mock struct my_template_mock
{ {
MOCK_METHOD_EXT(my_method, 0, void(), my_tag) MOCK_METHOD(my_method, 0, void(), my_tag)
MOCK_METHOD_EXT_TPL(my_method, 2, void(T, std::string), my_tpl_tag) MOCK_METHOD(my_method, 2, void(T, std::string), my_tpl_tag)
MOCK_METHOD_EXT_TPL(my_other_method, 0, void(), my_other_tag) MOCK_METHOD(my_other_method, 0, void(), my_other_tag)
}; };
} // namespace } // namespace
@ -212,8 +212,8 @@ struct my_template_base_class
template<typename T> template<typename T>
MOCK_BASE_CLASS(my_template_base_class_mock, my_template_base_class<T>) MOCK_BASE_CLASS(my_template_base_class_mock, my_template_base_class<T>)
{ {
MOCK_METHOD_EXT_TPL(my_method, 1, void(T), my_method) MOCK_METHOD(my_method, 1, void(T), my_method)
MOCK_METHOD_EXT_TPL(my_other_method, 0, void(), my_other_method) MOCK_METHOD(my_other_method, 0, void(), my_other_method)
}; };
} // namespace } // namespace
@ -307,7 +307,7 @@ namespace {
template<typename T> template<typename T>
MOCK_CLASS(my_constructed_template_class) MOCK_CLASS(my_constructed_template_class)
{ {
MOCK_CONSTRUCTOR_TPL(my_constructed_template_class, 2, (T, const std::string&), constructor) MOCK_CONSTRUCTOR(my_constructed_template_class, 2, (T, const std::string&), constructor)
}; };
} // namespace } // namespace
@ -366,7 +366,7 @@ BOOST_FIXTURE_TEST_CASE(failed_sequence_in_mocked_destructor_does_not_throw, moc
namespace { namespace {
MOCK_CLASS(boost_optional) MOCK_CLASS(boost_optional)
{ {
MOCK_METHOD_EXT(method, 0, boost::optional<my_observer&>(), tag) MOCK_METHOD(method, 0, boost::optional<my_observer&>(), tag)
}; };
} // namespace } // namespace
@ -451,7 +451,7 @@ void nothing(T)
struct member_pointer_mock_class struct member_pointer_mock_class
{ {
MOCK_CONST_METHOD_EXT(my_method, 0, void(), my_method) MOCK_CONST_METHOD(my_method, 0, void(), my_method)
}; };
} // namespace } // namespace
@ -511,7 +511,7 @@ namespace {
template<typename T> template<typename T>
struct some_template_class struct some_template_class
{ {
MOCK_STATIC_METHOD_TPL(some_static_method, 1, void(T), some_static_method) MOCK_STATIC_METHOD(some_static_method, 1, void(T), some_static_method)
}; };
} // namespace } // namespace
@ -532,7 +532,7 @@ BOOST_FIXTURE_TEST_CASE(a_static_method_in_a_template_class_can_be_mocked, mock_
namespace { namespace {
MOCK_CLASS(mock_class) MOCK_CLASS(mock_class)
{ {
MOCK_METHOD_EXT(m, 0, void(), t); MOCK_METHOD(m, 0, void(), t);
}; };
} // namespace } // namespace
@ -550,7 +550,7 @@ BOOST_FIXTURE_TEST_CASE(resetting_referenced_mock_class_does_not_crash, mock_err
namespace { namespace {
MOCK_CLASS(mock_class2) MOCK_CLASS(mock_class2)
{ {
MOCK_METHOD_EXT(m, 0, mock_class2(), t); MOCK_METHOD(m, 0, mock_class2(), t);
}; };
} // namespace } // namespace
@ -646,8 +646,8 @@ BOOST_FIXTURE_TEST_CASE(mock_class_is_thread_safe, mock_error_fixture)
namespace { namespace {
MOCK_CLASS(my_multi_mock) MOCK_CLASS(my_multi_mock)
{ {
MOCK_METHOD_EXT(m1, 1, void(int), m1); MOCK_METHOD(m1, 1, void(int), m1);
MOCK_METHOD_EXT(m2, 2, void(int, int), m2); MOCK_METHOD(m2, 2, void(int, int), m2);
}; };
} // namespace } // namespace
@ -742,6 +742,6 @@ BOOST_FIXTURE_TEST_CASE(std_unique_ptr_argument_is_supported_in_retrieve_constra
struct my_unique_ptr_class struct my_unique_ptr_class
{ {
MOCK_CONSTRUCTOR(my_unique_ptr_class, 1, (std::unique_ptr<int>), constructor) MOCK_CONSTRUCTOR(my_unique_ptr_class, 1, (std::unique_ptr<int>), constructor)
MOCK_METHOD_EXT(m, 1, void(std::unique_ptr<int>), m) MOCK_METHOD(m, 1, void(std::unique_ptr<int>), m)
MOCK_STATIC_METHOD(ms, 1, void(std::unique_ptr<int>), ms) MOCK_STATIC_METHOD(ms, 1, void(std::unique_ptr<int>), ms)
}; };

View file

@ -16,8 +16,8 @@
namespace { namespace {
struct my_custom_mock struct my_custom_mock
{ {
MOCK_METHOD_EXT(method, MOCK_MAX_ARGS, void(BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, int)), tag) MOCK_METHOD(method, MOCK_MAX_ARGS, void(BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, int)), tag)
MOCK_METHOD_EXT(method2, MOCK_MAX_ARGS, int(BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, int)), tag_2) MOCK_METHOD(method2, MOCK_MAX_ARGS, int(BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, int)), tag_2)
}; };
} // namespace } // namespace

View file

@ -19,7 +19,7 @@ void my_function(T& t)
} }
MOCK_CLASS(mock_class) MOCK_CLASS(mock_class)
{ {
MOCK_METHOD_EXT(my_method, 1, void(const std::string&), my_tag) MOCK_METHOD(my_method, 1, void(const std::string&), my_tag)
}; };
} // namespace } // namespace
@ -34,7 +34,7 @@ BOOST_FIXTURE_TEST_CASE(mock_object_for_static_polymorphism, mock_error_fixture)
namespace { namespace {
MOCK_CLASS(mock_class_with_operator) MOCK_CLASS(mock_class_with_operator)
{ {
MOCK_CONST_METHOD_EXT(operator+=, 1, mock_class_with_operator &(int), addition) MOCK_CONST_METHOD(operator+=, 1, mock_class_with_operator &(int), addition)
}; };
} // namespace } // namespace
@ -64,7 +64,9 @@ BOOST_FIXTURE_TEST_CASE(mock_conversion_operator, mock_error_fixture)
namespace { namespace {
template<typename T> template<typename T>
MOCK_CLASS(mock_template_class_with_conversion_operator) MOCK_CLASS(mock_template_class_with_conversion_operator)
{ MOCK_CONVERSION_OPERATOR_TPL(operator, T, conversion) }; {
MOCK_CONVERSION_OPERATOR(operator, T, conversion)
};
} // namespace } // namespace
BOOST_FIXTURE_TEST_CASE(mock_template_conversion_operator, mock_error_fixture) BOOST_FIXTURE_TEST_CASE(mock_template_conversion_operator, mock_error_fixture)
@ -111,7 +113,7 @@ namespace {
template<typename T> template<typename T>
MOCK_CLASS(mock_template_class_with_const_conversion_operator) MOCK_CLASS(mock_template_class_with_const_conversion_operator)
{ {
MOCK_CONST_CONVERSION_OPERATOR_TPL(operator, T, conversion) MOCK_CONST_CONVERSION_OPERATOR(operator, T, conversion)
}; };
} // namespace } // namespace
@ -127,7 +129,7 @@ namespace {
template<typename T> template<typename T>
MOCK_CLASS(mock_template_class_with_non_const_conversion_operator) MOCK_CLASS(mock_template_class_with_non_const_conversion_operator)
{ {
MOCK_NON_CONST_CONVERSION_OPERATOR_TPL(operator, T, conversion) MOCK_NON_CONST_CONVERSION_OPERATOR(operator, T, conversion)
}; };
} // namespace } // namespace
@ -142,12 +144,12 @@ BOOST_FIXTURE_TEST_CASE(mock_template_non_const_conversion_operator, mock_error_
namespace { namespace {
MOCK_CLASS(my_mock) MOCK_CLASS(my_mock)
{ {
MOCK_CONST_METHOD_EXT(my_method, 1, void(int), my_method) MOCK_CONST_METHOD(my_method, 1, void(int), my_method)
MOCK_CONST_METHOD_EXT(my_method_2, 1, void(int), my_method_2) MOCK_CONST_METHOD(my_method_2, 1, void(int), my_method_2)
}; };
} // namespace } // namespace
BOOST_FIXTURE_TEST_CASE(MOCK_CONST_METHOD_EXT_macro_defines_a_bindable_method, mock_error_fixture) BOOST_FIXTURE_TEST_CASE(MOCK_CONST_METHOD_macro_defines_a_bindable_method, mock_error_fixture)
{ {
my_mock m; my_mock m;
const auto f = std::bind(&my_mock::my_method, &m, 42); const auto f = std::bind(&my_mock::my_method, &m, 42);
@ -216,8 +218,8 @@ BOOST_FIXTURE_TEST_CASE(mock_object_const_shared_pointer_is_named, mock_error_fi
namespace { namespace {
struct my_custom_mock struct my_custom_mock
{ {
MOCK_METHOD_EXT(my_method, 0, void(), my_tag) MOCK_METHOD(my_method, 0, void(), my_tag)
MOCK_METHOD_EXT(my_method_2, 0, void(), my_tag_2) MOCK_METHOD(my_method_2, 0, void(), my_tag_2)
}; };
} // namespace } // namespace
@ -236,8 +238,8 @@ BOOST_FIXTURE_TEST_CASE(custom_mock_object_without_macros_and_without_inheriting
namespace { namespace {
struct my_custom_mock_object : mock::object struct my_custom_mock_object : mock::object
{ {
MOCK_METHOD_EXT(my_method, 0, void(), my_tag) MOCK_METHOD(my_method, 0, void(), my_tag)
MOCK_METHOD_EXT(my_method_2, 0, void(), my_tag_2) MOCK_METHOD(my_method_2, 0, void(), my_tag_2)
}; };
} // namespace } // namespace
@ -310,11 +312,11 @@ BOOST_FIXTURE_TEST_CASE(mock_static_function_is_named, mock_error_fixture)
namespace { namespace {
MOCK_CLASS(round_parenthesized_signature) MOCK_CLASS(round_parenthesized_signature)
{ {
MOCK_METHOD_EXT(m0, 0, MOCK_PROTECT_FUNCTION_SIG(std::map<int, int>()), m0) MOCK_METHOD(m0, 0, MOCK_PROTECT_SIGNATURE(std::map<int, int>()), m0)
MOCK_STATIC_METHOD(m1, 0, MOCK_PROTECT_FUNCTION_SIG(std::map<int, int>()), m1) MOCK_STATIC_METHOD(m1, 0, MOCK_PROTECT_SIGNATURE(std::map<int, int>()), m1)
MOCK_FUNCTOR(f0, MOCK_PROTECT_FUNCTION_SIG(std::map<int, int>())); MOCK_FUNCTOR(f0, MOCK_PROTECT_SIGNATURE(std::map<int, int>()));
}; };
MOCK_FUNCTION(fun0, 0, MOCK_PROTECT_FUNCTION_SIG(std::map<int, int>()), fun0) MOCK_FUNCTION(fun0, 0, MOCK_PROTECT_SIGNATURE(std::map<int, int>()), fun0)
} // namespace } // namespace
namespace { namespace {
@ -346,14 +348,14 @@ template<typename T>
MOCK_BASE_CLASS(variadic_tpl, base) MOCK_BASE_CLASS(variadic_tpl, base)
{ {
MOCK_METHOD(m1, 0, void()) MOCK_METHOD(m1, 0, void())
MOCK_METHOD_TPL(m2, 0, T()) MOCK_METHOD(m2, 0, T())
MOCK_METHOD_TPL(m3, 0, T(), m3) MOCK_METHOD(m3, 0, T(), m3)
MOCK_CONST_METHOD_TPL(m4, 0, T()) MOCK_CONST_METHOD(m4, 0, T())
MOCK_CONST_METHOD_TPL(m5, 0, T(), m5) MOCK_CONST_METHOD(m5, 0, T(), m5)
MOCK_NON_CONST_METHOD_TPL(m6, 0, T()) MOCK_NON_CONST_METHOD(m6, 0, T())
MOCK_NON_CONST_METHOD_TPL(m7, 0, T(), m7) MOCK_NON_CONST_METHOD(m7, 0, T(), m7)
MOCK_STATIC_METHOD_TPL(m8, 0, T()) MOCK_STATIC_METHOD(m8, 0, T())
MOCK_STATIC_METHOD_TPL(m9, 0, T(), m9) MOCK_STATIC_METHOD(m9, 0, T(), m9)
}; };
MOCK_BASE_CLASS(comma_base, std::map<int, int>) MOCK_BASE_CLASS(comma_base, std::map<int, int>)
@ -361,7 +363,7 @@ MOCK_BASE_CLASS(comma_base, std::map<int, int>)
MOCK_FUNCTION(fun1, 0, void()) MOCK_FUNCTION(fun1, 0, void())
MOCK_FUNCTION(fun2, 0, void(), fun2) MOCK_FUNCTION(fun2, 0, void(), fun2)
MOCK_FUNCTION(fun3, 0, MOCK_PROTECT_FUNCTION_SIG(std::map<int, int>())) MOCK_FUNCTION(fun3, 0, MOCK_PROTECT_SIGNATURE(std::map<int, int>()))
MOCK_FUNCTOR(f_variadic, std::map<int, int>()); MOCK_FUNCTOR(f_variadic, std::map<int, int>());
} // namespace } // namespace
@ -385,8 +387,8 @@ MOCK_BASE_CLASS(derived, base)
MOCK_CONSTRUCTOR(MOCK_STDCALL derived, 0, (), derived) MOCK_CONSTRUCTOR(MOCK_STDCALL derived, 0, (), derived)
MOCK_DESTRUCTOR(MOCK_STDCALL ~derived, derived) MOCK_DESTRUCTOR(MOCK_STDCALL ~derived, derived)
MOCK_CONVERSION_OPERATOR(MOCK_STDCALL operator, int, to_int) MOCK_CONVERSION_OPERATOR(MOCK_STDCALL operator, int, to_int)
MOCK_METHOD_EXT(MOCK_STDCALL m1, 0, void(), m1) MOCK_METHOD(MOCK_STDCALL m1, 0, void(), m1)
MOCK_METHOD_EXT(MOCK_STDCALL m2, 0, void(), m2) MOCK_METHOD(MOCK_STDCALL m2, 0, void(), m2)
MOCK_METHOD(MOCK_STDCALL m3, 0, void(), m3) MOCK_METHOD(MOCK_STDCALL m3, 0, void(), m3)
MOCK_STATIC_METHOD(MOCK_STDCALL m4, 0, void(), m4) MOCK_STATIC_METHOD(MOCK_STDCALL m4, 0, void(), m4)
}; };