GoogleTest: Mock object should be deleted but never is.
-
Hi,
Why are you creating that object on the heap rather than the stack ?
-
@henrik2016 said in GoogleTest: Mock object should be deleted but never is.:
_selectedConfValid = new MockOpcConf();
Youre still creating it on the heap, why not simply:
TestOpcUa() { MockOpcConf _selectedConfValid; // Allocate on the stack, no need to delete explicetly
-
@henrik2016 said in GoogleTest: Mock object should be deleted but never is.:
The function I would like to test need pointer.
And what is the problem? Just pass it the pointer then:
&_selectedConfValid
-
@jsulm But how can I modify the lambda function?
-
@henrik2016 What exactly do you want to change?
-
@jsulm I create 19 Mock-Objects like this:
shared_ptr<MockOpcNode> deviceNo = make_shared<MockOpcNode>();
At the end of my test, I have to delete all objects. How can I do this?
-
@henrik2016 said in GoogleTest: Mock object should be deleted but never is.:
At the end of my test, I have to delete all objects. How can I do this?
You don't if you do not allocate on the heap (don't use new) - that was the whole point of what @SGaist wrote.
So, why do you do it this way_selectedConfValid = new MockOpcConf();
intead of
MockOpcConf _selectedConfValid;
?
-
@jsulm I already use
MockOpcConf _selectedConfValid;
But I have got the other objects.