I have s scenario where in a local object is instantiated to call a method of that class i.e setSessionId()
. Defination of setSessionId is as follows:
int Cli::setSessionId()
{
SessionHandler oHandleSession;
return oHandleSession.getSessionId(sSessionId);
}
now in order to mock functions of SessionHandler
I have used macros to add virtual
keyword before the functions I want to mock, in this case getSessionId()
as this class is not abstract and functions are not pure virtual.(I know about Hi-Perf Dependency Injection but dont want to go in it at this stage)
Had the case been this
int Cli::setSessionId(SessionHandler* oHandleSession)
{
...
return oHandleSession->getSessionId(sSessionId);
}
It would have been simple to just pass the mocked object to the function setSessionid()
but since aggregation is used, how can I mock this function getSessionId()
?