0

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.

Roland Sarrazin
  • 1,203
  • 11
  • 29

1 Answers1

2

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.

dascandy
  • 7,184
  • 1
  • 29
  • 50
  • The current Hippomocks version doesn't contain any `MemberMock` method. It contains a `MockRepository::Member` whose syntax I don't manage to decipher, especially the template parameter `class B` in `template void Member(A *mck, C B::*member)`. – Roland Sarrazin Jan 21 '14 at 15:48
  • As per the clean TDD I completely agree but I'm using a third-party software I won't be able to get changed in a short term. – Roland Sarrazin Jan 21 '14 at 15:49
  • Aah... that syntax is slightly confusing. The first argument is the object, the second is the address of the member. A is your class, C is the class of the member and B is the actual class of C's owner (which may differ from A, and is specified differently to ensure we can then convert the pointer to get a proper base offset). You should be able to specify `Member(obj, &Class::iValue);` to initialize it. After this it's fully initialized and usable so you should be able to just assign to it after. – dascandy Jan 21 '14 at 19:52
  • Thanks for the clarification. I have edited the answer to reflect your hints, please cross check my edit. I have eventually failed in initializing the member as it is not accessible from the test class. I'll check whether I can forward port the `ClassMock`. – Roland Sarrazin Jan 22 '14 at 12:25