The latest version of Hippo Mocks (in its Git repository) looks to have added support for COM interfaces. I've tried mocking an ADO connection object; which took some tweaking of Hippo Mocks to build properly (seems the COM version of the code wasn't updated for changes in the rest of Hippo Mocks). I have it building now, but the following test fails:
MockRepository mocks;
auto pConn = mocks.Mock<ADONS::_Connection>();
mocks.OnCall(pConn, ADONS::_Connection::AddRef).Return(1);
ADONS::_ConnectionPtr conn = pConn;
The very first thing the smart pointer does is AddRef
the interface. My mock shouldn't care about reference counting, so I add a call expectation that simply returns 1
. However, as soon as AddRef
gets called, a HippoMocks::NotImplementedException
gets thrown.
Has anyone had success with mocking a COM interface with Hippo Mocks?
I had the same issue and solved it. The actual version of hippomocks is now published on github:
https://github.com/dascandy/hippomocks
Great appreciation for the provided links, which helped to find an idea for the fix.
UPDATE, Details about my implementation and the added COM support.
First I made it work, which the following test demonstrates
In order to make it work I had to patch several places in hippomocks.h, the most vital in virtual_function_index method. The correction ensures correct address calculation for the call on an interface.
Second, I added some common setup helpers for COM objects, providing standard behaviour for AddRef, Release and QueryInterface.
The tests show how to use it:
The helper methods AddComExpectations and ConnectComInterfaces are provided in a separate header "comsupport.h". The header is an add-on for Hippomocks: