Skip to content

Commit 9b976cf

Browse files
committed
test cleanups and some fixes
1 parent f3fe29d commit 9b976cf

File tree

70 files changed

+294
-237
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+294
-237
lines changed

src/core/qgsrenderchecker.cpp

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include <QDebug>
2828
#include <QBuffer>
2929

30+
static int renderCounter = 0;
31+
3032
QgsRenderChecker::QgsRenderChecker()
3133
: mReport( "" )
3234
, mMatchTarget( 0 )
@@ -43,16 +45,14 @@ QgsRenderChecker::QgsRenderChecker()
4345
QString QgsRenderChecker::controlImagePath() const
4446
{
4547
QString myDataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt
46-
QString myControlImageDir = myDataDir + QDir::separator() + "control_images" +
47-
QDir::separator() + mControlPathPrefix;
48+
QString myControlImageDir = myDataDir + "/control_images/" + mControlPathPrefix;
4849
return myControlImageDir;
4950
}
5051

5152
void QgsRenderChecker::setControlName( const QString &theName )
5253
{
5354
mControlName = theName;
54-
mExpectedImageFile = controlImagePath() + theName + QDir::separator() + mControlPathSuffix
55-
+ theName + ".png";
55+
mExpectedImageFile = controlImagePath() + theName + "/" + mControlPathSuffix + theName + ".png";
5656
}
5757

5858
QString QgsRenderChecker::imageToHash( QString theImageFile )
@@ -101,8 +101,7 @@ void QgsRenderChecker::drawBackground( QImage* image )
101101

102102
bool QgsRenderChecker::isKnownAnomaly( QString theDiffImageFile )
103103
{
104-
QString myControlImageDir = controlImagePath() + mControlName
105-
+ QDir::separator();
104+
QString myControlImageDir = controlImagePath() + mControlName + "/";
106105
QDir myDirectory = QDir( myControlImageDir );
107106
QStringList myList;
108107
QString myFilename = "*";
@@ -121,8 +120,7 @@ bool QgsRenderChecker::isKnownAnomaly( QString theDiffImageFile )
121120
mReport += "<tr><td colspan=3>"
122121
"Checking if " + myFile + " is a known anomaly.";
123122
mReport += "</td></tr>";
124-
QString myAnomalyHash = imageToHash( controlImagePath() + mControlName
125-
+ QDir::separator() + myFile );
123+
QString myAnomalyHash = imageToHash( controlImagePath() + mControlName + "/" + myFile );
126124
QString myHashMessage = QString(
127125
"Checking if anomaly %1 (hash %2)<br>" )
128126
.arg( myFile )
@@ -209,8 +207,7 @@ bool QgsRenderChecker::runTest( QString theTestName,
209207
// Save the pixmap to disk so the user can make a
210208
// visual assessment if needed
211209
//
212-
mRenderedImageFile = QDir::tempPath() + QDir::separator() +
213-
theTestName + "_result.png";
210+
mRenderedImageFile = QDir::tempPath() + "/" + theTestName + "_result.png";
214211

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

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

229-
QFile wldFile( QDir::tempPath() + QDir::separator() + theTestName + "_result.wld" );
226+
QFile wldFile( QDir::tempPath() + "/" + theTestName + "_result.wld" );
230227
if ( wldFile.open( QIODevice::WriteOnly ) )
231228
{
232229
QgsRectangle r = mMapSettings.extent();
@@ -286,9 +283,7 @@ bool QgsRenderChecker::compareImages( QString theTestName,
286283
QImage myDifferenceImage( myExpectedImage.width(),
287284
myExpectedImage.height(),
288285
QImage::Format_RGB32 );
289-
QString myDiffImageFile = QDir::tempPath() +
290-
QDir::separator() +
291-
theTestName + "_result_diff.png";
286+
QString myDiffImageFile = QDir::tempPath() + "/" + theTestName + "_result_diff.png";
292287
myDifferenceImage.fill( qRgb( 152, 219, 249 ) );
293288

294289
//check for mask
@@ -310,20 +305,22 @@ bool QgsRenderChecker::compareImages( QString theTestName,
310305
//
311306
// Set the report with the result
312307
//
313-
mReport = "<table>";
308+
mReport = QString( "<script src=\"file://%1/../renderchecker.js\"></script>\n" ).arg( TEST_DATA_DIR );
309+
mReport += "<table>";
314310
mReport += "<tr><td colspan=2>";
315-
mReport += "Test image and result image for " + theTestName + "<br>"
316-
"Expected size: " + QString::number( myExpectedImage.width() ).toLocal8Bit() + "w x " +
317-
QString::number( myExpectedImage.height() ).toLocal8Bit() + "h (" +
318-
QString::number( mMatchTarget ).toLocal8Bit() + " pixels)<br>"
319-
"Actual size: " + QString::number( myResultImage.width() ).toLocal8Bit() + "w x " +
320-
QString::number( myResultImage.height() ).toLocal8Bit() + "h (" +
321-
QString::number( myPixelCount ).toLocal8Bit() + " pixels)";
311+
mReport += QString( "Test image and result image for %1<br>"
312+
"Expected size: %2 w x %3 h (%4 pixels)<br>"
313+
"Actual size: %5 w x %6 h (%7 pixels)" )
314+
.arg( theTestName )
315+
.arg( myExpectedImage.width() ).arg( myExpectedImage.height() ).arg( mMatchTarget )
316+
.arg( myResultImage.width() ).arg( myResultImage.height() ).arg( myPixelCount );
317+
322318
mReport += "</td></tr>";
323-
mReport += "<tr><td colspan = 2>\n";
324-
mReport += "Expected Duration : <= " + QString::number( mElapsedTimeTarget ) +
325-
"ms (0 indicates not specified)<br>";
326-
mReport += "Actual Duration : " + QString::number( mElapsedTime ) + "ms<br>";
319+
mReport += "<tr><td colspan=2>\n";
320+
mReport += QString( "Expected Duration : <= %1 (0 indicates not specified)<br>"
321+
"Actual Duration : %2 ms<br></td></tr>" )
322+
.arg( mElapsedTimeTarget )
323+
.arg( mElapsedTime );
327324

328325
// limit image size in page to something reasonable
329326
int imgWidth = 420;
@@ -333,21 +330,23 @@ bool QgsRenderChecker::compareImages( QString theTestName,
333330
imgWidth = qMin( myExpectedImage.width(), imgWidth );
334331
imgHeight = myExpectedImage.height() * imgWidth / myExpectedImage.width();
335332
}
336-
QString myImagesString = "</td></tr>"
337-
"<tr><td>Test Result:</td><td>Expected Result:</td><td>Difference (all blue is good, any red is bad)</td></tr>\n"
338-
"<tr><td><img width=" + QString::number( imgWidth ) +
339-
" height=" + QString::number( imgHeight ) +
340-
" src=\"file://" +
341-
mRenderedImageFile +
342-
"\"></td>\n<td><img width=" + QString::number( imgWidth ) +
343-
" height=" + QString::number( imgHeight ) +
344-
" src=\"file://" +
345-
mExpectedImageFile +
346-
"\"></td>\n<td><img width=" + QString::number( imgWidth ) +
347-
" height=" + QString::number( imgHeight ) +
348-
" src=\"file://" +
349-
myDiffImageFile +
350-
"\"></td>\n</tr>\n</table>";
333+
334+
QString myImagesString = QString(
335+
"<tr>"
336+
"<td colspan=2>Compare actual and expected result</td>"
337+
"<td>Difference (all blue is good, any red is bad)</td>"
338+
"</tr>\n<tr>"
339+
"<td colspan=2 id=\"td-%1-%7\"></td>\n"
340+
"<td align=center><img width=%5 height=%6 src=\"file://%2\"></td>\n"
341+
"</tr>"
342+
"</table>\n"
343+
"<script>\naddComparison(\"td-%1-%7\",\"file://%3\",\"file://%4\",%5,%6);\n</script>\n" )
344+
.arg( theTestName )
345+
.arg( myDiffImageFile )
346+
.arg( mRenderedImageFile )
347+
.arg( mExpectedImageFile )
348+
.arg( imgWidth ).arg( imgHeight )
349+
.arg( renderCounter++ );
351350

352351
QString prefix;
353352
if ( !mControlPathPrefix.isNull() )

tests/renderchecker.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
function addComparison(id,rendered,expected,w,h) {
2+
var e = document.getElementById(id);
3+
4+
var div = document.createElement("DIV");
5+
div.style = "margin: 0 auto; font-size: 0;";
6+
e.appendChild(div);
7+
8+
var div0 = document.createElement("DIV");
9+
div0.style = "font-size: 0; position: relative;";
10+
div.appendChild(div0);
11+
12+
var img = document.createElement("IMG");
13+
img.src = rendered;
14+
img.width = w;
15+
img.height = h;
16+
// img.style = "height: auto; width:100%";
17+
div0.appendChild(img);
18+
19+
var div1 = document.createElement("DIV");
20+
div1.style.backgroundImage = "url('" + expected + "')";
21+
div1.style.backgroundSize = "cover";
22+
div1.style.position = "absolute";
23+
div1.style.left = 0;
24+
div1.style.top = 0;
25+
div1.style.height = "100%";
26+
div1.style.width = "50%";
27+
div1.style.fontSize = 0;
28+
div1.style.borderRight = "1px solid black";
29+
30+
div0.appendChild(div1);
31+
32+
var trackLocation = function(e) {
33+
var rect = img.getBoundingClientRect();
34+
var w = e.pageX - rect.left;
35+
if ( w <= img.offsetWidth ) {
36+
div1.style.width = w;
37+
}
38+
}
39+
40+
img.addEventListener( "mousemove", trackLocation, false );
41+
div0.addEventListener( "mousemove", trackLocation, false );
42+
}

tests/src/analysis/testopenstreetmap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void TestOpenStreetMap::download()
7272
// start download
7373
QgsOSMDownload download;
7474
download.setQuery( QgsOSMDownload::queryFromRect( rect ) );
75-
download.setOutputFileName( "/tmp/dl-test.osm" );
75+
download.setOutputFileName( QDir::tempPath() + "/dl-test.osm" );
7676
bool res = download.start();
7777
QVERIFY( res );
7878

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

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

101101
QgsOSMXmlImport import( xmlFilename, dbFilename );

tests/src/analysis/testqgsalignraster.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class TestAlignRaster : public QObject
4343
{
4444
GDALAllRegister();
4545

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

4848
QgsApplication::init(); // needed for CRS database
4949
}

tests/src/analysis/testqgsrastercalculator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void TestQgsRasterCalculator::initTestCase()
7272
QgsApplication::init();
7373
QgsApplication::initQgis();
7474

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

7777
QString landsatFileName = testDataDir + "landsat.tif";
7878
QFileInfo landsatRasterFileInfo( landsatFileName );

tests/src/analysis/testqgsvectoranalyzer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,20 @@ void TestQgsVectorAnalyzer::initTestCase()
6666
//create a map layer that will be used in all tests...
6767
QString myBaseFileName( TEST_DATA_DIR ); //defined in CmakeLists.txt
6868
QString myEndName = "lines.shp";
69-
QString myFileName = myBaseFileName + QDir::separator() + myEndName;
69+
QString myFileName = myBaseFileName + "/" + myEndName;
7070
qDebug() << myFileName;
7171
QFileInfo myLineInfo( myFileName );
7272
mpLineLayer = new QgsVectorLayer( myLineInfo.filePath(),
7373
myLineInfo.completeBaseName(), "ogr" );
7474

7575
myEndName = "polys.shp";
76-
myFileName = myBaseFileName + QDir::separator() + myEndName;
76+
myFileName = myBaseFileName + "/" + myEndName;
7777
QFileInfo myPolyInfo( myFileName );
7878
mpPolyLayer = new QgsVectorLayer( myPolyInfo.filePath(),
7979
myPolyInfo.completeBaseName(), "ogr" );
8080

8181
myEndName = "points.shp";
82-
myFileName = myBaseFileName + QDir::separator() + myEndName;
82+
myFileName = myBaseFileName + "/" + myEndName;
8383
QFileInfo myPointInfo( myFileName );
8484
mpPointLayer = new QgsVectorLayer( myPointInfo.filePath(),
8585
myPointInfo.completeBaseName(), "ogr" );
@@ -118,21 +118,21 @@ void TestQgsVectorAnalyzer::exportGeometryInfo()
118118

119119
void TestQgsVectorAnalyzer::simplifyGeometry()
120120
{
121-
QString myTmpDir = QDir::tempPath() + QDir::separator();
121+
QString myTmpDir = QDir::tempPath() + "/";
122122
QString myFileName = myTmpDir + "simplify_layer.shp";
123123
QVERIFY( mAnalyzer.simplify( mpLineLayer, myFileName, 1.0 ) );
124124
}
125125

126126
void TestQgsVectorAnalyzer::polygonCentroids()
127127
{
128-
QString myTmpDir = QDir::tempPath() + QDir::separator();
128+
QString myTmpDir = QDir::tempPath() + "/";
129129
QString myFileName = myTmpDir + "centroid_layer.shp";
130130
QVERIFY( mAnalyzer.centroids( mpPolyLayer, myFileName ) );
131131
}
132132

133133
void TestQgsVectorAnalyzer::layerExtent()
134134
{
135-
QString myTmpDir = QDir::tempPath() + QDir::separator();
135+
QString myTmpDir = QDir::tempPath() + "/";
136136
QString myFileName = myTmpDir + "extent_layer.shp";
137137
QVERIFY( mAnalyzer.extent( mpPointLayer, myFileName ) );
138138
}

tests/src/analysis/testqgszonalstatistics.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ void TestQgsZonalStatistics::initTestCase()
5656
QgsApplication::showSettings();
5757

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

6262
// copy test data to temp directory
6363
QDir testDir( myTestDataPath );

tests/src/app/testqgisappclipboard.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void TestQgisAppClipboard::initTestCase()
6565
// init QGIS's paths - true means that all path will be inited from prefix
6666
QgsApplication::init();
6767
QgsApplication::initQgis();
68-
mTestDataDir = QString( TEST_DATA_DIR ) + QDir::separator(); //defined in CmakeLists.txt
68+
mTestDataDir = QString( TEST_DATA_DIR ) + "/"; //defined in CmakeLists.txt
6969
mQgisApp = new QgisApp();
7070
}
7171

tests/src/core/qgscompositionchecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ bool QgsCompositionChecker::testComposition( QString &theReport, int page, int p
7878
mComposition->renderPage( &p, page );
7979
p.end();
8080

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

8484
setRenderedImage( renderedFilePath );

tests/src/core/regression1141.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void Regression1141::initTestCase()
8787
QgsApplication::initQgis();
8888
QgsApplication::showSettings();
8989
// compute our test file name:
90-
QString myTmpDir = QDir::tempPath() + QDir::separator();
90+
QString myTmpDir = QDir::tempPath() + "/";
9191
mFileName = myTmpDir + "ąęćń.shp";
9292
}
9393

tests/src/core/regression992.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void Regression992::initTestCase()
7878

7979
//create some objects that will be used in all tests...
8080
//create a raster layer that will be used in all tests...
81-
mTestDataDir = QString( TEST_DATA_DIR ) + QDir::separator(); //defined in CMakeLists.txt
81+
mTestDataDir = QString( TEST_DATA_DIR ) + "/"; //defined in CMakeLists.txt
8282
QString myFileName = mTestDataDir + "rgbwcmyk01_YeGeo.jp2";
8383
QFileInfo myRasterFileInfo( myFileName );
8484
mpRasterLayer = new QgsRasterLayer( myRasterFileInfo.filePath(),
@@ -104,7 +104,7 @@ void Regression992::initTestCase()
104104
//runs after all tests
105105
void Regression992::cleanupTestCase()
106106
{
107-
QString myReportFile = QDir::tempPath() + QDir::separator() + "qgistest.html";
107+
QString myReportFile = QDir::tempPath() + "/qgistest.html";
108108
QFile myFile( myReportFile );
109109
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
110110
{

tests/src/core/testcontrastenhancements.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void TestContrastEnhancements::initTestCase()
5252
//runs after all tests
5353
void TestContrastEnhancements::cleanupTestCase()
5454
{
55-
QString myReportFile = QDir::tempPath() + QDir::separator() + "qgistest.html";
55+
QString myReportFile = QDir::tempPath() + "/qgistest.html";
5656
QFile myFile( myReportFile );
5757
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
5858
{

tests/src/core/testmaprendererjob.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ void TestQgsMapRendererJob::testNormal()
9393

9494
// TODO: custom painter
9595

96-
imgS.save( "/tmp/imgS.png" );
97-
imgP.save( "/tmp/imgP.png" );
98-
//img.save("/tmp/img5.png");
96+
imgS.save( QDir::tempPath() + "/imgS.png" );
97+
imgP.save( QDir::tempPath() + "/imgP.png" );
98+
//img.save( QDir::tempPath() + "/img5.png");
9999

100100
QCOMPARE( imgS, imgP );
101101
}

tests/src/core/testqgis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void TestQGis::initTestCase()
5050
//runs after all tests
5151
void TestQGis::cleanupTestCase()
5252
{
53-
QString myReportFile = QDir::tempPath() + QDir::separator() + "qgistest.html";
53+
QString myReportFile = QDir::tempPath() + "/qgistest.html";
5454
QFile myFile( myReportFile );
5555
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
5656
{

tests/src/core/testqgsatlascomposition.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void TestQgsAtlasComposition::initTestCase()
104104
mMapSettings = new QgsMapSettings();
105105

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

135-
QString myReportFile = QDir::tempPath() + QDir::separator() + "qgistest.html";
135+
QString myReportFile = QDir::tempPath() + "/qgistest.html";
136136
QFile myFile( myReportFile );
137137
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
138138
{

0 commit comments

Comments
 (0)