Add macros to StatementMacros

This commit is contained in:
Alexander Grund 2020-09-15 14:22:58 +02:00
parent e1ac66a4c1
commit 035ad716bf
No known key found for this signature in database
GPG key ID: E92C451FC21EF13F
35 changed files with 5224 additions and 1208 deletions

View file

@ -133,6 +133,26 @@ Standard: c++14
StatementMacros: StatementMacros:
- Q_UNUSED - Q_UNUSED
- QT_REQUIRE_VERSION - QT_REQUIRE_VERSION
- MOCK_CLASS
- MOCK_BASE_CLASS
- MOCK_CONSTRUCTOR
- MOCK_DESTRUCTOR
- MOCK_METHOD
- MOCK_CONST_METHOD
- MOCK_NON_CONST_METHOD
- MOCK_METHOD_EXT
- MOCK_CONST_METHOD_EXT
- MOCK_NON_CONST_METHOD_EXT
- MOCK_METHOD_TPL
- MOCK_CONST_METHOD_TPL
- MOCK_NON_CONST_METHOD_TPL
- MOCK_STATIC_METHOD
- MOCK_STATIC_METHOD_TPL
- MOCK_CONVERSION_OPERATOR
- MOCK_CONST_CONVERSION_OPERATOR
- MOCK_NON_CONST_CONVERSION_OPERATOR
- MOCK_CONST_CONVERSION_OPERATOR_TPL
- MOCK_NON_CONST_CONVERSION_OPERATOR_TPL
TabWidth: 8 TabWidth: 8
UseCRLF: false UseCRLF: false
UseTab: Never UseTab: Never

View file

@ -99,7 +99,10 @@ public:
}; };
//] //]
MOCK_BASE_CLASS(mock_view, view){ MOCK_METHOD(display, 1) }; MOCK_BASE_CLASS(mock_view, view)
{
MOCK_METHOD(display, 1)
};
class calculator class calculator
{ {

View file

@ -22,14 +22,16 @@ namespace limitations_comma_in_macro_solution_1 {
//[ limitations_comma_in_macro_solution_1 //[ limitations_comma_in_macro_solution_1
typedef my_base_class<int, int> my_base_type; typedef my_base_class<int, int> my_base_type;
MOCK_BASE_CLASS(my_mock, my_base_type){}; MOCK_BASE_CLASS(my_mock, my_base_type)
{};
//] //]
} // namespace limitations_comma_in_macro_solution_1 } // namespace limitations_comma_in_macro_solution_1
namespace limitations_comma_in_macro_solution_2 { namespace limitations_comma_in_macro_solution_2 {
//[ limitations_comma_in_macro_solution_2 //[ limitations_comma_in_macro_solution_2
template<typename T1, typename T2> template<typename T1, typename T2>
MOCK_BASE_CLASS(my_mock, my_base_class<T1 BOOST_PP_COMMA() T2>){}; MOCK_BASE_CLASS(my_mock, my_base_class<T1 BOOST_PP_COMMA() T2>)
{};
//] //]
} // namespace limitations_comma_in_macro_solution_2 } // namespace limitations_comma_in_macro_solution_2

View file

@ -34,10 +34,10 @@ void derived::method(int) {}
namespace limitations_const_parameter_warning_solution { namespace limitations_const_parameter_warning_solution {
//[ limitations_const_parameter_warning_solution //[ limitations_const_parameter_warning_solution
MOCK_BASE_CLASS(mock_base, base){ void method(const int i){ method_stub(i); MOCK_BASE_CLASS(mock_base, base)
} // namespace limitations_const_parameter_warning_solution {
MOCK_METHOD(method_stub, 1, void(int), method) void method(const int i) { method_stub(i); } // namespace limitations_const_parameter_warning_solution
} MOCK_METHOD(method_stub, 1, void(int), method)
; };
//] //]
} } // namespace limitations_const_parameter_warning_solution

View file

@ -18,7 +18,10 @@ public:
virtual void method(int* i) = 0; virtual void method(int* i) = 0;
}; };
MOCK_BASE_CLASS(mock_base, base){ MOCK_METHOD(method, 1) }; MOCK_BASE_CLASS(mock_base, base)
{
MOCK_METHOD(method, 1)
};
//] //]
} // namespace } // namespace

View file

@ -20,5 +20,8 @@ public:
//] //]
//[ limitations_non_virtual_method_problem_2 //[ limitations_non_virtual_method_problem_2
MOCK_BASE_CLASS(mock_base, base){ MOCK_METHOD(method, 0) }; MOCK_BASE_CLASS(mock_base, base)
{
MOCK_METHOD(method, 0)
};
//] //]

View file

@ -23,6 +23,10 @@ private:
//] //]
//[ limitations_protected_private_method_solution //[ limitations_protected_private_method_solution
MOCK_BASE_CLASS(mock_base, base){ MOCK_METHOD(method_1, 0, void()) MOCK_METHOD(method_2, 0, void()) }; MOCK_BASE_CLASS(mock_base, base)
{
MOCK_METHOD(method_1, 0, void())
MOCK_METHOD(method_2, 0, void())
};
//] //]
} // namespace } // namespace

View file

@ -24,6 +24,9 @@ public:
//[ limitations_template_base_class_method_solution //[ limitations_template_base_class_method_solution
template<typename T> template<typename T>
MOCK_BASE_CLASS(mock_base, base<T>){ MOCK_METHOD(method, 1, void()) }; MOCK_BASE_CLASS(mock_base, base<T>)
{
MOCK_METHOD(method, 1, void())
};
//] //]
} // namespace } // namespace

View file

@ -29,8 +29,11 @@ void function_under_test(T t) // T is supposed to model the previous concept
//] //]
//[ limitations_template_method_solution //[ limitations_template_method_solution
MOCK_CLASS(mock_concept){ MOCK_METHOD(method, 1, void(int), method_int) MOCK_CLASS(mock_concept)
MOCK_METHOD(method, 1, void(const char*), method_string) }; {
MOCK_METHOD(method, 1, void(int), method_int)
MOCK_METHOD(method, 1, void(const char*), method_string)
};
//] //]
} // namespace limitations_template_method_problem } // namespace limitations_template_method_problem

View file

@ -21,10 +21,10 @@ struct base_class
//] //]
//[ limitations_throw_specifier_solution //[ limitations_throw_specifier_solution
MOCK_BASE_CLASS(mock_class, base_class){ void method() throw(){ method_proxy(); MOCK_BASE_CLASS(mock_class, base_class)
} // namespace {
MOCK_METHOD(method_proxy, 0, void(), method) void method() throw() { method_proxy(); } // namespace
} MOCK_METHOD(method_proxy, 0, void(), method)
; };
//] //]
} } // namespace

View file

@ -17,6 +17,6 @@ MOCK_BASE_CLASS(mock_view, view) // declare a 'mock_view' class implementing 'vi
{ {
MOCK_METHOD(display, 1) // implement the 'display' method from 'view' (taking 1 argument) MOCK_METHOD(display, 1) // implement the 'display' method from 'view' (taking 1 argument)
}; };
//] //]
#endif // MOCK_VIEW #endif // MOCK_VIEW

View file

@ -43,7 +43,10 @@ void check(bool& condition, F flush, int attempts = 100, int sleep = 100)
} }
} }
MOCK_BASE_CLASS(mock_base_class, base_class){ MOCK_METHOD(method, 0) }; MOCK_BASE_CLASS(mock_base_class, base_class)
{
MOCK_METHOD(method, 0)
};
void set_bool(bool& b) void set_bool(bool& b)
{ {
b = true; b = true;

View file

@ -27,8 +27,11 @@ void function(base_class&); // the function will call 'method' with a functor to
#include <boost/test/auto_unit_test.hpp> #include <boost/test/auto_unit_test.hpp>
namespace { namespace {
MOCK_BASE_CLASS(mock_class, base_class){ MOCK_METHOD(method, 1) }; MOCK_BASE_CLASS(mock_class, base_class)
} {
MOCK_METHOD(method, 1)
};
} // namespace
BOOST_AUTO_TEST_CASE(how_to_invoke_a_functor_passed_as_parameter_of_a_mock_method) BOOST_AUTO_TEST_CASE(how_to_invoke_a_functor_passed_as_parameter_of_a_mock_method)
{ {

View file

@ -25,7 +25,8 @@ std::ostream& operator<<(std::ostream& os, const my_class& c) // my_class is ser
return os << "my_class( " << c.data_ << " )"; return os << "my_class( " << c.data_ << " )";
} }
MOCK_CLASS(my_mock){ MOCK_CLASS(my_mock)
{
MOCK_METHOD(method, 1, void(const my_class&)) // how to simply write a custom constraint ? MOCK_METHOD(method, 1, void(const my_class&)) // how to simply write a custom constraint ?
}; };
} // namespace } // namespace

View file

@ -31,8 +31,11 @@ public:
#include <boost/test/auto_unit_test.hpp> #include <boost/test/auto_unit_test.hpp>
namespace { namespace {
MOCK_BASE_CLASS(mock_base_class, base_class){ MOCK_METHOD(method, 1) }; MOCK_BASE_CLASS(mock_base_class, base_class)
} {
MOCK_METHOD(method, 1)
};
} // namespace
BOOST_AUTO_TEST_CASE(method_is_called_two_times_with_the_same_value) BOOST_AUTO_TEST_CASE(method_is_called_two_times_with_the_same_value)
{ {

View file

@ -12,7 +12,8 @@
namespace class_example_1 { namespace class_example_1 {
//[ class_example_1 //[ class_example_1
MOCK_CLASS(mock_class){}; MOCK_CLASS(mock_class)
{};
BOOST_AUTO_TEST_CASE(demonstrates_instantiating_a_mock_class) BOOST_AUTO_TEST_CASE(demonstrates_instantiating_a_mock_class)
{ {
@ -24,7 +25,8 @@ BOOST_AUTO_TEST_CASE(demonstrates_instantiating_a_mock_class)
namespace class_example_2 { namespace class_example_2 {
//[ class_example_2 //[ class_example_2
template<typename T> template<typename T>
MOCK_CLASS(mock_class){}; MOCK_CLASS(mock_class)
{};
BOOST_AUTO_TEST_CASE(demonstrates_instantiating_a_template_mock_class) BOOST_AUTO_TEST_CASE(demonstrates_instantiating_a_template_mock_class)
{ {
@ -38,7 +40,8 @@ namespace class_example_3 {
struct base_class struct base_class
{}; {};
MOCK_BASE_CLASS(mock_class, base_class){}; MOCK_BASE_CLASS(mock_class, base_class)
{};
BOOST_AUTO_TEST_CASE(demonstrates_instantiating_a_derived_mock_class) BOOST_AUTO_TEST_CASE(demonstrates_instantiating_a_derived_mock_class)
{ {
@ -54,7 +57,8 @@ struct base_class
{}; {};
template<typename T> template<typename T>
MOCK_BASE_CLASS(mock_class, base_class<T>){}; MOCK_BASE_CLASS(mock_class, base_class<T>)
{};
BOOST_AUTO_TEST_CASE(demonstrates_instantiating_a_template_derived_mock_class) BOOST_AUTO_TEST_CASE(demonstrates_instantiating_a_template_derived_mock_class)
{ {
@ -113,7 +117,8 @@ struct base_class
virtual void method(int) = 0; virtual void method(int) = 0;
}; };
MOCK_BASE_CLASS(mock_class, base_class){ MOCK_BASE_CLASS(mock_class, base_class)
{
MOCK_METHOD(method, 1) // only possible when referring unambiguously to a base class method MOCK_METHOD(method, 1) // only possible when referring unambiguously to a base class method
}; };
//] //]
@ -128,7 +133,8 @@ struct base_class
virtual void method(float) = 0; virtual void method(float) = 0;
}; };
MOCK_BASE_CLASS(mock_class, base_class){ MOCK_BASE_CLASS(mock_class, base_class)
{
MOCK_METHOD( MOCK_METHOD(
method, method,
2, 2,
@ -151,7 +157,8 @@ struct base_class
virtual void method(float) const = 0; virtual void method(float) const = 0;
}; };
MOCK_BASE_CLASS(mock_class, base_class){ MOCK_BASE_CLASS(mock_class, base_class)
{
MOCK_METHOD(method, 1, void(float)) // this generates both const and non-const versions MOCK_METHOD(method, 1, void(float)) // this generates both const and non-const versions
}; };
//] //]
@ -166,7 +173,8 @@ struct base_class
virtual void method(float) const = 0; virtual void method(float) const = 0;
}; };
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 MOCK_CONST_METHOD(method, 1, void(float), identifier_1) // this generates only the const version
MOCK_NON_CONST_METHOD(method, MOCK_NON_CONST_METHOD(method,
1, 1,
@ -195,7 +203,8 @@ struct mock_class : base_class
namespace member_function_example_6 { namespace member_function_example_6 {
//[ member_function_example_6 //[ member_function_example_6
MOCK_CLASS(mock_class){ MOCK_CLASS(mock_class)
{
MOCK_NON_CONST_METHOD(operator=, MOCK_NON_CONST_METHOD(operator=,
1, 1,
mock_class &(const mock_class&), mock_class &(const mock_class&),
@ -207,7 +216,8 @@ MOCK_CLASS(mock_class){
namespace member_function_example_7 { namespace member_function_example_7 {
//[ member_function_example_7 //[ member_function_example_7
template<typename T> template<typename T>
MOCK_CLASS(mock_class){ MOCK_CLASS(mock_class)
{
MOCK_METHOD_TPL( MOCK_METHOD_TPL(
method, method,
1, 1,
@ -218,10 +228,10 @@ MOCK_CLASS(mock_class){
namespace member_function_example_8 { namespace member_function_example_8 {
//[ member_function_example_8 //[ member_function_example_8
MOCK_CLASS(mock_class){ MOCK_CLASS(mock_class)
MOCK_METHOD(method, {
0, MOCK_METHOD(
BOOST_IDENTITY_TYPE((std::map<int, int>()))) // the signature must be wrapped in BOOST_IDENTITY_TYPE if method, 0, BOOST_IDENTITY_TYPE((std::map<int, int>()))) // the signature must be wrapped in BOOST_IDENTITY_TYPE if
// the return type contains a comma // the return type contains a comma
}; };
//] //]
@ -230,7 +240,8 @@ MOCK_CLASS(mock_class){
#ifdef BOOST_MSVC #ifdef BOOST_MSVC
namespace member_function_example_9 { 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, MOCK_METHOD(__stdcall method,
0, 0,
void(), void(),
@ -242,21 +253,28 @@ MOCK_CLASS(mock_class){
namespace static_member_function_example_1 { namespace static_member_function_example_1 {
//[ static_member_function_example_1 //[ static_member_function_example_1
MOCK_CLASS(mock_class){ MOCK_STATIC_METHOD(method, 1, float(int)) }; MOCK_CLASS(mock_class)
{
MOCK_STATIC_METHOD(method, 1, float(int))
};
//] //]
} // namespace static_member_function_example_1 } // namespace static_member_function_example_1
namespace static_member_function_example_2 { namespace static_member_function_example_2 {
//[ static_member_function_example_2 //[ static_member_function_example_2
template<typename T> template<typename T>
MOCK_CLASS(mock_class){ MOCK_STATIC_METHOD_TPL(method, 1, void(T)) }; MOCK_CLASS(mock_class)
{
MOCK_STATIC_METHOD_TPL(method, 1, void(T))
};
//] //]
} // namespace static_member_function_example_2 } // namespace static_member_function_example_2
#ifdef BOOST_MSVC #ifdef BOOST_MSVC
namespace static_member_function_example_3 { 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, MOCK_STATIC_METHOD(__stdcall method,
0, 0,
void(), void(),
@ -268,51 +286,70 @@ MOCK_CLASS(mock_class){
namespace constructor_example_1 { namespace constructor_example_1 {
//[ constructor_example_1 //[ constructor_example_1
MOCK_CLASS(mock_class){ MOCK_CONSTRUCTOR(mock_class, 2, (int, const std::string&), identifier) }; MOCK_CLASS(mock_class)
{
MOCK_CONSTRUCTOR(mock_class, 2, (int, const std::string&), identifier)
};
//] //]
} // namespace constructor_example_1 } // namespace constructor_example_1
namespace constructor_example_2 { namespace constructor_example_2 {
//[ constructor_example_2 //[ constructor_example_2
template<typename T> template<typename T>
MOCK_CLASS(mock_class){ MOCK_CONSTRUCTOR(mock_class, 2, (int, const std::string&), identifier) MOCK_CLASS(mock_class)
MOCK_CONSTRUCTOR_TPL(mock_class, 2, (T, const std::string&), identifier_2) }; {
MOCK_CONSTRUCTOR(mock_class, 2, (int, const std::string&), identifier)
MOCK_CONSTRUCTOR_TPL(mock_class, 2, (T, const std::string&), identifier_2)
};
//] //]
} // namespace constructor_example_2 } // namespace constructor_example_2
#ifdef BOOST_MSVC #ifdef BOOST_MSVC
namespace constructor_example_3 { namespace constructor_example_3 {
//[ constructor_example_3 //[ constructor_example_3
MOCK_CLASS(mock_class){ MOCK_CONSTRUCTOR(__stdcall mock_class, 0, (), constructor) }; MOCK_CLASS(mock_class)
{
MOCK_CONSTRUCTOR(__stdcall mock_class, 0, (), constructor)
};
//] //]
} // namespace constructor_example_3 } // namespace constructor_example_3
#endif #endif
namespace destructor_example_1 { namespace destructor_example_1 {
//[ destructor_example_1 //[ destructor_example_1
MOCK_CLASS(mock_class){ MOCK_DESTRUCTOR(~mock_class, destructor) }; MOCK_CLASS(mock_class)
{
MOCK_DESTRUCTOR(~mock_class, destructor)
};
//] //]
} // namespace destructor_example_1 } // namespace destructor_example_1
#ifdef BOOST_MSVC #ifdef BOOST_MSVC
namespace destructor_example_2 { namespace destructor_example_2 {
//[ destructor_example_2 //[ destructor_example_2
MOCK_CLASS(mock_class){ MOCK_DESTRUCTOR(__stdcall ~mock_class, destructor) }; MOCK_CLASS(mock_class)
{
MOCK_DESTRUCTOR(__stdcall ~mock_class, destructor)
};
//] //]
} // namespace destructor_example_2 } // namespace destructor_example_2
#endif #endif
namespace conversion_operator_example_1 { namespace conversion_operator_example_1 {
//[ conversion_operator_example_1 //[ conversion_operator_example_1
MOCK_CLASS(mock_class){ MOCK_CONVERSION_OPERATOR(operator, int, conversion_to_int) MOCK_CLASS(mock_class)
MOCK_CONST_CONVERSION_OPERATOR(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)
};
//] //]
} // namespace conversion_operator_example_1 } // namespace conversion_operator_example_1
namespace conversion_operator_example_2 { namespace conversion_operator_example_2 {
//[ conversion_operator_example_2 //[ 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_TPL(operator, T, conversion_to_T) // the _TPL variants must be used if the signature
// 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)
@ -324,7 +361,10 @@ MOCK_CLASS(mock_class){
#ifdef BOOST_MSVC #ifdef BOOST_MSVC
namespace conversion_operator_example_3 { namespace conversion_operator_example_3 {
//[ conversion_operator_example_3 //[ conversion_operator_example_3
MOCK_CLASS(mock_class){ MOCK_CONVERSION_OPERATOR(__stdcall operator, int, conversion_to_int) }; MOCK_CLASS(mock_class)
{
MOCK_CONVERSION_OPERATOR(__stdcall operator, int, conversion_to_int)
};
//] //]
} // namespace conversion_operator_example_3 } // namespace conversion_operator_example_3
#endif #endif
@ -379,8 +419,11 @@ BOOST_AUTO_TEST_CASE(demonstrates_instantiating_a_mock_functor)
namespace expectation_example_1 { namespace expectation_example_1 {
//[ expectation_example_1 //[ expectation_example_1
MOCK_CLASS(mock_class){ MOCK_METHOD(method, 1, int(int), method) MOCK_CLASS(mock_class)
MOCK_METHOD(method, 2, void(const std::string&, float), method2) }; {
MOCK_METHOD(method, 1, int(int), method)
MOCK_METHOD(method, 2, void(const std::string&, float), method2)
};
BOOST_AUTO_TEST_CASE(demonstrates_configuring_mock_objects) BOOST_AUTO_TEST_CASE(demonstrates_configuring_mock_objects)
{ {
@ -395,7 +438,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_configuring_mock_objects)
namespace invocation_example_1 { namespace invocation_example_1 {
//[ invocation_example_1 //[ invocation_example_1
MOCK_CLASS(mock_class){ MOCK_METHOD(method, 2, void(int, const std::string&)) }; MOCK_CLASS(mock_class)
{
MOCK_METHOD(method, 2, void(int, const std::string&))
};
BOOST_AUTO_TEST_CASE(demonstrates_setting_up_invocations_on_a_mock_method) BOOST_AUTO_TEST_CASE(demonstrates_setting_up_invocations_on_a_mock_method)
{ {
@ -429,7 +475,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_setting_up_an_invocation_on_a_mock_function)
namespace invocation_example_4 { namespace invocation_example_4 {
//[ invocation_example_4 //[ invocation_example_4
MOCK_CLASS(mock_class){ MOCK_STATIC_METHOD(method, 1, void(int)) }; MOCK_CLASS(mock_class)
{
MOCK_STATIC_METHOD(method, 1, void(int))
};
BOOST_AUTO_TEST_CASE(demonstrates_setting_up_an_invocation_on_a_mock_static_method) BOOST_AUTO_TEST_CASE(demonstrates_setting_up_an_invocation_on_a_mock_static_method)
{ {
@ -442,7 +491,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_setting_up_an_invocation_on_a_mock_static_meth
namespace constraints_example_1 { namespace constraints_example_1 {
//[ constraints_example_1 //[ constraints_example_1
MOCK_CLASS(mock_class){ MOCK_METHOD(method, 2, void(int, const std::string&)) }; MOCK_CLASS(mock_class)
{
MOCK_METHOD(method, 2, void(int, const std::string&))
};
BOOST_AUTO_TEST_CASE(demonstrates_adding_builtin_constraints) BOOST_AUTO_TEST_CASE(demonstrates_adding_builtin_constraints)
{ {
@ -455,7 +507,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_adding_builtin_constraints)
namespace constraints_example_2 { namespace constraints_example_2 {
//[ constraints_example_2 //[ constraints_example_2
MOCK_CLASS(mock_class){ MOCK_METHOD(method, 1, void(int)) }; MOCK_CLASS(mock_class)
{
MOCK_METHOD(method, 1, void(int))
};
bool custom_constraint(int actual) bool custom_constraint(int actual)
{ {
@ -472,7 +527,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_adding_a_custom_constraint_with_a_free_functio
namespace constraints_example_3 { namespace constraints_example_3 {
//[ constraints_example_3 //[ constraints_example_3
MOCK_CLASS(mock_class){ MOCK_METHOD(method, 1, void(int)) }; MOCK_CLASS(mock_class)
{
MOCK_METHOD(method, 1, void(int))
};
bool custom_constraint(int expected, int actual) bool custom_constraint(int expected, int actual)
{ {
@ -490,7 +548,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_adding_a_custom_constraint_with_a_standard_lib
namespace constraints_example_4 { namespace constraints_example_4 {
//[ constraints_example_4 //[ constraints_example_4
MOCK_CLASS(mock_class){ MOCK_METHOD(method, 1, void(int)) }; MOCK_CLASS(mock_class)
{
MOCK_METHOD(method, 1, void(int))
};
bool custom_constraint(int expected, int actual) bool custom_constraint(int expected, int actual)
{ {
@ -511,7 +572,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_adding_a_custom_constraint_with_boost_bind)
namespace constraints_example_5 { namespace constraints_example_5 {
//[ constraints_example_5 //[ constraints_example_5
MOCK_CLASS(mock_class){ MOCK_METHOD(method, 1, void(int)) }; MOCK_CLASS(mock_class)
{
MOCK_METHOD(method, 1, void(int))
};
BOOST_AUTO_TEST_CASE(demonstrates_adding_a_custom_constraint_with_boost_lambda) BOOST_AUTO_TEST_CASE(demonstrates_adding_a_custom_constraint_with_boost_lambda)
{ {
@ -527,7 +591,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_adding_a_custom_constraint_with_boost_lambda)
namespace constraints_example_6 { namespace constraints_example_6 {
//[ constraints_example_6 //[ constraints_example_6
MOCK_CLASS(mock_class){ MOCK_METHOD(method, 1, void(int)) }; MOCK_CLASS(mock_class)
{
MOCK_METHOD(method, 1, void(int))
};
BOOST_AUTO_TEST_CASE(demonstrates_adding_a_custom_constraint_with_boost_phoenix) BOOST_AUTO_TEST_CASE(demonstrates_adding_a_custom_constraint_with_boost_phoenix)
{ {
@ -542,7 +609,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_adding_a_custom_constraint_with_boost_phoenix)
namespace constraints_example_7 { namespace constraints_example_7 {
//[ constraints_example_7 //[ constraints_example_7
MOCK_CLASS(mock_class){ MOCK_METHOD(method, 1, void(int)) }; MOCK_CLASS(mock_class)
{
MOCK_METHOD(method, 1, void(int))
};
BOOST_AUTO_TEST_CASE(demonstrates_adding_a_constraint_with_cxx11_lambda) BOOST_AUTO_TEST_CASE(demonstrates_adding_a_constraint_with_cxx11_lambda)
{ {
@ -556,7 +626,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_adding_a_constraint_with_cxx11_lambda)
namespace constraints_example_8 { namespace constraints_example_8 {
//[ constraints_example_8 //[ constraints_example_8
MOCK_CLASS(mock_class){ MOCK_METHOD(method, 2, void(int, const std::string&)) }; MOCK_CLASS(mock_class)
{
MOCK_METHOD(method, 2, void(int, const std::string&))
};
BOOST_AUTO_TEST_CASE(demonstrates_combining_constraints) BOOST_AUTO_TEST_CASE(demonstrates_combining_constraints)
{ {
@ -568,7 +641,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_combining_constraints)
namespace constraints_example_9 { namespace constraints_example_9 {
//[ constraints_example_9 //[ constraints_example_9
MOCK_CLASS(mock_class){ MOCK_METHOD(method, 2, void(const std::string&, std::size_t)) }; MOCK_CLASS(mock_class)
{
MOCK_METHOD(method, 2, void(const std::string&, std::size_t))
};
bool custom_constraint(const std::string& actual_1, std::size_t actual_2) bool custom_constraint(const std::string& actual_1, std::size_t actual_2)
{ {
@ -585,11 +661,20 @@ BOOST_AUTO_TEST_CASE(demonstrates_one_constraint_for_all_arguments)
namespace sequence_example_1 { namespace sequence_example_1 {
//[ sequence_example_1 //[ sequence_example_1
MOCK_CLASS(mock_class_1){ MOCK_METHOD(method_1, 0, void()) }; MOCK_CLASS(mock_class_1)
{
MOCK_METHOD(method_1, 0, void())
};
MOCK_CLASS(mock_class_2){ MOCK_METHOD(method_2, 0, void()) }; MOCK_CLASS(mock_class_2)
{
MOCK_METHOD(method_2, 0, void())
};
MOCK_CLASS(mock_class_3){ MOCK_METHOD(method_3, 0, void()) }; MOCK_CLASS(mock_class_3)
{
MOCK_METHOD(method_3, 0, void())
};
BOOST_AUTO_TEST_CASE(demonstrates_enforcing_several_expectation_orders) BOOST_AUTO_TEST_CASE(demonstrates_enforcing_several_expectation_orders)
{ {
@ -609,7 +694,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_enforcing_several_expectation_orders)
namespace action_example_1 { namespace action_example_1 {
//[ action_example_1 //[ action_example_1
MOCK_CLASS(mock_class){ MOCK_METHOD(method, 1, int(int)) }; MOCK_CLASS(mock_class)
{
MOCK_METHOD(method, 1, int(int))
};
int function(int i) int function(int i)
{ {
@ -634,7 +722,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_configuring_actions)
namespace action_example_2 { namespace action_example_2 {
//[ action_example_2 //[ action_example_2
MOCK_CLASS(mock_class){ MOCK_METHOD(method, 0, int&()) }; MOCK_CLASS(mock_class)
{
MOCK_METHOD(method, 0, int&())
};
BOOST_AUTO_TEST_CASE(demonstrates_configuring_actions_with_references) BOOST_AUTO_TEST_CASE(demonstrates_configuring_actions_with_references)
{ {
@ -649,7 +740,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_configuring_actions_with_references)
namespace verification_example_1 { namespace verification_example_1 {
//[ verification_example_1 //[ verification_example_1
MOCK_CLASS(mock_class){ MOCK_METHOD(method, 0, void()) }; MOCK_CLASS(mock_class)
{
MOCK_METHOD(method, 0, void())
};
BOOST_AUTO_TEST_CASE(demonstrates_verifying_a_mock_method) BOOST_AUTO_TEST_CASE(demonstrates_verifying_a_mock_method)
{ {
@ -687,7 +781,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_verifying_a_mock_function)
namespace verification_example_4 { namespace verification_example_4 {
//[ verification_example_4 //[ verification_example_4
MOCK_CLASS(mock_class){ MOCK_STATIC_METHOD(method, 0, void()) }; MOCK_CLASS(mock_class)
{
MOCK_STATIC_METHOD(method, 0, void())
};
BOOST_AUTO_TEST_CASE(demonstrates_verifying_a_static_mock_method) BOOST_AUTO_TEST_CASE(demonstrates_verifying_a_static_mock_method)
{ {
@ -701,7 +798,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_verifying_a_static_mock_method)
namespace reset_example_1 { namespace reset_example_1 {
//[ reset_example_1 //[ reset_example_1
MOCK_CLASS(mock_class){ MOCK_METHOD(method, 0, void()) }; MOCK_CLASS(mock_class)
{
MOCK_METHOD(method, 0, void())
};
BOOST_AUTO_TEST_CASE(demonstrates_resetting_a_mock_method) BOOST_AUTO_TEST_CASE(demonstrates_resetting_a_mock_method)
{ {
@ -739,7 +839,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_resetting_a_mock_function)
namespace reset_example_4 { namespace reset_example_4 {
//[ reset_example_4 //[ reset_example_4
MOCK_CLASS(mock_class){ MOCK_STATIC_METHOD(method, 0, void()) }; MOCK_CLASS(mock_class)
{
MOCK_STATIC_METHOD(method, 0, void())
};
BOOST_AUTO_TEST_CASE(demonstrates_resetting_a_static_mock_method) BOOST_AUTO_TEST_CASE(demonstrates_resetting_a_static_mock_method)
{ {

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -16,5 +16,8 @@ struct my_base
virtual void my_method(int) = 0; virtual void my_method(int) = 0;
}; };
MOCK_BASE_CLASS(my_class, my_base){ MOCK_METHOD(my_method, 0) }; MOCK_BASE_CLASS(my_class, my_base)
{
MOCK_METHOD(my_method, 0)
};
} // namespace } // namespace

View file

@ -9,7 +9,10 @@
#include <turtle/mock.hpp> #include <turtle/mock.hpp>
namespace { namespace {
MOCK_CLASS(my_class){ MOCK_METHOD_EXT(my_method, 1, void(int), my_method) }; MOCK_CLASS(my_class)
{
MOCK_METHOD_EXT(my_method, 1, void(int), my_method)
};
bool constraint(int, int); bool constraint(int, int);
void test_case() void test_case()

View file

@ -9,7 +9,10 @@
#include <turtle/mock.hpp> #include <turtle/mock.hpp>
namespace { namespace {
MOCK_CLASS(my_class){ MOCK_METHOD_EXT(my_method, 1, void(int), my_method) }; MOCK_CLASS(my_class)
{
MOCK_METHOD_EXT(my_method, 1, void(int), my_method)
};
void test_case() void test_case()
{ {
my_class c; my_class c;

View file

@ -9,7 +9,10 @@
#include <turtle/mock.hpp> #include <turtle/mock.hpp>
namespace { namespace {
MOCK_CLASS(my_class){ MOCK_METHOD_EXT(my_method, 1, void(int), my_method) }; MOCK_CLASS(my_class)
{
MOCK_METHOD_EXT(my_method, 1, void(int), my_method)
};
void test_case() void test_case()
{ {
my_class c; my_class c;

View file

@ -9,7 +9,10 @@
#include <turtle/mock.hpp> #include <turtle/mock.hpp>
namespace { namespace {
MOCK_CLASS(my_class){ MOCK_METHOD_EXT(my_method, 0, int(), my_method) }; MOCK_CLASS(my_class)
{
MOCK_METHOD_EXT(my_method, 0, int(), my_method)
};
void test_case() void test_case()
{ {
my_class c; my_class c;

View file

@ -9,7 +9,10 @@
#include <turtle/mock.hpp> #include <turtle/mock.hpp>
namespace { namespace {
MOCK_CLASS(my_class){ MOCK_METHOD_EXT(my_method, 0, std::string(), my_method) }; MOCK_CLASS(my_class)
{
MOCK_METHOD_EXT(my_method, 0, std::string(), my_method)
};
void test_case() void test_case()
{ {
my_class c; my_class c;

View file

@ -9,7 +9,10 @@
#include <turtle/mock.hpp> #include <turtle/mock.hpp>
namespace { namespace {
MOCK_CLASS(my_class){ MOCK_METHOD_EXT(my_method, 0, void(), my_method) }; MOCK_CLASS(my_class)
{
MOCK_METHOD_EXT(my_method, 0, void(), my_method)
};
void test_case() void test_case()
{ {
my_class c; my_class c;

View file

@ -14,5 +14,8 @@ struct my_base
virtual ~my_base() {} virtual ~my_base() {}
}; };
MOCK_BASE_CLASS(my_class, my_base){ MOCK_METHOD(my_method, 0) }; MOCK_BASE_CLASS(my_class, my_base)
{
MOCK_METHOD(my_method, 0)
};
} // namespace } // namespace

View file

@ -17,5 +17,8 @@ struct my_base
virtual void my_method(int, int, int, int, int, int, int, int, int, int) = 0; virtual void my_method(int, int, int, int, int, int, int, int, int, int) = 0;
}; };
MOCK_BASE_CLASS(my_class, my_base){ MOCK_METHOD(my_method, 10) }; MOCK_BASE_CLASS(my_class, my_base)
{
MOCK_METHOD(my_method, 10)
};
} // namespace } // namespace

View file

@ -10,5 +10,8 @@
namespace { namespace {
template<typename T> template<typename T>
MOCK_CLASS(my_class){ MOCK_METHOD_EXT(my_method, 1, void(T), my_method) }; MOCK_CLASS(my_class)
} {
MOCK_METHOD_EXT(my_method, 1, void(T), my_method)
};
} // namespace

View file

@ -15,5 +15,8 @@ struct my_base
virtual void my_method(int) = 0; virtual void my_method(int) = 0;
}; };
MOCK_BASE_CLASS(my_class, my_base){ MOCK_METHOD(my_method, 2) }; MOCK_BASE_CLASS(my_class, my_base)
{
MOCK_METHOD(my_method, 2)
};
} // namespace } // namespace

View file

@ -9,7 +9,10 @@
#include <turtle/mock.hpp> #include <turtle/mock.hpp>
namespace { namespace {
MOCK_CLASS(my_class){ MOCK_METHOD_EXT(my_method, 1, void(int), my_method) }; MOCK_CLASS(my_class)
{
MOCK_METHOD_EXT(my_method, 1, void(int), my_method)
};
void test_case() void test_case()
{ {
my_class c; my_class c;

View file

@ -46,8 +46,11 @@ BOOST_FIXTURE_TEST_CASE(custom_mock_object_without_macros, mock_error_fixture)
} }
namespace { namespace {
MOCK_CLASS(my_mock){ MOCK_METHOD_EXT(my_method, 1, int(int), my_tag) }; MOCK_CLASS(my_mock)
} {
MOCK_METHOD_EXT(my_method, 1, int(int), my_tag)
};
} // namespace
BOOST_FIXTURE_TEST_CASE(basic_mock_object_usage, mock_error_fixture) BOOST_FIXTURE_TEST_CASE(basic_mock_object_usage, mock_error_fixture)
{ {
@ -82,8 +85,11 @@ public:
virtual void my_method(int) = 0; virtual void my_method(int) = 0;
}; };
MOCK_BASE_CLASS(my_ambiguited_mock, my_ambiguited_interface){ MOCK_METHOD_EXT(my_method, 0, void(), my_tag1) MOCK_BASE_CLASS(my_ambiguited_mock, my_ambiguited_interface)
MOCK_METHOD_EXT(my_method, 1, void(int), my_tag_2) }; {
MOCK_METHOD_EXT(my_method, 0, void(), my_tag1)
MOCK_METHOD_EXT(my_method, 1, void(int), my_tag_2)
};
} // namespace } // namespace
BOOST_FIXTURE_TEST_CASE(mock_object_method_disambiguation, mock_error_fixture) BOOST_FIXTURE_TEST_CASE(mock_object_method_disambiguation, mock_error_fixture)
@ -103,9 +109,11 @@ public:
virtual void my_method() const = 0; virtual void my_method() const = 0;
}; };
MOCK_BASE_CLASS(my_const_ambiguited_mock, MOCK_BASE_CLASS(my_const_ambiguited_mock, my_const_ambiguited_interface)
my_const_ambiguited_interface){ MOCK_NON_CONST_METHOD_EXT(my_method, 0, void(), tag1) {
MOCK_CONST_METHOD_EXT(my_method, 0, void(), tag_2) }; MOCK_NON_CONST_METHOD_EXT(my_method, 0, void(), tag1)
MOCK_CONST_METHOD_EXT(my_method, 0, void(), tag_2)
};
} // namespace } // namespace
BOOST_FIXTURE_TEST_CASE(mock_object_method_const_disambiguation, mock_error_fixture) BOOST_FIXTURE_TEST_CASE(mock_object_method_const_disambiguation, mock_error_fixture)
@ -118,8 +126,11 @@ BOOST_FIXTURE_TEST_CASE(mock_object_method_const_disambiguation, mock_error_fixt
} }
namespace { namespace {
MOCK_CLASS(my_undefined_mock){ MOCK_METHOD_EXT(m, 1, void(undefined&), t) }; MOCK_CLASS(my_undefined_mock)
} {
MOCK_METHOD_EXT(m, 1, void(undefined&), t)
};
} // namespace
BOOST_FIXTURE_TEST_CASE(mock_object_method_with_declared_but_not_defined_parameter_is_valid, mock_error_fixture) BOOST_FIXTURE_TEST_CASE(mock_object_method_with_declared_but_not_defined_parameter_is_valid, mock_error_fixture)
{ {
@ -194,8 +205,8 @@ struct my_template_base_class
virtual void my_other_method() = 0; virtual void my_other_method() = 0;
}; };
template<typename T> template<typename T>
MOCK_BASE_CLASS(my_template_base_class_mock, MOCK_BASE_CLASS(my_template_base_class_mock, my_template_base_class<T>)
my_template_base_class<T>){ MOCK_METHOD_EXT_TPL(my_method, 1, void(T), my_method) { MOCK_METHOD_EXT_TPL(my_method, 1, void(T), my_method)
MOCK_METHOD_EXT_TPL(my_other_method, 0, void(), my_other_method) }; MOCK_METHOD_EXT_TPL(my_other_method, 0, void(), my_other_method) };
} // namespace } // namespace
@ -234,9 +245,15 @@ private:
int value_; int value_;
}; };
MOCK_BASE_CLASS(my_mock_observer, my_observer){ MOCK_METHOD(notify, 1) }; MOCK_BASE_CLASS(my_mock_observer, my_observer)
{
MOCK_METHOD(notify, 1)
};
MOCK_BASE_CLASS(my_mock_manager, my_manager){ MOCK_METHOD(get_observer, 0) }; MOCK_BASE_CLASS(my_mock_manager, my_manager)
{
MOCK_METHOD(get_observer, 0)
};
struct fixture : mock_error_fixture struct fixture : mock_error_fixture
{ {
@ -259,8 +276,11 @@ BOOST_FIXTURE_TEST_CASE(basic_mock_object_collaboration_usage, fixture)
} }
namespace { namespace {
MOCK_CLASS(my_constructed_class){ MOCK_CONSTRUCTOR(my_constructed_class, 2, (int, const std::string&), constructor) }; MOCK_CLASS(my_constructed_class)
} {
MOCK_CONSTRUCTOR(my_constructed_class, 2, (int, const std::string&), constructor)
};
} // namespace
BOOST_FIXTURE_TEST_CASE(mocking_a_constructor, mock_error_fixture) BOOST_FIXTURE_TEST_CASE(mocking_a_constructor, mock_error_fixture)
{ {
@ -272,10 +292,9 @@ BOOST_FIXTURE_TEST_CASE(mocking_a_constructor, mock_error_fixture)
namespace { 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_TPL(my_constructed_template_class, 2, (T, const std::string&), constructor) };
}; } // namespace
}
BOOST_FIXTURE_TEST_CASE(mocking_a_template_class_constructor, mock_error_fixture) BOOST_FIXTURE_TEST_CASE(mocking_a_template_class_constructor, mock_error_fixture)
{ {
@ -286,8 +305,11 @@ BOOST_FIXTURE_TEST_CASE(mocking_a_template_class_constructor, mock_error_fixture
} }
namespace { namespace {
MOCK_CLASS(my_destroyed_class){ MOCK_DESTRUCTOR(~my_destroyed_class, destructor) }; MOCK_CLASS(my_destroyed_class)
} {
MOCK_DESTRUCTOR(~my_destroyed_class, destructor)
};
} // namespace
BOOST_FIXTURE_TEST_CASE(mocking_a_destructor, mock_error_fixture) BOOST_FIXTURE_TEST_CASE(mocking_a_destructor, mock_error_fixture)
{ {
@ -327,8 +349,11 @@ BOOST_FIXTURE_TEST_CASE(failed_sequence_in_mocked_destructor_does_not_throw, moc
} }
namespace { namespace {
MOCK_CLASS(boost_optional){ MOCK_METHOD_EXT(method, 0, boost::optional<my_observer&>(), tag) }; MOCK_CLASS(boost_optional)
} {
MOCK_METHOD_EXT(method, 0, boost::optional<my_observer&>(), tag)
};
} // namespace
BOOST_FIXTURE_TEST_CASE(boost_optional_on_base_class_reference_as_return_type_is_supported, mock_error_fixture) BOOST_FIXTURE_TEST_CASE(boost_optional_on_base_class_reference_as_return_type_is_supported, mock_error_fixture)
{ {
@ -527,7 +552,8 @@ namespace {
template<typename T1, typename T2> template<typename T1, typename T2>
struct my_base struct my_base
{}; {};
MOCK_BASE_CLASS(my_comma_mock, my_base<int BOOST_PP_COMMA() int>){}; MOCK_BASE_CLASS(my_comma_mock, my_base<int BOOST_PP_COMMA() int>)
{};
} // namespace } // namespace
#ifdef MOCK_THREAD_SAFE #ifdef MOCK_THREAD_SAFE

View file

@ -18,7 +18,10 @@ void my_function(T& t)
{ {
t.my_method("some parameter"); t.my_method("some parameter");
} }
MOCK_CLASS(mock_class){ MOCK_METHOD_EXT(my_method, 1, void(const std::string&), my_tag) }; MOCK_CLASS(mock_class)
{
MOCK_METHOD_EXT(my_method, 1, void(const std::string&), my_tag)
};
} // namespace } // namespace
BOOST_FIXTURE_TEST_CASE(mock_object_for_static_polymorphism, mock_error_fixture) BOOST_FIXTURE_TEST_CASE(mock_object_for_static_polymorphism, mock_error_fixture)
@ -30,8 +33,11 @@ BOOST_FIXTURE_TEST_CASE(mock_object_for_static_polymorphism, mock_error_fixture)
} }
namespace { namespace {
MOCK_CLASS(mock_class_with_operator){ MOCK_CONST_METHOD_EXT(operator+=, 1, mock_class_with_operator &(int), addition) }; MOCK_CLASS(mock_class_with_operator)
} {
MOCK_CONST_METHOD_EXT(operator+=, 1, mock_class_with_operator &(int), addition)
};
} // namespace
BOOST_FIXTURE_TEST_CASE(mock_addition_operator, mock_error_fixture) BOOST_FIXTURE_TEST_CASE(mock_addition_operator, mock_error_fixture)
{ {
@ -42,8 +48,11 @@ BOOST_FIXTURE_TEST_CASE(mock_addition_operator, mock_error_fixture)
} }
namespace { namespace {
MOCK_CLASS(mock_class_with_conversion_operator){ MOCK_CONVERSION_OPERATOR(operator, int, conversion) }; MOCK_CLASS(mock_class_with_conversion_operator)
} {
MOCK_CONVERSION_OPERATOR(operator, int, conversion)
};
} // namespace
BOOST_FIXTURE_TEST_CASE(mock_conversion_operator, mock_error_fixture) BOOST_FIXTURE_TEST_CASE(mock_conversion_operator, mock_error_fixture)
{ {
@ -55,8 +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_CONVERSION_OPERATOR_TPL(operator, T, conversion) }; MOCK_CLASS(mock_template_class_with_conversion_operator)
} { MOCK_CONVERSION_OPERATOR_TPL(operator, T, conversion) };
} // namespace
BOOST_FIXTURE_TEST_CASE(mock_template_conversion_operator, mock_error_fixture) BOOST_FIXTURE_TEST_CASE(mock_template_conversion_operator, mock_error_fixture)
{ {
@ -67,8 +77,11 @@ BOOST_FIXTURE_TEST_CASE(mock_template_conversion_operator, mock_error_fixture)
} }
namespace { namespace {
MOCK_CLASS(mock_class_with_const_conversion_operator){ MOCK_CONST_CONVERSION_OPERATOR(operator, int, conversion) }; MOCK_CLASS(mock_class_with_const_conversion_operator)
} {
MOCK_CONST_CONVERSION_OPERATOR(operator, int, conversion)
};
} // namespace
BOOST_FIXTURE_TEST_CASE(mock_const_conversion_operator, mock_error_fixture) BOOST_FIXTURE_TEST_CASE(mock_const_conversion_operator, mock_error_fixture)
{ {
@ -80,8 +93,11 @@ BOOST_FIXTURE_TEST_CASE(mock_const_conversion_operator, mock_error_fixture)
} }
namespace { namespace {
MOCK_CLASS(mock_class_with_non_const_conversion_operator){ MOCK_CONST_CONVERSION_OPERATOR(operator, int, conversion) }; MOCK_CLASS(mock_class_with_non_const_conversion_operator)
} {
MOCK_CONST_CONVERSION_OPERATOR(operator, int, conversion)
};
} // namespace
BOOST_FIXTURE_TEST_CASE(mock_non_const_conversion_operator, mock_error_fixture) BOOST_FIXTURE_TEST_CASE(mock_non_const_conversion_operator, mock_error_fixture)
{ {
@ -94,10 +110,11 @@ BOOST_FIXTURE_TEST_CASE(mock_non_const_conversion_operator, mock_error_fixture)
namespace { 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_TPL(operator, T, conversion)
}; };
} } // namespace
BOOST_FIXTURE_TEST_CASE(mock_template_const_conversion_operator, mock_error_fixture) BOOST_FIXTURE_TEST_CASE(mock_template_const_conversion_operator, mock_error_fixture)
{ {
@ -109,10 +126,11 @@ BOOST_FIXTURE_TEST_CASE(mock_template_const_conversion_operator, mock_error_fixt
namespace { 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_TPL(operator, T, conversion)
}; };
} } // namespace
BOOST_FIXTURE_TEST_CASE(mock_template_non_const_conversion_operator, mock_error_fixture) BOOST_FIXTURE_TEST_CASE(mock_template_non_const_conversion_operator, mock_error_fixture)
{ {
@ -123,9 +141,12 @@ BOOST_FIXTURE_TEST_CASE(mock_template_non_const_conversion_operator, mock_error_
} }
namespace { namespace {
MOCK_CLASS(my_mock){ MOCK_CONST_METHOD_EXT(my_method, 1, void(int), my_method) MOCK_CLASS(my_mock)
MOCK_CONST_METHOD_EXT(my_method_2, 1, void(int), my_method_2) }; {
} MOCK_CONST_METHOD_EXT(my_method, 1, void(int), my_method)
MOCK_CONST_METHOD_EXT(my_method_2, 1, void(int), my_method_2)
};
} // namespace
BOOST_FIXTURE_TEST_CASE(MOCK_CONST_METHOD_EXT_macro_defines_a_bindable_method, mock_error_fixture) BOOST_FIXTURE_TEST_CASE(MOCK_CONST_METHOD_EXT_macro_defines_a_bindable_method, mock_error_fixture)
{ {
@ -297,8 +318,11 @@ BOOST_FIXTURE_TEST_CASE(mock_function_is_named, mock_error_fixture)
} }
namespace { namespace {
MOCK_CLASS(static_function_class){ MOCK_STATIC_METHOD(f, 1, float(int), f) }; MOCK_CLASS(static_function_class)
} {
MOCK_STATIC_METHOD(f, 1, float(int), f)
};
} // namespace
BOOST_FIXTURE_TEST_CASE(mock_static_function_is_named, mock_error_fixture) BOOST_FIXTURE_TEST_CASE(mock_static_function_is_named, mock_error_fixture)
{ {
@ -327,20 +351,37 @@ struct base
virtual void m11() = 0; virtual void m11() = 0;
}; };
MOCK_BASE_CLASS(variadic, base){ MOCK_METHOD(m1, 0) MOCK_METHOD(m2, 0, void()) MOCK_METHOD(m3, 0, void(), m3) MOCK_BASE_CLASS(variadic, base)
MOCK_CONST_METHOD(m10, 0) MOCK_CONST_METHOD(m4, 0, void()) {
MOCK_CONST_METHOD(m5, 0, void(), m5) MOCK_NON_CONST_METHOD(m11, 0) MOCK_METHOD(m1, 0)
MOCK_NON_CONST_METHOD(m6, 0, void()) MOCK_NON_CONST_METHOD(m7, 0, void(), m7) MOCK_METHOD(m2, 0, void())
MOCK_STATIC_METHOD(m8, 0, void()) MOCK_STATIC_METHOD(m9, 0, void(), m9) }; MOCK_METHOD(m3, 0, void(), m3)
MOCK_CONST_METHOD(m10, 0)
MOCK_CONST_METHOD(m4, 0, void())
MOCK_CONST_METHOD(m5, 0, void(), m5)
MOCK_NON_CONST_METHOD(m11, 0)
MOCK_NON_CONST_METHOD(m6, 0, void())
MOCK_NON_CONST_METHOD(m7, 0, void(), m7)
MOCK_STATIC_METHOD(m8, 0, void())
MOCK_STATIC_METHOD(m9, 0, void(), m9)
};
template<typename T> template<typename T>
MOCK_BASE_CLASS(variadic_tpl, base){ MOCK_METHOD(m1, 0, void()) MOCK_METHOD_TPL(m2, 0, T()) MOCK_BASE_CLASS(variadic_tpl, base)
MOCK_METHOD_TPL(m3, 0, T(), m3) MOCK_CONST_METHOD_TPL(m4, 0, T()) {
MOCK_CONST_METHOD_TPL(m5, 0, T(), m5) MOCK_NON_CONST_METHOD_TPL(m6, 0, T()) MOCK_METHOD(m1, 0, void())
MOCK_NON_CONST_METHOD_TPL(m7, 0, T(), m7) MOCK_STATIC_METHOD_TPL(m8, 0, T()) MOCK_METHOD_TPL(m2, 0, T())
MOCK_STATIC_METHOD_TPL(m9, 0, T(), m9) }; MOCK_METHOD_TPL(m3, 0, T(), m3)
MOCK_CONST_METHOD_TPL(m4, 0, T())
MOCK_CONST_METHOD_TPL(m5, 0, T(), m5)
MOCK_NON_CONST_METHOD_TPL(m6, 0, T())
MOCK_NON_CONST_METHOD_TPL(m7, 0, T(), m7)
MOCK_STATIC_METHOD_TPL(m8, 0, T())
MOCK_STATIC_METHOD_TPL(m9, 0, T(), m9)
};
MOCK_BASE_CLASS(comma_base, std::map<int, int>){}; 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)
@ -359,10 +400,16 @@ struct base
virtual void m1() = 0; virtual void m1() = 0;
}; };
MOCK_BASE_CLASS(derived, base){ MOCK_METHOD(m1, 0) }; MOCK_BASE_CLASS(derived, base)
{
MOCK_METHOD(m1, 0)
};
template<typename T> template<typename T>
MOCK_BASE_CLASS(derived_tpl, base){ MOCK_METHOD_EXT(m1, 0, void(), m1) }; MOCK_BASE_CLASS(derived_tpl, base)
{
MOCK_METHOD_EXT(m1, 0, void(), m1)
};
} // namespace } // namespace
#endif // MOCK_VARIADIC_MACROS #endif // MOCK_VARIADIC_MACROS
@ -381,7 +428,9 @@ struct base
virtual void MOCK_STDCALL m1() = 0; virtual void MOCK_STDCALL m1() = 0;
}; };
MOCK_BASE_CLASS(derived, base){ MOCK_CONSTRUCTOR(MOCK_STDCALL derived, 0, (), derived) MOCK_BASE_CLASS(derived, base)
{
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_EXT(MOCK_STDCALL m1, 0, void(), m1)
@ -389,7 +438,8 @@ MOCK_BASE_CLASS(derived, base){ MOCK_CONSTRUCTOR(MOCK_STDCALL derived, 0, (), de
#ifdef MOCK_VARIADIC_MACROS #ifdef MOCK_VARIADIC_MACROS
MOCK_METHOD(MOCK_STDCALL m3, 0, void(), m3) MOCK_METHOD(MOCK_STDCALL m3, 0, void(), m3)
#endif #endif
MOCK_STATIC_METHOD(MOCK_STDCALL m4, 0, void(), m4) }; MOCK_STATIC_METHOD(MOCK_STDCALL m4, 0, void(), m4)
};
MOCK_FUNCTION(MOCK_STDCALL f, 0, void(), f) MOCK_FUNCTION(MOCK_STDCALL f, 0, void(), f)
} // namespace stdcall } // namespace stdcall