Skip to content

Commit

Permalink
Fix leaks in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 26, 2015
1 parent 2b478af commit 46abe34
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 11 deletions.
5 changes: 4 additions & 1 deletion tests/src/analysis/testqgsrastercalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Email : nyall dot dawson at gmail dot com
#include "qgsrasterlayer.h"
#include "qgsrastermatrix.h"
#include "qgsapplication.h"

#include "qgsmaplayerregistry.h"

Q_DECLARE_METATYPE( QgsRasterCalcNode::Operator );

Expand Down Expand Up @@ -84,6 +84,9 @@ void TestQgsRasterCalculator::initTestCase()
QFileInfo landsat4326RasterFileInfo( landsat4326FileName );
mpLandsatRasterLayer4326 = new QgsRasterLayer( landsat4326RasterFileInfo.filePath(),
landsat4326RasterFileInfo.completeBaseName() );

QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpLandsatRasterLayer << mpLandsatRasterLayer4326 );
}

void TestQgsRasterCalculator::cleanupTestCase()
Expand Down
4 changes: 4 additions & 0 deletions tests/src/analysis/testqgszonalstatistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "qgsapplication.h"
#include "qgsvectorlayer.h"
#include "qgszonalstatistics.h"
#include "qgsmaplayerregistry.h"

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

mVectorLayer = new QgsVectorLayer( myTempPath + "polys.shp", "poly", "ogr" );
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mVectorLayer );

mRasterPath = myTempPath + "edge_problem.asc";
}

Expand Down
1 change: 0 additions & 1 deletion tests/src/core/testqgsexpressioncontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ void TestQgsExpressionContext::contextCopy()
void TestQgsExpressionContext::contextStackFunctions()
{
QgsExpression::registerFunction( new GetTestValueFunction(), true );
QgsExpression::registerFunction( new GetTestValueFunction2(), true );

QgsExpressionContext context;
//test retrieving from empty stack
Expand Down
2 changes: 0 additions & 2 deletions tests/src/core/testqgsmaprotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ void TestQgsMapRotation::cleanupTestCase()
delete mMapSettings;
QgsApplication::exitQgis();

// TODO: delete layers (or is it done by exitQgis ?)

QString myReportFile = QDir::tempPath() + "/qgistest.html";
QFile myFile( myReportFile );
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
Expand Down
17 changes: 16 additions & 1 deletion tests/src/core/testqgsogcutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
//qgis includes...
#include <qgsgeometry.h>
#include <qgsogcutils.h>

#include "qgsapplication.h"

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

void initTestCase()
{
//
// Runs once before any tests are run
//
// init QGIS's paths - true means that all path will be inited from prefix
QgsApplication::init();
QgsApplication::initQgis();
}

void cleanupTestCase()
{
QgsApplication::exitQgis();
}

void testGeometryFromGML();
void testGeometryToGML();

Expand Down
16 changes: 10 additions & 6 deletions tests/src/core/testqgsrasterlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,37 +281,41 @@ bool TestQgsRasterLayer::testColorRamp( QString name, QgsVectorColorRampV2* colo
void TestQgsRasterLayer::colorRamp1()
{
// gradient ramp
QgsVectorGradientColorRampV2* colorRamp = new QgsVectorGradientColorRampV2( QColor( Qt::red ), QColor( Qt::black ) );
QgsVectorGradientColorRampV2 colorRamp( QColor( Qt::red ), QColor( Qt::black ) );
QgsGradientStopsList stops;
stops.append( QgsGradientStop( 0.5, QColor( Qt::white ) ) );
colorRamp->setStops( stops );
colorRamp.setStops( stops );

// QVERIFY( testColorRamp( "raster_colorRamp1", colorRamp, QgsColorRampShader::INTERPOLATED, 5 ) );
QVERIFY( testColorRamp( "raster_colorRamp1", colorRamp, QgsColorRampShader::DISCRETE, 10 ) );
QVERIFY( testColorRamp( "raster_colorRamp1", &colorRamp, QgsColorRampShader::DISCRETE, 10 ) );
}

void TestQgsRasterLayer::colorRamp2()
{
QgsVectorColorBrewerColorRampV2 ramp( "BrBG", 10 );
// ColorBrewer ramp
QVERIFY( testColorRamp( "raster_colorRamp2",
new QgsVectorColorBrewerColorRampV2( "BrBG", 10 ),
&ramp,
QgsColorRampShader::DISCRETE, 10 ) );
}

void TestQgsRasterLayer::colorRamp3()
{
// cpt-city ramp, discrete
QgsCptCityArchive::initArchives();
QgsCptCityColorRampV2 ramp( "cb/div/BrBG", "_10" );
QVERIFY( testColorRamp( "raster_colorRamp3",
new QgsCptCityColorRampV2( "cb/div/BrBG", "_10" ),
&ramp,
QgsColorRampShader::DISCRETE, 10 ) );
QgsCptCityArchive::clearArchives();
}

void TestQgsRasterLayer::colorRamp4()
{
// cpt-city ramp, continuous
QgsCptCityColorRampV2 ramp( "grass/elevation", "" );
QVERIFY( testColorRamp( "raster_colorRamp4",
new QgsCptCityColorRampV2( "grass/elevation", "" ),
&ramp,
QgsColorRampShader::DISCRETE, 10 ) );
}

Expand Down
1 change: 1 addition & 0 deletions tests/src/core/testqgsrastersublayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ void TestQgsRasterSubLayer::initTestCase()
qDebug() << "raster metadata: " << mpRasterLayer->dataProvider()->metadata();
mReport += "raster metadata: " + mpRasterLayer->dataProvider()->metadata();

QgsMapLayerRegistry::instance()->addMapLayer( mpRasterLayer );
}
else
{
Expand Down
1 change: 1 addition & 0 deletions tests/src/core/testqgsstylev2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ void TestStyleV2::cleanupTestCase()
// don't save
// mStyle->save();
delete mStyle;
QgsCptCityArchive::clearArchives();
QgsApplication::exitQgis();

QString myReportFile = QDir::tempPath() + "/qgistest.html";
Expand Down
2 changes: 2 additions & 0 deletions tests/src/providers/testqgsgdalprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ void TestQgsGdalProvider::scaleDataType()
//raster is an integer data type, but has a scale < 1, so data type must be float
QCOMPARE( rp->dataType( 1 ), QGis::Float32 );
QCOMPARE( rp->srcDataType( 1 ), QGis::Float32 );
delete provider;
}

void TestQgsGdalProvider::warpedVrt()
Expand All @@ -100,6 +101,7 @@ void TestQgsGdalProvider::warpedVrt()
QVERIFY( qgsDoubleNear( rp->extent().xMaximum(), 3118999, 1 ) );
QVERIFY( qgsDoubleNear( rp->extent().yMinimum(), 2281355, 1 ) );
QVERIFY( qgsDoubleNear( rp->extent().yMaximum(), 3129683, 1 ) );
delete provider;
}

QTEST_MAIN( TestQgsGdalProvider )
Expand Down

0 comments on commit 46abe34

Please sign in to comment.