Skip to content

Commit e8fcdfd

Browse files
author
timlinux
committed
Added unit test to replicate crash when a raster is removed from the registry
git-svn-id: http://svn.osgeo.org/qgis/trunk@10206 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 3908cbe commit e8fcdfd

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

tests/src/core/testqgsrasterlayer.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <qgsmaplayerregistry.h>
3535
#include <qgsapplication.h>
3636
#include <qgsmaprenderer.h>
37+
#include <qgsmaplayerregistry.h>
3738

3839
//qgis unit test includes
3940
#include <qgsrenderchecker.h>
@@ -57,6 +58,7 @@ class TestQgsRasterLayer: public QObject
5758
void landsatBasic875Qml();
5859
void checkDimensions();
5960
void buildExternalOverviews();
61+
void registry();
6062
private:
6163
bool render( QString theFileName );
6264
bool setQml( QString theType );
@@ -204,6 +206,28 @@ void TestQgsRasterLayer::buildExternalOverviews()
204206
//cleanup
205207
delete mypLayer;
206208
}
209+
210+
211+
void TestQgsRasterLayer::registry()
212+
{
213+
QString myTempPath = QDir::tempPath() + QDir::separator();
214+
QFile::remove( myTempPath + "landsat.tif.ovr" );
215+
QFile::copy( mTestDataDir + "landsat.tif", myTempPath + "landsat.tif" );
216+
QFileInfo myRasterFileInfo( myTempPath + "landsat.tif" );
217+
QgsRasterLayer * mypLayer = new QgsRasterLayer( myRasterFileInfo.filePath(),
218+
myRasterFileInfo.completeBaseName() );
219+
220+
QgsMapLayerRegistry::instance()->addMapLayer(mypLayer,false);
221+
QgsMapLayerRegistry::instance()->removeMapLayer(mypLayer->getLayerID());
222+
//cleanup
223+
delete mypLayer;
224+
}
225+
226+
//
227+
// Helper methods
228+
//
229+
230+
207231
bool TestQgsRasterLayer::render( QString theTestType )
208232
{
209233
mReport += "<h2>" + theTestType + "</h2>\n";

tests/src/core/testqgsrenderers.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class TestQgsRenderers: public QObject
5151
void continuousSymbol();
5252
void checkClassificationFieldMismatch();
5353
private:
54+
bool mTestHasError;
5455
bool setQml( QString theType ); //uniquevalue / continuous / single /
5556
bool imageCheck( QString theType ); //as above
5657
QgsMapRenderer * mpMapRenderer;
@@ -64,6 +65,7 @@ class TestQgsRenderers: public QObject
6465

6566
void TestQgsRenderers::initTestCase()
6667
{
68+
mTestHasError = false;
6769
// init QGIS's paths - true means that all path will be inited from prefix
6870
QString qgisPath = QCoreApplication::applicationDirPath();
6971
QgsApplication::setPrefixPath( INSTALL_PREFIX, true );

0 commit comments

Comments
 (0)