| 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 "CReasonerTestfileErrorEvaluator.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Test { |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
CReasonerTestfileErrorEvaluator::CReasonerTestfileErrorEvaluator() : CLogIdentifier("::Konclude::Test::ReasonerTestfileErrorEvaluator",this) { |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
CReasonerTestfileErrorEvaluator::~CReasonerTestfileErrorEvaluator() { |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
CReasonerTestfileEvaluator *CReasonerTestfileErrorEvaluator::evaluateTestfile(CReasonerTestfileTest *test, const QByteArray &resultingByteArray) { |
| 39 |
QDomDocument document; |
| 40 |
if (document.setContent(resultingByteArray,true)) { |
| 41 |
QDomElement documentEl(document.documentElement()); |
| 42 |
checkTestResponseErrors(test->getTestResults(),&documentEl); |
| 43 |
} else { |
| 44 |
test->getTestResults()->addTestResult(false,false,false,false,0); |
| 45 |
} |
| 46 |
return this; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
CReasonerTestfileErrorEvaluator *CReasonerTestfileErrorEvaluator::checkTestResponseErrors(CReasonerTestfileTestResult *testResult, QDomElement *node) { |
| 51 |
|
| 52 |
QDomElement documentElement(*node); |
| 53 |
|
| 54 |
QString docElemName = documentElement.tagName(); |
| 55 |
if (docElemName == "ox:ResponseMessage" || docElemName == "ResponseMessage") { |
| 56 |
QDomElement responseElement = documentElement.firstChildElement(); |
| 57 |
|
| 58 |
double totalResponseTime = 0; |
| 59 |
bool responseError = false; |
| 60 |
bool wrongResult = false; |
| 61 |
|
| 62 |
while (!responseElement.isNull()) { |
| 63 |
bool unknownElement = false; |
| 64 |
bool errorElement = false; |
| 65 |
bool hasResponseTime = false; |
| 66 |
qint64 responseTime = 0; |
| 67 |
QString respElemName = responseElement.tagName(); |
| 68 |
if (respElemName == "ox:KB" || respElemName == "KB") { |
| 69 |
} else if (respElemName == "ox:OK" || respElemName == "OK") { |
| 70 |
} else if (respElemName == "ox:Error" || respElemName == "Error") { |
| 71 |
QDomElement errResult = responseElement.firstChildElement("BooleanResponse"); |
| 72 |
if (errResult.isNull()) { |
| 73 |
errResult = responseElement.firstChildElement("ox:BooleanResponse"); |
| 74 |
} |
| 75 |
if (errResult.isNull()) { |
| 76 |
errorElement = true; |
| 77 |
} else { |
| 78 |
wrongResult = true; |
| 79 |
QString boolRespString = errResult.attribute("result"); |
| 80 |
LOG(WARNING,getLogDomain(),logTr("WRONG result of tested reasoner is '%1'.").arg(boolRespString),this); |
| 81 |
} |
| 82 |
} else if (respElemName == "ox:BooleanResponse" || respElemName == "BooleanResponse") { |
| 83 |
QString respTimeString = responseElement.attribute("response-time",""); |
| 84 |
if (!respTimeString.isEmpty()) { |
| 85 |
bool convertResponseTimeSuccess = false; |
| 86 |
responseTime = respTimeString.toLongLong(&convertResponseTimeSuccess); |
| 87 |
if (convertResponseTimeSuccess) { |
| 88 |
hasResponseTime = true; |
| 89 |
} |
| 90 |
} |
| 91 |
QString boolRespString = responseElement.attribute("result"); |
| 92 |
LOG(INFO,getLogDomain(),logTr("Reasoner calculated correct result: '%1'.").arg(boolRespString),this); |
| 93 |
|
| 94 |
} else if (respElemName == "#text") { |
| 95 |
// ignoring text nodes |
| 96 |
} else if (respElemName == "#comment") { |
| 97 |
// ignoring comment nodes |
| 98 |
} else { |
| 99 |
unknownElement = true; |
| 100 |
} |
| 101 |
|
| 102 |
if (unknownElement || errorElement) { |
| 103 |
responseError = true; |
| 104 |
} |
| 105 |
if (hasResponseTime) { |
| 106 |
totalResponseTime += responseTime; |
| 107 |
} |
| 108 |
responseElement = responseElement.nextSiblingElement(); |
| 109 |
} |
| 110 |
|
| 111 |
testResult->addTestResult(false,false,responseError,!wrongResult,totalResponseTime); |
| 112 |
} |
| 113 |
return this; |
| 114 |
|
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
}; // end namespace Test |
| 119 |
|
| 120 |
}; // end namespace Konclude |