Skip to content
Permalink
Browse files

Fix leaks in tests

  • Loading branch information
nyalldawson committed Aug 26, 2015
1 parent 2b478af commit 46abe34b8ca531ad1efbdeeab11e42f880076e29
@@ -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 );

@@ -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()
@@ -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
@@ -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";
}

@@ -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
@@ -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 ) )
@@ -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
@@ -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();

@@ -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 ) );
}

@@ -104,6 +104,7 @@ void TestQgsRasterSubLayer::initTestCase()
qDebug() << "raster metadata: " << mpRasterLayer->dataProvider()->metadata();
mReport += "raster metadata: " + mpRasterLayer->dataProvider()->metadata();

QgsMapLayerRegistry::instance()->addMapLayer( mpRasterLayer );
}
else
{
@@ -160,6 +160,7 @@ void TestStyleV2::cleanupTestCase()
// don't save
// mStyle->save();
delete mStyle;
QgsCptCityArchive::clearArchives();
QgsApplication::exitQgis();

QString myReportFile = QDir::tempPath() + "/qgistest.html";
@@ -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()
@@ -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 )

0 comments on commit 46abe34

Please sign in to comment.
You can’t perform that action at this time.