Skip to content
Permalink
Browse files

Fix a bunch of leaks in unit tests

  • Loading branch information
nyalldawson committed Aug 25, 2015
1 parent 24b8405 commit 385a608a0b18961e34e6cd805d8f9242654aa0ec
@@ -165,6 +165,7 @@ void TestQgsColorSchemeRegistry::removeScheme()
QVERIFY( registry->schemes().length() == 0 );
//try removing a scheme not in the registry
QVERIFY( !registry->removeColorScheme( recentScheme ) );
delete recentScheme;
}

void TestQgsColorSchemeRegistry::matchingSchemes()
@@ -80,6 +80,7 @@ void TestQgsComposerGroup::cleanupTestCase()
{
delete mComposition;
delete mMapSettings;
QgsApplication::exitQgis();

QString myReportFile = QDir::tempPath() + "/qgistest.html";
QFile myFile( myReportFile );
@@ -83,8 +83,12 @@ void TestQgsComposerModel::initTestCase()

void TestQgsComposerModel::cleanupTestCase()
{
delete mItem1;
delete mItem2;
delete mItem3;
delete mComposition;
delete mMapSettings;
QgsApplication::exitQgis();
}

void TestQgsComposerModel::init()
@@ -232,6 +236,9 @@ void TestQgsComposerModel::removeItem()
QCOMPARE( mComposition->itemsModel()->rowCount(), 0 );
//also check scene list
QCOMPARE( mComposition->itemsModel()->mItemsInScene.size(), 0 );

delete item1;
delete item2;
}

void TestQgsComposerModel::reorderUp()
@@ -459,6 +466,7 @@ void TestQgsComposerModel::setItemRemoved()
QCOMPARE( mComposition->itemsModel()->mItemsInScene.size(), 2 );
QCOMPARE( mComposition->itemsModel()->mItemsInScene.at( 0 ), mItem2 );
QCOMPARE( mComposition->itemsModel()->mItemsInScene.at( 1 ), mItem1 );
delete label;
}

void TestQgsComposerModel::rebuildZListWithRemoved()
@@ -80,6 +80,8 @@ void TestQgsComposerMultiFrame::cleanupTestCase()
myQTextStream << mReport;
myFile.close();
}

QgsApplication::exitQgis();
}

void TestQgsComposerMultiFrame::init()
@@ -83,6 +83,8 @@ void TestQgsComposerObject::cleanupTestCase()
myQTextStream << mReport;
myFile.close();
}

QgsApplication::exitQgis();
}

void TestQgsComposerObject::init()
@@ -99,6 +99,7 @@ void TestQgsComposerPicture::initTestCase()

void TestQgsComposerPicture::cleanupTestCase()
{
delete mComposerPicture;
delete mComposition;
delete mMapSettings;

@@ -115,6 +115,9 @@ void TestQgsComposerRotation::cleanupTestCase()
mComposition->removeItem( mComposerMap );
delete mComposerMap;
}

delete mComposerLabel;
delete mComposerRect;
delete mComposition;
delete mMapSettings;

@@ -104,6 +104,7 @@ void TestQgsComposerTable::initTestCase()

void TestQgsComposerTable::cleanupTestCase()
{
delete mComposerMap;
delete mComposition;
delete mMapSettings;

@@ -129,6 +129,7 @@ void TestQgsComposerTableV2::init()
mComposition->setPaperSize( 297, 210 ); //A4 portrait

mComposerAttributeTable = new QgsComposerAttributeTableV2( mComposition, false );
mComposition->addMultiFrame( mComposerAttributeTable );

mFrame1 = new QgsComposerFrame( mComposition, mComposerAttributeTable, 5, 5, 100, 30 );
mFrame2 = new QgsComposerFrame( mComposition, mComposerAttributeTable, 5, 40, 100, 30 );
@@ -463,6 +463,8 @@ void TestQgsComposerUtils::readDataDefinedProperty()
QVERIFY( !( dataDefinedProperties.value( QgsComposerObject::TestProperty ) )->useExpression() );
QCOMPARE(( dataDefinedProperties.value( QgsComposerObject::TestProperty ) )->expressionString(), QString() );
QCOMPARE(( dataDefinedProperties.value( QgsComposerObject::TestProperty ) )->field(), QString() );

qDeleteAll( dataDefinedProperties );
}

void TestQgsComposerUtils::readDataDefinedPropertyMap()
@@ -519,6 +521,7 @@ void TestQgsComposerUtils::readDataDefinedPropertyMap()
QVERIFY( !( dataDefinedProperties.value( QgsComposerObject::TestProperty ) )->useExpression() );
QCOMPARE(( dataDefinedProperties.value( QgsComposerObject::TestProperty ) )->expressionString(), QString( "test expression 3" ) );
QCOMPARE(( dataDefinedProperties.value( QgsComposerObject::TestProperty ) )->field(), QString( "test field 3" ) );
qDeleteAll( dataDefinedProperties );
}

void TestQgsComposerUtils::writeDataDefinedPropertyMap()
@@ -569,6 +572,7 @@ void TestQgsComposerUtils::writeDataDefinedPropertyMap()
QCOMPARE( dd3Elem.attribute( "useExpr", "bad" ), QString( "true" ) );
QCOMPARE( dd3Elem.attribute( "expr", "bad" ), QString( "expression 3" ) );
QCOMPARE( dd3Elem.attribute( "field", "bad" ), QString( "field 3" ) );
qDeleteAll( dataDefinedProperties );
}

void TestQgsComposerUtils::scaledFontPixelSize()
@@ -19,7 +19,8 @@
#include <QSettings>
#include <QSharedPointer>

#include <qgsdatadefined.h>
#include "qgsdatadefined.h"
#include "qgsapplication.h"

/** \ingroup UnitTests
* Unit tests for QgsDataDefined
@@ -49,12 +50,13 @@ class TestQgsDataDefined: public QObject

void TestQgsDataDefined::initTestCase()
{

QgsApplication::init();
QgsApplication::initQgis();
}

void TestQgsDataDefined::cleanupTestCase()
{

QgsApplication::exitQgis();
}

void TestQgsDataDefined::init()
@@ -90,8 +90,7 @@ class TestQgsDiagram : public QObject
myPointFileInfo.completeBaseName(), "ogr" );

// Register the layer with the registry
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mPointsLayer );
QgsMapLayerRegistry::instance()->addMapLayer( mPointsLayer );

// Create map composition to draw on
mMapSettings->setLayers( QStringList() << mPointsLayer->id() );
@@ -102,8 +101,6 @@ class TestQgsDiagram : public QObject
// will be called after the last testfunction was executed.
void cleanupTestCase()
{
QgsApplication::exitQgis();

delete mMapSettings;

QString myReportFile = QDir::tempPath() + "/qgistest.html";
@@ -115,6 +112,7 @@ class TestQgsDiagram : public QObject
myFile.close();
//QDesktopServices::openUrl( "file:///" + myReportFile );
}
QgsApplication::exitQgis();
}

// will be called before each testfunction is executed
@@ -304,8 +304,8 @@ void TestQgsExpressionContext::contextCopy()

void TestQgsExpressionContext::contextStackFunctions()
{
QgsExpression::registerFunction( new GetTestValueFunction() );
QgsExpression::registerFunction( new GetTestValueFunction2() );
QgsExpression::registerFunction( new GetTestValueFunction(), true );
QgsExpression::registerFunction( new GetTestValueFunction2(), true );

QgsExpressionContext context;
//test retrieving from empty stack
@@ -381,7 +381,7 @@ void TestQgsExpressionContext::evaluate()
QVERIFY( !expShorthandBad.evaluate( &context ).isValid() );

//test with a function provided by a context
QgsExpression::registerFunction( new ModifiableFunction( 0 ) );
QgsExpression::registerFunction( new ModifiableFunction( 0 ), true );
QgsExpression testExpWContextFunction( "test_function(1)" );
QVERIFY( !testExpWContextFunction.evaluate( ).isValid() );

@@ -595,6 +595,7 @@ void TestQgsExpressionContext::layerScope()
QCOMPARE( layerScope->variable( "testvar" ), QVariant() );
QCOMPARE( layerScope->variable( "var1" ).toString(), QString( "val1" ) );
QCOMPARE( layerScope->variable( "var2" ).toString(), QString( "val2" ) );
delete layerScope;
}

void TestQgsExpressionContext::featureBasedContext()
@@ -121,12 +121,13 @@ void TestQgsMapRotation::initTestCase()

TestQgsMapRotation::~TestQgsMapRotation()
{
delete mMapSettings;

}

//runs after all tests
void TestQgsMapRotation::cleanupTestCase()
{
delete mMapSettings;
QgsApplication::exitQgis();

// TODO: delete layers (or is it done by exitQgis ?)
@@ -897,6 +897,7 @@ void TestQgsPaintEffect::composer()
p.end();

bool result = imageCheck( "painteffect_composer", outputImage );
delete composition;
QVERIFY( result );
}

@@ -108,8 +108,8 @@ bool TestQgsRasterFileWriter::writeTest( QString theRasterName )
qDebug() << myFileName;
QFileInfo myRasterFileInfo( myFileName );

QgsRasterLayer * mpRasterLayer = new QgsRasterLayer( myRasterFileInfo.filePath(),
myRasterFileInfo.completeBaseName() );
QScopedPointer<QgsRasterLayer> mpRasterLayer( new QgsRasterLayer( myRasterFileInfo.filePath(),
myRasterFileInfo.completeBaseName() ) );
qDebug() << theRasterName << " metadata: " << mpRasterLayer->dataProvider()->metadata();

if ( !mpRasterLayer->isValid() ) return false;
@@ -17,15 +17,23 @@
#include <QObject>
#include <QString>

#include <qgsscaleexpression.h>
#include "qgsscaleexpression.h"
#include "qgsapplication.h"

class TestQgsScaleExpression: public QObject
{
Q_OBJECT
private slots:

void initTestCase() {}
void cleanupTestCase() {}
void initTestCase()
{
QgsApplication::init();
QgsApplication::initQgis();
}
void cleanupTestCase()
{
QgsApplication::exitQgis();
}

void parsing()
{
@@ -185,8 +185,8 @@ void TestQgsVectorLayer::cleanupTestCase()
myFile.close();
//QDesktopServices::openUrl( "file:///" + myReportFile );
}
delete mpMapRenderer;
QgsApplication::exitQgis();

}

void TestQgsVectorLayer::QgsVectorLayerNonSpatialIterator()
@@ -71,21 +71,21 @@ void TestQgsMapToolZoom::cleanup()
void TestQgsMapToolZoom::zeroDragArea()
{
QPoint point = QPoint( 15, 15 );
QMouseEvent *press = new QMouseEvent( QEvent::MouseButtonPress, point ,
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier );
QMouseEvent *move = new QMouseEvent( QEvent::MouseMove, point,
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier );
QMouseEvent *releases = new QMouseEvent( QEvent::MouseButtonRelease, point,
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier );
QMouseEvent press( QEvent::MouseButtonPress, point ,
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier );
QMouseEvent move( QEvent::MouseMove, point,
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier );
QMouseEvent releases( QEvent::MouseButtonRelease, point,
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier );

QgsMapToolZoom* tool = new QgsMapToolZoom( canvas, false );
// Just set some made up extent so that we can zoom.
canvas->setExtent( QgsRectangle( 0, 0, 20, 20 ) );

QgsRectangle before = canvas->extent();
tool->canvasPressEvent( press );
tool->canvasMoveEvent( move );
tool->canvasReleaseEvent( releases );
tool->canvasPressEvent( &press );
tool->canvasMoveEvent( &move );
tool->canvasReleaseEvent( &releases );
QgsRectangle after = canvas->extent();
// We don't really care if we zoom in or out here just that the extent did
// change we

0 comments on commit 385a608

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