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

Issue with mock with shared_ptr used in self-invocation #153

Closed
ericlemes opened this issue Aug 13, 2018 · 10 comments
Closed

Issue with mock with shared_ptr used in self-invocation #153

ericlemes opened this issue Aug 13, 2018 · 10 comments

Comments

@ericlemes
Copy link
Collaborator

I've created a test to capture this issue, but didn't find out how to fix yet.


	class ISomeInterface3 {
	public:
		virtual ~ISomeInterface3() { }
		
		virtual void methodWithSomeSharedPointer(std::shared_ptr<ISomeInterface3> listener) = 0;
	};

	void production_shared_ptr_mock_used_in_invocation() {		
		Mock<ISomeInterface3> mockDevAssertListener;
		std::shared_ptr<ISomeInterface3> devAssertListener = std::shared_ptr<ISomeInterface3>(&mockDevAssertListener.get());

		fakeit::Fake(Dtor(mockDevAssertListener));						
		fakeit::Fake(Method(mockDevAssertListener, methodWithSomeSharedPointer));
						
		devAssertListener->methodWithSomeSharedPointer(devAssertListener);
		devAssertListener = nullptr;
	}

I think this issue happens because some of the invocations store the shared_ptr and because of the order things are destructed it calls the destructor after the internal mock object is killed.

@eranpeer
Copy link
Owner

eranpeer commented Aug 14, 2018 via email

@ericlemes
Copy link
Collaborator Author

Good to know that helped. I was struggling to fix it, since I don't understand the code very well. I'll get there eventually.

If the test pass, it is definitely fixed.

@eranpeer
Copy link
Owner

eranpeer commented Aug 15, 2018 via email

@eranpeer
Copy link
Owner

eranpeer commented Aug 16, 2018 via email

@ericlemes
Copy link
Collaborator Author

ericlemes commented Aug 16, 2018 via email

@eranpeer
Copy link
Owner

eranpeer commented Aug 17, 2018 via email

@helmesjo
Copy link
Contributor

Should this be closed?

@VirtualTim
Copy link

VirtualTim commented Apr 19, 2021

@helmesjo it looks like this code is currently still commented out: 19bd30a.

@FranckRJ
Copy link
Collaborator

It's intended as far as I understand, it's not necessary anymore.

@FranckRJ
Copy link
Collaborator

FranckRJ commented May 2, 2021

Because it look like it's fixed (cannot reproduce) I'll close it.

@FranckRJ FranckRJ closed this as completed May 2, 2021
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

No branches or pull requests

5 participants