chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
When I trying to mock the method it is throwing the following error:

Assert failed. The function 'pressureRateClass::getCalculatedStr' returns by value (type is 'ATL::CStringT'). However Isolator++ cannot fake it since its default constructor couldn't be found.

Is there any workaround for this method method whose return type is CString,

I have mocked the method as follow:

CString currentVolume = "200";
pressureRateClass* totalVolumeOfStageFake = FAKE_ALL<pressureRateClass>();
While mocking one of the method as follow:
WHEN_CALLED(totalVolumeOfStageFake->getCalculatedStr()).Return(currentVolume);
asked by cvmohan (1.1k points)

1 Answer

0 votes

Hi Cvmohan,

Thank you for contacting us.

Can you please share with me the code of the method: getCalculatedStr?

Also, can you try replacing the when called line into this line:
WHEN_CALLED(totalVolumeOfStageFake->getCalculatedStr()).Return(&currentVolume);

Notice the ByVal return.

Cheers,

Alon Sapozhnikov.

Support Specialist.

answered by Alon_TypeMock (8.9k points)

Hi Alon,

Please Find the code of getCalculatedStr() function it returns CString type and method type is a const (inspector) Basically I am trying to Mock this method it returns the error that can't fake return types of CString

Assert failed. The function 'pressureRateClass::getCalculatedStr' returns by value (type is 'ATL::CStringT'). However Isolator++ cannot fake it since its default constructor couldn't be found.

CString pressureRateClass::getCalculatedStr() const

{

CString rtnString;

double input{}, output{};

int display{}, storage{};

CString formatStr;

if (dataPtr == nullptr && floatDataPtr == nullptr)

{

rtnString = "N/A";

return (rtnString);

}

display = unit.GetDisplayUnits();

storage = unit.GetStorageUnits();

if (floatDataPtr)

{

input = (double)multi * *floatDataPtr;

if ((input <= (FRAME_DATA_NOT_AVAILABLE + 1.0)) && (input >= (FRAME_DATA_NOT_AVAILABLE - 1.0))) return ("N/A");

}

else

{

input = (double)multi * *dataPtr;

if ((input <= (FRAME_DATA_NOT_AVAILABLE + 1.0)) && (input >= (FRAME_DATA_NOT_AVAILABLE - 1.0)))

return ("N/A");  // FRAME_DATA_NOT_AVAILABLE is a negitive value.

}

unit.ConvertValue(storage, input, display, output);

// rtnString.Format ("%8.4g %s", output, unit.GetUnitName());

formatStr = unit.GetUnitFormat(DISPLAY_UNITS, FORMAT_WIDTH);

formatStr += " %s";

rtnString.Format(formatStr, output, (const char*)unit.GetUnitName());

// GetUnitName defaults to display variable

return rtnString;

}

Hi Cvmohan,

Thank you for the detailed information.

Did you try the solution I suggested in my previous comment above?

I mean, the return ByVal option:

 WHEN_CALLED(totalVolumeOfStageFake->getCalculatedStr()).Return(&currentVolume);

Please keep me posted.

Cheers,

Alon Sapozhnikov.

Support Specialist.

...