Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix a bunch of leaks in unit tests
  • Loading branch information
nyalldawson committed Aug 25, 2015
1 parent 24b8405 commit 385a608
Show file tree
Hide file tree
Showing 19 changed files with 61 additions and 26 deletions.
1 change: 1 addition & 0 deletions tests/src/core/testqgscolorschemeregistry.cpp
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions tests/src/core/testqgscomposergroup.cpp
Expand Up @@ -80,6 +80,7 @@ void TestQgsComposerGroup::cleanupTestCase()
{
delete mComposition;
delete mMapSettings;
QgsApplication::exitQgis();

QString myReportFile = QDir::tempPath() + "/qgistest.html";
QFile myFile( myReportFile );
Expand Down
8 changes: 8 additions & 0 deletions tests/src/core/testqgscomposermodel.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions tests/src/core/testqgscomposermultiframe.cpp
Expand Up @@ -80,6 +80,8 @@ void TestQgsComposerMultiFrame::cleanupTestCase()
myQTextStream << mReport;
myFile.close();
}

QgsApplication::exitQgis();
}

void TestQgsComposerMultiFrame::init()
Expand Down
2 changes: 2 additions & 0 deletions tests/src/core/testqgscomposerobject.cpp
Expand Up @@ -83,6 +83,8 @@ void TestQgsComposerObject::cleanupTestCase()
myQTextStream << mReport;
myFile.close();
}

QgsApplication::exitQgis();
}

void TestQgsComposerObject::init()
Expand Down
1 change: 1 addition & 0 deletions tests/src/core/testqgscomposerpicture.cpp
Expand Up @@ -99,6 +99,7 @@ void TestQgsComposerPicture::initTestCase()

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

Expand Down
3 changes: 3 additions & 0 deletions tests/src/core/testqgscomposerrotation.cpp
Expand Up @@ -115,6 +115,9 @@ void TestQgsComposerRotation::cleanupTestCase()
mComposition->removeItem( mComposerMap );
delete mComposerMap;
}

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

Expand Down
1 change: 1 addition & 0 deletions tests/src/core/testqgscomposertable.cpp
Expand Up @@ -104,6 +104,7 @@ void TestQgsComposerTable::initTestCase()

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

Expand Down
1 change: 1 addition & 0 deletions tests/src/core/testqgscomposertablev2.cpp
Expand Up @@ -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 );
Expand Down
4 changes: 4 additions & 0 deletions tests/src/core/testqgscomposerutils.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 5 additions & 3 deletions tests/src/core/testqgsdatadefined.cpp
Expand Up @@ -19,7 +19,8 @@
#include <QSettings>
#include <QSharedPointer>

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

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

void TestQgsDataDefined::initTestCase()
{

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

void TestQgsDataDefined::cleanupTestCase()
{

QgsApplication::exitQgis();
}

void TestQgsDataDefined::init()
Expand Down
6 changes: 2 additions & 4 deletions tests/src/core/testqgsdiagram.cpp
Expand Up @@ -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() );
Expand All @@ -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";
Expand All @@ -115,6 +112,7 @@ class TestQgsDiagram : public QObject
myFile.close();
//QDesktopServices::openUrl( "file:///" + myReportFile );
}
QgsApplication::exitQgis();
}

// will be called before each testfunction is executed
Expand Down
7 changes: 4 additions & 3 deletions tests/src/core/testqgsexpressioncontext.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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() );

Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion tests/src/core/testqgsmaprotation.cpp
Expand Up @@ -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 ?)
Expand Down
1 change: 1 addition & 0 deletions tests/src/core/testqgspainteffect.cpp
Expand Up @@ -897,6 +897,7 @@ void TestQgsPaintEffect::composer()
p.end();

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

Expand Down
4 changes: 2 additions & 2 deletions tests/src/core/testqgsrasterfilewriter.cpp
Expand Up @@ -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;
Expand Down
14 changes: 11 additions & 3 deletions tests/src/core/testqgsscaleexpression.cpp
Expand Up @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/src/core/testqgsvectorlayer.cpp
Expand Up @@ -185,8 +185,8 @@ void TestQgsVectorLayer::cleanupTestCase()
myFile.close();
//QDesktopServices::openUrl( "file:///" + myReportFile );
}
delete mpMapRenderer;
QgsApplication::exitQgis();

}

void TestQgsVectorLayer::QgsVectorLayerNonSpatialIterator()
Expand Down
18 changes: 9 additions & 9 deletions tests/src/gui/testqgsmaptoolzoom.cpp
Expand Up @@ -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
Expand Down

0 comments on commit 385a608

Please sign in to comment.