Skip to content

Commit

Permalink
Update test to newer methods
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 25, 2023
1 parent 184dd70 commit 6ce7645
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions tests/src/core/testqgsvectortilelayer.cpp
Expand Up @@ -20,7 +20,6 @@
//qgis includes...
#include "qgsapplication.h"
#include "qgsproject.h"
#include "qgsrenderchecker.h"
#include "qgstiles.h"
#include "qgsvectortilebasicrenderer.h"
#include "qgsvectortilelayer.h"
Expand All @@ -47,15 +46,13 @@ class TestQgsVectorTileLayer : public QgsTest
Q_OBJECT

public:
TestQgsVectorTileLayer() : QgsTest( QStringLiteral( "Vector Tile Layer Tests" ) ) {}
TestQgsVectorTileLayer() : QgsTest( QStringLiteral( "Vector Tile Layer Tests" ), QStringLiteral( "vector_tile" ) ) {}

private:
QString mDataDir;
QgsVectorTileLayer *mLayer = nullptr;
QgsMapSettings *mMapSettings = nullptr;

bool imageCheck( const QString &testType, QgsVectorTileLayer *layer, QgsRectangle extent );

private slots:
void initTestCase();// will be called before the first testfunction is executed.
void cleanupTestCase();// will be called after the last testfunction was executed.
Expand Down Expand Up @@ -103,6 +100,7 @@ void TestQgsVectorTileLayer::initTestCase()

mMapSettings = new QgsMapSettings();
mMapSettings->setLayers( QList<QgsMapLayer *>() << mLayer );
mMapSettings->setOutputDpi( 96 );

// let's have some standard style config for the layer
QColor polygonFillColor = Qt::blue;
Expand Down Expand Up @@ -142,25 +140,12 @@ void TestQgsVectorTileLayer::test_basic()
QCOMPARE( mLayer->properties(), Qgis::MapLayerProperties( Qgis::MapLayerProperty::IsBasemapLayer ) );
}


bool TestQgsVectorTileLayer::imageCheck( const QString &testType, QgsVectorTileLayer *layer, QgsRectangle extent )
{
mMapSettings->setExtent( extent );
mMapSettings->setDestinationCrs( layer->crs() );
mMapSettings->setOutputDpi( 96 );
QgsRenderChecker myChecker;
myChecker.setControlPathPrefix( QStringLiteral( "vector_tile" ) );
myChecker.setControlName( "expected_" + testType );
myChecker.setMapSettings( *mMapSettings );
myChecker.setColorTolerance( 15 );
const bool myResultFlag = myChecker.runTest( testType, 0 );
mReport += myChecker.report();
return myResultFlag;
}

void TestQgsVectorTileLayer::test_render()
{
QVERIFY( imageCheck( "render_test_basic", mLayer, mLayer->extent() ) );
mMapSettings->setExtent( mLayer->extent() );
mMapSettings->setDestinationCrs( mLayer->crs() );
QVERIFY( renderMapSettingsCheck( QStringLiteral( "render_test_basic" ),
QStringLiteral( "render_test_basic" ), *mMapSettings, 0, 15 ) );
}

void TestQgsVectorTileLayer::test_render_withClip()
Expand All @@ -171,7 +156,11 @@ void TestQgsVectorTileLayer::test_render_withClip()
region2.setFeatureClip( QgsMapClippingRegion::FeatureClippingType::ClipToIntersection );
mMapSettings->addClippingRegion( region );
mMapSettings->addClippingRegion( region2 );
const bool res = imageCheck( "render_painterclip", mLayer, mLayer->extent() );

mMapSettings->setExtent( mLayer->extent() );
mMapSettings->setDestinationCrs( mLayer->crs() );
const bool res = renderMapSettingsCheck( QStringLiteral( "render_painterclip" ),
QStringLiteral( "render_painterclip" ), *mMapSettings, 0, 15 );
mMapSettings->setClippingRegions( QList< QgsMapClippingRegion >() );
QVERIFY( res );
}
Expand Down Expand Up @@ -213,11 +202,16 @@ void TestQgsVectorTileLayer::test_labeling()
Qt::transparent, 0,
Qt::transparent, Qt::transparent, 0 ) );
mLayer->setRenderer( rend ); // takes ownership
bool res1 = imageCheck( "render_test_labeling", mLayer, mLayer->extent() );

mMapSettings->setExtent( mLayer->extent() );
mMapSettings->setDestinationCrs( mLayer->crs() );
const bool res1 = renderMapSettingsCheck( QStringLiteral( "render_test_labeling" ),
QStringLiteral( "render_test_labeling" ), *mMapSettings, 0, 15 );

// disable label rendering
mLayer->setLabelsEnabled( false );
bool res2 = imageCheck( "render_test_labeling_disabled", mLayer, mLayer->extent() );
const bool res2 = renderMapSettingsCheck( QStringLiteral( "render_test_labeling_disabled" ),
QStringLiteral( "render_test_labeling_disabled" ), *mMapSettings, 0, 15 );

mLayer->setRenderer( oldRenderer );

Expand Down Expand Up @@ -556,7 +550,10 @@ void TestQgsVectorTileLayer::test_polygonWithLineStyle()
rend->setStyles( QList<QgsVectorTileBasicRendererStyle>() << bgst << st );
layer->setRenderer( rend ); // takes ownership

QVERIFY( imageCheck( "render_test_polygon_with_line_style", layer.get(), layer->extent() ) );
mMapSettings->setExtent( layer->extent() );
mMapSettings->setDestinationCrs( layer->crs() );
QVERIFY( renderMapSettingsCheck( QStringLiteral( "render_test_polygon_with_line_style" ),
QStringLiteral( "render_test_polygon_with_line_style" ), *mMapSettings, 0, 15 ) );
}

void TestQgsVectorTileLayer::test_polygonWithMarker()
Expand Down Expand Up @@ -592,7 +589,10 @@ void TestQgsVectorTileLayer::test_polygonWithMarker()
rend->setStyles( QList<QgsVectorTileBasicRendererStyle>() << bgst << st );
layer->setRenderer( rend ); // takes ownership

QVERIFY( imageCheck( "render_test_polygon_with_marker", layer.get(), layer->extent() ) );
mMapSettings->setExtent( layer->extent() );
mMapSettings->setDestinationCrs( layer->crs() );
QVERIFY( renderMapSettingsCheck( QStringLiteral( "render_test_polygon_with_marker" ),
QStringLiteral( "render_test_polygon_with_marker" ), *mMapSettings, 0, 15 ) );
}

void TestQgsVectorTileLayer::test_styleMinZoomBeyondTileMaxZoom()
Expand Down Expand Up @@ -631,7 +631,10 @@ void TestQgsVectorTileLayer::test_styleMinZoomBeyondTileMaxZoom()
rend->setStyles( QList<QgsVectorTileBasicRendererStyle>() << bgst << st );
layer->setRenderer( rend ); // takes ownership

QVERIFY( imageCheck( "render_test_style_min_zoom", layer.get(), QgsRectangle( -1180017, 4261973, 155871, 5474783 ) ) );
mMapSettings->setExtent( QgsRectangle( -1180017, 4261973, 155871, 5474783 ) );
mMapSettings->setDestinationCrs( layer->crs() );
QVERIFY( renderMapSettingsCheck( QStringLiteral( "render_test_style_min_zoom" ),
QStringLiteral( "render_test_style_min_zoom" ), *mMapSettings, 0, 15 ) );
}


Expand Down

0 comments on commit 6ce7645

Please sign in to comment.