45 #include <QStringList> 48 #include <QTextStream> 68 bool compareDouble(QString _key , QVariant _result, QVariant _reference) {
71 double tolerance = std::numeric_limits<double>::epsilon();
75 QStringList referenceData = _reference.toString().split(
':');
76 if ( referenceData.size() == 2) {
77 tolerance = referenceData[1].toDouble();
81 double result = _result.toDouble();
82 double reference = referenceData[0].toDouble();
84 if ( fabs(result-reference) <= tolerance ) {
89 std::cerr.precision(40);
90 std::cerr <<
"===================================================================\n";
91 std::cerr <<
"Comparison failed for key " << _key.toStdString() <<
" :\n";
92 std::cerr <<
"Result: " << result <<
"\n";
93 std::cerr <<
"Expected: " << reference <<
"\n";
94 std::cerr <<
"Difference: " << fabs(result-reference) <<
"\n";
95 std::cerr <<
"Allowed tolerance was: " << tolerance <<
"\n";
96 std::cerr <<
"===================================================================\n";
102 bool compareString(QString _key ,QVariant _result, QVariant _reference) {
104 QString resultStr = _result.toString().simplified();
105 QString resultRef = _reference.toString().simplified();
107 if (resultStr == resultRef ) {
110 std::cerr <<
"Comparison failed for key " << _key.toStdString() <<
" :\n";
111 std::cerr <<
"Result: " << resultStr.toStdString() <<
" ; Expected: " << resultRef.toStdString() <<
"\n";
117 int main(
int argv,
char **args)
119 std::cout <<
"============================================================\n" ;
120 std::cout <<
"Executing compare tool\n";
121 std::cout <<
"Comparing results to reference:\n" ;
128 std::cerr <<
"Wrong number of arguments!\n";
129 std::cerr <<
"Usage:\n";
130 std::cerr <<
"compareTool ResultFile ReferenceFile\n";
134 QString file1(args[1]);
135 QString file2(args[2]);
137 QFileInfo resultFileInfo(file1);
138 if ( !resultFileInfo.exists() ) {
139 std::cerr <<
"ERROR! Result file: " << file1.toStdString() <<
" does not exist!\n";
144 QFileInfo referenceFileInfo(file2);
145 if ( !referenceFileInfo.exists() ) {
146 std::cerr <<
"ERROR! Reference file: " << file2.toStdString() <<
" does not exist!\n";
150 QSettings resultFile(file1,QSettings::IniFormat);
151 QSettings referenceFile(file2,QSettings::IniFormat);
153 if ( resultFile.status() != QSettings::NoError) {
154 std::cerr <<
"QSettings error when opening result file: " << file1.toStdString() <<
"\n";
158 if ( referenceFile.status() != QSettings::NoError) {
159 std::cerr <<
"QSettings error when opening result reference file: " << file2.toStdString() <<
"\n";
163 QStringList toplevelKeys = referenceFile.childKeys();
164 QStringList groups = referenceFile.childGroups();
166 if ( groups.size() == 0 ) {
167 for (
int i = 0 ; i < toplevelKeys.size(); ++i) {
168 if ( resultFile.contains(toplevelKeys[i]) ) {
169 if ( toplevelKeys[i].endsWith(
"_DOUBLE") ) {
170 ok &= compareDouble(toplevelKeys[i],resultFile.value(toplevelKeys[i]), referenceFile.value(toplevelKeys[i]));
172 ok &= compareString( toplevelKeys[i],resultFile.value(toplevelKeys[i]), referenceFile.value(toplevelKeys[i]));
174 std::cerr <<
"Missing key in result file: " << toplevelKeys[i].toStdString() <<
"\n";
182 std::cerr <<
"Multiple levels!" <<
"\n";
188 std::cerr <<
"At least one of the tests failed!\n";