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

@ -12,7 +12,8 @@
namespace class_example_1 {
//[ class_example_1
MOCK_CLASS(mock_class){};
MOCK_CLASS(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 {
//[ class_example_2
template<typename T>
MOCK_CLASS(mock_class){};
MOCK_CLASS(mock_class)
{};
BOOST_AUTO_TEST_CASE(demonstrates_instantiating_a_template_mock_class)
{
@ -38,7 +40,8 @@ namespace class_example_3 {
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)
{
@ -54,7 +57,8 @@ struct base_class
{};
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)
{
@ -113,7 +117,8 @@ struct base_class
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
};
//]
@ -128,7 +133,8 @@ struct base_class
virtual void method(float) = 0;
};
MOCK_BASE_CLASS(mock_class, base_class){
MOCK_BASE_CLASS(mock_class, base_class)
{
MOCK_METHOD(
method,
2,
@ -151,7 +157,8 @@ struct base_class
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
};
//]
@ -166,7 +173,8 @@ struct base_class
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_NON_CONST_METHOD(method,
1,
@ -195,7 +203,8 @@ struct mock_class : base_class
namespace member_function_example_6 {
//[ member_function_example_6
MOCK_CLASS(mock_class){
MOCK_CLASS(mock_class)
{
MOCK_NON_CONST_METHOD(operator=,
1,
mock_class &(const mock_class&),
@ -207,7 +216,8 @@ MOCK_CLASS(mock_class){
namespace member_function_example_7 {
//[ member_function_example_7
template<typename T>
MOCK_CLASS(mock_class){
MOCK_CLASS(mock_class)
{
MOCK_METHOD_TPL(
method,
1,
@ -218,11 +228,11 @@ MOCK_CLASS(mock_class){
namespace member_function_example_8 {
//[ member_function_example_8
MOCK_CLASS(mock_class){
MOCK_METHOD(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
MOCK_CLASS(mock_class)
{
MOCK_METHOD(
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
};
//]
} // namespace member_function_example_8
@ -230,7 +240,8 @@ MOCK_CLASS(mock_class){
#ifdef BOOST_MSVC
namespace member_function_example_9 {
//[ member_function_example_9
MOCK_CLASS(mock_class){
MOCK_CLASS(mock_class)
{
MOCK_METHOD(__stdcall method,
0,
void(),
@ -242,21 +253,28 @@ MOCK_CLASS(mock_class){
namespace 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_2 {
//[ static_member_function_example_2
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
#ifdef BOOST_MSVC
namespace static_member_function_example_3 {
//[ static_member_function_example_3
MOCK_CLASS(mock_class){
MOCK_CLASS(mock_class)
{
MOCK_STATIC_METHOD(__stdcall method,
0,
void(),
@ -268,55 +286,74 @@ MOCK_CLASS(mock_class){
namespace 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_2 {
//[ constructor_example_2
template<typename T>
MOCK_CLASS(mock_class){ MOCK_CONSTRUCTOR(mock_class, 2, (int, const std::string&), identifier)
MOCK_CONSTRUCTOR_TPL(mock_class, 2, (T, const std::string&), identifier_2) };
MOCK_CLASS(mock_class)
{
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
#ifdef BOOST_MSVC
namespace 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
#endif
namespace 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
#ifdef BOOST_MSVC
namespace 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
#endif
namespace conversion_operator_example_1 {
//[ conversion_operator_example_1
MOCK_CLASS(mock_class){ MOCK_CONVERSION_OPERATOR(operator, int, conversion_to_int)
MOCK_CONST_CONVERSION_OPERATOR(operator, const std::string&, conversion_to_string) };
MOCK_CLASS(mock_class)
{
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_2 {
//[ conversion_operator_example_2
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
// includes a template parameter of the class
MOCK_CONST_CONVERSION_OPERATOR(operator, const std::string&, const_conversion_to_string)
MOCK_NON_CONST_CONVERSION_OPERATOR(operator, const std::string&, non_const_conversion_to_string)
MOCK_NON_CONST_CONVERSION_OPERATOR(operator, const std::string&, non_const_conversion_to_string)
};
//]
} // namespace conversion_operator_example_2
@ -324,7 +361,10 @@ MOCK_CLASS(mock_class){
#ifdef BOOST_MSVC
namespace conversion_operator_example_3 {
//[ conversion_operator_example_3
MOCK_CLASS(mock_class){ MOCK_CONVERSION_OPERATOR(__stdcall operator, int, conversion_to_int) };
MOCK_CLASS(mock_class)
{
MOCK_CONVERSION_OPERATOR(__stdcall operator, int, conversion_to_int)
};
//]
} // namespace conversion_operator_example_3
#endif
@ -379,8 +419,11 @@ BOOST_AUTO_TEST_CASE(demonstrates_instantiating_a_mock_functor)
namespace expectation_example_1 {
//[ expectation_example_1
MOCK_CLASS(mock_class){ MOCK_METHOD(method, 1, int(int), method)
MOCK_METHOD(method, 2, void(const std::string&, float), method2) };
MOCK_CLASS(mock_class)
{
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)
{
@ -395,7 +438,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_configuring_mock_objects)
namespace 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)
{
@ -429,7 +475,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_setting_up_an_invocation_on_a_mock_function)
namespace 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)
{
@ -442,7 +491,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_setting_up_an_invocation_on_a_mock_static_meth
namespace 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)
{
@ -455,7 +507,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_adding_builtin_constraints)
namespace 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)
{
@ -472,7 +527,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_adding_a_custom_constraint_with_a_free_functio
namespace 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)
{
@ -490,7 +548,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_adding_a_custom_constraint_with_a_standard_lib
namespace 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)
{
@ -511,7 +572,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_adding_a_custom_constraint_with_boost_bind)
namespace 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)
{
@ -527,7 +591,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_adding_a_custom_constraint_with_boost_lambda)
namespace 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)
{
@ -542,7 +609,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_adding_a_custom_constraint_with_boost_phoenix)
namespace 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)
{
@ -556,7 +626,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_adding_a_constraint_with_cxx11_lambda)
namespace 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)
{
@ -568,7 +641,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_combining_constraints)
namespace 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)
{
@ -585,11 +661,20 @@ BOOST_AUTO_TEST_CASE(demonstrates_one_constraint_for_all_arguments)
namespace 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)
{
@ -609,7 +694,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_enforcing_several_expectation_orders)
namespace 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)
{
@ -634,7 +722,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_configuring_actions)
namespace 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)
{
@ -649,7 +740,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_configuring_actions_with_references)
namespace 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)
{
@ -687,7 +781,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_verifying_a_mock_function)
namespace 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)
{
@ -701,7 +798,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_verifying_a_static_mock_method)
namespace 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)
{
@ -739,7 +839,10 @@ BOOST_AUTO_TEST_CASE(demonstrates_resetting_a_mock_function)
namespace 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)
{