sinojelly / mockcpp

Two C/C++ testing tools, mockcpp and testngpp.
Apache License 2.0
66 stars 39 forks source link

MOCKER函数不生效 #59

Open izxl007 opened 3 months ago

izxl007 commented 3 months ago

需要测试的代码

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打桩的函数也没有生效,而是直接调用了原函数。

请问有没有碰到类似的问题,以及有没有解决办法