-
Notifications
You must be signed in to change notification settings - Fork 170
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
Mocks and std::unique_ptr #10
Comments
Hi, |
Ok, It works! You can mock the dtor now! Mock<SomeInterface> mock;
Fake(Dtor(mock)); // Stub the dtor to do nothing!!
SomeInterface * i = &mock.get();
std::unique_ptr<SomeInterface> ptr(i); You can do much more than that: void mock_virtual_dtor_with_when() {
int a = 0;
Mock<SomeInterface> mock;
When(Dtor(mock)).Do([&](){a++; });
SomeInterface * i = &(mock.get());
delete i; // a++
delete i; // a++
ASSERT_EQUAL(2, a);
} Enjoy! |
Thanks for your effort! I will certainly try this out next week. |
Hi, it works fine now. I have just a small remark: At this line GCC 4.8 gives the warning |
Sure, I'll fix it this weekend.
|
Done! I fixed the gcc warning. |
I have a similar crash here with Qt's QSharedPointer. Used current master branch!
The code:
|
What happens when both the mock and the unique_ptr (that points to the mocked instance) are deleted? {
Mock<SomeType> mock;
Fake(Dtor(mock));
std::unique_ptr<SomeType> ptr {&mock.get()};
} // <- both are deleted I'm having some issues and I suspect it has to do with this.. |
How am I supposed to pass a mock as unique pointer?
For example:
This code crashes on exiting the test because both
Mock
andHandler
take ownership of theObject
instance. Could you add some release method toMock
which releases ownership but still holds a weak reference to the object? Or is there another way to handle this?The text was updated successfully, but these errors were encountered: