HippoMocks mocking return values by ref

后端 未结 2 807
离开以前
离开以前 2021-01-25 20:19
class IEmployeeServiceProxy
{
public:
    virtual ~IEmployeeServiceProxy() { }
    virtual void AddEmployee(const Employee&) = 0;
    virtual int GetEmployees(std::v         


        
相关标签:
2条回答
  • 2021-01-25 20:42

    The Git version (most recent one) has an option for Out parameters which are pretty much this. To use

    std::vector<int> args; args.push_back(1); args.push_back(2);
    mocks.ExpectCall(mock, IInterface::function).With(Out(arg));
    
    0 讨论(0)
  • 2021-01-25 20:45

    you have to provide the object for the reference yourself, make sure the mock uses it using With and you can alter it passing a function to Do, which also provides the return value. It does not matter how many reference arguments there are. Example:

    int AddSomeEmployees( std::vector< Employee >& v )
    {
      v.push_back( Employee() );
      return 0;
    }
    
      //test code
    std::vector< int > arg;
    
    mocks.ExpectCall( empSvcMock, IEmployeeServiceProxy::GetEmployees ).With( arg ).Do( AddSomeEmployees );
    

    Note that Do can take any kind of function, also std::function, lambdas etc.

    0 讨论(0)
提交回复
热议问题