I could really use some help mocking the dependencies in this scenario.
I have a client function that I need to test. It takes a 3rd party API resource and calls a method on it, populating the rest of its arguments with the output:
void ClassA::enumerateConnectedDevices(ThirdPartyAPI::BusManager & busMgr, QList<QByteArray> &devices, QStringList &descriptions)
At some point in this function s flow, it makes a call on the busMgr object whose signature looks like this:
ThirdPartyAPI::Error busMgr.GetNumOfCameras(...)
And the client code that uses that call looks like this:
ThirdPartyAPI::Error err = busMgr.GetNumOfCameras(&numCameras);
if (err != ThirdPartyAPI::ERROR_OK) { // compares against some enum
cout << "Error: " << err.GetDescription();
}
The problem I ran into is the copy of the error returned from GetNumberOfCameras to the err local variable. Mocking out the BusManager and Error classes works until that copy is made. Since the mock error is a subclass of ThirdPartyAPI::Error, the assignment operator slices the mock away. The third party API constructs valid error objects and returns them. Client code can only copy-construct or assign them.
All I need is to return valid mock error objects from my mocked BusManager for the SUT method to be testable. I m open to refactoring the SUT method as long as the intent remains the same.
Any suggestions will be greatly appreciated!
Cheers,
Alex