26 #include <QCryptographicHash>
34 mTabStyle =
"border-spacing: 0px; border-width: 1px 1px 0 0; border-style: solid;";
35 mCellStyle =
"border-width: 0 0 1px 1px; border-style: solid; font-size: smaller; text-align: center;";
42 QString theExpectedKey, QString theExpectedUri )
49 if ( !verifiedProvider || !verifiedProvider->
isValid() )
51 error( QString(
"Cannot load provider %1 with URI: %2" ).arg( theVerifiedKey ).arg( theVerifiedUri ),
mReport );
57 if ( !expectedProvider || !expectedProvider->
isValid() )
59 error( QString(
"Cannot load provider %1 with URI: %2" ).arg( theExpectedKey ).arg( theExpectedUri ),
mReport );
63 if ( !ok )
return false;
65 mReport += QString(
"Verified URI: %1<br>" ).arg( theVerifiedUri.replace(
"&",
"&" ) );
66 mReport += QString(
"Expected URI: %1<br>" ).arg( theExpectedUri.replace(
"&",
"&" ) );
79 if ( verifiedProvider->
extent() != expectedProvider->
extent() ) ok =
false;
84 if ( !ok )
return false;
87 for (
int band = 1; band <= expectedProvider->
bandCount(); band++ )
90 mReport += QString(
"<h3>Band %1</h3>\n" ).arg( band );
132 if ( !statsOk || !typesOk )
139 mReport +=
"<td>Data comparison</td>";
142 mReport += QString(
"<td style='%1 %2 border: 1px solid'>wrong value<br>expected value</td></tr>" ).arg(
mCellStyle ).arg(
mErrStyle );
146 int width = expectedProvider->
xSize();
147 int height = expectedProvider->
ySize();
151 if ( !expectedBlock || !expectedBlock->
isValid() ||
152 !verifiedBlock || !verifiedBlock->
isValid() )
155 mReport +=
"cannot read raster block";
160 QString htmlTable = QString(
"<table style='%1'>" ).arg(
mTabStyle );
161 for (
int row = 0; row < height; row ++ )
164 for (
int col = 0; col < width; col ++ )
167 double verifiedVal = verifiedBlock->
value( row, col );
168 double expectedVal = expectedBlock->
value( row, col );
171 if (
compare( verifiedVal, expectedVal, 0 ) )
173 valStr = QString(
"%1" ).arg( verifiedVal );
179 valStr = QString(
"%1<br>%2" ).arg( verifiedVal ).arg( expectedVal );
183 htmlTable +=
"</tr>";
185 htmlTable +=
"</table>";
189 delete expectedBlock;
190 delete verifiedBlock;
192 delete verifiedProvider;
193 delete expectedProvider;
199 theReport += QString(
"<font style='%1'>Error: " ).arg(
mErrMsgStyle );
200 theReport += theMessage;
201 theReport +=
"</font>";
208 return 1. * qPow( 10, qRound( log10( qAbs( val ) ) - places ) );
214 html += QString(
"<tr><th style='%1'>Param name</th><th style='%1'>Verified value</th><th style='%1'>Expected value</th><th style='%1'>Difference</th><th style='%1'>Tolerance</th></tr>" ).arg(
mCellStyle );
220 bool ok = verifiedVal == expectedVal;
221 compareRow( theParamName, QString::number( verifiedVal ), QString::number( expectedVal ), theReport, ok, QString::number( verifiedVal - expectedVal ) );
222 if ( !ok ) theOk =
false;
228 return ( qIsNaN( verifiedVal ) && qIsNaN( expectedVal ) ) || ( qAbs( verifiedVal - expectedVal ) <= theTolerance );
231 void QgsRasterChecker::compare( QString theParamName,
double verifiedVal,
double expectedVal, QString &theReport,
bool &theOk,
double theTolerance )
233 bool ok =
compare( verifiedVal, expectedVal, theTolerance );
234 compareRow( theParamName, QString::number( verifiedVal ), QString::number( expectedVal ), theReport, ok, QString::number( verifiedVal - expectedVal ), QString::number( theTolerance ) );
235 if ( !ok ) theOk =
false;
238 void QgsRasterChecker::compareRow( QString theParamName, QString verifiedVal, QString expectedVal, QString &theReport,
bool theOk, QString theDifference, QString theTolerance )
240 theReport +=
"<tr>\n";
241 theReport += QString(
"<td style='%1'>%2</td><td style='%1 %3'>%4</td><td style='%1'>%5</td>\n" ).arg(
mCellStyle ).arg( theParamName ).arg( theOk ?
mOkStyle :
mErrStyle ).arg( verifiedVal ).arg( expectedVal );
242 theReport += QString(
"<td style='%1'>%2</td>\n" ).arg(
mCellStyle ).arg( theDifference );
243 theReport += QString(
"<td style='%1'>%2</td>\n" ).arg(
mCellStyle ).arg( theTolerance );
244 theReport +=
"</tr>";