Is it necessary to free a shared_ptr?
I'm using Boost library to benefit from the smart pointers : shared_ptr.
I suspect that in my unit test, i'm doing a bad assignment.
What are the drawbacks of my implementation, specially the instuction that
has //suspected comment?
Do I need to free shared_ptr pointers (impossible to do in the way i'm
assigning in my unit test, i guess)?
Any advice? Thanks a lot!
In Class2 declaration:
static boost::shared_ptr<Class1> getInstanceOfClass1();
In Class2 definition:
boost::shared_ptr<Class1> Class2::getInstanceOfClass1()
{
boost::shared_ptr<Class1> inst1 = boost::make_shared<Class1>();
//.... some instructions on inst1
return inst1 ;
}
In a Unit Test using Boost.Test:
BOOST_AUTO_TEST_CASE( test_some_label_here )
{
string input;
//instructions...
// mocking the input
//...
Class2 a = *(Class2::getInstanceOfClass1()); //suspected
int code = a.useInputAndReturnCode(input);
// having CODE_X as a macro
BOOST_CHECK_EQUAL(code, CODE_X);
}
No comments:
Post a Comment