0

在使用 Hippomocks 时,我们很难期望将 byref 参数传递给函数。

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

IBar 是一个接口。

然后我有一个函数调用:

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

这是测试:

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();
}

运行测试会给我以下错误:

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

非常感谢!

4

1 回答 1

0

我认为你应该使用这样的东西:

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

查看 HippoMocks 本身的单元测试: https ://github.com/dascandy/hippomocks/blob/master/HippoMocksTest/test_ref_args.cpp

于 2017-11-06T08:26:29.990 回答