This header-only library add gMock functionality for methods with number of arguments from 11 up to 15.
gMock is a C++ framework for writing mock classes. Mock methods are defined by MOCK_METHODn()
marco. However it can handle up to 10 arguments. But in some cases we need more.
For example we have such declaration of WINAPI
function with 11 arguments:
NTSTATUS WINAPI NtCreateUserProcess(
PHANDLE phProcess,
PHANDLE threadHandle,
ACCESS_MASK processDesiredAccess,
ACCESS_MASK threadDesiredAccess,
POBJECT_ATTRIBUTES processObjectAttributes,
POBJECT_ATTRIBUTES threadObjectAttributes,
ULONG processFlags,
ULONG threadFlags,
PRTL_USER_PROCESS_PARAMETERS processParameters,
PVOID createInfo,
PVOID attributeList
);
Before gmock-more-args we had to wrap arguments into structure:
struct CreateUserProcessParams
{
PHANDLE phProcess;
PHANDLE ThreadHandle;
ACCESS_MASK ProcessDesiredAccess;
ACCESS_MASK ThreadDesiredAccess;
POBJECT_ATTRIBUTES ProcessObjectAttributes;
POBJECT_ATTRIBUTES ThreadObjectAttributes;
ULONG ProcessFlags;
ULONG ThreadFlags;
PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
PVOID CreateInfo;
PVOID AttributeLis;
};
And pass it like a single argument:
MOCK_METHOD1(MockNtCreateUserProcess, NTSTATUS(CreateUserProcessParams params));
With gmock-more-args we just use MOCK_METHOD11
:
MOCK_GLOBAL_FUNC11(MockNtCreateUserProcess, NTSTATUS(
PHANDLE phProcess,
PHANDLE ThreadHandle,
ACCESS_MASK ProcessDesiredAccess,
ACCESS_MASK ThreadDesiredAccess,
POBJECT_ATTRIBUTES ProcessObjectAttributes,
POBJECT_ATTRIBUTES ThreadObjectAttributes,
ULONG ProcessFlags,
ULONG ThreadFlags,
PRTL_USER_PROCESS_PARAMETERS ProcessParameters,
PVOID CreateInfo,
PVOID AttributeLis
));
Compatibility of gmock-more-args with different gMock versions:
gmock-more-args | gMock |
---|---|
1.0.x | 1.8.0 |
- | 1.8.1 |
1.1.x | 1.10.0-1.11.0 |
At first your project needs to know about gmock-more-args.
- Add
gmock-more-args/include
to the project include paths. - Add
#include <gmock-more-args/gmock-more-args.h>
after gMock include.
Syntax is exactly the same as in gMock. For example, to mock method methodWith11Args
with 11 int
arguments and int
result you have to write declaration:
MOCK_METHOD11(methodWith11Args, int(int, int, int, int, int, int, int, int, int, int, int));
Samples live in the separate repository.
gmock-more-args is licensed under the MIT License. You can freely use it in your commercial or opensource software.
- Added compatibility with gMock 1.11.0
- Added compatibility with gMock 1.10.0
- Added compatibility with gMock 1.8.0
- Initial public release