Skip to content

Commit

Permalink
Add a unit test (would crash without the fix)
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Oct 26, 2022
1 parent 9e853bd commit f0df3e1
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/src/core/testqgsrasterlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "qgsrastertransparency.h"
#include "qgspalettedrasterrenderer.h"
#include "qgsrasterlayertemporalproperties.h"
#include "qgsmaplayerrenderer.h"

//qgis unit test includes
#include <qgsrenderchecker.h>
Expand Down Expand Up @@ -101,6 +102,7 @@ class TestQgsRasterLayer : public QgsTest
void sample();
void testTemporalProperties();
void rotatedRaster();
void forceRasterRender();


private:
Expand Down Expand Up @@ -1055,5 +1057,18 @@ void TestQgsRasterLayer::rotatedRaster()
QVERIFY( render( QStringLiteral( "raster_rotated_rgba" ) ) );
}

void TestQgsRasterLayer::forceRasterRender()
{
QVERIFY2( mpLandsatRasterLayer->isValid(), "landsat.tif layer is not valid!" );

mMapSettings->setDestinationCrs( mpLandsatRasterLayer->crs() );
mMapSettings->setExtent( QgsRectangle( 10, 10, 11, 11 ) ); // outside of layer extent
mMapSettings->setLayers( QList<QgsMapLayer *>() << mpLandsatRasterLayer );

QgsRenderContext context( QgsRenderContext::fromMapSettings( *mMapSettings ) );
std::unique_ptr<QgsMapLayerRenderer> layerRenderer( mpLandsatRasterLayer->createMapRenderer( context ) );
layerRenderer->forceRasterRender(); // this should not crash
}

QGSTEST_MAIN( TestQgsRasterLayer )
#include "testqgsrasterlayer.moc"

0 comments on commit f0df3e1

Please sign in to comment.