Debian Codegraph @

Source/Parser/CXMLTestsuiteCommandParser.cpp

raw
1 /*
2 * Copyright (C) 2013-2015, 2019 by the Konclude Developer Team.
3 *
4 * This file is part of the reasoning system Konclude.
5 * For details and support, see <http://konclude.com/>.
6 *
7 * Konclude is free software: you can redistribute it and/or modify
8 * it under the terms of version 3 of the GNU Lesser General Public
9 * License (LGPLv3) as published by the Free Software Foundation.
10 *
11 * Konclude is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU (Lesser) General Public License for more details.
15 *
16 * You should have received a copy of the GNU (Lesser) General Public
17 * License along with Konclude. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include "CXMLTestsuiteCommandParser.h"
22
23
24 namespace Konclude {
25
26 namespace Parser {
27
28
29
30 CXMLTestsuiteCommandParser::CXMLTestsuiteCommandParser() : CLogIdentifier("::Konclude::Parser::XMLTestsuiteCommandParser",this) {
31 LOG(INFO,"::Konclude::Parser::XMLTestsuiteCommandParser",logTr("XML Testsuite Parser initialized."),this);
32 command = 0;
33 recorder = 0;
34 delegater = 0;
35 }
36
37
38 CXMLTestsuiteCommandParser::~CXMLTestsuiteCommandParser() {
39 }
40
41
42
43
44 bool CXMLTestsuiteCommandParser::realizeCommand(CParseTestsuiteCommandsCommand *parseCommand, CCommandDelegater *commandDelegater) {
45 delegater = commandDelegater;
46 command = parseCommand;
47 if (command) {
48 recorder = command->getRecorder();
49 }
50 sourcePath = command->getSourcePath();
51 CStartProcessCommandRecord::makeRecord(recorder,getLogDomain(),command);
52 QByteArray *byteArray = command->getByteArray();
53 bool success = parse(*byteArray);
54 CStopProcessCommandRecord::makeRecord(recorder,getLogDomain(),command);
55 CFinishProcessCommandRecord::makeRecord(recorder,getLogDomain(),command);
56 return success;
57 }
58
59
60 bool CXMLTestsuiteCommandParser::parse(const QByteArray &content) {
61 bool successfullParsed = true;
62
63
64 QDomDocument document;
65
66 document.setContent(content,true);
67
68 QDomElement documentElement(document.documentElement());
69
70 successfullParsed = parse(&documentElement);
71
72 return successfullParsed;
73 }
74
75
76 bool CXMLTestsuiteCommandParser::parse(QDomElement *node) {
77 bool successfullParsed = true;
78
79 QDomElement documentElement(*node);
80
81 QString docElemName = documentElement.tagName();
82 if (docElemName == "ox:RequestMessage" || docElemName == "RequestMessage") {
83 LOG(INFO,getLogDomain(),logTr("Found OWLlink-Request Node."),this);
84 parseOWLlinkTestsuiteRequestNode(&documentElement);
85 } else {
86 successfullParsed = false;
87 CNotSupportedNodeErrorRecord::makeRecord(docElemName,recorder,getLogDomain(),command);
88 }
89
90 return successfullParsed;
91 }
92
93
94
95 bool CXMLTestsuiteCommandParser::realizeCommand(CParseTestsuiteXMLNodeCommand *testsuiteNodeCommand, CCommandDelegater *commandDelegater) {
96 delegater = commandDelegater;
97 nodeCommand = testsuiteNodeCommand;
98 if (nodeCommand) {
99 recorder = nodeCommand->getRecorder();
100 }
101 CStartProcessCommandRecord::makeRecord(recorder,getLogDomain(),nodeCommand);
102 QDomElement testsuiteNode = nodeCommand->getTestsuiteNode();
103
104 sourcePath = nodeCommand->getSourcePath();
105
106 QString docElemName = testsuiteNode.tagName();
107 if (docElemName == "ox:TestTestsuite" || docElemName == "TestTestsuite") {
108 CTestTestsuiteCommand *testTestsuiteComm = parseTestTestsuiteNode(&testsuiteNode);
109 nodeCommand->makeToSubCommand(testTestsuiteComm);
110 QDomElement testNode = testsuiteNode.firstChildElement();
111 while (!testNode.isNull()) {
112 QString testNodeElemName = testNode.tagName();
113
114 if (testNodeElemName == "ox:TestTestfileErrors" || testNodeElemName == "TestTestfileErrors") {
115 CTestTestfileCommand *testfileTestComm = parseTestTestfileNode(&testNode,testTestsuiteComm);
116 }
117
118 testNode = testNode.nextSiblingElement();
119 }
120 delegater->delegateCommand(testTestsuiteComm);
121
122 } else {
123 CNotSupportedNodeErrorRecord::makeRecord(docElemName,recorder,getLogDomain(),nodeCommand);
124 CCommand *skipComm = new CSkipUnsupportedCommandCommand(docElemName);
125 delegater->delegateCommand(skipComm);
126 }
127
128 CStopProcessCommandRecord::makeRecord(recorder,getLogDomain(),nodeCommand);
129 CFinishProcessCommandRecord::makeRecord(recorder,getLogDomain(),nodeCommand);
130 return true;
131 }
132
133
134
135 void CXMLTestsuiteCommandParser::parseOWLlinkTestsuiteRequestNode(QDomElement *requestNode) {
136 QDomElement node = requestNode->firstChildElement();
137
138 CPreconditionCommand *lastPreComm = 0;
139
140 while (!node.isNull()) {
141 // build for each node an expression
142
143 CPreconditionCommand *preComm;
144
145 QString docElemName = node.tagName();
146 if (docElemName == "ox:TestTestsuite" || docElemName == "TestTestsuite") {
147 CTestTestsuiteCommand *testTestsuiteComm = parseTestTestsuiteNode(&node);
148 QDomElement testNode = node.firstChildElement();
149 while (!testNode.isNull()) {
150 QString testNodeElemName = testNode.tagName();
151
152 if (testNodeElemName == "ox:TestTestfileErrors" || testNodeElemName == "TestTestfileErrors") {
153 CTestTestfileCommand *testfileTestComm = parseTestTestfileNode(&testNode,testTestsuiteComm);
154 }
155
156 testNode = testNode.nextSiblingElement();
157 }
158 preComm = testTestsuiteComm;
159 } else {
160 CNotSupportedNodeErrorRecord::makeRecord(docElemName,recorder,getLogDomain(),command);
161 preComm = new CSkipUnsupportedCommandCommand(docElemName);
162 }
163
164
165 if (preComm) {
166
167
168 if (lastPreComm) {
169 preComm->addCommandPrecondition(new CCommandProcessedPrecondition(lastPreComm));
170 }
171 if (command) {
172 command->makeToSubCommand(preComm);
173 }
174 if (delegater) {
175 delegater->delegateCommand(preComm);
176 }
177
178 lastPreComm = preComm;
179
180 }
181
182 preComm = 0;
183
184 node = node.nextSiblingElement();
185 }
186 }
187
188
189
190 CTestTestsuiteCommand *CXMLTestsuiteCommandParser::parseTestTestsuiteNode(QDomElement *node) {
191 QString nameString = node->attribute("name","Unamed Testsuite");
192 CReasonerTestsuiteTest *testsuiteTest = new CReasonerTestsuiteTest();
193 CTestTestsuiteCommand *testTestSuiteCommand = new CTestTestsuiteCommand(nameString);
194 testTestSuiteCommand->setTestsuiteTest(testsuiteTest);
195 QFileInfo fiSP(sourcePath);
196
197 QString loopCountString = node->attribute("defaultTestLoops","1");
198 bool convSucc = false;
199 qint64 loopCount = loopCountString.toLongLong(&convSucc);
200 if (convSucc) {
201 testsuiteTest->setDefaultTestLoopCount(loopCount);
202 }
203
204 if (node->hasAttribute("defaultTimeout")) {
205 QString timeoutString = node->attribute("defaultTimeout","0");
206 convSucc = false;
207 qint64 defTimeout = timeoutString.toLongLong(&convSucc);
208 if (convSucc) {
209 testsuiteTest->setDefaultTimeout(defTimeout);
210 }
211 }
212
213 if (fiSP.absoluteDir().exists()) {
214 testsuiteTest->setDefaultWorkingDirectory(fiSP.absolutePath());
215 }
216
217 if (node->hasAttribute("defaultWorkingDirectory")) {
218 QString workingDir = node->attribute("defaultWorkingDirectory");
219 testsuiteTest->setDefaultWorkingDirectory(workingDir);
220 }
221
222 return testTestSuiteCommand;
223 }
224
225
226
227 CTestTestfileCommand *CXMLTestsuiteCommandParser::parseTestTestfileNode(QDomElement *node, CTestTestsuiteCommand *testTestsuiteComm) {
228 CReasonerTestsuiteTest *testsuiteTest = testTestsuiteComm->getTestsuiteTest();
229 CReasonerTestfileTest *testfileTest = testsuiteTest->createTestfileTest();
230 CTestTestfileCommand *testTestfileComm = new CTestTestfileCommand(testfileTest,testTestsuiteComm);
231
232 if (node->hasAttribute("testLoops")) {
233 QString loopCountString = node->attribute("testLoops","1");
234 bool convSucc = false;
235 qint64 loopCount = loopCountString.toLongLong(&convSucc);
236 if (convSucc) {
237 testfileTest->setTestLoopCount(loopCount);
238 }
239 }
240
241 if (node->hasAttribute("timeout")) {
242 QString timeoutString = node->attribute("timeout");
243 bool convSucc = false;
244 qint64 timeout = timeoutString.toLongLong(&convSucc);
245 if (convSucc) {
246 testfileTest->setTimeout(timeout);
247 }
248 }
249
250 if (node->hasAttribute("workingDirectory")) {
251 QString workingDir = node->attribute("workingDirectory");
252 testfileTest->setWorkingDirectory(workingDir);
253 }
254
255 if (node->hasAttribute("requestSource")) {
256 QString requestSource = node->attribute("requestSource");
257 testfileTest->setTestRequestFile(requestSource);
258 }
259
260 if (node->hasAttribute("expectedResponseSource")) {
261 QString expResponseSource = node->attribute("expectedResponseSource");
262 testfileTest->setTestExpectedResponseFile(expResponseSource);
263 }
264 return testTestfileComm;
265 }
266
267
268
269 }; // end namespace Parser
270
271 }; // end namespace Konclude