Equivalent of Hippomocks' previously existing MockRepository::ClassMock

665 views Asked by At

In the official version 3.1 of Hippomocks (https://www.assembla.com/spaces/hippomocks/wiki/Home) there used to be a MockRepository::ClassMock that constructed mocked objects (contrary to MockRepository::InterfaceMock that doesn't) which can be very useful when dealing with non-virtual class methods.

The current version's MockRepository::Mock does what MockRepository::InterfaceMock did in my opinion. Is there any possibility to construct mocked objects with the current version?

Rationale for my not taking the version 3.1: I need the also very useful ExpectCallFunc to test functions that don't belong to classes which was introduced later.

Rationale for not using placement new: Placement new would construct the object after being mocked by Hippomocks thus "resetting" the virtual function table previously altered by Hippomocks.

1

There are 1 answers

4
dascandy On BEST ANSWER

No, there isn't. You can mock methods and members now, which as far as I could tell should catch all cases where your class needs something to exist. You would use MockRepository::MemberMock(obj, &Class::iValue) to initialize the member.

If you really need ClassMock it's probably best to first think why you need it; in clean TDD it's never necessary so there's something that might need refactoring to avoid that situation. Then again, you can also backport ExpectCallFunc; it's a fairly separate functionality so it should be reasonably backportable. If you do though, take the current git version from Github as it has verified C method mocking for Linux/Windows/Mac X86 and X86-64 and on Raspbian/ARM.