문제

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

how to prevent m_EmpSvcMock from being destroyed internally by HippoMock? When passing a mock to a shared_ptr, both would destroy the mock.

EDIT - Answer:

m_Mocks.ExpectCallDestructor(m_EmpSvcMock.get());
m_EmpSvcMock.reset();
도움이 되었습니까?

해결책

In the Git version (from Assembla) you can tell it to register a destructor to be called. Added bonus is that it will warn you about functions called on it after that with a ZombieMockException, so if you do leak a pointer somewhere and it gets used you'll know with a readable error.

다른 팁

use a helper like this, which creates a shared_ptr with a no-op deleter:

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 );
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top