mockcpp
mockcpp copied to clipboard
MOCKER函数不生效
需要测试的代码
void nfs4_op_getattr_Free(nfs_resop4 *res)
{
GETATTR4res *resp = &res->nfs_resop4_u.opgetattr;
if (resp->status == NFS4_OK)
nfs4_Fattr_Free(&resp->GETATTR4res_u.resok4.obj_attributes);
}
测试代码
TEST_F(Nfs4OpGetattrFreeTest, StatusIsNFS4_OK) {
res.nfs_resop4_u.opgetattr.status = NFS4_OK;
MOCKER(nfs4_Fattr_Free)
.expect(once())
.with(any());
nfs4_op_getattr_Free(&res);
GlobalMockObject::verify();
}
执行报如下错误: [ RUN ] Nfs4OpGetattrFreeTest.StatusIsNFS4_OK /home/mockcpp-master/src/ChainableMockObjectBase.cpp:84: Failure Invocation is expected only once(), but it's been invoked 0 times method(nfs4_Fattr_Free) .expects(once()) .invoked(0) .with(); unknown file: Failure C++ exception with description "failed due to mockcpp exception" thrown in the test body. [ FAILED ] Nfs4OpGetattrFreeTest.StatusIsNFS4_OK (0 ms)
分析上述报错的原因是:mock对象nfs4_Fattr_Free没有被调用。测试其他函数,MOCKER打桩的函数也没有生效,而是直接调用了原函数。
请问有没有碰到类似的问题,以及有没有解决办法