Skip to content
Permalink
Browse files

test cleanups and some fixes

  • Loading branch information
jef-n committed Jul 2, 2015
1 parent f3fe29d commit 9b976cfe264898d983f24cacd6367917f27a7cca
Showing with 294 additions and 237 deletions.
  1. +40 −41 src/core/qgsrenderchecker.cpp
  2. +42 −0 tests/renderchecker.js
  3. +2 −2 tests/src/analysis/testopenstreetmap.cpp
  4. +1 −1 tests/src/analysis/testqgsalignraster.cpp
  5. +1 −1 tests/src/analysis/testqgsrastercalculator.cpp
  6. +6 −6 tests/src/analysis/testqgsvectoranalyzer.cpp
  7. +2 −2 tests/src/analysis/testqgszonalstatistics.cpp
  8. +1 −1 tests/src/app/testqgisappclipboard.cpp
  9. +1 −1 tests/src/core/qgscompositionchecker.cpp
  10. +1 −1 tests/src/core/regression1141.cpp
  11. +2 −2 tests/src/core/regression992.cpp
  12. +1 −1 tests/src/core/testcontrastenhancements.cpp
  13. +3 −3 tests/src/core/testmaprendererjob.cpp
  14. +1 −1 tests/src/core/testqgis.cpp
  15. +2 −2 tests/src/core/testqgsatlascomposition.cpp
  16. +2 −2 tests/src/core/testqgsblendmodes.cpp
  17. +2 −2 tests/src/core/testqgscomposerdd.cpp
  18. +1 −1 tests/src/core/testqgscomposereffects.cpp
  19. +1 −1 tests/src/core/testqgscomposergroup.cpp
  20. +4 −4 tests/src/core/testqgscomposerhtml.cpp
  21. +1 −1 tests/src/core/testqgscomposerlabel.cpp
  22. +2 −2 tests/src/core/testqgscomposermap.cpp
  23. +1 −1 tests/src/core/testqgscomposermapgrid.cpp
  24. +2 −2 tests/src/core/testqgscomposermapoverview.cpp
  25. +1 −1 tests/src/core/testqgscomposermultiframe.cpp
  26. +2 −2 tests/src/core/testqgscomposerobject.cpp
  27. +1 −1 tests/src/core/testqgscomposerpaper.cpp
  28. +3 −3 tests/src/core/testqgscomposerpicture.cpp
  29. +2 −2 tests/src/core/testqgscomposerrotation.cpp
  30. +19 −16 tests/src/core/testqgscomposerscalebar.cpp
  31. +1 −1 tests/src/core/testqgscomposershapes.cpp
  32. +1 −1 tests/src/core/testqgscomposertable.cpp
  33. +4 −4 tests/src/core/testqgscomposertablev2.cpp
  34. +2 −2 tests/src/core/testqgscomposerutils.cpp
  35. +1 −1 tests/src/core/testqgscomposition.cpp
  36. +1 −1 tests/src/core/testqgscoordinatereferencesystem.cpp
  37. +2 −2 tests/src/core/testqgsdiagram.cpp
  38. +1 −1 tests/src/core/testqgsdistancearea.cpp
  39. +2 −2 tests/src/core/testqgsgeometry.cpp
  40. +2 −2 tests/src/core/testqgsgradients.cpp
  41. +12 −9 tests/src/core/testqgsimageoperation.cpp
  42. +2 −2 tests/src/core/testqgsinvertedpolygonrenderer.cpp
  43. +33 −20 tests/src/core/testqgslegendrenderer.cpp
  44. +1 −1 tests/src/core/testqgsmaplayer.cpp
  45. +3 −3 tests/src/core/testqgsmaprenderer.cpp
  46. +2 −2 tests/src/core/testqgsmaprotation.cpp
  47. +1 −1 tests/src/core/testqgsnetworkcontentfetcher.cpp
  48. +4 −4 tests/src/core/testqgspainteffect.cpp
  49. +1 −1 tests/src/core/testqgspoint.cpp
  50. +2 −2 tests/src/core/testqgsrasterfilewriter.cpp
  51. +2 −2 tests/src/core/testqgsrasterfill.cpp
  52. +4 −4 tests/src/core/testqgsrasterlayer.cpp
  53. +2 −2 tests/src/core/testqgsrastersublayer.cpp
  54. +2 −2 tests/src/core/testqgsrenderers.cpp
  55. +1 −1 tests/src/core/testqgsrulebasedrenderer.cpp
  56. +2 −2 tests/src/core/testqgsshapeburst.cpp
  57. +3 −3 tests/src/core/testqgsstylev2.cpp
  58. +2 −2 tests/src/core/testqgsvectordataprovider.cpp
  59. +2 −2 tests/src/core/testqgsvectorlayer.cpp
  60. +3 −3 tests/src/core/testqgsvectorlayercache.cpp
  61. +2 −2 tests/src/core/testziplayer.cpp
  62. +1 −1 tests/src/gui/testprojectionissues.cpp
  63. +1 −1 tests/src/gui/testqgsdualview.cpp
  64. +9 −10 tests/src/gui/testqgsquickprint.cpp
  65. +6 −6 tests/src/gui/testqgsrasterhistogram.cpp
  66. +1 −1 tests/src/gui/testqgsrubberband.cpp
  67. +4 −4 tests/src/providers/testqgsgdalprovider.cpp
  68. +12 −12 tests/src/providers/testqgswcspublicservers.cpp
  69. +5 −6 tests/src/python/test_qgsnetworkcontentfetcher.py
  70. +2 −3 tests/src/python/test_qgszonalstatistics.py
@@ -27,6 +27,8 @@
#include <QDebug>
#include <QBuffer>

static int renderCounter = 0;

QgsRenderChecker::QgsRenderChecker()
: mReport( "" )
, mMatchTarget( 0 )
@@ -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 )
@@ -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 = "*";
@@ -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 )
@@ -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() );
@@ -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();
@@ -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
@@ -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;
@@ -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() )
@@ -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 );
}
@@ -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 );

@@ -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 );
@@ -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
}
@@ -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 );
@@ -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" );
@@ -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 ) );
}
@@ -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 );
@@ -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();
}

@@ -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 );
@@ -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";
}

@@ -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(),
@@ -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 ) )
{
@@ -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 ) )
{
@@ -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 );
}
@@ -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 ) )
{
@@ -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" );
@@ -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 ) )
{

0 comments on commit 9b976cf

Please sign in to comment.
You can’t perform that action at this time.