IEmployeeServiceProxy* empSvcMock = m_Mocks.InterfaceMock<IEmployeeServiceProxy>();
m_EmpSvcMock.reset(empSvcMock); // shared_ptr because my class Client ctor expects a shared_ptr<IEmployeeServiceProxy>
Client client(m_EmpSvcMock);如何防止HippoMock在内部销毁m_EmpSvcMock?当将模拟传递给shared_ptr时,两者都会破坏模拟。
编辑-回答:
m_Mocks.ExpectCallDestructor(m_EmpSvcMock.get());
m_EmpSvcMock.reset();发布于 2012-08-02 15:53:02
在Git版本(来自Assembla)中,您可以告诉它注册一个要调用的析构函数。额外的好处是,它将警告你调用了函数之后,通过一个ZombieMockException,所以如果你确实泄漏了某个地方的指针,它被使用了,你将知道一个可读的错误。
发布于 2012-08-02 15:37:42
使用像这样的帮助器,它创建一个带有no-op deleter的shared_ptr:
template< class T >
void NoDelete( T* )
{
}
template< class T >
std::shared_ptr< T > make_shared_ref( T* t )
{
return std::shared_ptr< T >( t, NoDelete< T > );
}
//usage
m_EmpSvcMoc = make_shared_ref( empSvcMock );https://stackoverflow.com/questions/11772911
复制相似问题