Coder Social home page Coder Social logo

gmock-more-args's Introduction

gmock-more-args Build Status

This header-only library add gMock functionality for methods with number of arguments from 11 up to 15.

Introduction

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

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

Usage

Step 1: Adding includes

At first your project needs to know about gmock-more-args.

  1. Add gmock-more-args/include to the project include paths.
  2. Add #include <gmock-more-args/gmock-more-args.h> after gMock include.

Step 2: Declare mock method with more than 10 arguments

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

Samples live in the separate repository.

License

gmock-more-args is licensed under the MIT License. You can freely use it in your commercial or opensource software.

Version history

Version 1.1.1 (18 Feb 2022)

  • Added compatibility with gMock 1.11.0

Version 1.1.0 (18 Apr 2019)

  • Added compatibility with gMock 1.10.0

Version 1.0.1 (18 Apr 2019)

  • Added compatibility with gMock 1.8.0

Version 1.0.0 (12 Oct 2017)

  • Initial public release

gmock-more-args's People

Contributors

cuprumator avatar grivus avatar sergiusthebest avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

flexxxman

gmock-more-args's Issues

Align with new gmock

Your code is not working any more with newest gmock, since internal::FunctionMockerBase declaration is not visible any more

Align with gmock 1.10.0

Working on using gmock 1.10.0 and this library and came across a compatibility issue. Seeing how it went up to 1.8.1, I am looking to see if this repo can provide another update. Gives the same error as the previous issue opened (internal::FunctionMockerBase declaration is not visible any more)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.