Skip to content

Commit

Permalink
Finished first pass implementation for anomaly testing in renderchecker.
Browse files Browse the repository at this point in the history
  • Loading branch information
timlinux committed Apr 14, 2012
1 parent 83b1bf5 commit 7be2d96
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 6 deletions.
69 changes: 64 additions & 5 deletions tests/src/core/qgsrenderchecker.cpp
Expand Up @@ -20,7 +20,8 @@
#include <QPainter>
#include <QImage>
#include <QTime>

#include <QCryptographicHash>
#include <QByteArray>

QgsRenderChecker::QgsRenderChecker( ) :
mReport( "" ),
Expand All @@ -46,8 +47,50 @@ QString QgsRenderChecker::controlImagePath() const
void QgsRenderChecker::setControlName(const QString theName)
{
mControlName = theName;
mExpectedImageFile = controlImagePath() + theName + QDir::separator() +
theName + ".png";
mExpectedImageFile = controlImagePath() + theName + QDir::separator()
+ theName + ".png";
}

bool QgsRenderChecker::isKnownAnomaly( QImage theDifferenceImage )
{
QString myControlImageDir = controlImagePath() + mControlName
+ QDir::separator();
QDir myDirectory = QDir(myControlImageDir);
QStringList myList;
QString myFilename = "*";
myList = myDirectory.entryList(QStringList(myFilename),
QDir::Files | QDir::NoSymLinks);
//remove the control file from teh list as the anomalies are
//all files except the control file
myList.removeAt(myList.indexOf(mExpectedImageFile));
//todo compare each hash to diff path
QByteArray myData((const char*)theDifferenceImage.bits(),
theDifferenceImage.numBytes());
QByteArray mySourceHash = QCryptographicHash::hash(
myData, QCryptographicHash::Md5);
for (int i = 0; i < myList.size(); ++i)
{
QString myFile = myList.at(i);
mReport += "<tr><td colspan=3>"
"Checking if " + myFile + " is a known anomaly.";
mReport += "</td></tr>";
QImage myAnomalyImage( myFile );
QByteArray myData((const char*)myAnomalyImage.bits(),
myAnomalyImage.numBytes());
QByteArray myAnomolyHash = QCryptographicHash::hash(
myData, QCryptographicHash::Md5);
if ( mySourceHash.toHex() == myAnomolyHash.toHex() )
{
mReport += "<tr><td colspan=3>"
"Anomaly found! " + myFile;
mReport += "</td></tr>";
return true;
}
}
mReport += "<tr><td colspan=3>"
"No anomaly found! ";
mReport += "</td></tr>";
return false;
}

bool QgsRenderChecker::runTest( QString theTestName,
Expand Down Expand Up @@ -214,11 +257,27 @@ bool QgsRenderChecker::compareImages( QString theTestName,
mReport += "<tr><td colspan=3>" +
QString::number( mMismatchCount ) + "/" +
QString::number( mMatchTarget ) +
" pixels mismatched";
" pixels mismatched (allowed threshold: " +
QString::number( theMismatchCount ) + ")";
mReport += "</td></tr>";

bool myAnomalyMatchFlag = isKnownAnomaly( myDifferenceImage );

if ( myAnomalyMatchFlag )
{
mReport += "<tr><td colspan=3>"
"Difference image matched a known anomaly - passing test! "
"</td></tr>";
return true;
}
else
{
mReport += "<tr><td colspan=3>"
"Difference image did not match any known anomaly."
"</td></tr>";
}

if ( mMismatchCount <= theMismatchCount )
if ( mMismatchCount <= theMismatchCount)
{
mReport += "<tr><td colspan = 3>\n";
mReport += "Test image and result image for " + theTestName + " are matched<br>";
Expand Down
12 changes: 11 additions & 1 deletion tests/src/core/qgsrenderchecker.h
Expand Up @@ -18,7 +18,7 @@

#include <QString>
#include <qgsmaprenderer.h>

class QImage;

/** \ingroup UnitTests
* This is a helper class for unit tests that need to
Expand Down Expand Up @@ -74,7 +74,17 @@ class QgsRenderChecker
* @note: make sure to call setExpectedImage and setRenderedImage first.
*/
bool compareImages( QString theTestName, unsigned int theMismatchCount=0 );
/** Get a list of all teh anomalies. An anomaly is a rendered difference
* file where there is some red pixel content (indicating a render check
* mismatch), but where the output was still acceptible. If the render
* diff matches one of these anomalies we will still consider it to be
* acceptible.
* @return a bool indicating if the diff matched one of the anomaly files
*/
bool isKnownAnomaly( QImage theDifferenceImage );

private:

QString mReport;
QString mExpectedImageFile;
QString mControlName;
Expand Down

0 comments on commit 7be2d96

Please sign in to comment.