Add a unit test (would crash without the fix)

This commit is contained in:
Martin Dobias 2022-10-25 15:10:35 +02:00
parent 9e853bd415
commit f0df3e1f59

View File

@ -46,6 +46,7 @@
#include "qgsrastertransparency.h"
#include "qgspalettedrasterrenderer.h"
#include "qgsrasterlayertemporalproperties.h"
#include "qgsmaplayerrenderer.h"
//qgis unit test includes
#include <qgsrenderchecker.h>
@ -101,6 +102,7 @@ class TestQgsRasterLayer : public QgsTest
void sample();
void testTemporalProperties();
void rotatedRaster();
void forceRasterRender();
private:
@ -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"