From 6ce764552f37e7ec02ec87bb2f2c3a0c4af4a9e4 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 24 Oct 2023 14:20:52 +1000 Subject: [PATCH] Update test to newer methods --- tests/src/core/testqgsvectortilelayer.cpp | 57 ++++++++++++----------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/tests/src/core/testqgsvectortilelayer.cpp b/tests/src/core/testqgsvectortilelayer.cpp index e869b17c81db..b12cb5bcb6a3 100644 --- a/tests/src/core/testqgsvectortilelayer.cpp +++ b/tests/src/core/testqgsvectortilelayer.cpp @@ -20,7 +20,6 @@ //qgis includes... #include "qgsapplication.h" #include "qgsproject.h" -#include "qgsrenderchecker.h" #include "qgstiles.h" #include "qgsvectortilebasicrenderer.h" #include "qgsvectortilelayer.h" @@ -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. @@ -103,6 +100,7 @@ void TestQgsVectorTileLayer::initTestCase() mMapSettings = new QgsMapSettings(); mMapSettings->setLayers( QList() << mLayer ); + mMapSettings->setOutputDpi( 96 ); // let's have some standard style config for the layer QColor polygonFillColor = Qt::blue; @@ -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() @@ -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 ); } @@ -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 ); @@ -556,7 +550,10 @@ void TestQgsVectorTileLayer::test_polygonWithLineStyle() rend->setStyles( QList() << 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() @@ -592,7 +589,10 @@ void TestQgsVectorTileLayer::test_polygonWithMarker() rend->setStyles( QList() << 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() @@ -631,7 +631,10 @@ void TestQgsVectorTileLayer::test_styleMinZoomBeyondTileMaxZoom() rend->setStyles( QList() << 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 ) ); }