Skip to content

Commit

Permalink
Re #8487. Eliminate Poco-related leaks in test.
Browse files Browse the repository at this point in the history
  • Loading branch information
RussellTaylor committed Mar 6, 2014
1 parent 668b03e commit ce7af19
Showing 1 changed file with 44 additions and 39 deletions.
83 changes: 44 additions & 39 deletions Code/Mantid/Framework/Geometry/test/MDGeometryXMLBuilderTest.h
Expand Up @@ -20,6 +20,7 @@
#include <Poco/DOM/NodeFilter.h>
#include <Poco/File.h>
#include <Poco/Path.h>
#include <Poco/AutoPtr.h>

using namespace Mantid;
using namespace Mantid::Geometry;
Expand Down Expand Up @@ -195,18 +196,18 @@ void testWithOrinaryDimensionOnly()
Poco::XML::DOMParser pParser;
std::string xmlToParse = builder.create(); //Serialize the geometry.

Poco::XML::Document* pDoc = pParser.parseString(xmlToParse);
Poco::AutoPtr<Poco::XML::Document> pDoc = pParser.parseString(xmlToParse);
Poco::XML::Element* pRootElem = pDoc->documentElement();

//Check that the number of dimensions provided is correct.
TSM_ASSERT_EQUALS("Wrong number of dimensions in geometry xml", 1, pRootElem->getElementsByTagName("Dimension")->length());
Poco::AutoPtr<Poco::XML::NodeList> dimension = pRootElem->getElementsByTagName("Dimension");
TSM_ASSERT_EQUALS("Wrong number of dimensions in geometry xml", 1, dimension->length());

//Check that mapping nodes give correct mappings.
Poco::XML::Element* dimensionSetElement = pRootElem;
TSM_ASSERT_EQUALS("Should have no DimensionY mapping", "", dimensionSetElement->getChildElement("XDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("Should have no DimensionY mapping", "", dimensionSetElement->getChildElement("YDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("Should have no DimensionZ mapping", "", dimensionSetElement->getChildElement("ZDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("Should have no DimensionT mapping", "", dimensionSetElement->getChildElement("TDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("Should have no DimensionY mapping", "", pRootElem->getChildElement("XDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("Should have no DimensionY mapping", "", pRootElem->getChildElement("YDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("Should have no DimensionZ mapping", "", pRootElem->getChildElement("ZDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("Should have no DimensionT mapping", "", pRootElem->getChildElement("TDimension")->getChildElement("RefDimensionId")->innerText());
}

void testManyOrinaryDimensions()
Expand Down Expand Up @@ -250,18 +251,18 @@ void testWithXDimensionOnly()
Poco::XML::DOMParser pParser;
std::string xmlToParse = builder.create(); //Serialize the geometry.

Poco::XML::Document* pDoc = pParser.parseString(xmlToParse);
Poco::AutoPtr<Poco::XML::Document> pDoc = pParser.parseString(xmlToParse);
Poco::XML::Element* pRootElem = pDoc->documentElement();

//Check that the number of dimensions provided is correct.
TSM_ASSERT_EQUALS("Wrong number of dimensions in geometry xml", 1, pRootElem->getElementsByTagName("Dimension")->length());
Poco::AutoPtr<Poco::XML::NodeList> dimension = pRootElem->getElementsByTagName("Dimension");
TSM_ASSERT_EQUALS("Wrong number of dimensions in geometry xml", 1, dimension->length());

//Check that mapping nodes give correct mappings.
Poco::XML::Element* dimensionSetElement = pRootElem;
TSM_ASSERT_EQUALS("No DimensionX mapping is incorrect", "a", dimensionSetElement->getChildElement("XDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("Should have no DimensionY mapping", "", dimensionSetElement->getChildElement("YDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("Should have no DimensionZ mapping", "", dimensionSetElement->getChildElement("ZDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("Should have no DimensionT mapping", "", dimensionSetElement->getChildElement("TDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("No DimensionX mapping is incorrect", "a", pRootElem->getChildElement("XDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("Should have no DimensionY mapping", "", pRootElem->getChildElement("YDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("Should have no DimensionZ mapping", "", pRootElem->getChildElement("ZDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("Should have no DimensionT mapping", "", pRootElem->getChildElement("TDimension")->getChildElement("RefDimensionId")->innerText());
}

void testWithXYDimensionOnly()
Expand All @@ -282,18 +283,18 @@ void testWithXYDimensionOnly()
Poco::XML::DOMParser pParser;
std::string xmlToParse = builder.create(); //Serialize the geometry.

Poco::XML::Document* pDoc = pParser.parseString(xmlToParse);
Poco::AutoPtr<Poco::XML::Document> pDoc = pParser.parseString(xmlToParse);
Poco::XML::Element* pRootElem = pDoc->documentElement();

//Check that the number of dimensions provided is correct.
TSM_ASSERT_EQUALS("Wrong number of dimensions in geometry xml", 2, pRootElem->getElementsByTagName("Dimension")->length());
Poco::AutoPtr<Poco::XML::NodeList> dimension = pRootElem->getElementsByTagName("Dimension");
TSM_ASSERT_EQUALS("Wrong number of dimensions in geometry xml", 2, dimension->length());

//Check that mapping nodes give correct mappings.
Poco::XML::Element* dimensionSetElement = pRootElem;
TSM_ASSERT_EQUALS("No DimensionX mapping is incorrect", "a", dimensionSetElement->getChildElement("XDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("Should have no DimensionY mapping", "b", dimensionSetElement->getChildElement("YDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("Should have no DimensionZ mapping", "", dimensionSetElement->getChildElement("ZDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("Should have no DimensionT mapping", "", dimensionSetElement->getChildElement("TDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("No DimensionX mapping is incorrect", "a", pRootElem->getChildElement("XDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("Should have no DimensionY mapping", "b", pRootElem->getChildElement("YDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("Should have no DimensionZ mapping", "", pRootElem->getChildElement("ZDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("Should have no DimensionT mapping", "", pRootElem->getChildElement("TDimension")->getChildElement("RefDimensionId")->innerText());
}

void testWithXYZDimensionOnly()
Expand All @@ -319,18 +320,18 @@ void testWithXYZDimensionOnly()
Poco::XML::DOMParser pParser;
std::string xmlToParse = builder.create(); //Serialize the geometry.

Poco::XML::Document* pDoc = pParser.parseString(xmlToParse);
Poco::AutoPtr<Poco::XML::Document> pDoc = pParser.parseString(xmlToParse);
Poco::XML::Element* pRootElem = pDoc->documentElement();

//Check that the number of dimensions provided is correct.
TSM_ASSERT_EQUALS("Wrong number of dimensions in geometry xml", 3, pRootElem->getElementsByTagName("Dimension")->length());
Poco::AutoPtr<Poco::XML::NodeList> dimension = pRootElem->getElementsByTagName("Dimension");
TSM_ASSERT_EQUALS("Wrong number of dimensions in geometry xml", 3, dimension->length());

//Check that mapping nodes give correct mappings.
Poco::XML::Element* dimensionSetElement = pRootElem;
TSM_ASSERT_EQUALS("No DimensionX mapping is incorrect", "a", dimensionSetElement->getChildElement("XDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("Should have no DimensionY mapping", "b", dimensionSetElement->getChildElement("YDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("Should have no DimensionZ mapping", "c", dimensionSetElement->getChildElement("ZDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("Should have no DimensionT mapping", "", dimensionSetElement->getChildElement("TDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("No DimensionX mapping is incorrect", "a", pRootElem->getChildElement("XDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("Should have no DimensionY mapping", "b", pRootElem->getChildElement("YDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("Should have no DimensionZ mapping", "c", pRootElem->getChildElement("ZDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("Should have no DimensionT mapping", "", pRootElem->getChildElement("TDimension")->getChildElement("RefDimensionId")->innerText());
}

void testFullCreate()
Expand Down Expand Up @@ -362,24 +363,28 @@ void testFullCreate()
Poco::XML::DOMParser pParser;
std::string xmlToParse = builder.create(); //Serialize the geometry.

Poco::XML::Document* pDoc = pParser.parseString(xmlToParse);
Poco::AutoPtr<Poco::XML::Document> pDoc = pParser.parseString(xmlToParse);
Poco::XML::Element* pRootElem = pDoc->documentElement();

//Check that the number of dimensions provided is correct.
TSM_ASSERT_EQUALS("Wrong number of dimensions in geometry xml", 4, pRootElem->getElementsByTagName("Dimension")->length());
Poco::AutoPtr<Poco::XML::NodeList> dimension = pRootElem->getElementsByTagName("Dimension");
TSM_ASSERT_EQUALS("Wrong number of dimensions in geometry xml", 4, dimension->length());

//Check that mapping nodes have been provided.
TSM_ASSERT_EQUALS("No DimensionX in geometry xml", 1, pRootElem->getElementsByTagName("XDimension")->length());
TSM_ASSERT_EQUALS("No DimensionY in geometry xml", 1, pRootElem->getElementsByTagName("YDimension")->length());
TSM_ASSERT_EQUALS("No DimensionZ in geometry xml", 1, pRootElem->getElementsByTagName("ZDimension")->length());
TSM_ASSERT_EQUALS("No DimensionT in geometry xml", 1, pRootElem->getElementsByTagName("TDimension")->length());
Poco::AutoPtr<Poco::XML::NodeList> xdimension = pRootElem->getElementsByTagName("XDimension");
TSM_ASSERT_EQUALS("No DimensionX in geometry xml", 1, xdimension->length());
Poco::AutoPtr<Poco::XML::NodeList> ydimension = pRootElem->getElementsByTagName("YDimension");
TSM_ASSERT_EQUALS("No DimensionY in geometry xml", 1, ydimension->length());
Poco::AutoPtr<Poco::XML::NodeList> zdimension = pRootElem->getElementsByTagName("ZDimension");
TSM_ASSERT_EQUALS("No DimensionZ in geometry xml", 1, zdimension->length());
Poco::AutoPtr<Poco::XML::NodeList> tdimension = pRootElem->getElementsByTagName("TDimension");
TSM_ASSERT_EQUALS("No DimensionT in geometry xml", 1, tdimension->length());

//Check that mapping nodes give correct mappings.
Poco::XML::Element* dimensionSetElement = pRootElem;
TSM_ASSERT_EQUALS("No DimensionX mapping is incorrect", "a", dimensionSetElement->getChildElement("XDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("No DimensionY mapping is incorrect", "b", dimensionSetElement->getChildElement("YDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("No DimensionZ mapping is incorrect", "c", dimensionSetElement->getChildElement("ZDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("No DimensionT mapping is incorrect", "d", dimensionSetElement->getChildElement("TDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("No DimensionX mapping is incorrect", "a", pRootElem->getChildElement("XDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("No DimensionY mapping is incorrect", "b", pRootElem->getChildElement("YDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("No DimensionZ mapping is incorrect", "c", pRootElem->getChildElement("ZDimension")->getChildElement("RefDimensionId")->innerText());
TSM_ASSERT_EQUALS("No DimensionT mapping is incorrect", "d", pRootElem->getChildElement("TDimension")->getChildElement("RefDimensionId")->innerText());
}

};
Expand Down

0 comments on commit ce7af19

Please sign in to comment.