Skip to content

Commit 46abe34

Browse files
committedAug 26, 2015
Fix leaks in tests
1 parent 2b478af commit 46abe34

9 files changed

+38
-11
lines changed
 

‎tests/src/analysis/testqgsrastercalculator.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Email : nyall dot dawson at gmail dot com
1919
#include "qgsrasterlayer.h"
2020
#include "qgsrastermatrix.h"
2121
#include "qgsapplication.h"
22-
22+
#include "qgsmaplayerregistry.h"
2323

2424
Q_DECLARE_METATYPE( QgsRasterCalcNode::Operator );
2525

@@ -84,6 +84,9 @@ void TestQgsRasterCalculator::initTestCase()
8484
QFileInfo landsat4326RasterFileInfo( landsat4326FileName );
8585
mpLandsatRasterLayer4326 = new QgsRasterLayer( landsat4326RasterFileInfo.filePath(),
8686
landsat4326RasterFileInfo.completeBaseName() );
87+
88+
QgsMapLayerRegistry::instance()->addMapLayers(
89+
QList<QgsMapLayer *>() << mpLandsatRasterLayer << mpLandsatRasterLayer4326 );
8790
}
8891

8992
void TestQgsRasterCalculator::cleanupTestCase()

‎tests/src/analysis/testqgszonalstatistics.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "qgsapplication.h"
2020
#include "qgsvectorlayer.h"
2121
#include "qgszonalstatistics.h"
22+
#include "qgsmaplayerregistry.h"
2223

2324
/** \ingroup UnitTests
2425
* This is a unit test for the zonal statistics class
@@ -69,6 +70,9 @@ void TestQgsZonalStatistics::initTestCase()
6970
}
7071

7172
mVectorLayer = new QgsVectorLayer( myTempPath + "polys.shp", "poly", "ogr" );
73+
QgsMapLayerRegistry::instance()->addMapLayers(
74+
QList<QgsMapLayer *>() << mVectorLayer );
75+
7276
mRasterPath = myTempPath + "edge_problem.asc";
7377
}
7478

‎tests/src/core/testqgsexpressioncontext.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ void TestQgsExpressionContext::contextCopy()
305305
void TestQgsExpressionContext::contextStackFunctions()
306306
{
307307
QgsExpression::registerFunction( new GetTestValueFunction(), true );
308-
QgsExpression::registerFunction( new GetTestValueFunction2(), true );
309308

310309
QgsExpressionContext context;
311310
//test retrieving from empty stack

‎tests/src/core/testqgsmaprotation.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ void TestQgsMapRotation::cleanupTestCase()
130130
delete mMapSettings;
131131
QgsApplication::exitQgis();
132132

133-
// TODO: delete layers (or is it done by exitQgis ?)
134-
135133
QString myReportFile = QDir::tempPath() + "/qgistest.html";
136134
QFile myFile( myReportFile );
137135
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )

‎tests/src/core/testqgsogcutils.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
//qgis includes...
2121
#include <qgsgeometry.h>
2222
#include <qgsogcutils.h>
23-
23+
#include "qgsapplication.h"
2424

2525
/** \ingroup UnitTests
2626
* This is a unit test for OGC utilities
@@ -30,6 +30,21 @@ class TestQgsOgcUtils : public QObject
3030
Q_OBJECT
3131
private slots:
3232

33+
void initTestCase()
34+
{
35+
//
36+
// Runs once before any tests are run
37+
//
38+
// init QGIS's paths - true means that all path will be inited from prefix
39+
QgsApplication::init();
40+
QgsApplication::initQgis();
41+
}
42+
43+
void cleanupTestCase()
44+
{
45+
QgsApplication::exitQgis();
46+
}
47+
3348
void testGeometryFromGML();
3449
void testGeometryToGML();
3550

‎tests/src/core/testqgsrasterlayer.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,37 +281,41 @@ bool TestQgsRasterLayer::testColorRamp( QString name, QgsVectorColorRampV2* colo
281281
void TestQgsRasterLayer::colorRamp1()
282282
{
283283
// gradient ramp
284-
QgsVectorGradientColorRampV2* colorRamp = new QgsVectorGradientColorRampV2( QColor( Qt::red ), QColor( Qt::black ) );
284+
QgsVectorGradientColorRampV2 colorRamp( QColor( Qt::red ), QColor( Qt::black ) );
285285
QgsGradientStopsList stops;
286286
stops.append( QgsGradientStop( 0.5, QColor( Qt::white ) ) );
287-
colorRamp->setStops( stops );
287+
colorRamp.setStops( stops );
288288

289289
// QVERIFY( testColorRamp( "raster_colorRamp1", colorRamp, QgsColorRampShader::INTERPOLATED, 5 ) );
290-
QVERIFY( testColorRamp( "raster_colorRamp1", colorRamp, QgsColorRampShader::DISCRETE, 10 ) );
290+
QVERIFY( testColorRamp( "raster_colorRamp1", &colorRamp, QgsColorRampShader::DISCRETE, 10 ) );
291291
}
292292

293293
void TestQgsRasterLayer::colorRamp2()
294294
{
295+
QgsVectorColorBrewerColorRampV2 ramp( "BrBG", 10 );
295296
// ColorBrewer ramp
296297
QVERIFY( testColorRamp( "raster_colorRamp2",
297-
new QgsVectorColorBrewerColorRampV2( "BrBG", 10 ),
298+
&ramp,
298299
QgsColorRampShader::DISCRETE, 10 ) );
299300
}
300301

301302
void TestQgsRasterLayer::colorRamp3()
302303
{
303304
// cpt-city ramp, discrete
304305
QgsCptCityArchive::initArchives();
306+
QgsCptCityColorRampV2 ramp( "cb/div/BrBG", "_10" );
305307
QVERIFY( testColorRamp( "raster_colorRamp3",
306-
new QgsCptCityColorRampV2( "cb/div/BrBG", "_10" ),
308+
&ramp,
307309
QgsColorRampShader::DISCRETE, 10 ) );
310+
QgsCptCityArchive::clearArchives();
308311
}
309312

310313
void TestQgsRasterLayer::colorRamp4()
311314
{
312315
// cpt-city ramp, continuous
316+
QgsCptCityColorRampV2 ramp( "grass/elevation", "" );
313317
QVERIFY( testColorRamp( "raster_colorRamp4",
314-
new QgsCptCityColorRampV2( "grass/elevation", "" ),
318+
&ramp,
315319
QgsColorRampShader::DISCRETE, 10 ) );
316320
}
317321

‎tests/src/core/testqgsrastersublayer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ void TestQgsRasterSubLayer::initTestCase()
104104
qDebug() << "raster metadata: " << mpRasterLayer->dataProvider()->metadata();
105105
mReport += "raster metadata: " + mpRasterLayer->dataProvider()->metadata();
106106

107+
QgsMapLayerRegistry::instance()->addMapLayer( mpRasterLayer );
107108
}
108109
else
109110
{

‎tests/src/core/testqgsstylev2.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ void TestStyleV2::cleanupTestCase()
160160
// don't save
161161
// mStyle->save();
162162
delete mStyle;
163+
QgsCptCityArchive::clearArchives();
163164
QgsApplication::exitQgis();
164165

165166
QString myReportFile = QDir::tempPath() + "/qgistest.html";

‎tests/src/providers/testqgsgdalprovider.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ void TestQgsGdalProvider::scaleDataType()
8282
//raster is an integer data type, but has a scale < 1, so data type must be float
8383
QCOMPARE( rp->dataType( 1 ), QGis::Float32 );
8484
QCOMPARE( rp->srcDataType( 1 ), QGis::Float32 );
85+
delete provider;
8586
}
8687

8788
void TestQgsGdalProvider::warpedVrt()
@@ -100,6 +101,7 @@ void TestQgsGdalProvider::warpedVrt()
100101
QVERIFY( qgsDoubleNear( rp->extent().xMaximum(), 3118999, 1 ) );
101102
QVERIFY( qgsDoubleNear( rp->extent().yMinimum(), 2281355, 1 ) );
102103
QVERIFY( qgsDoubleNear( rp->extent().yMaximum(), 3129683, 1 ) );
104+
delete provider;
103105
}
104106

105107
QTEST_MAIN( TestQgsGdalProvider )

0 commit comments

Comments
 (0)
Please sign in to comment.