dascandy / hippomocks

GNU Lesser General Public License v2.1
192 stars 65 forks source link

Support unique ptr #82

Open APokorny opened 7 years ago

APokorny commented 7 years ago

This adds support for mock objects controlled by unique_ptr. In this proposal the mock repository is not the owner of the mock object - it just assists in construction. The verification of expectations thus happens when the mock object is destroyed.

Use the new UniqueMock function (or UniqueMock(Deleter d)) to construct a mock object within a unique_ptr. For example in your test you can write:

   MockRepository mocks;
   Type* mocked_thing{nullptr};
   ObjectUnderTest  obj{Hippomocks::tee(mocked_thing, mocks.UniqueMock<Type>())};

   mocks.ExpectCall(mocked_thing, Type::beTypy);
APokorny commented 7 years ago

Is there anything missing here?

dascandy commented 7 years ago

Only time for me to review your change. I'll find some time the next two days.

sameer-chaudhari commented 6 years ago

@dascandy Are you planning to merge to cpp 11 branch. We are planning to use cpp11 branch for our code base. Which require unique ptr mocking support. Apologies I am quite new to git hub

dascandy commented 5 years ago

@APokorny Time got lost here. From what I can tell it's similar to adding an ExpectDestructor to a regular mock & returning a unique_ptr directly? That would be a much smaller delta to the existing code base & not require a new subclass...