Skip to content

Commit

Permalink
test fixes:
Browse files Browse the repository at this point in the history
* port python test to sip api v2 (fixes #8314)
* introduce compareWkt for more tolerant WKT comparisions in C++ tests
* require UTF-8 locale for regression1141 test on linux
  • Loading branch information
jef-n committed Jul 19, 2013
1 parent 6831498 commit 51074d7
Show file tree
Hide file tree
Showing 34 changed files with 177 additions and 91 deletions.
1 change: 1 addition & 0 deletions scripts/spelling.dat
Original file line number Diff line number Diff line change
Expand Up @@ -467,3 +467,4 @@ widht:width
heigth:height
heigh:height
delimted:delimited
teh:the
8 changes: 4 additions & 4 deletions src/core/qgsrenderchecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ bool QgsRenderChecker::isKnownAnomaly( QString theDiffImageFile )
QString myFilename = "*";
myList = myDirectory.entryList( QStringList( myFilename ),
QDir::Files | QDir::NoSymLinks );
//remove the control file from teh list as the anomalies are
//remove the control file from the list as the anomalies are
//all files except the control file
myList.removeAt( myList.indexOf( mExpectedImageFile ) );

Expand Down Expand Up @@ -241,11 +241,11 @@ bool QgsRenderChecker::compareImages( QString theTestName,
//
QString myDashMessage = "<DartMeasurementFile name=\"Rendered Image " + theTestName + "\""
" type=\"image/png\">" + mRenderedImageFile +
"</DartMeasurementFile>"
"</DartMeasurementFile>\n"
"<DartMeasurementFile name=\"Expected Image " + theTestName + "\" type=\"image/png\">" +
mExpectedImageFile + "</DartMeasurementFile>"
mExpectedImageFile + "</DartMeasurementFile>\n"
"<DartMeasurementFile name=\"Difference Image " + theTestName + "\" type=\"image/png\">" +
myDiffImageFile + "</DartMeasurementFile>";
myDiffImageFile + "</DartMeasurementFile>\n";
qDebug( ) << myDashMessage;

//
Expand Down
54 changes: 53 additions & 1 deletion src/core/qgsrenderchecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@
#ifndef QGSRENDERCHECKER_H
#define QGSRENDERCHECKER_H

#include <qgis.h>
#include <QDir>
#include <QString>
#include <QRegExp>
#include <QList>

#include <qgsmaprenderer.h>
#include <qgslogger.h>

class QImage;

/** \ingroup UnitTests
Expand Down Expand Up @@ -86,7 +92,7 @@ class CORE_EXPORT QgsRenderChecker
* @note: make sure to call setExpectedImage and setRenderedImage first.
*/
bool compareImages( QString theTestName, unsigned int theMismatchCount = 0, QString theRenderedImageFile = "" );
/** Get a list of all teh anomalies. An anomaly is a rendered difference
/** Get a list of all the 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
Expand All @@ -110,4 +116,50 @@ class CORE_EXPORT QgsRenderChecker

}; // class QgsRenderChecker


/** Compare two WKT strings with some tolerance
* @param a first WKT string
* @param b second WKT string
* @param tolerance tolerance to use (optional, defaults to 0.000001)
* @return bool indicating if the WKT are sufficiently equal
*/

inline bool compareWkt( QString a, QString b, double tolerance = 0.000001 )
{
QgsDebugMsg( QString( "a:%1 b:%2 tol:%3" ).arg( a ).arg( b ).arg( tolerance ) );
QRegExp re( "-?\\d+(?:\\.\\d+)?(?:[eE]\\d+)?" );

QString a0( a ), b0( b );
a0.replace( re, "#" );
b0.replace( re, "#" );

QgsDebugMsg( QString( "a0:%1 b0:%2" ).arg( a0 ).arg( b0 ) );

if ( a0 != b0 )
return false;

QList<double> al, bl;

int pos;
for ( pos = 0; ( pos = re.indexIn( a, pos ) ) != -1; pos += re.matchedLength() )
{
al << re.cap( 0 ).toDouble();
}
for ( pos = 0; ( pos = re.indexIn( b, pos ) ) != -1; pos += re.matchedLength() )
{
bl << re.cap( 0 ).toDouble();
}

if ( al.size() != bl.size() )
return false;

for ( int i = 0; i < al.size(); i++ )
{
if ( !qgsDoubleNear( al[i], bl[i], tolerance ) )
return false;
}

return true;
}

#endif
16 changes: 15 additions & 1 deletion tests/src/core/regression1141.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <QObject>
#include <QPainter>
#include <QTime>
#include <iostream>

#include <QApplication>
#include <QDesktopServices>
Expand All @@ -35,6 +34,11 @@
#include <qgsfield.h>
#include <qgis.h> //defines GEOWkt
#include <qgsproviderregistry.h>
#include <qgslogger.h>

#if defined(linux)
#include <langinfo.h>
#endif


/** \ingroup UnitTests
Expand Down Expand Up @@ -90,6 +94,16 @@ void Regression1141::cleanupTestCase()

void Regression1141::diacriticalTest()
{
#if defined(linux)
const char *cs = nl_langinfo( CODESET );
QgsDebugMsg( QString( "CODESET:%1" ).arg( cs ? cs : "unset" ) );
if ( !cs || strcmp( cs, "UTF-8" ) != 0 )
{
QSKIP( "This test requires a UTF-8 locale", SkipSingle );
return;
}
#endif

//create some objects that will be used in all tests...
mEncoding = "UTF-8";
QgsField myField( "ąęćń", QVariant::Int, "int", 10, 0, "Value on lon" );
Expand Down
3 changes: 2 additions & 1 deletion tests/src/core/testqgsexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <qgsexpression.h>
#include <qgsfeature.h>
#include <qgsgeometry.h>
#include <qgsrenderchecker.h>

#if QT_VERSION < 0x40701
// See http://hub.qgis.org/issues/4284
Expand Down Expand Up @@ -809,7 +810,7 @@ class TestQgsExpression: public QObject

QCOMPARE( out.canConvert<QgsGeometry>(), true );
QgsGeometry outGeom = out.value<QgsGeometry>();
QCOMPARE( outGeom.exportToWkt(), result->exportToWkt() );
QVERIFY( compareWkt( outGeom.exportToWkt(), result->exportToWkt() ) );
}

void eval_special_columns()
Expand Down
1 change: 0 additions & 1 deletion tests/src/core/testqgsgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,6 @@ void TestQgsGeometry::dumpPolyline( QgsPolyline &thePolyline )
mpPainter->drawPolyline( myPoints );
}


QTEST_MAIN( TestQgsGeometry )
#include "moc_testqgsgeometry.cxx"

1 change: 1 addition & 0 deletions tests/src/python/qgis_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
'Copyright (c) 2011 German Carrillo, '
'geotux_tuxman@linuxmail.org')

import qgis

from PyQt4.QtCore import QObject
from qgis.core import QgsMapLayerRegistry
Expand Down
4 changes: 3 additions & 1 deletion tests/src/python/qgscompositionchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* *
***************************************************************************/
'''
import qgis

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
Expand Down Expand Up @@ -92,7 +94,7 @@ def compareImages( self, imgExpected, imgRendered, differenceImagePath ):
mismatchCount = mismatchCount + 1
differenceImage.setPixel( j, i, qRgb( 255, 0, 0 ) )

if not differenceImagePath.isEmpty():
if differenceImagePath != "":
differenceImage.save( differenceImagePath, "PNG" )

#allow pixel deviation of 1 percent
Expand Down
4 changes: 3 additions & 1 deletion tests/src/python/test_qgsanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
import unittest
import sys
import os
import qgis

from utilities import unitTestDataPath, getQgisTestApp
from PyQt4.QtCore import QFileInfo, QDir, QStringList
from PyQt4.QtCore import QFileInfo, QDir
from PyQt4.QtXml import QDomDocument

# support python < 2.7 via unittest2
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/test_qgsapplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import qgis
from utilities import getQgisTestApp, unittest
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()

Expand Down
27 changes: 14 additions & 13 deletions tests/src/python/test_qgsatlascomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* *
***************************************************************************/
'''
import qgis
import unittest
from utilities import *
from PyQt4.QtCore import *
Expand All @@ -28,14 +29,14 @@ class TestQgsAtlasComposition(unittest.TestCase):

def testCase(self):
self.TEST_DATA_DIR = unitTestDataPath()
vectorFileInfo = QFileInfo( self.TEST_DATA_DIR + QDir().separator().toAscii() + "france_parts.shp")
vectorFileInfo = QFileInfo( self.TEST_DATA_DIR + QDir().separator() + "france_parts.shp")
mVectorLayer = QgsVectorLayer( vectorFileInfo.filePath(), vectorFileInfo.completeBaseName(), "ogr" )

QgsMapLayerRegistry.instance().addMapLayers( [mVectorLayer] )

# create composition with composer map
mMapRenderer = QgsMapRenderer()
layerStringList = QStringList()
layerStringList = []
layerStringList.append( mVectorLayer.id() )
mMapRenderer.setLayerSet( layerStringList )
mMapRenderer.setProjectionsEnabled( True )
Expand Down Expand Up @@ -102,7 +103,7 @@ def filename_test( self ):
self.mAtlas.beginRender()
for i in range(0, self.mAtlas.numFeatures()):
self.mAtlas.prepareForFeature( i )
expected = QString( "output_%1" ).arg(i+1)
expected = "output_%d" % (i+1)
assert self.mAtlas.currentFilename() == expected
self.mAtlas.endRender()

Expand All @@ -118,10 +119,10 @@ def autoscale_render_test( self ):

checker = QgsCompositionChecker()
res = checker.testComposition( "Atlas autoscale test", self.mComposition, \
QString( self.TEST_DATA_DIR ) + QDir.separator() + \
self.TEST_DATA_DIR + QDir.separator() + \
"control_images" + QDir.separator() + \
"expected_composermapatlas" + QDir.separator() + \
QString( "autoscale_%1.png" ).arg( i ) )
"autoscale_%d.png" % i )
assert res[0] == True
self.mAtlas.endRender()

Expand All @@ -137,10 +138,10 @@ def fixedscale_render_test( self ):

checker = QgsCompositionChecker()
res = checker.testComposition( "Atlas fixed scale test", self.mComposition, \
QString( self.TEST_DATA_DIR ) + QDir.separator() + \
self.TEST_DATA_DIR + QDir.separator() + \
"control_images" + QDir.separator() + \
"expected_composermapatlas" + QDir.separator() + \
QString( "fixedscale_%1.png" ).arg( i ) )
"fixedscale_%d.png" % i )
assert res[0] == True
self.mAtlas.endRender()

Expand All @@ -157,10 +158,10 @@ def hidden_render_test( self ):

checker = QgsCompositionChecker()
res = checker.testComposition( "Atlas hidden test", self.mComposition, \
QString( self.TEST_DATA_DIR ) + QDir.separator() + \
self.TEST_DATA_DIR + QDir.separator() + \
"control_images" + QDir.separator() + \
"expected_composermapatlas" + QDir.separator() + \
QString( "hiding_%1.png" ).arg( i ) )
"hiding_%d.png" % i )
assert res[0] == True
self.mAtlas.endRender()

Expand All @@ -181,10 +182,10 @@ def sorting_render_test( self ):

checker = QgsCompositionChecker()
res = checker.testComposition( "Atlas sorting test", self.mComposition, \
QString( self.TEST_DATA_DIR ) + QDir.separator() + \
self.TEST_DATA_DIR + QDir.separator() + \
"control_images" + QDir.separator() + \
"expected_composermapatlas" + QDir.separator() + \
QString( "sorting_%1.png" ).arg( i ) )
"sorting_%d.png" % i )
assert res[0] == True
self.mAtlas.endRender()

Expand All @@ -206,10 +207,10 @@ def filtering_render_test( self ):

checker = QgsCompositionChecker()
res = checker.testComposition( "Atlas filtering test", self.mComposition, \
QString( self.TEST_DATA_DIR ) + QDir.separator() + \
self.TEST_DATA_DIR + QDir.separator() + \
"control_images" + QDir.separator() + \
"expected_composermapatlas" + QDir.separator() + \
QString( "filtering_%1.png" ).arg( i ) )
"filtering_%d.png" % i )
assert res[0] == True
self.mAtlas.endRender()

Expand Down
9 changes: 5 additions & 4 deletions tests/src/python/test_qgsblendmodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
__revision__ = '$Format:%H$'

import os
import qgis

from PyQt4.QtCore import *
from PyQt4.QtGui import *
Expand Down Expand Up @@ -95,7 +96,7 @@ def testVectorBlending(self):
"""Test that blend modes work for vector layers."""

#Add vector layers to map
myLayers = QStringList()
myLayers = []
myLayers.append(self.mLineLayer.id())
myLayers.append(self.mPolygonLayer.id())
self.mMapRenderer.setLayerSet(myLayers)
Expand All @@ -121,7 +122,7 @@ def testVectorFeatureBlending(self):
"""Test that feature blend modes work for vector layers."""

#Add vector layers to map
myLayers = QStringList()
myLayers = []
myLayers.append(self.mLineLayer.id())
myLayers.append(self.mPolygonLayer.id())
self.mMapRenderer.setLayerSet(myLayers)
Expand All @@ -145,7 +146,7 @@ def testVectorLayerTransparency(self):
"""Test that layer transparency works for vector layers."""

#Add vector layers to map
myLayers = QStringList()
myLayers = []
myLayers.append(self.mLineLayer.id())
myLayers.append(self.mPolygonLayer.id())
self.mMapRenderer.setLayerSet(myLayers)
Expand All @@ -165,7 +166,7 @@ def testVectorLayerTransparency(self):
def testRasterBlending(self):
"""Test that blend modes work for raster layers."""
#Add raster layers to map
myLayers = QStringList()
myLayers = []
myLayers.append(self.mRasterLayer1.id())
myLayers.append(self.mRasterLayer2.id())
self.mMapRenderer.setLayerSet(myLayers)
Expand Down
4 changes: 2 additions & 2 deletions tests/src/python/test_qgscomposereffects.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
__revision__ = '$Format:%H$'

import os
from PyQt4.QtCore import (QStringList,
QFileInfo)
import qgis
from PyQt4.QtCore import QFileInfo
from PyQt4.QtXml import QDomDocument
from PyQt4.QtGui import (QPainter, QColor)

Expand Down
5 changes: 3 additions & 2 deletions tests/src/python/test_qgscomposerhtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

import unittest
import os
from PyQt4.QtCore import QUrl, QString, qDebug
import qgis
from PyQt4.QtCore import QUrl, qDebug
from PyQt4.QtXml import QDomDocument
from qgis.core import (QgsComposition,
QgsComposerHtml,
Expand Down Expand Up @@ -54,7 +55,7 @@ def controlImagePath(self, theImageName):
def htmlUrl(self):
"""Helper to get the url of the html doc."""
myPath = os.path.join(TEST_DATA_DIR, "html_table.html")
myUrl = QUrl(QString("file:///%1").arg(myPath))
myUrl = QUrl("file:///%1").arg(myPath)
return myUrl

@expectedFailure
Expand Down
Loading

0 comments on commit 51074d7

Please sign in to comment.