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;";
36 mOkStyle =
"background: #00ff00;";
37 mErrStyle =
"background: #ff0000;";
38 mErrMsgStyle =
"color: #ff0000;";
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(
"&",
"&" ) );
69 mReport += QString(
"<table style='%1'>\n" ).arg( mTabStyle );
70 mReport += compareHead();
72 compare(
"Band count", verifiedProvider->
bandCount(), expectedProvider->
bandCount(), mReport, ok );
74 compare(
"Width", verifiedProvider->
xSize(), expectedProvider->
xSize(), mReport, ok );
75 compare(
"Height", verifiedProvider->
ySize(), expectedProvider->
ySize(), mReport, ok );
79 if ( verifiedProvider->
extent() != expectedProvider->
extent() ) ok =
false;
82 mReport +=
"</table>\n";
84 if ( !ok )
return false;
87 for (
int band = 1; band <= expectedProvider->
bandCount(); band++ )
89 mReport += QString(
"<h3>Band %1</h3>\n" ).arg( band );
90 mReport += QString(
"<table style='%1'>\n" ).arg( mTabStyle );
91 mReport += compareHead();
95 compare(
"Source data type", verifiedProvider->
srcDataType( band ), expectedProvider->
srcDataType( band ), mReport, typesOk );
96 compare(
"Data type", verifiedProvider->
dataType( band ), expectedProvider->
dataType( band ), mReport, typesOk );
115 tol = tolerance( expectedStats.
mean );
116 compare(
"Mean", verifiedStats.
mean, expectedStats.
mean, mReport, statsOk, tol );
119 tol = tolerance( expectedStats.
stdDev, 1 );
120 compare(
"Standard deviation", verifiedStats.
stdDev, expectedStats.
stdDev, mReport, statsOk, tol );
122 mReport +=
"</table>";
125 if ( !statsOk || !typesOk )
131 mReport +=
"<table><tr>";
132 mReport +=
"<td>Data comparison</td>";
133 mReport += QString(
"<td style='%1 %2 border: 1px solid'>correct value</td>" ).arg( mCellStyle ).arg( mOkStyle );
134 mReport +=
"<td></td>";
135 mReport += QString(
"<td style='%1 %2 border: 1px solid'>wrong value<br>expected value</td></tr>" ).arg( mCellStyle ).arg( mErrStyle );
136 mReport +=
"</tr></table>";
139 int width = expectedProvider->
xSize();
140 int height = expectedProvider->
ySize();
144 if ( !expectedBlock || !expectedBlock->
isValid() ||
145 !verifiedBlock || !verifiedBlock->
isValid() )
148 mReport +=
"cannot read raster block";
153 QString htmlTable = QString(
"<table style='%1'>" ).arg( mTabStyle );
154 for (
int row = 0; row < height; row ++ )
157 for (
int col = 0; col < width; col ++ )
160 double verifiedVal = verifiedBlock->
value( row, col );
161 double expectedVal = expectedBlock->
value( row, col );
164 if ( compare( verifiedVal, expectedVal, 0 ) )
166 valStr = QString(
"%1" ).arg( verifiedVal );
172 valStr = QString(
"%1<br>%2" ).arg( verifiedVal ).arg( expectedVal );
174 htmlTable += QString(
"<td style='%1 %2'>%3</td>" ).arg( mCellStyle ).arg( cellOk ? mOkStyle : mErrStyle ).arg( valStr );
176 htmlTable +=
"</tr>";
178 htmlTable +=
"</table>";
180 mReport += htmlTable;
182 delete expectedBlock;
183 delete verifiedBlock;
185 delete verifiedProvider;
186 delete expectedProvider;
190 void QgsRasterChecker::error( QString theMessage, QString &theReport )
192 theReport += QString(
"<font style='%1'>Error: " ).arg( mErrMsgStyle );
193 theReport += theMessage;
194 theReport +=
"</font>";
197 double QgsRasterChecker::tolerance(
double val,
int places )
201 return 1. * qPow( 10, qRound( log10( qAbs( val ) ) - places ) );
204 QString QgsRasterChecker::compareHead()
207 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 );
211 void QgsRasterChecker::compare( QString theParamName,
int verifiedVal,
int expectedVal, QString &theReport,
bool &theOk )
213 bool ok = verifiedVal == expectedVal;
214 compareRow( theParamName, QString::number( verifiedVal ), QString::number( expectedVal ), theReport, ok, QString::number( verifiedVal - expectedVal ) );
215 if ( !ok ) theOk =
false;
218 bool QgsRasterChecker::compare(
double verifiedVal,
double expectedVal,
double theTolerance )
221 return ( qIsNaN( verifiedVal ) && qIsNaN( expectedVal ) ) || ( qAbs( verifiedVal - expectedVal ) <= theTolerance );
224 void QgsRasterChecker::compare( QString theParamName,
double verifiedVal,
double expectedVal, QString &theReport,
bool &theOk,
double theTolerance )
226 bool ok = compare( verifiedVal, expectedVal, theTolerance );
227 compareRow( theParamName, QString::number( verifiedVal ), QString::number( expectedVal ), theReport, ok, QString::number( verifiedVal - expectedVal ), QString::number( theTolerance ) );
228 if ( !ok ) theOk =
false;
231 void QgsRasterChecker::compareRow( QString theParamName, QString verifiedVal, QString expectedVal, QString &theReport,
bool theOk, QString theDifference, QString theTolerance )
233 theReport +=
"<tr>\n";
234 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 );
235 theReport += QString(
"<td style='%1'>%2</td>\n" ).arg( mCellStyle ).arg( theDifference );
236 theReport += QString(
"<td style='%1'>%2</td>\n" ).arg( mCellStyle ).arg( theTolerance );
237 theReport +=
"</tr>";