Skip to content

Commit

Permalink
Fix more memory leaks in MD classes & tests.
Browse files Browse the repository at this point in the history
Refs #11512
  • Loading branch information
martyngigg committed Apr 14, 2015
1 parent 338323e commit f05603c
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 8 deletions.
Expand Up @@ -112,7 +112,7 @@ std::string CoordTransformDistance::toXMLString() const {

AutoPtr<Element> coordTransformTypeElement = pDoc->createElement("Type");
coordTransformTypeElement->appendChild(
pDoc->createTextNode("CoordTransformDistance"));
AutoPtr<Text>(pDoc->createTextNode("CoordTransformDistance")));
coordTransformElement->appendChild(coordTransformTypeElement);

AutoPtr<Element> paramListElement = pDoc->createElement("ParameterList");
Expand Down
Expand Up @@ -9,6 +9,8 @@
#include <iostream>
#include "MantidAPI/CoordTransform.h"

#include <boost/scoped_ptr.hpp>

using namespace Mantid;
using namespace Mantid::DataObjects;
using Mantid::API::CoordTransform;
Expand All @@ -30,13 +32,14 @@ class CoordTransformDistanceTest : public CxxTest::TestSuite
bool used[4] = {true, false, true, true};
CoordTransformDistance ct(4, center, used);
// A copy was made
TS_ASSERT_DIFFERS(ct.getCenter(), center);
const coord_t *transformCentres = ct.getCenter();
TS_ASSERT_DIFFERS(transformCentres, center);
const bool * usedDims = ct.getDimensionsUsed();
TS_ASSERT_DIFFERS(ct.getDimensionsUsed(), used);

// Contents are good
compare(4, center, ct.getCenter());
for (size_t i=0; i<4; i++)
TS_ASSERT_EQUALS( used[i], ct.getDimensionsUsed()[i]);
TS_ASSERT_EQUALS( used[i], usedDims[i]);
}


Expand All @@ -48,7 +51,7 @@ class CoordTransformDistanceTest : public CxxTest::TestSuite
bool used[2] = {true, true};
CoordTransformDistance ct(2,center,used);

CoordTransform * clone = ct.clone();
boost::scoped_ptr<CoordTransform> clone(ct.clone());
coord_t out = 0;
coord_t in1[2] = {0, 3};
TS_ASSERT_THROWS_NOTHING( clone->apply(in1, &out) );
Expand Down
56 changes: 55 additions & 1 deletion Code/Mantid/Framework/DataObjects/test/MDBoxIteratorTest.h
Expand Up @@ -79,6 +79,12 @@ class MDBoxIteratorTest : public CxxTest::TestSuite
D212 = dynamic_cast<ibox_t *>(C21->getChild(2));
D213 = dynamic_cast<ibox_t *>(C21->getChild(3));
}

void tearDown()
{
delete A->getBoxController();
delete A;
}

//--------------------------------------------------------------------------------------
void test_ctor_with_null_box_fails()
Expand Down Expand Up @@ -125,6 +131,8 @@ class MDBoxIteratorTest : public CxxTest::TestSuite
// Calling next again does not cause problems.
TS_ASSERT( !it->next() );
TS_ASSERT( !it->next() );

delete it;
}

void test_depth_limit_1()
Expand All @@ -138,6 +146,8 @@ class MDBoxIteratorTest : public CxxTest::TestSuite
TS_ASSERT( nextIs(it, B3) );
TS_ASSERT( !it->next() );
TS_ASSERT( !it->next() );

delete it;
}

void test_depth_limit_0()
Expand All @@ -147,6 +157,8 @@ class MDBoxIteratorTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS( it->getBox(), A);
TS_ASSERT( !it->next() );
TS_ASSERT( !it->next() );

delete it;
}

void test_starting_deeper()
Expand All @@ -160,6 +172,8 @@ class MDBoxIteratorTest : public CxxTest::TestSuite
TS_ASSERT( nextIs(it, C03) );
TS_ASSERT( !it->next() );
TS_ASSERT( !it->next() );

delete it;
}

void test_leaf_only()
Expand All @@ -184,6 +198,8 @@ class MDBoxIteratorTest : public CxxTest::TestSuite
// No more!
TS_ASSERT( !it->next() );
TS_ASSERT( !it->next() );

delete it;
}

void test_leaf_only_depth_2()
Expand All @@ -204,6 +220,8 @@ class MDBoxIteratorTest : public CxxTest::TestSuite
TS_ASSERT( nextIs(it, B3) );
TS_ASSERT( !it->next() );
TS_ASSERT( !it->next() );

delete it;
}

void test_leaf_only_depth_1()
Expand All @@ -217,6 +235,8 @@ class MDBoxIteratorTest : public CxxTest::TestSuite
TS_ASSERT( nextIs(it, B3) );
TS_ASSERT( !it->next() );
TS_ASSERT( !it->next() );

delete it;
}

void test_leaf_only_depth_0()
Expand All @@ -227,6 +247,8 @@ class MDBoxIteratorTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS( it->getBox(), A);
TS_ASSERT( !it->next() );
TS_ASSERT( !it->next() );

delete it;
}

void test_leaf_only_starting_deeper()
Expand All @@ -242,6 +264,8 @@ class MDBoxIteratorTest : public CxxTest::TestSuite
TS_ASSERT( nextIs(it, C23) );
TS_ASSERT( !it->next() );
TS_ASSERT( !it->next() );

delete it;
}

void test_leaf_only_starting_deeper_depth_limited()
Expand All @@ -254,6 +278,8 @@ class MDBoxIteratorTest : public CxxTest::TestSuite
TS_ASSERT( nextIs(it, C23) );
TS_ASSERT( !it->next() );
TS_ASSERT( !it->next() );

delete it;
}

//--------------------------------------------------------------------------------------
Expand All @@ -271,6 +297,8 @@ class MDBoxIteratorTest : public CxxTest::TestSuite

BoxController *const bc = A->getBoxController();
delete bc;
delete it;
delete A;
}

//--------------------------------------------------------------------------------------
Expand Down Expand Up @@ -302,7 +330,8 @@ class MDBoxIteratorTest : public CxxTest::TestSuite

BoxController *const bc = A->getBoxController();
delete bc;

delete it;
delete A;
}
//--------------------------------------------------------------------------------------
void test_iterator_withImplicitFunction_above11()
Expand All @@ -314,6 +343,7 @@ class MDBoxIteratorTest : public CxxTest::TestSuite

// Create an iterator
it = new MDBoxIterator<MDLeanEvent<1>,1>(A, 20, false, func);
delete func;

// Start with the top one
TS_ASSERT_EQUALS( it->getBox(), A);
Expand All @@ -335,6 +365,8 @@ class MDBoxIteratorTest : public CxxTest::TestSuite
// No more!
TS_ASSERT( !it->next() );
TS_ASSERT( !it->next() );

delete it;
}

//--------------------------------------------------------------------------------------
Expand All @@ -347,6 +379,7 @@ class MDBoxIteratorTest : public CxxTest::TestSuite

// Create an iterator
it = new MDBoxIterator<MDLeanEvent<1>,1>(A, 20, true, func);
delete func;

// C00-C01 are outside the range, so the first one is C02
TS_ASSERT_EQUALS( it->getBox(), C02);
Expand All @@ -363,6 +396,8 @@ class MDBoxIteratorTest : public CxxTest::TestSuite
// No more!
TS_ASSERT( !it->next() );
TS_ASSERT( !it->next() );

delete it;
}


Expand All @@ -376,6 +411,7 @@ class MDBoxIteratorTest : public CxxTest::TestSuite

// Create an iterator
it = new MDBoxIterator<MDLeanEvent<1>,1>(A, 20, false, func);
delete func;

// Start with the top one
TS_ASSERT_EQUALS( it->getBox(), A);
Expand All @@ -394,6 +430,8 @@ class MDBoxIteratorTest : public CxxTest::TestSuite
// No more!
TS_ASSERT( !it->next() );
TS_ASSERT( !it->next() );

delete it;
}


Expand All @@ -408,6 +446,7 @@ class MDBoxIteratorTest : public CxxTest::TestSuite

// Create an iterator
it = new MDBoxIterator<MDLeanEvent<1>,1>(A, 20, false, func);
delete func;

// Go down to the only two leaf boxes that are in range
TS_ASSERT_EQUALS( it->getBox(), A);
Expand All @@ -418,6 +457,8 @@ class MDBoxIteratorTest : public CxxTest::TestSuite
// No more!
TS_ASSERT( !it->next() );
TS_ASSERT( !it->next() );

delete it;
}

//--------------------------------------------------------------------------------------
Expand All @@ -431,13 +472,16 @@ class MDBoxIteratorTest : public CxxTest::TestSuite

// Create an iterator
it = new MDBoxIterator<MDLeanEvent<1>,1>(A, 20, true, func);
delete func;

// Only two leaf boxes are in range
TS_ASSERT_EQUALS( it->getBox(), D211);
TS_ASSERT( nextIs(it, D212) );
// No more!
TS_ASSERT( !it->next() );
TS_ASSERT( !it->next() );

delete it;
}

//--------------------------------------------------------------------------------------
Expand All @@ -449,11 +493,14 @@ class MDBoxIteratorTest : public CxxTest::TestSuite

// Create an iterator
it = new MDBoxIterator<MDLeanEvent<1>,1>(A, 20, false, func);
delete func;

// Returns the first box but that's it
TS_ASSERT_EQUALS( it->getBox(), A);
TS_ASSERT( !it->next() );
TS_ASSERT( !it->next() );

delete it;
}

//--------------------------------------------------------------------------------------
Expand All @@ -465,10 +512,14 @@ class MDBoxIteratorTest : public CxxTest::TestSuite

// Create an iterator
it = new MDBoxIterator<MDLeanEvent<1>,1>(A, 20, true, func);
delete func;

// Nothing in the iterator!
TS_ASSERT_EQUALS( it->getDataSize(), 0);
TS_ASSERT( !it->next() );
TS_ASSERT( !it->next() );

delete it;
}

void test_getIsMasked()
Expand Down Expand Up @@ -542,6 +593,9 @@ class MDBoxIteratorTest : public CxxTest::TestSuite
TSM_ASSERT_EQUALS("Should NOT have skipped to the second box", 2, evaluationIterator->getPosition());
TS_ASSERT_THROWS_NOTHING(evaluationIterator->next());
TSM_ASSERT_EQUALS("Should NOT have skipped to the third box", 3, evaluationIterator->getPosition());

delete setupIterator;
delete evaluationIterator;
}

void test_custom_skipping_policy()
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/DataObjects/test/MDBoxTest.h
Expand Up @@ -390,10 +390,10 @@ static void destroySuite(MDBoxTest * suite) { delete suite; }
b.addEvent(ev);
b.addEvent(ev);
b.addEvent(ev);
std::vector<MDLeanEvent<2> > * events;
events = b.getEventsCopy();
std::vector<MDLeanEvent<2> > * events = b.getEventsCopy();
TS_ASSERT_EQUALS( events->size(), 3);
TS_ASSERT_EQUALS( (*events)[2].getSignal(), 4.0);
delete events;
}

void test_sptr()
Expand Down

0 comments on commit f05603c

Please sign in to comment.