Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support unique ptr #82

Open
wants to merge 7 commits into
base: cpp11
Choose a base branch
from
Open

Conversation

APokorny
Copy link

@APokorny APokorny commented Jul 8, 2017

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 and others added 7 commits July 8, 2017 16:37
This allows creating default unique_ptr<T> mock objects.

Signed-off-by: Andreas Pokorny <[email protected]>
This assumes that the destructor of "base" is actually called.

Signed-off-by: Andreas Pokorny <[email protected]>
Solves the common case of capturing an object to formulate expectations while forwarding exclusive ownership to the class under test

Signed-off-by: Andreas Pokorny <[email protected]>
Signed-off-by: Andreas Pokorny <[email protected]>
@APokorny
Copy link
Author

Is there anything missing here?

@dascandy
Copy link
Owner

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

@sameer-chaudhari
Copy link

@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
Copy link
Owner

@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...

jeremy-ir added a commit to jeremy-ir/hippomocks that referenced this pull request Jun 12, 2022
[Issue/Feature Description]
Mocking of unique_ptr is currently not supported in HippoMocks.

[Resolution]
Cherry-pick changes from dascandy#82 which
add support for unique_ptr.
jeremy-ir added a commit to jeremy-ir/hippomocks that referenced this pull request Jun 12, 2022
[Issue/Feature Description]
Mocking of unique_ptr is currently not supported in HippoMocks.

[Resolution]
Cherry-pick changes from dascandy#82 which
add support for unique_ptr.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants