mimic++ v9.2.1
Loading...
Searching...
No Matches
facade

Contains utility to simplify the process of generating forwarding facade functions. More...

Collaboration diagram for facade:

Topics

 detail
 Contains several macros, used for facade implementation.
 
 interfaces
 [Deprecated] Utilities to simplify interface mocking.
 

Macros

#define MIMICPP_ADD_OVERLOAD(ret, param_type_list, ...)
 Adds an overload to the currently built facade.
 
#define ADD_OVERLOAD   MIMICPP_ADD_OVERLOAD
 Shorthand variant of MIMICPP_ADD_OVERLOAD.
 
#define MIMICPP_MAKE_OVERLOADED_FACADE_EXT(traits, target_name, fn_name, linkage, ...)
 The most powerful entry point for creating a facade overload-set.
 
#define MAKE_OVERLOADED_FACADE_EXT   MIMICPP_MAKE_OVERLOADED_FACADE_EXT
 Shorthand variant of MIMICPP_MAKE_OVERLOADED_FACADE_EXT.
 
#define MIMICPP_MAKE_FACADE_EXT(traits, target_name, fn_name, linkage, ret, param_type_list, ...)
 The most powerful entry point for creating a single facade function.
 
#define MAKE_FACADE_EXT   MIMICPP_MAKE_FACADE_EXT
 Shorthand variant of MIMICPP_MAKE_FACADE_EXT.
 
#define MIMICPP_MAKE_OVERLOADED_MEMBER_MOCK(fn_name, ...)
 Entry point for mocking a member method overload-set.
 
#define MAKE_OVERLOADED_MEMBER_MOCK   MIMICPP_MAKE_OVERLOADED_MEMBER_MOCK
 Shorthand variant of MIMICPP_MAKE_OVERLOADED_MEMBER_MOCK.
 
#define MIMICPP_MAKE_MEMBER_MOCK(fn_name, ret, param_type_list, ...)
 Entry point for mocking a single member method.
 
#define MAKE_MEMBER_MOCK   MIMICPP_MAKE_MEMBER_MOCK
 Shorthand variant of MIMICPP_MAKE_MEMBER_MOCK.
 
#define MIMICPP_MAKE_OVERLOADED_MEMBER_MOCK_WITH_THIS(fn_name, ...)
 Entry point for mocking a member method overload-set with an explicit this pointer.
 
#define MAKE_OVERLOADED_MEMBER_MOCK_WITH_THIS   MIMICPP_MAKE_OVERLOADED_MEMBER_MOCK_WITH_THIS
 Shorthand variant of MIMICPP_MAKE_OVERLOADED_MEMBER_MOCK_WITH_THIS.
 
#define MIMICPP_MAKE_MEMBER_MOCK_WITH_THIS(fn_name, ret, param_type_list, ...)
 Entry point for mocking a single member method with an explicit this pointer.
 
#define MAKE_MEMBER_MOCK_WITH_THIS   MIMICPP_MAKE_MEMBER_MOCK_WITH_THIS
 Shorthand variant of MIMICPP_MAKE_MEMBER_MOCK_WITH_THIS.
 

Detailed Description

Contains utility to simplify the process of generating forwarding facade functions.

While this library tries avoiding macros when possible, sometimes we must not be too stubborn. Making interface mocking more enjoyable is such a situation. While this can, of course, be done without macros, this quickly becomes annoying, due to the necessary boilerplate code.

class Interface
{
public:
virtual ~Interface() = default;
virtual void foo() = 0;
};
class Derived
: public Interface
{
public:
~Derived() override = default;
// Begin boilerplate
// we build our mock object by hand
mimicpp::Mock<void()> foo_{};
// and forward the incoming call from the interface function to the mock object.
void foo() override
{
return foo_();
}
// End boilerplate
};
// this may be a function from somewhere else, working with an interface.
constexpr auto my_function = [](Interface& obj) {
obj.foo();
};
Derived mock{};
SCOPED_EXP mock.foo_.expect_call();
my_function(mock);

mimic++ therefore introduces several macros, which helps to reduce the effort to a minimum. With them, the boilerplate can be reduced to this macro invocation, which effectively does the same as before:

MAKE_MEMBER_MOCK(foo, void, (), override);
#define MAKE_MEMBER_MOCK
Shorthand variant of MIMICPP_MAKE_MEMBER_MOCK.
Definition Facade.hpp:444

The good news is that these macros are just a thin layer around the macro-free core and can thus be easily avoided. Nevertheless, mimic++ still aims to become as macro-less as possible. As soon as reflection becomes available, an attempt will be made to solve this feature completely in the C++ language (hopefully with c++26, but only time will tell).

Multiple inheritance

This use-case is fully supported, without any special tricks.

namespace expect = mimicpp::expect;
namespace finally = mimicpp::finally;
class InterfaceA
{
public:
virtual ~InterfaceA() = default;
virtual void foo() = 0;
virtual void bar() = 0;
};
class InterfaceB
{
public:
virtual ~InterfaceB() = default;
virtual void foo() = 0;
virtual int bar() const noexcept = 0;
};
class Derived
: public InterfaceA,
public InterfaceB
{
public:
~Derived() override = default;
// Both interfaces have a foo() method with the same signature, so we do not need to overload.
MAKE_MEMBER_MOCK(foo, void, (), override); // mocks both foo() methods from InterfaceA and InterfaceB
// Both interfaces have a bar() method, but with different signature. So, let's work on that overload-set.
bar,
ADD_OVERLOAD(void, (), override), // from InterfaceA
ADD_OVERLOAD(int, (), const noexcept override)); // from InterfaceB
};
// let's build a function, which requires the InterfaceA
constexpr auto use_interfaceA = [](InterfaceA& obj) {
obj.foo();
obj.bar();
};
// and another, which requires the InterfaceB
constexpr auto use_interfaceB = [](InterfaceB& obj) {
obj.foo();
std::ignore = obj.bar(); // InterfaceB::bar returns an int, just explicitly ignore it here
};
// setting up the expectations isn't any different from the previous examples
Derived mock{};
SCOPED_EXP mock.foo_.expect_call()
and expect::twice();
SCOPED_EXP mock.bar_.expect_call(); // selects the non-const overload of bar()
SCOPED_EXP std::as_const(mock).bar_.expect_call() // selects the const overload of bar()
and finally::returns(42);
use_interfaceA(mock); // calls foo() and the non-const bar()
use_interfaceB(mock); // calls foo() and the const bar()

Mocks and variadic templates

Due to the nature of the mimicpp::Mock design, it directly supports packs without any question.

template <typename... Args>
class VariadicClass
{
public:
mimicpp::Mock<void(Args...)> myMock{};
};
VariadicClass myClass{};
SCOPED_EXP myClass.myMock.expect_call();
myClass.myMock();
VariadicClass<const std::string&, int> myOtherClass{};
SCOPED_EXP myOtherClass.myMock.expect_call("Hello, World!", 1337);
myOtherClass.myMock("Hello, World!", 1337);

The interesting part is: Do the facade macros also support variadic templates?

Yes they do! Both handle packs correctly.

template <typename... Args>
class VariadicInterface
{
public:
virtual ~VariadicInterface() = default;
virtual void foo(Args...) = 0;
virtual int bar(int, Args...) = 0;
virtual std::string bar(Args..., int, Args...) const = 0; // you can go absolutely crazy!
};
template <typename... Args>
class VariadicDerived final
: public VariadicInterface<Args...>
{
public:
MAKE_MEMBER_MOCK(foo, void, (Args...), override);
bar,
ADD_OVERLOAD(int, (int, Args...), override),
ADD_OVERLOAD(std::string, (Args..., int, Args...), const override));
};

They can then be used with arbitrary template arguments.

VariadicDerived mock{};
SCOPED_EXP mock.foo_.expect_call(); // foo has no arguments
mock.foo();
SCOPED_EXP mock.bar_.expect_call(42) // both bars have just an int parameter. This will select the non-const
and finally::returns(1337); // version, which returns an int.
SCOPED_EXP std::as_const(mock).bar_.expect_call(42) // to refer to the const version, just use a const ref
and finally::returns(std::string{"Hello, World!"}); // this returns a std::string
REQUIRE("Hello, World!" == std::as_const(mock).bar(42));
REQUIRE(1337 == mock.bar(42));
VariadicDerived<int, std::string> mock{};
SCOPED_EXP mock.foo_.expect_call(1337, matches::range::has_size(3));
mock.foo(1337, "Hey"); // second param size of 3 (without null-terminator).
See also
A more detailed explanation about the internals can be found here https://dnkpp.github.io/2024-12-15-simultaneous-pack-expansion-inside-macros/

Macro Definition Documentation

◆ ADD_OVERLOAD

#define ADD_OVERLOAD   MIMICPP_ADD_OVERLOAD

Shorthand variant of MIMICPP_ADD_OVERLOAD.

Adds an overload to the currently built facade.

Parameters
retThe return type.
param_type_listThe parameter types.
...Two optional arguments can be supplied, where
  • the first specifies the function specifiers (e.g. &, const, noexcept, override, etc.), and
  • the second specifies the call-convention.

◆ MAKE_FACADE_EXT

#define MAKE_FACADE_EXT   MIMICPP_MAKE_FACADE_EXT

Shorthand variant of MIMICPP_MAKE_FACADE_EXT.

The most powerful entry point for creating a single facade function.

Parameters
traitsThe facade-traits.
target_nameThe name of the underlying target object.
fn_nameThe name of the facade function.
linkageThe linkage for the facade function and the target object.
...Two optional arguments can be supplied, where
  • the first specifies the function specifiers (e.g. &, const, noexcept, override, etc.), and
  • the second specifies the call-convention.

This macro defines a single target object for one method signature and generates a corresponding facade function. The facade function forwards its calls to the underlying target object.

◆ MAKE_MEMBER_MOCK

#define MAKE_MEMBER_MOCK   MIMICPP_MAKE_MEMBER_MOCK

Shorthand variant of MIMICPP_MAKE_MEMBER_MOCK.

Entry point for mocking a single member method.

Parameters
fn_nameThe method name.
param_type_listThe list of parameter types.
...Two optional arguments can be supplied, where
  • the first specifies the function specifiers (e.g. &, const, noexcept, override, etc.), and
  • the second specifies the call-convention.

This macro defines a single mock member-object for one method signature and generates a corresponding facade member function. The facade member function forwards its calls to the underlying mock object-member.

The mock member-object name is the content of fn_name suffixed by an additional _.

◆ MAKE_MEMBER_MOCK_WITH_THIS

#define MAKE_MEMBER_MOCK_WITH_THIS   MIMICPP_MAKE_MEMBER_MOCK_WITH_THIS

Shorthand variant of MIMICPP_MAKE_MEMBER_MOCK_WITH_THIS.

Entry point for mocking a single member method with an explicit this pointer.

Parameters
fn_nameThe method name.
param_type_listThe list of parameter types.
...Two optional arguments can be supplied, where
  • the first specifies the function specifiers (e.g. &, const, noexcept, override, etc.), and
  • the second specifies the call-convention.

This macro defines a single mock member-object for one method signature and generates a corresponding facade member function. The facade member function forwards its calls to the underlying mock object-member and prepends an explicit this pointer to the argument list.

The mock member-object name is the content of fn_name suffixed by an additional _.

Attention
This macro requires a self_type alias to be defined in the class where the mock is declared. If self_type does not match the actual containing type, the behavior is undefined.
namespace finally = mimicpp::finally;
class Base
{
public:
virtual ~Base() = default;
virtual int foo() const
{
return 42;
}
};
class Derived
: public Base
{
public:
~Derived() override = default;
// This alias is required because the `..._WITH_THIS` macros are not able to determine the current type by themselves.
using self_type = Derived;
// This generates the override method and a mock object named foo_, which expects an explicit *this* param.
// => `Mock<int(Derived const*) const>`
MAKE_MEMBER_MOCK_WITH_THIS(foo, int, (), const override);
};
Derived object{};
// The first param behaves like an actual *this* pointer.
SCOPED_EXP object.foo_.expect_call(&object)
// Let's redirect the call to the actual `Base::foo` implementation.
and finally::returns_apply_all_result_of([](auto* self) { return self->Base::foo(); });
CHECK(42 == object.foo());

◆ MAKE_OVERLOADED_FACADE_EXT

#define MAKE_OVERLOADED_FACADE_EXT   MIMICPP_MAKE_OVERLOADED_FACADE_EXT

Shorthand variant of MIMICPP_MAKE_OVERLOADED_FACADE_EXT.

The most powerful entry point for creating a facade overload-set.

Parameters
traitsThe facade-traits.
target_nameThe name of the underlying target object.
fn_nameThe name of the facade overload-set.
linkageThe linkage for the facade functions and the target object.
...Overloads must be declared using the MIMICPP_ADD_OVERLOAD macro.

This macro defines a single target object that supports an arbitrary number of overloads. Each overload is implemented as its own facade function, forwarding calls to the underlying target object.

◆ MAKE_OVERLOADED_MEMBER_MOCK

#define MAKE_OVERLOADED_MEMBER_MOCK   MIMICPP_MAKE_OVERLOADED_MEMBER_MOCK

Shorthand variant of MIMICPP_MAKE_OVERLOADED_MEMBER_MOCK.

Entry point for mocking a member method overload-set.

Parameters
fn_nameThe name of the overload-set.
...Overloads must be declared using the MIMICPP_ADD_OVERLOAD macro.

This macro defines a single member mock object that supports an arbitrary number of member function overloads. Each overload is implemented as its own facade member function, forwarding calls to the underlying mock member-object.

The mock member-object name is the content of fn_name suffixed by an additional _.

class Interface
{
public:
virtual ~Interface() = default;
virtual void foo() = 0;
virtual void foo() const noexcept = 0;
};
class Derived
: public Interface
{
public:
~Derived() override = default;
// this generates both overrides and a mock object named `foo_`
foo,
ADD_OVERLOAD(void, (), override),
ADD_OVERLOAD(void, (), const noexcept override)); // note the `const noexcept` specifications as third argument
};
// this may be a function from somewhere else, working with an immutable interface.
constexpr auto my_function = [](Interface const& obj) {
obj.foo();
};
Derived mock{};
SCOPED_EXP std::as_const(mock).foo_.expect_call(); // We explicitly require the const overload to be called.
my_function(mock);

◆ MAKE_OVERLOADED_MEMBER_MOCK_WITH_THIS

#define MAKE_OVERLOADED_MEMBER_MOCK_WITH_THIS   MIMICPP_MAKE_OVERLOADED_MEMBER_MOCK_WITH_THIS

Shorthand variant of MIMICPP_MAKE_OVERLOADED_MEMBER_MOCK_WITH_THIS.

Entry point for mocking a member method overload-set with an explicit this pointer.

Parameters
fn_nameThe name of the overload-set.
...Overloads must be declared using the MIMICPP_ADD_OVERLOAD macro.

This macro defines a single member mock object that supports an arbitrary number of member function overloads. Each overload is implemented as its own facade member function, forwarding calls to the underlying mock member-object while prepending an explicit this pointer to the argument list.

The mock member-object name is the content of fn_name suffixed by an additional _.

Attention
This macro requires a self_type alias to be defined in the class where the mock is declared. If self_type does not match the actual containing type, the behavior is undefined.
namespace finally = mimicpp::finally;
class Base
{
public:
virtual ~Base() = default;
virtual int foo() const
{
return 42;
}
};
class Derived
: public Base
{
public:
~Derived() override = default;
// This alias is required because the `..._WITH_THIS` macros are not able to determine the current type by themselves.
using self_type = Derived;
// This generates the override method and a mock object named foo_, which expects an explicit *this* param.
// => `Mock<int(Derived const*) const>`
MAKE_MEMBER_MOCK_WITH_THIS(foo, int, (), const override);
};
Derived object{};
// The first param behaves like an actual *this* pointer.
SCOPED_EXP object.foo_.expect_call(&object)
// Let's redirect the call to the actual `Base::foo` implementation.
and finally::returns_apply_all_result_of([](auto* self) { return self->Base::foo(); });
CHECK(42 == object.foo());

◆ MIMICPP_ADD_OVERLOAD

#define MIMICPP_ADD_OVERLOAD ( ret,
param_type_list,
... )
Value:
__VA_ARGS__, \
MIMICPP_DETAIL_MAKE_OVERLOAD_INFOS_BASIC)(ret, param_type_list, __VA_ARGS__, )
#define MIMICPP_DETAIL_MAKE_OVERLOAD_INFOS_BASIC(ret, param_type_list,...)
Simple overload, extending the overload info (enclosed by parentheses).
Definition Facade.hpp:183
#define MIMICPP_DETAIL_MAKE_OVERLOAD_INFOS_ALL(ret, param_type_list, specs, call_convention,...)
Base overload, extending the overload info (enclosed by parentheses).
Definition Facade.hpp:158
#define MIMICPP_DETAIL_MAKE_OVERLOAD_INFOS_SPECS(ret, param_type_list, specs,...)
Simple overload, extending the overload info (enclosed by parentheses).
Definition Facade.hpp:174
#define MIMICPP_DETAIL_SELECT_MAKE_OVERLOAD_INFOS(_1, _2, N,...)
Selects the correct overload, depending on the number of arguments.
Definition Facade.hpp:191

Adds an overload to the currently built facade.

Parameters
retThe return type.
param_type_listThe parameter types.
...Two optional arguments can be supplied, where
  • the first specifies the function specifiers (e.g. &, const, noexcept, override, etc.), and
  • the second specifies the call-convention.

◆ MIMICPP_MAKE_FACADE_EXT

#define MIMICPP_MAKE_FACADE_EXT ( traits,
target_name,
fn_name,
linkage,
ret,
param_type_list,
... )
Value:
traits, \
target_name, \
fn_name, \
linkage, \
MIMICPP_ADD_OVERLOAD(ret, param_type_list __VA_OPT__(, ) __VA_ARGS__))
#define MIMICPP_ADD_OVERLOAD(ret, param_type_list,...)
Adds an overload to the currently built facade.
Definition Facade.hpp:306
#define MIMICPP_MAKE_OVERLOADED_FACADE_EXT(traits, target_name, fn_name, linkage,...)
The most powerful entry point for creating a facade overload-set.
Definition Facade.hpp:335

The most powerful entry point for creating a single facade function.

Parameters
traitsThe facade-traits.
target_nameThe name of the underlying target object.
fn_nameThe name of the facade function.
linkageThe linkage for the facade function and the target object.
...Two optional arguments can be supplied, where
  • the first specifies the function specifiers (e.g. &, const, noexcept, override, etc.), and
  • the second specifies the call-convention.

This macro defines a single target object for one method signature and generates a corresponding facade function. The facade function forwards its calls to the underlying target object.

◆ MIMICPP_MAKE_MEMBER_MOCK

#define MIMICPP_MAKE_MEMBER_MOCK ( fn_name,
ret,
param_type_list,
... )
Value:
fn_name, \
MIMICPP_ADD_OVERLOAD(ret, param_type_list __VA_OPT__(, ) __VA_ARGS__))
#define MIMICPP_MAKE_OVERLOADED_MEMBER_MOCK(fn_name,...)
Entry point for mocking a member method overload-set.
Definition Facade.hpp:399

Entry point for mocking a single member method.

Parameters
fn_nameThe method name.
param_type_listThe list of parameter types.
...Two optional arguments can be supplied, where
  • the first specifies the function specifiers (e.g. &, const, noexcept, override, etc.), and
  • the second specifies the call-convention.

This macro defines a single mock member-object for one method signature and generates a corresponding facade member function. The facade member function forwards its calls to the underlying mock object-member.

The mock member-object name is the content of fn_name suffixed by an additional _.

◆ MIMICPP_MAKE_MEMBER_MOCK_WITH_THIS

#define MIMICPP_MAKE_MEMBER_MOCK_WITH_THIS ( fn_name,
ret,
param_type_list,
... )
Value:
fn_name, \
MIMICPP_ADD_OVERLOAD(ret, param_type_list __VA_OPT__(, ) __VA_ARGS__))
#define MIMICPP_MAKE_OVERLOADED_MEMBER_MOCK_WITH_THIS(fn_name,...)
Entry point for mocking a member method overload-set with an explicit this pointer.
Definition Facade.hpp:466

Entry point for mocking a single member method with an explicit this pointer.

Parameters
fn_nameThe method name.
param_type_listThe list of parameter types.
...Two optional arguments can be supplied, where
  • the first specifies the function specifiers (e.g. &, const, noexcept, override, etc.), and
  • the second specifies the call-convention.

This macro defines a single mock member-object for one method signature and generates a corresponding facade member function. The facade member function forwards its calls to the underlying mock object-member and prepends an explicit this pointer to the argument list.

The mock member-object name is the content of fn_name suffixed by an additional _.

Attention
This macro requires a self_type alias to be defined in the class where the mock is declared. If self_type does not match the actual containing type, the behavior is undefined.
namespace finally = mimicpp::finally;
class Base
{
public:
virtual ~Base() = default;
virtual int foo() const
{
return 42;
}
};
class Derived
: public Base
{
public:
~Derived() override = default;
// This alias is required because the `..._WITH_THIS` macros are not able to determine the current type by themselves.
using self_type = Derived;
// This generates the override method and a mock object named foo_, which expects an explicit *this* param.
// => `Mock<int(Derived const*) const>`
MAKE_MEMBER_MOCK_WITH_THIS(foo, int, (), const override);
};
Derived object{};
// The first param behaves like an actual *this* pointer.
SCOPED_EXP object.foo_.expect_call(&object)
// Let's redirect the call to the actual `Base::foo` implementation.
and finally::returns_apply_all_result_of([](auto* self) { return self->Base::foo(); });
CHECK(42 == object.foo());

◆ MIMICPP_MAKE_OVERLOADED_FACADE_EXT

#define MIMICPP_MAKE_OVERLOADED_FACADE_EXT ( traits,
target_name,
fn_name,
linkage,
... )
Value:
traits, \
target_name, \
fn_name, \
linkage, \
__VA_ARGS__)
#define MIMICPP_DETAIL_GENERATE_FACADE_FUNCTION(ignore, traits, target_name, fn_name, linkage, ret, call_convention, param_type_list, specs, param_list, forward_list,...)
Creates a single facade function.
Definition Facade.hpp:241
#define MIMICPP_DETAIL_GENERATE_FACADE(fn_op, traits, target_name, fn_name, linkage,...)
Creates all overloads for a specific function facade and the target object.
Definition Facade.hpp:288

The most powerful entry point for creating a facade overload-set.

Parameters
traitsThe facade-traits.
target_nameThe name of the underlying target object.
fn_nameThe name of the facade overload-set.
linkageThe linkage for the facade functions and the target object.
...Overloads must be declared using the MIMICPP_ADD_OVERLOAD macro.

This macro defines a single target object that supports an arbitrary number of overloads. Each overload is implemented as its own facade function, forwarding calls to the underlying target object.

◆ MIMICPP_MAKE_OVERLOADED_MEMBER_MOCK

#define MIMICPP_MAKE_OVERLOADED_MEMBER_MOCK ( fn_name,
... )
Value:
fn_name##_, \
fn_name, \
, \
__VA_ARGS__)
basic_as_member< Mock > mock_as_member
Definition Facade.hpp:155

Entry point for mocking a member method overload-set.

Parameters
fn_nameThe name of the overload-set.
...Overloads must be declared using the MIMICPP_ADD_OVERLOAD macro.

This macro defines a single member mock object that supports an arbitrary number of member function overloads. Each overload is implemented as its own facade member function, forwarding calls to the underlying mock member-object.

The mock member-object name is the content of fn_name suffixed by an additional _.

class Interface
{
public:
virtual ~Interface() = default;
virtual void foo() = 0;
virtual void foo() const noexcept = 0;
};
class Derived
: public Interface
{
public:
~Derived() override = default;
// this generates both overrides and a mock object named `foo_`
foo,
ADD_OVERLOAD(void, (), override),
ADD_OVERLOAD(void, (), const noexcept override)); // note the `const noexcept` specifications as third argument
};
// this may be a function from somewhere else, working with an immutable interface.
constexpr auto my_function = [](Interface const& obj) {
obj.foo();
};
Derived mock{};
SCOPED_EXP std::as_const(mock).foo_.expect_call(); // We explicitly require the const overload to be called.
my_function(mock);

◆ MIMICPP_MAKE_OVERLOADED_MEMBER_MOCK_WITH_THIS

#define MIMICPP_MAKE_OVERLOADED_MEMBER_MOCK_WITH_THIS ( fn_name,
... )
Value:
fn_name##_, \
fn_name, \
, \
__VA_ARGS__)
basic_as_member_with_this< Self, Mock > mock_as_member_with_this
Definition Facade.hpp:190

Entry point for mocking a member method overload-set with an explicit this pointer.

Parameters
fn_nameThe name of the overload-set.
...Overloads must be declared using the MIMICPP_ADD_OVERLOAD macro.

This macro defines a single member mock object that supports an arbitrary number of member function overloads. Each overload is implemented as its own facade member function, forwarding calls to the underlying mock member-object while prepending an explicit this pointer to the argument list.

The mock member-object name is the content of fn_name suffixed by an additional _.

Attention
This macro requires a self_type alias to be defined in the class where the mock is declared. If self_type does not match the actual containing type, the behavior is undefined.
namespace finally = mimicpp::finally;
class Base
{
public:
virtual ~Base() = default;
virtual int foo() const
{
return 42;
}
};
class Derived
: public Base
{
public:
~Derived() override = default;
// This alias is required because the `..._WITH_THIS` macros are not able to determine the current type by themselves.
using self_type = Derived;
// This generates the override method and a mock object named foo_, which expects an explicit *this* param.
// => `Mock<int(Derived const*) const>`
MAKE_MEMBER_MOCK_WITH_THIS(foo, int, (), const override);
};
Derived object{};
// The first param behaves like an actual *this* pointer.
SCOPED_EXP object.foo_.expect_call(&object)
// Let's redirect the call to the actual `Base::foo` implementation.
and finally::returns_apply_all_result_of([](auto* self) { return self->Base::foo(); });
CHECK(42 == object.foo());