Newer
Older
#ifndef TEST_COMPOSITE_FUNCTION_PARSER_H_
#define TEST_COMPOSITE_FUNCTION_PARSER_H_
#include "FunctionParserTest.h"
#include <vector>
#include <memory>
#include <boost/scoped_ptr.hpp>
#include "MantidMDAlgorithms/InvalidParameterParser.h"
#include "MantidMDAlgorithms/CompositeImplicitFunctionParser.h"
//#include "MantidMDAlgorithms/PlaneImplicitFunctionParser.h"
#include "MantidMDAlgorithms/CompositeImplicitFunction.h"
Federico Montesino Pouzols
committed
#include <Poco/AutoPtr.h>
#include <Poco/DOM/DOMParser.h>
#include <Poco/DOM/Document.h>
#include <Poco/DOM/Element.h>
Federico Montesino Pouzols
committed
class CompositeImplicitFunctionParserTest : public CxxTest::TestSuite,
FunctionParserTest {
Federico Montesino Pouzols
committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
void disabled_testBadXMLSchemaThrows(void) {
using namespace Mantid::MDAlgorithms;
Poco::XML::DOMParser pParser;
std::string xmlToParse = "<?xml version=\"1.0\" "
"encoding=\"utf-8\"?><X><Type>"
"CompositeImplicitFunction</Type><ParameterList></"
"ParameterList></X>";
Poco::AutoPtr<Poco::XML::Document> pDoc = pParser.parseString(xmlToParse);
Poco::XML::Element *pRootElem = pDoc->documentElement();
CompositeImplicitFunctionParser functionParser;
TSM_ASSERT_THROWS("Should have thrown invalid_argument exception as "
"Function element was expected, but not found.",
functionParser.createFunctionBuilder(pRootElem),
std::invalid_argument);
}
void disabled_testNoSuccessorFunctionParserThrows(void) {
using namespace Mantid::MDAlgorithms;
Poco::XML::DOMParser pParser;
std::string xmlToParse = "<?xml version=\"1.0\" "
"encoding=\"utf-8\"?><Function><Type>"
"CompositeImplicitFunction</Type><ParameterList></"
"ParameterList></Function>";
Poco::AutoPtr<Poco::XML::Document> pDoc = pParser.parseString(xmlToParse);
Poco::XML::Element *pRootElem = pDoc->documentElement();
CompositeImplicitFunctionParser functionParser;
TSM_ASSERT_THROWS(
"There is no successor parser setup for the PlaneFunctionParser",
functionParser.createFunctionBuilder(pRootElem), std::runtime_error);
}
void disabled_testCallsFunctionParserChain() {
using namespace Mantid::MDAlgorithms;
using namespace Mantid::API;
Poco::XML::DOMParser pParser;
std::string xmlToParse = "<?xml version=\"1.0\" "
"encoding=\"utf-8\"?><Function><Type>"
"OtherFunctionType</Type><ParameterList></"
"ParameterList></Function>";
Poco::AutoPtr<Poco::XML::Document> pDoc = pParser.parseString(xmlToParse);
Poco::XML::Element *pRootElem = pDoc->documentElement();
MockFunctionParser *mockFuncParser =
new MockFunctionParser(constructRootParameterParser());
EXPECT_CALL(*mockFuncParser, createFunctionBuilder(testing::_)).Times(1);
CompositeImplicitFunctionParser functionParser;
functionParser.setSuccessorParser(mockFuncParser);
ImplicitFunctionBuilder *builder =
functionParser.createFunctionBuilder(pRootElem);
delete builder;
TSM_ASSERT("Incorrect calling of nested successor function parsers",
testing::Mock::VerifyAndClearExpectations(mockFuncParser))
}
Federico Montesino Pouzols
committed
void disabled_testParseCompositeFunction(void) {
using namespace Mantid::MDAlgorithms;
using namespace Mantid::API;
Poco::XML::DOMParser pParser;
std::string xmlToParse =
std::string("<?xml version=\"1.0\" encoding=\"utf-8\"?>") +
"<Function>" + "<Type>CompositeImplicitFunction</Type>" + "<Function>" +
"<Type>PlaneImplicitFunction</Type>" + "<ParameterList>" +
"<Parameter><Type>NormalParameter</Type><Value>-1, -2, "
"-3</Value></Parameter>" +
"<Parameter><Type>OriginParameter</Type><Value>1, 2, "
"3</Value></Parameter>" +
"<Parameter><Type>WidthParameter</Type><Value>7</Value></Parameter>" +
"</ParameterList>" + "</Function>" + "<Function>" +
"<Type>PlaneImplicitFunction</Type>" + "<ParameterList>" +
"<Parameter><Type>NormalParameter</Type><Value>-1, -2, "
"-3</Value></Parameter>" +
"<Parameter><Type>OriginParameter</Type><Value>1, 2, "
"3</Value></Parameter>" +
"<Parameter><Type>WidthParameter</Type><Value>7</Value></Parameter>" +
"</ParameterList>" + "</Function>" + "</Function>";
Poco::AutoPtr<Poco::XML::Document> pDoc = pParser.parseString(xmlToParse);
Poco::XML::Element *pRootElem = pDoc->documentElement();
Federico Montesino Pouzols
committed
CompositeImplicitFunctionParser functionParser;
ImplicitFunctionParser *planeParser = new PlaneImplicitFunctionParser;
planeParser->setParameterParser(constructRootParameterParser());
functionParser.setSuccessorParser(planeParser);
ImplicitFunctionBuilder *implicitFunctionBuilder =
functionParser.createFunctionBuilder(pRootElem);
Mantid::Geometry::MDImplicitFunction_sptr impFunction(
implicitFunctionBuilder->create());
Federico Montesino Pouzols
committed
CompositeImplicitFunction *compositeFunction =
dynamic_cast<CompositeImplicitFunction *>(impFunction.get());
Federico Montesino Pouzols
committed
TSM_ASSERT(
"A composite implicit function should have been created from the xml.",
compositeFunction != NULL);
TSM_ASSERT_EQUALS("The composite does not contain the expected number of "
"next-level nested functions.",
2, compositeFunction->getNFunctions())
}