51 #include <QStringList>
54 #include <QTextStream>
74 bool compareDouble(QString _key , QVariant _result, QVariant _reference) {
77 double tolerance = std::numeric_limits<double>::epsilon();
81 QStringList referenceData = _reference.toString().split(
':');
82 if ( referenceData.size() == 2) {
83 tolerance = referenceData[1].toDouble();
87 double result = _result.toDouble();
88 double reference = referenceData[0].toDouble();
90 if ( fabs(result-reference) <= tolerance ) {
95 std::cerr.precision(40);
96 std::cerr <<
"===================================================================\n";
97 std::cerr <<
"Comparison failed for key " << _key.toStdString() <<
" :\n";
98 std::cerr <<
"Result: " << result <<
"\n";
99 std::cerr <<
"Expected: " << reference <<
"\n";
100 std::cerr <<
"Difference: " << fabs(result-reference) <<
"\n";
101 std::cerr <<
"Allowed tolerance was: " << tolerance <<
"\n";
102 std::cerr <<
"===================================================================\n";
108 bool compareString(QString _key ,QVariant _result, QVariant _reference) {
110 QString resultStr = _result.toString().simplified();
111 QString resultRef = _reference.toString().simplified();
113 if (resultStr == resultRef ) {
116 std::cerr <<
"Comparison failed for key " << _key.toStdString() <<
" :\n";
117 std::cerr <<
"Result: " << resultStr.toStdString() <<
" ; Expected: " << resultRef.toStdString() <<
"\n";
123 int main(
int argv,
char **args)
125 std::cout <<
"============================================================\n" ;
126 std::cout <<
"Executing compare tool\n";
127 std::cout <<
"Comparing results to reference:\n" ;
134 std::cerr <<
"Wrong number of arguments!\n";
135 std::cerr <<
"Usage:\n";
136 std::cerr <<
"compareTool ResultFile ReferenceFile\n";
140 QString file1(args[1]);
141 QString file2(args[2]);
143 QFileInfo resultFileInfo(file1);
144 if ( !resultFileInfo.exists() ) {
145 std::cerr <<
"ERROR! Result file: " << file1.toStdString() <<
" does not exist!\n";
150 QFileInfo referenceFileInfo(file2);
151 if ( !referenceFileInfo.exists() ) {
152 std::cerr <<
"ERROR! Reference file: " << file2.toStdString() <<
" does not exist!\n";
156 QSettings resultFile(file1,QSettings::IniFormat);
157 QSettings referenceFile(file2,QSettings::IniFormat);
159 if ( resultFile.status() != QSettings::NoError) {
160 std::cerr <<
"QSettings error when opening result file: " << file1.toStdString() <<
"\n";
164 if ( referenceFile.status() != QSettings::NoError) {
165 std::cerr <<
"QSettings error when opening result reference file: " << file2.toStdString() <<
"\n";
169 QStringList toplevelKeys = referenceFile.childKeys();
170 QStringList groups = referenceFile.childGroups();
172 if ( groups.size() == 0 ) {
173 for (
int i = 0 ; i < toplevelKeys.size(); ++i) {
174 if ( resultFile.contains(toplevelKeys[i]) ) {
175 if ( toplevelKeys[i].endsWith(
"_DOUBLE") ) {
176 ok &= compareDouble(toplevelKeys[i],resultFile.value(toplevelKeys[i]), referenceFile.value(toplevelKeys[i]));
178 ok &= compareString( toplevelKeys[i],resultFile.value(toplevelKeys[i]), referenceFile.value(toplevelKeys[i]));
180 std::cerr <<
"Missing key in result file: " << toplevelKeys[i].toStdString() <<
"\n";
188 std::cerr <<
"Multiple levels!" <<
"\n";
194 std::cerr <<
"At least one of the tests failed!\n";