0

While using Hippomocks, we are having difficulties expecting that a byref argument was passed to a function.

class A
{
public:
    virtual ~A();
    virtual void foo(IBar& callback, const unsigned x);
};

IBar being an interface.

I then have a function that calls:

void Service::baz()
{a.foo(callback, 1);}

Here's the test:

TEST_FIXTURE(PigScalesServiceTest, test_something)
{
    A* aMock = mockRepository.Mock<A>();
    IBar* callback = mockRepository.Mock<IBar>(); 
    Service service(*amock, *callback);

    mockRepository.ExpectCall(aMock, A::foo).With(*callback, 1);
    service.baz();
}

Running the test will give me the following error:

Function A::foo(???,1) called with mismatching expectation!
Expections set:
Expectation for A::foo(???,1) on the mock at 0x0x10969908 was not satisfied.

Thanks a lot!

Lee
  • 3
  • 2
  • As a side note, changing the problematic function so that it receives a pointer instead of a reference works perfectly. We just have not come across a code example of expecting calls where references are passed to functions using hippomocks. – Lee Nov 02 '17 at 19:32

1 Answers1

0

I think you should use something like this:

mockRepository.ExpectCall(aMock, A::foo).With(byRef(*callback), 1);

Look at the unit tests of HippoMocks itself: https://github.com/dascandy/hippomocks/blob/master/HippoMocksTest/test_ref_args.cpp