I'm currently creating a test for a legacy code and stuck with this error message when running my test (see below):
Exception thrown at 0x0F5001EF (Control.dll) in sample.exe:
0xC0000005: Access violation reading location 0xDDDDDDDD.
I understand that 0xDDDDDDDD means code was trying to access an already deleted pointer. But what I do not understand is where it was 'prematurely' deleted.
I've kept it to the very bare minimum. Here is my code
CDevice::CDevice()
{
numLedRows = numLedCols = 0;
}
CDevice::~CDevice()
{
std::cout << "destructor!" << std::endl;
}
HRESULT CDevice::Init(IDevice* control)
{
HRESULT hr = S_OK;
deviceCtl.reset(control);
return hr;
}
where:
std::unique_ptr<IDevice> deviceCtl;
And my test:
TEST_F(deviceControlTest, test2)
{
sut_->Init(deviceMock_.get());
}
where
std::unique_ptr<CDevice> sut_;
std::unique_ptr<DeviceMock> deviceMock_;
and in SetUp...
sut_ = std::make_unique<CDevice>();
deviceMock_ = std::make_unique<DeviceMock>();
I have also tried using shared_ptr for DeviceMock, same behavior.
Is this something wrong with my code? Or is it my test?? Any suggestions will be greatly appreciated!