Skip to content

Commit

Permalink
Re #8357. Fix leak in test by breaking cyclic reference.
Browse files Browse the repository at this point in the history
The BoxController & BoxControllerDummyIO objects were each holding a
shared_ptr back to the other.
  • Loading branch information
RussellTaylor committed Mar 19, 2014
1 parent 845efec commit 72fed1a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions Code/Mantid/Framework/API/test/BoxControllerTest.h
Expand Up @@ -202,12 +202,12 @@ class BoxControllerTest : public CxxTest::TestSuite

void test_CloneFileBased()
{
BoxController_sptr a = boost::shared_ptr<BoxController>(new BoxController(2));
auto a = boost::make_shared<BoxController>(2);
a->setMaxDepth(4);
a->setSplitInto(10);
a->setMaxDepth(10);
a->setMaxId(123456);
boost::shared_ptr<IBoxControllerIO> pS(new MantidTestHelpers::BoxControllerDummyIO(a));
boost::shared_ptr<IBoxControllerIO> pS(new MantidTestHelpers::BoxControllerDummyIO(a.get()));
TS_ASSERT_THROWS_NOTHING(a->setFileBacked(pS,"fakeFile"));
TS_ASSERT(a->isFileBacked());

Expand All @@ -216,7 +216,7 @@ class BoxControllerTest : public CxxTest::TestSuite
compareBoxControllers(*a, *b);

TS_ASSERT(!b->isFileBacked());
boost::shared_ptr<IBoxControllerIO> pS2(new MantidTestHelpers::BoxControllerDummyIO(b));
boost::shared_ptr<IBoxControllerIO> pS2(new MantidTestHelpers::BoxControllerDummyIO(b.get()));
TS_ASSERT_THROWS_NOTHING(b->setFileBacked(pS2,"fakeFile2"));

// Check that settings are the same but BC are different
Expand All @@ -229,8 +229,8 @@ class BoxControllerTest : public CxxTest::TestSuite

void test_MRU_access()
{
BoxController_sptr a = boost::shared_ptr<BoxController>(new BoxController(2));
boost::shared_ptr<IBoxControllerIO> pS(new MantidTestHelpers::BoxControllerDummyIO(a));
auto a = boost::make_shared<BoxController>(2);
boost::shared_ptr<IBoxControllerIO> pS(new MantidTestHelpers::BoxControllerDummyIO(a.get()));
a->setFileBacked(pS,"existingFakeFile");
DiskBuffer * dbuf = a->getFileIO();

Expand All @@ -250,10 +250,10 @@ class BoxControllerTest : public CxxTest::TestSuite

void test_openCloseFileBacked()
{
BoxController_sptr a = boost::shared_ptr<BoxController>(new BoxController(2));
auto a = boost::make_shared<BoxController>(2);
TS_ASSERT(!a->isFileBacked());

boost::shared_ptr<IBoxControllerIO> pS(new MantidTestHelpers::BoxControllerDummyIO(a));
boost::shared_ptr<IBoxControllerIO> pS(new MantidTestHelpers::BoxControllerDummyIO(a.get()));
TS_ASSERT_THROWS_NOTHING(a->setFileBacked(pS,"fakeFile"));

TSM_ASSERT("Box controller should have open faked file",pS->isOpened());
Expand Down
Expand Up @@ -46,7 +46,7 @@ namespace MantidTestHelpers
class DLLExport BoxControllerDummyIO : public Mantid::API::IBoxControllerIO
{
public:
BoxControllerDummyIO(Mantid::API::BoxController_sptr theBC);
BoxControllerDummyIO(const Mantid::API::BoxController* theBC);

///@return true if the file to write events is opened and false otherwise
virtual bool isOpened()const
Expand Down Expand Up @@ -90,7 +90,7 @@ namespace MantidTestHelpers
// the file Handler responsible for Nexus IO operations;
mutable std::vector<float> fileContents;
/// shared pointer to the box controller, which is repsoponsible for this IO
Mantid::API::BoxController_sptr m_bc;
const Mantid::API::BoxController* m_bc;

mutable Mantid::Kernel::Mutex m_fileMutex;
/// number of bytes in the event coorinates (coord_t length). Set by setDataType but can be defined statically with coord_t
Expand Down
Expand Up @@ -16,7 +16,7 @@ namespace MantidTestHelpers
/**Constructor
@param bc shared pointer to the box controller which will use this IO operations
*/
BoxControllerDummyIO::BoxControllerDummyIO(Mantid::API::BoxController_sptr bc) :
BoxControllerDummyIO::BoxControllerDummyIO(const Mantid::API::BoxController* bc) :
m_bc(bc),
m_CoordSize(4),
m_TypeName("MDEvent"),
Expand Down

0 comments on commit 72fed1a

Please sign in to comment.