/
AffineMatrixParameterParserTest.h
116 lines (92 loc) · 3.71 KB
/
AffineMatrixParameterParserTest.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#ifndef AFFINE_MATRIX_PARAMETER_PARSER_TEST_H
#define AFFINE_MATRIX_PARAMETER_PARSER_TEST_H
#include <Poco/DOM/AutoPtr.h>
#include <Poco/DOM/DOMParser.h>
#include <Poco/DOM/Document.h>
#include <Poco/DOM/Element.h>
#include <cxxtest/TestSuite.h>
#include "MantidMDEvents/AffineMatrixParameterParser.h"
using namespace Mantid::MDEvents;
class AffineMatrixParameterParserTest : public CxxTest::TestSuite
{
public:
void testParse2by2()
{
Poco::XML::DOMParser pParser;
std::string xmlToParse = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Parameter><Type>AffineMatrixParameter</Type><Value>1,2;3,4;5,6</Value></Parameter>";
Poco::AutoPtr<Poco::XML::Document> pDoc = pParser.parseString(xmlToParse);
Poco::XML::Element* pRootElem = pDoc->documentElement();
AffineMatrixParameterParser parser;
AffineMatrixParameter* parameter = parser.createParameter(pRootElem);
AffineMatrixType product = parameter->getAffineMatrix();
//Check that matrix is recovered.
TSM_ASSERT(1, product[0][0]);
TSM_ASSERT(2, product[0][1]);
TSM_ASSERT(3, product[1][0]);
TSM_ASSERT(4, product[1][1]);
TSM_ASSERT(5, product[2][0]);
TSM_ASSERT(6, product[2][1]);
delete parameter;
}
void testParse3by3()
{
Poco::XML::DOMParser pParser;
std::string xmlToParse = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Parameter><Type>AffineMatrixParameter</Type><Value>1,2,3;4,5,6;7,8,9</Value></Parameter>";
Poco::AutoPtr<Poco::XML::Document> pDoc = pParser.parseString(xmlToParse);
Poco::XML::Element* pRootElem = pDoc->documentElement();
AffineMatrixParameterParser parser;
AffineMatrixParameter* parameter = parser.createParameter(pRootElem);
AffineMatrixType product = parameter->getAffineMatrix();
//Check that matrix is recovered.
TSM_ASSERT(1, product[0][0]);
TSM_ASSERT(2, product[0][1]);
TSM_ASSERT(3, product[0][2]);
TSM_ASSERT(4, product[1][0]);
TSM_ASSERT(5, product[1][1]);
TSM_ASSERT(6, product[1][2]);
TSM_ASSERT(7, product[2][0]);
TSM_ASSERT(8, product[2][1]);
TSM_ASSERT(9, product[2][2]);
delete parameter;
}
void testParse4by4()
{
Poco::XML::DOMParser pParser;
std::string xmlToParse = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Parameter><Type>AffineMatrixParameter</Type><Value>1,2,3,4;5,6,7,8;9,10,11,12</Value></Parameter>";
Poco::AutoPtr<Poco::XML::Document> pDoc = pParser.parseString(xmlToParse);
Poco::XML::Element* pRootElem = pDoc->documentElement();
AffineMatrixParameterParser parser;
AffineMatrixParameter* parameter = parser.createParameter(pRootElem);
AffineMatrixType product = parameter->getAffineMatrix();
//Check that matrix is recovered.
TSM_ASSERT(1, product[0][0]);
TSM_ASSERT(2, product[0][1]);
TSM_ASSERT(3, product[0][2]);
TSM_ASSERT(4, product[0][3]);
TSM_ASSERT(5, product[1][0]);
TSM_ASSERT(6, product[1][1]);
TSM_ASSERT(7, product[1][2]);
TSM_ASSERT(8, product[1][3]);
TSM_ASSERT(9, product[2][0]);
TSM_ASSERT(10, product[2][1]);
TSM_ASSERT(11, product[2][2]);
TSM_ASSERT(12, product[2][3]);
delete parameter;
}
void testThrowsOnCallSetSuccessor()
{
AffineMatrixParameterParser parser;
AffineMatrixParameterParser otherParser;
TS_ASSERT_THROWS(parser.setSuccessorParser(&otherParser), std::runtime_error);
}
void testThrowsIfWrongXML()
{
Poco::XML::DOMParser pParser;
std::string xmlToParse = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Parameter><Type>SOME_OTHER_PARAMETER_TYPE</Type><Value></Value></Parameter>";
Poco::AutoPtr<Poco::XML::Document> pDoc = pParser.parseString(xmlToParse);
Poco::XML::Element* pRootElem = pDoc->documentElement();
AffineMatrixParameterParser parser;
TS_ASSERT_THROWS(parser.createParameter(pRootElem), std::runtime_error);
}
};
#endif