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
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes

CTime not working when the function return type is by value. Here is the example 

Class to be Tested

#include <atltime.h>

class Address

{
public:
CTime& GetTime_BYREF() { throw; }
CTime GetTime_BYVAL() { throw; }

}

Test Method

TEST_METHOD(TimeTest)

{

Address *address = FAKE<Address>();

WHEN_CALLED(address->GetTime_BYREF()).Return(BY_REF(CTime::GetCurrentTime())); // Works

WHEN_CALLED(address->GetTime_BYVAL()).Return(BY_VAL(CTime::GetCurrentTime())); // Crashes

}

}

asked by selvendran.ayyaswamy (1.6k points)
reshown ago by Alon_TypeMock

1 Answer

0 votes

Hi Selva,

I have looked into this issue and the solution is creating a dummy object of type CTime before you set up the WHEN_CALLED behavior.

Example:

Address* address = FAKE<Address>();
auto a = new CTime();
WHEN_CALLED(address->GetTime_BYVAL()).Return(BY_VAL(CTime::GetCurrentTime()));

The reason this test fails is because the linker doesn't add the debug information of the default constructor of the CTime type, and Typemock cannot find it, which explains the error message.

Hope this helps.

Best,
Tom Milchman
Typemock Support Specialist

answered by Tom_Typemock (1.5k points)
edited by Tom_Typemock
...