mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-07 00:03:52 -05:00
Update TestQgsLabelingEngineV2 to use render checker, reenable on Travis
This commit is contained in:
parent
ecbd691ca4
commit
1aefa17fbd
@ -1,2 +1,2 @@
|
|||||||
xvfb-run ctest -V -E 'qgis_labelingenginev2|qgis_openstreetmaptest|qgis_wcsprovidertest' -S ./qgis-test-travis.ctest --output-on-failure
|
xvfb-run ctest -V -E 'qgis_openstreetmaptest|qgis_wcsprovidertest' -S ./qgis-test-travis.ctest --output-on-failure
|
||||||
|
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
ctest -V -E 'qgis_labelingenginev2|qgis_openstreetmaptest|qgis_wcsprovidertest|PyQgsServer' -S ./qgis-test-travis.ctest --output-on-failure
|
ctest -V -E 'qgis_openstreetmaptest|qgis_wcsprovidertest|PyQgsServer' -S ./qgis-test-travis.ctest --output-on-failure
|
||||||
|
|
||||||
|
|||||||
@ -24,41 +24,78 @@
|
|||||||
#include <qgsvectorlayerdiagramprovider.h>
|
#include <qgsvectorlayerdiagramprovider.h>
|
||||||
#include <qgsvectorlayerlabeling.h>
|
#include <qgsvectorlayerlabeling.h>
|
||||||
#include <qgsvectorlayerlabelprovider.h>
|
#include <qgsvectorlayerlabelprovider.h>
|
||||||
|
#include "qgsrenderchecker.h"
|
||||||
|
#include "qgsfontutils.h"
|
||||||
|
|
||||||
class TestQgsLabelingEngineV2 : public QObject
|
class TestQgsLabelingEngineV2 : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
TestQgsLabelingEngineV2() : vl( 0 ) {}
|
TestQgsLabelingEngineV2() : vl( 0 ) {}
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void initTestCase();
|
void initTestCase();
|
||||||
void cleanupTestCase();
|
void cleanupTestCase();
|
||||||
|
void init();// will be called before each testfunction is executed.
|
||||||
|
void cleanup();// will be called after every testfunction.
|
||||||
void testBasic();
|
void testBasic();
|
||||||
void testDiagrams();
|
void testDiagrams();
|
||||||
void testRuleBased();
|
void testRuleBased();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QgsVectorLayer* vl;
|
QgsVectorLayer* vl;
|
||||||
|
|
||||||
|
QString mReport;
|
||||||
|
|
||||||
|
void setDefaultLabelParams( QgsVectorLayer* layer );
|
||||||
|
bool imageCheck( const QString& testName, QImage &image, int mismatchCount );
|
||||||
};
|
};
|
||||||
|
|
||||||
void TestQgsLabelingEngineV2::initTestCase()
|
void TestQgsLabelingEngineV2::initTestCase()
|
||||||
{
|
{
|
||||||
|
mReport += "<h1>Labeling Engine V2 Tests</h1>\n";
|
||||||
|
|
||||||
QgsApplication::init();
|
QgsApplication::init();
|
||||||
QgsApplication::initQgis();
|
QgsApplication::initQgis();
|
||||||
QgsApplication::showSettings();
|
QgsApplication::showSettings();
|
||||||
|
QgsFontUtils::loadStandardTestFonts( QStringList() << "Bold" );
|
||||||
QString filename = QString( TEST_DATA_DIR ) + "/points.shp";
|
|
||||||
|
|
||||||
vl = new QgsVectorLayer( filename, "points", "ogr" );
|
|
||||||
Q_ASSERT( vl->isValid() );
|
|
||||||
QgsMapLayerRegistry::instance()->addMapLayer( vl );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestQgsLabelingEngineV2::cleanupTestCase()
|
void TestQgsLabelingEngineV2::cleanupTestCase()
|
||||||
{
|
{
|
||||||
QgsApplication::exitQgis();
|
QgsApplication::exitQgis();
|
||||||
|
QString myReportFile = QDir::tempPath() + "/qgistest.html";
|
||||||
|
QFile myFile( myReportFile );
|
||||||
|
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
|
||||||
|
{
|
||||||
|
QTextStream myQTextStream( &myFile );
|
||||||
|
myQTextStream << mReport;
|
||||||
|
myFile.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestQgsLabelingEngineV2::init()
|
||||||
|
{
|
||||||
|
QString filename = QString( TEST_DATA_DIR ) + "/points.shp";
|
||||||
|
vl = new QgsVectorLayer( filename, "points", "ogr" );
|
||||||
|
Q_ASSERT( vl->isValid() );
|
||||||
|
QgsMapLayerRegistry::instance()->addMapLayer( vl );
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestQgsLabelingEngineV2::cleanup()
|
||||||
|
{
|
||||||
|
QgsMapLayerRegistry::instance()->removeMapLayer( vl->id( ) );
|
||||||
|
vl = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestQgsLabelingEngineV2::setDefaultLabelParams( QgsVectorLayer* layer )
|
||||||
|
{
|
||||||
|
layer->setCustomProperty( "labeling/fontFamily", QgsFontUtils::getStandardTestFont( "Bold" ).family() );
|
||||||
|
layer->setCustomProperty( "labeling/namedStyle", "Bold" );
|
||||||
|
layer->setCustomProperty( "labeling/textColorR", "200" );
|
||||||
|
layer->setCustomProperty( "labeling/textColorG", "0" );
|
||||||
|
layer->setCustomProperty( "labeling/textColorB", "200" );
|
||||||
|
}
|
||||||
|
|
||||||
void TestQgsLabelingEngineV2::testBasic()
|
void TestQgsLabelingEngineV2::testBasic()
|
||||||
{
|
{
|
||||||
@ -67,6 +104,7 @@ void TestQgsLabelingEngineV2::testBasic()
|
|||||||
mapSettings.setOutputSize( size );
|
mapSettings.setOutputSize( size );
|
||||||
mapSettings.setExtent( vl->extent() );
|
mapSettings.setExtent( vl->extent() );
|
||||||
mapSettings.setLayers( QStringList() << vl->id() );
|
mapSettings.setLayers( QStringList() << vl->id() );
|
||||||
|
mapSettings.setOutputDpi( 96 );
|
||||||
|
|
||||||
// first render the map and labeling separately
|
// first render the map and labeling separately
|
||||||
|
|
||||||
@ -83,6 +121,7 @@ void TestQgsLabelingEngineV2::testBasic()
|
|||||||
vl->setCustomProperty( "labeling", "pal" );
|
vl->setCustomProperty( "labeling", "pal" );
|
||||||
vl->setCustomProperty( "labeling/enabled", true );
|
vl->setCustomProperty( "labeling/enabled", true );
|
||||||
vl->setCustomProperty( "labeling/fieldName", "Class" );
|
vl->setCustomProperty( "labeling/fieldName", "Class" );
|
||||||
|
setDefaultLabelParams( vl );
|
||||||
|
|
||||||
QgsLabelingEngineV2 engine;
|
QgsLabelingEngineV2 engine;
|
||||||
engine.setMapSettings( mapSettings );
|
engine.setMapSettings( mapSettings );
|
||||||
@ -92,6 +131,8 @@ void TestQgsLabelingEngineV2::testBasic()
|
|||||||
|
|
||||||
p.end();
|
p.end();
|
||||||
|
|
||||||
|
QVERIFY( imageCheck( "labeling_basic", img, 0 ) );
|
||||||
|
|
||||||
// now let's test the variant when integrated into rendering loop
|
// now let's test the variant when integrated into rendering loop
|
||||||
|
|
||||||
job.start();
|
job.start();
|
||||||
@ -100,7 +141,7 @@ void TestQgsLabelingEngineV2::testBasic()
|
|||||||
|
|
||||||
vl->setCustomProperty( "labeling/enabled", false );
|
vl->setCustomProperty( "labeling/enabled", false );
|
||||||
|
|
||||||
QCOMPARE( img, img2 );
|
QVERIFY( imageCheck( "labeling_basic", img2, 0 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestQgsLabelingEngineV2::testDiagrams()
|
void TestQgsLabelingEngineV2::testDiagrams()
|
||||||
@ -110,6 +151,7 @@ void TestQgsLabelingEngineV2::testDiagrams()
|
|||||||
mapSettings.setOutputSize( size );
|
mapSettings.setOutputSize( size );
|
||||||
mapSettings.setExtent( vl->extent() );
|
mapSettings.setExtent( vl->extent() );
|
||||||
mapSettings.setLayers( QStringList() << vl->id() );
|
mapSettings.setLayers( QStringList() << vl->id() );
|
||||||
|
mapSettings.setOutputDpi( 96 );
|
||||||
|
|
||||||
// first render the map and diagrams separately
|
// first render the map and diagrams separately
|
||||||
|
|
||||||
@ -134,14 +176,15 @@ void TestQgsLabelingEngineV2::testDiagrams()
|
|||||||
|
|
||||||
p.end();
|
p.end();
|
||||||
|
|
||||||
|
QVERIFY( imageCheck( "labeling_point_diagrams", img, 0 ) );
|
||||||
|
|
||||||
// now let's test the variant when integrated into rendering loop
|
// now let's test the variant when integrated into rendering loop
|
||||||
job.start();
|
job.start();
|
||||||
job.waitForFinished();
|
job.waitForFinished();
|
||||||
QImage img2 = job.renderedImage();
|
QImage img2 = job.renderedImage();
|
||||||
|
|
||||||
QCOMPARE( img, img2 );
|
|
||||||
|
|
||||||
vl->loadDefaultStyle( res );
|
vl->loadDefaultStyle( res );
|
||||||
|
QVERIFY( imageCheck( "labeling_point_diagrams", img2, 0 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -152,6 +195,7 @@ void TestQgsLabelingEngineV2::testRuleBased()
|
|||||||
mapSettings.setOutputSize( size );
|
mapSettings.setOutputSize( size );
|
||||||
mapSettings.setExtent( vl->extent() );
|
mapSettings.setExtent( vl->extent() );
|
||||||
mapSettings.setLayers( QStringList() << vl->id() );
|
mapSettings.setLayers( QStringList() << vl->id() );
|
||||||
|
mapSettings.setOutputDpi( 96 );
|
||||||
|
|
||||||
// set up most basic rule-based labeling for layer
|
// set up most basic rule-based labeling for layer
|
||||||
QgsRuleBasedLabeling::Rule* root = new QgsRuleBasedLabeling::Rule( 0 );
|
QgsRuleBasedLabeling::Rule* root = new QgsRuleBasedLabeling::Rule( 0 );
|
||||||
@ -162,6 +206,12 @@ void TestQgsLabelingEngineV2::testRuleBased()
|
|||||||
s1.obstacle = false;
|
s1.obstacle = false;
|
||||||
s1.dist = 2;
|
s1.dist = 2;
|
||||||
s1.distInMapUnits = false;
|
s1.distInMapUnits = false;
|
||||||
|
s1.textColor = QColor( 200, 0, 200 );
|
||||||
|
s1.textFont = QgsFontUtils::getStandardTestFont( "Bold" );
|
||||||
|
s1.placement = QgsPalLayerSettings::OverPoint;
|
||||||
|
s1.quadOffset = QgsPalLayerSettings::QuadrantAboveLeft;
|
||||||
|
s1.displayAll = true;
|
||||||
|
|
||||||
root->appendChild( new QgsRuleBasedLabeling::Rule( new QgsPalLayerSettings( s1 ) ) );
|
root->appendChild( new QgsRuleBasedLabeling::Rule( new QgsPalLayerSettings( s1 ) ) );
|
||||||
|
|
||||||
QgsPalLayerSettings s2;
|
QgsPalLayerSettings s2;
|
||||||
@ -170,18 +220,22 @@ void TestQgsLabelingEngineV2::testRuleBased()
|
|||||||
s2.obstacle = false;
|
s2.obstacle = false;
|
||||||
s2.dist = 2;
|
s2.dist = 2;
|
||||||
s2.textColor = Qt::red;
|
s2.textColor = Qt::red;
|
||||||
|
s2.textFont = QgsFontUtils::getStandardTestFont( "Bold" );
|
||||||
|
s2.placement = QgsPalLayerSettings::OverPoint;
|
||||||
|
s2.quadOffset = QgsPalLayerSettings::QuadrantBelowRight;
|
||||||
|
s2.displayAll = true;
|
||||||
s2.setDataDefinedProperty( QgsPalLayerSettings::Size, true, true, "18", QString() );
|
s2.setDataDefinedProperty( QgsPalLayerSettings::Size, true, true, "18", QString() );
|
||||||
|
|
||||||
root->appendChild( new QgsRuleBasedLabeling::Rule( new QgsPalLayerSettings( s2 ), 0, 0, "Class = 'Jet'" ) );
|
root->appendChild( new QgsRuleBasedLabeling::Rule( new QgsPalLayerSettings( s2 ), 0, 0, "Class = 'Jet'" ) );
|
||||||
|
|
||||||
vl->setLabeling( new QgsRuleBasedLabeling( root ) );
|
vl->setLabeling( new QgsRuleBasedLabeling( root ) );
|
||||||
|
setDefaultLabelParams( vl );
|
||||||
|
|
||||||
QgsMapRendererSequentialJob job( mapSettings );
|
QgsMapRendererSequentialJob job( mapSettings );
|
||||||
job.start();
|
job.start();
|
||||||
job.waitForFinished();
|
job.waitForFinished();
|
||||||
QImage img = job.renderedImage();
|
QImage img = job.renderedImage();
|
||||||
|
QVERIFY( imageCheck( "labeling_rulebased", img, 0 ) );
|
||||||
img.save( "/tmp/rules.png" );
|
|
||||||
|
|
||||||
// test read/write rules
|
// test read/write rules
|
||||||
QDomDocument doc, doc2, doc3;
|
QDomDocument doc, doc2, doc3;
|
||||||
@ -213,5 +267,28 @@ void TestQgsLabelingEngineV2::testRuleBased()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TestQgsLabelingEngineV2::imageCheck( const QString& testName, QImage &image, int mismatchCount )
|
||||||
|
{
|
||||||
|
//draw background
|
||||||
|
QImage imageWithBackground( image.width(), image.height(), QImage::Format_RGB32 );
|
||||||
|
QgsRenderChecker::drawBackground( &imageWithBackground );
|
||||||
|
QPainter painter( &imageWithBackground );
|
||||||
|
painter.drawImage( 0, 0, image );
|
||||||
|
painter.end();
|
||||||
|
|
||||||
|
mReport += "<h2>" + testName + "</h2>\n";
|
||||||
|
QString tempDir = QDir::tempPath() + "/";
|
||||||
|
QString fileName = tempDir + testName + ".png";
|
||||||
|
imageWithBackground.save( fileName, "PNG" );
|
||||||
|
QgsRenderChecker checker;
|
||||||
|
checker.setControlPathPrefix( "labelingenginev2" );
|
||||||
|
checker.setControlName( "expected_" + testName );
|
||||||
|
checker.setRenderedImage( fileName );
|
||||||
|
checker.setColorTolerance( 2 );
|
||||||
|
bool resultFlag = checker.compareImages( testName, mismatchCount );
|
||||||
|
mReport += checker.report();
|
||||||
|
return resultFlag;
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN( TestQgsLabelingEngineV2 )
|
QTEST_MAIN( TestQgsLabelingEngineV2 )
|
||||||
#include "testqgslabelingenginev2.moc"
|
#include "testqgslabelingenginev2.moc"
|
||||||
|
|||||||
BIN
tests/testdata/control_images/labelingenginev2/expected_labeling_basic/expected_labeling_basic.png
vendored
Normal file
BIN
tests/testdata/control_images/labelingenginev2/expected_labeling_basic/expected_labeling_basic.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 35 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
6
tests/testdata/points_diagrams.qml
vendored
6
tests/testdata/points_diagrams.qml
vendored
@ -17,7 +17,7 @@
|
|||||||
<prop k="offset_map_unit_scale" v="0,0"/>
|
<prop k="offset_map_unit_scale" v="0,0"/>
|
||||||
<prop k="offset_unit" v="MM"/>
|
<prop k="offset_unit" v="MM"/>
|
||||||
<prop k="outline_color" v="#000000"/>
|
<prop k="outline_color" v="#000000"/>
|
||||||
<prop k="outline_width" v="1"/>
|
<prop k="outline_width" v="0.2"/>
|
||||||
<prop k="outline_width_map_unit_scale" v="0,0"/>
|
<prop k="outline_width_map_unit_scale" v="0,0"/>
|
||||||
<prop k="outline_width_unit" v="MM"/>
|
<prop k="outline_width_unit" v="MM"/>
|
||||||
<prop k="scale_method" v="diameter"/>
|
<prop k="scale_method" v="diameter"/>
|
||||||
@ -37,7 +37,7 @@
|
|||||||
<prop k="offset_map_unit_scale" v="0,0"/>
|
<prop k="offset_map_unit_scale" v="0,0"/>
|
||||||
<prop k="offset_unit" v="MM"/>
|
<prop k="offset_unit" v="MM"/>
|
||||||
<prop k="outline_color" v="#000000"/>
|
<prop k="outline_color" v="#000000"/>
|
||||||
<prop k="outline_width" v="1"/>
|
<prop k="outline_width" v="0.2"/>
|
||||||
<prop k="outline_width_map_unit_scale" v="0,0"/>
|
<prop k="outline_width_map_unit_scale" v="0,0"/>
|
||||||
<prop k="outline_width_unit" v="MM"/>
|
<prop k="outline_width_unit" v="MM"/>
|
||||||
<prop k="scale_method" v="diameter"/>
|
<prop k="scale_method" v="diameter"/>
|
||||||
@ -57,7 +57,7 @@
|
|||||||
<prop k="offset_map_unit_scale" v="0,0"/>
|
<prop k="offset_map_unit_scale" v="0,0"/>
|
||||||
<prop k="offset_unit" v="MM"/>
|
<prop k="offset_unit" v="MM"/>
|
||||||
<prop k="outline_color" v="#000000"/>
|
<prop k="outline_color" v="#000000"/>
|
||||||
<prop k="outline_width" v="1"/>
|
<prop k="outline_width" v="0.2"/>
|
||||||
<prop k="outline_width_map_unit_scale" v="0,0"/>
|
<prop k="outline_width_map_unit_scale" v="0,0"/>
|
||||||
<prop k="outline_width_unit" v="MM"/>
|
<prop k="outline_width_unit" v="MM"/>
|
||||||
<prop k="scale_method" v="diameter"/>
|
<prop k="scale_method" v="diameter"/>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user