Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOCKER函数不生效 #59

Open
izxl007 opened this issue Jun 25, 2024 · 0 comments
Open

MOCKER函数不生效 #59

izxl007 opened this issue Jun 25, 2024 · 0 comments

Comments

@izxl007
Copy link

izxl007 commented Jun 25, 2024

需要测试的代码

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant