Skip to content

Commit

Permalink
test cleanups and some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jul 2, 2015
1 parent f3fe29d commit 9b976cf
Show file tree
Hide file tree
Showing 70 changed files with 294 additions and 237 deletions.
81 changes: 40 additions & 41 deletions src/core/qgsrenderchecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <QDebug>
#include <QBuffer>

static int renderCounter = 0;

QgsRenderChecker::QgsRenderChecker()
: mReport( "" )
, mMatchTarget( 0 )
Expand All @@ -43,16 +45,14 @@ QgsRenderChecker::QgsRenderChecker()
QString QgsRenderChecker::controlImagePath() const
{
QString myDataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt
QString myControlImageDir = myDataDir + QDir::separator() + "control_images" +
QDir::separator() + mControlPathPrefix;
QString myControlImageDir = myDataDir + "/control_images/" + mControlPathPrefix;
return myControlImageDir;
}

void QgsRenderChecker::setControlName( const QString &theName )
{
mControlName = theName;
mExpectedImageFile = controlImagePath() + theName + QDir::separator() + mControlPathSuffix
+ theName + ".png";
mExpectedImageFile = controlImagePath() + theName + "/" + mControlPathSuffix + theName + ".png";
}

QString QgsRenderChecker::imageToHash( QString theImageFile )
Expand Down Expand Up @@ -101,8 +101,7 @@ void QgsRenderChecker::drawBackground( QImage* image )

bool QgsRenderChecker::isKnownAnomaly( QString theDiffImageFile )
{
QString myControlImageDir = controlImagePath() + mControlName
+ QDir::separator();
QString myControlImageDir = controlImagePath() + mControlName + "/";
QDir myDirectory = QDir( myControlImageDir );
QStringList myList;
QString myFilename = "*";
Expand All @@ -121,8 +120,7 @@ bool QgsRenderChecker::isKnownAnomaly( QString theDiffImageFile )
mReport += "<tr><td colspan=3>"
"Checking if " + myFile + " is a known anomaly.";
mReport += "</td></tr>";
QString myAnomalyHash = imageToHash( controlImagePath() + mControlName
+ QDir::separator() + myFile );
QString myAnomalyHash = imageToHash( controlImagePath() + mControlName + "/" + myFile );
QString myHashMessage = QString(
"Checking if anomaly %1 (hash %2)<br>" )
.arg( myFile )
Expand Down Expand Up @@ -209,8 +207,7 @@ bool QgsRenderChecker::runTest( QString theTestName,
// Save the pixmap to disk so the user can make a
// visual assessment if needed
//
mRenderedImageFile = QDir::tempPath() + QDir::separator() +
theTestName + "_result.png";
mRenderedImageFile = QDir::tempPath() + "/" + theTestName + "_result.png";

myImage.setDotsPerMeterX( myExpectedImage.dotsPerMeterX() );
myImage.setDotsPerMeterY( myExpectedImage.dotsPerMeterY() );
Expand All @@ -226,7 +223,7 @@ bool QgsRenderChecker::runTest( QString theTestName,

//create a world file to go with the image...

QFile wldFile( QDir::tempPath() + QDir::separator() + theTestName + "_result.wld" );
QFile wldFile( QDir::tempPath() + "/" + theTestName + "_result.wld" );
if ( wldFile.open( QIODevice::WriteOnly ) )
{
QgsRectangle r = mMapSettings.extent();
Expand Down Expand Up @@ -286,9 +283,7 @@ bool QgsRenderChecker::compareImages( QString theTestName,
QImage myDifferenceImage( myExpectedImage.width(),
myExpectedImage.height(),
QImage::Format_RGB32 );
QString myDiffImageFile = QDir::tempPath() +
QDir::separator() +
theTestName + "_result_diff.png";
QString myDiffImageFile = QDir::tempPath() + "/" + theTestName + "_result_diff.png";
myDifferenceImage.fill( qRgb( 152, 219, 249 ) );

//check for mask
Expand All @@ -310,20 +305,22 @@ bool QgsRenderChecker::compareImages( QString theTestName,
//
// Set the report with the result
//
mReport = "<table>";
mReport = QString( "<script src=\"file://%1/../renderchecker.js\"></script>\n" ).arg( TEST_DATA_DIR );
mReport += "<table>";
mReport += "<tr><td colspan=2>";
mReport += "Test image and result image for " + theTestName + "<br>"
"Expected size: " + QString::number( myExpectedImage.width() ).toLocal8Bit() + "w x " +
QString::number( myExpectedImage.height() ).toLocal8Bit() + "h (" +
QString::number( mMatchTarget ).toLocal8Bit() + " pixels)<br>"
"Actual size: " + QString::number( myResultImage.width() ).toLocal8Bit() + "w x " +
QString::number( myResultImage.height() ).toLocal8Bit() + "h (" +
QString::number( myPixelCount ).toLocal8Bit() + " pixels)";
mReport += QString( "Test image and result image for %1<br>"
"Expected size: %2 w x %3 h (%4 pixels)<br>"
"Actual size: %5 w x %6 h (%7 pixels)" )
.arg( theTestName )
.arg( myExpectedImage.width() ).arg( myExpectedImage.height() ).arg( mMatchTarget )
.arg( myResultImage.width() ).arg( myResultImage.height() ).arg( myPixelCount );

mReport += "</td></tr>";
mReport += "<tr><td colspan = 2>\n";
mReport += "Expected Duration : <= " + QString::number( mElapsedTimeTarget ) +
"ms (0 indicates not specified)<br>";
mReport += "Actual Duration : " + QString::number( mElapsedTime ) + "ms<br>";
mReport += "<tr><td colspan=2>\n";
mReport += QString( "Expected Duration : <= %1 (0 indicates not specified)<br>"
"Actual Duration : %2 ms<br></td></tr>" )
.arg( mElapsedTimeTarget )
.arg( mElapsedTime );

// limit image size in page to something reasonable
int imgWidth = 420;
Expand All @@ -333,21 +330,23 @@ bool QgsRenderChecker::compareImages( QString theTestName,
imgWidth = qMin( myExpectedImage.width(), imgWidth );
imgHeight = myExpectedImage.height() * imgWidth / myExpectedImage.width();
}
QString myImagesString = "</td></tr>"
"<tr><td>Test Result:</td><td>Expected Result:</td><td>Difference (all blue is good, any red is bad)</td></tr>\n"
"<tr><td><img width=" + QString::number( imgWidth ) +
" height=" + QString::number( imgHeight ) +
" src=\"file://" +
mRenderedImageFile +
"\"></td>\n<td><img width=" + QString::number( imgWidth ) +
" height=" + QString::number( imgHeight ) +
" src=\"file://" +
mExpectedImageFile +
"\"></td>\n<td><img width=" + QString::number( imgWidth ) +
" height=" + QString::number( imgHeight ) +
" src=\"file://" +
myDiffImageFile +
"\"></td>\n</tr>\n</table>";

QString myImagesString = QString(
"<tr>"
"<td colspan=2>Compare actual and expected result</td>"
"<td>Difference (all blue is good, any red is bad)</td>"
"</tr>\n<tr>"
"<td colspan=2 id=\"td-%1-%7\"></td>\n"
"<td align=center><img width=%5 height=%6 src=\"file://%2\"></td>\n"
"</tr>"
"</table>\n"
"<script>\naddComparison(\"td-%1-%7\",\"file://%3\",\"file://%4\",%5,%6);\n</script>\n" )
.arg( theTestName )
.arg( myDiffImageFile )
.arg( mRenderedImageFile )
.arg( mExpectedImageFile )
.arg( imgWidth ).arg( imgHeight )
.arg( renderCounter++ );

QString prefix;
if ( !mControlPathPrefix.isNull() )
Expand Down
42 changes: 42 additions & 0 deletions tests/renderchecker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function addComparison(id,rendered,expected,w,h) {
var e = document.getElementById(id);

var div = document.createElement("DIV");
div.style = "margin: 0 auto; font-size: 0;";
e.appendChild(div);

var div0 = document.createElement("DIV");
div0.style = "font-size: 0; position: relative;";
div.appendChild(div0);

var img = document.createElement("IMG");
img.src = rendered;
img.width = w;
img.height = h;
// img.style = "height: auto; width:100%";
div0.appendChild(img);

var div1 = document.createElement("DIV");
div1.style.backgroundImage = "url('" + expected + "')";
div1.style.backgroundSize = "cover";
div1.style.position = "absolute";
div1.style.left = 0;
div1.style.top = 0;
div1.style.height = "100%";
div1.style.width = "50%";
div1.style.fontSize = 0;
div1.style.borderRight = "1px solid black";

div0.appendChild(div1);

var trackLocation = function(e) {
var rect = img.getBoundingClientRect();
var w = e.pageX - rect.left;
if ( w <= img.offsetWidth ) {
div1.style.width = w;
}
}

img.addEventListener( "mousemove", trackLocation, false );
div0.addEventListener( "mousemove", trackLocation, false );
}
4 changes: 2 additions & 2 deletions tests/src/analysis/testopenstreetmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void TestOpenStreetMap::download()
// start download
QgsOSMDownload download;
download.setQuery( QgsOSMDownload::queryFromRect( rect ) );
download.setOutputFileName( "/tmp/dl-test.osm" );
download.setOutputFileName( QDir::tempPath() + "/dl-test.osm" );
bool res = download.start();
QVERIFY( res );

Expand All @@ -95,7 +95,7 @@ void TestOpenStreetMap::download()

void TestOpenStreetMap::importAndQueries()
{
QString dbFilename = "/tmp/testdata.db";
QString dbFilename = QDir::tempPath() + "/testdata.db";
QString xmlFilename = TEST_DATA_DIR "/openstreetmap/testdata.xml";

QgsOSMXmlImport import( xmlFilename, dbFilename );
Expand Down
2 changes: 1 addition & 1 deletion tests/src/analysis/testqgsalignraster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class TestAlignRaster : public QObject
{
GDALAllRegister();

SRC_FILE = QString( TEST_DATA_DIR ) + QDir::separator() + "float1-16.tif";
SRC_FILE = QString( TEST_DATA_DIR ) + "/float1-16.tif";

QgsApplication::init(); // needed for CRS database
}
Expand Down
2 changes: 1 addition & 1 deletion tests/src/analysis/testqgsrastercalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void TestQgsRasterCalculator::initTestCase()
QgsApplication::init();
QgsApplication::initQgis();

QString testDataDir = QString( TEST_DATA_DIR ) + QDir::separator(); //defined in CmakeLists.txt
QString testDataDir = QString( TEST_DATA_DIR ) + "/"; //defined in CmakeLists.txt

QString landsatFileName = testDataDir + "landsat.tif";
QFileInfo landsatRasterFileInfo( landsatFileName );
Expand Down
12 changes: 6 additions & 6 deletions tests/src/analysis/testqgsvectoranalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ void TestQgsVectorAnalyzer::initTestCase()
//create a map layer that will be used in all tests...
QString myBaseFileName( TEST_DATA_DIR ); //defined in CmakeLists.txt
QString myEndName = "lines.shp";
QString myFileName = myBaseFileName + QDir::separator() + myEndName;
QString myFileName = myBaseFileName + "/" + myEndName;
qDebug() << myFileName;
QFileInfo myLineInfo( myFileName );
mpLineLayer = new QgsVectorLayer( myLineInfo.filePath(),
myLineInfo.completeBaseName(), "ogr" );

myEndName = "polys.shp";
myFileName = myBaseFileName + QDir::separator() + myEndName;
myFileName = myBaseFileName + "/" + myEndName;
QFileInfo myPolyInfo( myFileName );
mpPolyLayer = new QgsVectorLayer( myPolyInfo.filePath(),
myPolyInfo.completeBaseName(), "ogr" );

myEndName = "points.shp";
myFileName = myBaseFileName + QDir::separator() + myEndName;
myFileName = myBaseFileName + "/" + myEndName;
QFileInfo myPointInfo( myFileName );
mpPointLayer = new QgsVectorLayer( myPointInfo.filePath(),
myPointInfo.completeBaseName(), "ogr" );
Expand Down Expand Up @@ -118,21 +118,21 @@ void TestQgsVectorAnalyzer::exportGeometryInfo()

void TestQgsVectorAnalyzer::simplifyGeometry()
{
QString myTmpDir = QDir::tempPath() + QDir::separator();
QString myTmpDir = QDir::tempPath() + "/";
QString myFileName = myTmpDir + "simplify_layer.shp";
QVERIFY( mAnalyzer.simplify( mpLineLayer, myFileName, 1.0 ) );
}

void TestQgsVectorAnalyzer::polygonCentroids()
{
QString myTmpDir = QDir::tempPath() + QDir::separator();
QString myTmpDir = QDir::tempPath() + "/";
QString myFileName = myTmpDir + "centroid_layer.shp";
QVERIFY( mAnalyzer.centroids( mpPolyLayer, myFileName ) );
}

void TestQgsVectorAnalyzer::layerExtent()
{
QString myTmpDir = QDir::tempPath() + QDir::separator();
QString myTmpDir = QDir::tempPath() + "/";
QString myFileName = myTmpDir + "extent_layer.shp";
QVERIFY( mAnalyzer.extent( mpPointLayer, myFileName ) );
}
Expand Down
4 changes: 2 additions & 2 deletions tests/src/analysis/testqgszonalstatistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ void TestQgsZonalStatistics::initTestCase()
QgsApplication::showSettings();

QString myDataPath( TEST_DATA_DIR ); //defined in CmakeLists.txt
QString myTestDataPath = myDataPath + QDir::separator() + "zonalstatistics" + QDir::separator();
QString myTempPath = QDir::tempPath() + QDir::separator();
QString myTestDataPath = myDataPath + "/zonalstatistics/";
QString myTempPath = QDir::tempPath() + "/";

// copy test data to temp directory
QDir testDir( myTestDataPath );
Expand Down
2 changes: 1 addition & 1 deletion tests/src/app/testqgisappclipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void TestQgisAppClipboard::initTestCase()
// init QGIS's paths - true means that all path will be inited from prefix
QgsApplication::init();
QgsApplication::initQgis();
mTestDataDir = QString( TEST_DATA_DIR ) + QDir::separator(); //defined in CmakeLists.txt
mTestDataDir = QString( TEST_DATA_DIR ) + "/"; //defined in CmakeLists.txt
mQgisApp = new QgisApp();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/src/core/qgscompositionchecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ bool QgsCompositionChecker::testComposition( QString &theReport, int page, int p
mComposition->renderPage( &p, page );
p.end();

QString renderedFilePath = QDir::tempPath() + QDir::separator() + QFileInfo( mTestName ).baseName() + "_rendered.png";
QString renderedFilePath = QDir::tempPath() + "/" + QFileInfo( mTestName ).baseName() + "_rendered.png";
outputImage.save( renderedFilePath, "PNG" );

setRenderedImage( renderedFilePath );
Expand Down
2 changes: 1 addition & 1 deletion tests/src/core/regression1141.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void Regression1141::initTestCase()
QgsApplication::initQgis();
QgsApplication::showSettings();
// compute our test file name:
QString myTmpDir = QDir::tempPath() + QDir::separator();
QString myTmpDir = QDir::tempPath() + "/";
mFileName = myTmpDir + "ąęćń.shp";
}

Expand Down
4 changes: 2 additions & 2 deletions tests/src/core/regression992.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void Regression992::initTestCase()

//create some objects that will be used in all tests...
//create a raster layer that will be used in all tests...
mTestDataDir = QString( TEST_DATA_DIR ) + QDir::separator(); //defined in CMakeLists.txt
mTestDataDir = QString( TEST_DATA_DIR ) + "/"; //defined in CMakeLists.txt
QString myFileName = mTestDataDir + "rgbwcmyk01_YeGeo.jp2";
QFileInfo myRasterFileInfo( myFileName );
mpRasterLayer = new QgsRasterLayer( myRasterFileInfo.filePath(),
Expand All @@ -104,7 +104,7 @@ void Regression992::initTestCase()
//runs after all tests
void Regression992::cleanupTestCase()
{
QString myReportFile = QDir::tempPath() + QDir::separator() + "qgistest.html";
QString myReportFile = QDir::tempPath() + "/qgistest.html";
QFile myFile( myReportFile );
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
{
Expand Down
2 changes: 1 addition & 1 deletion tests/src/core/testcontrastenhancements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void TestContrastEnhancements::initTestCase()
//runs after all tests
void TestContrastEnhancements::cleanupTestCase()
{
QString myReportFile = QDir::tempPath() + QDir::separator() + "qgistest.html";
QString myReportFile = QDir::tempPath() + "/qgistest.html";
QFile myFile( myReportFile );
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
{
Expand Down
6 changes: 3 additions & 3 deletions tests/src/core/testmaprendererjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ void TestQgsMapRendererJob::testNormal()

// TODO: custom painter

imgS.save( "/tmp/imgS.png" );
imgP.save( "/tmp/imgP.png" );
//img.save("/tmp/img5.png");
imgS.save( QDir::tempPath() + "/imgS.png" );
imgP.save( QDir::tempPath() + "/imgP.png" );
//img.save( QDir::tempPath() + "/img5.png");

QCOMPARE( imgS, imgP );
}
Expand Down
2 changes: 1 addition & 1 deletion tests/src/core/testqgis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void TestQGis::initTestCase()
//runs after all tests
void TestQGis::cleanupTestCase()
{
QString myReportFile = QDir::tempPath() + QDir::separator() + "qgistest.html";
QString myReportFile = QDir::tempPath() + "/qgistest.html";
QFile myFile( myReportFile );
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
{
Expand Down
4 changes: 2 additions & 2 deletions tests/src/core/testqgsatlascomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void TestQgsAtlasComposition::initTestCase()
mMapSettings = new QgsMapSettings();

//create maplayers from testdata and add to layer registry
QFileInfo vectorFileInfo( QString( TEST_DATA_DIR ) + QDir::separator() + "france_parts.shp" );
QFileInfo vectorFileInfo( QString( TEST_DATA_DIR ) + "/france_parts.shp" );
mVectorLayer = new QgsVectorLayer( vectorFileInfo.filePath(),
vectorFileInfo.completeBaseName(),
"ogr" );
Expand Down Expand Up @@ -132,7 +132,7 @@ void TestQgsAtlasComposition::cleanupTestCase()
delete mComposition;
QgsApplication::exitQgis();

QString myReportFile = QDir::tempPath() + QDir::separator() + "qgistest.html";
QString myReportFile = QDir::tempPath() + "/qgistest.html";
QFile myFile( myReportFile );
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
{
Expand Down
Loading

0 comments on commit 9b976cf

Please sign in to comment.