Skip to content

Commit

Permalink
Fix some leaks in test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 8, 2017
1 parent f945123 commit a80258f
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 21 deletions.
24 changes: 12 additions & 12 deletions tests/src/core/testqgslegendrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@ void TestQgsLegendRenderer::testMapUnits()
sym->setSizeUnit( QgsUnitTypes::RenderMillimeters );
catRenderer->updateCategorySymbol( 2, sym );

QgsLayerTreeGroup* root = new QgsLayerTreeGroup();
std::unique_ptr< QgsLayerTreeGroup > root( new QgsLayerTreeGroup() );
root->addLayer( mVL3 );
QgsLayerTreeModel legendModel( root );
QgsLayerTreeModel legendModel( root.get() );

QgsLegendSettings settings;
_setStandardTestFont( settings );
Expand Down Expand Up @@ -481,9 +481,9 @@ void TestQgsLegendRenderer::testFilterByMapSameSymbol()

QString testName = QStringLiteral( "legend_filter_by_map_dupe" );

QgsLayerTreeGroup* root = new QgsLayerTreeGroup();
std::unique_ptr< QgsLayerTreeGroup > root( new QgsLayerTreeGroup() );
root->addLayer( vl4 );
QgsLayerTreeModel legendModel( root );
QgsLayerTreeModel legendModel( root.get() );

QgsMapSettings mapSettings;
// extent and size to include only the red and green points
Expand All @@ -507,7 +507,7 @@ bool TestQgsLegendRenderer::_testLegendColumns( int itemCount, int columnCount,
QgsFillSymbol* sym = new QgsFillSymbol();
sym->setColor( Qt::cyan );

QgsLayerTreeGroup* root = new QgsLayerTreeGroup();
std::unique_ptr< QgsLayerTreeGroup > root( new QgsLayerTreeGroup() );

QList< QgsVectorLayer* > layers;
for ( int i = 1; i <= itemCount; ++i )
Expand All @@ -520,7 +520,7 @@ bool TestQgsLegendRenderer::_testLegendColumns( int itemCount, int columnCount,
}
delete sym;

QgsLayerTreeModel legendModel( root );
QgsLayerTreeModel legendModel( root.get() );
QgsLegendSettings settings;
settings.setColumnCount( columnCount );
_setStandardTestFont( settings, QStringLiteral( "Bold" ) );
Expand Down Expand Up @@ -565,10 +565,10 @@ void TestQgsLegendRenderer::testRasterBorder()
{
QString testName = QStringLiteral( "legend_raster_border" );

QgsLayerTreeGroup* root = new QgsLayerTreeGroup();
std::unique_ptr< QgsLayerTreeGroup > root( new QgsLayerTreeGroup() );
root->addLayer( mRL );

QgsLayerTreeModel legendModel( root );
QgsLayerTreeModel legendModel( root.get() );

QgsLegendSettings settings;
_setStandardTestFont( settings );
Expand Down Expand Up @@ -673,9 +673,9 @@ void TestQgsLegendRenderer::testDiagramAttributeLegend()
dls.setShowAllDiagrams( true );
vl4->setDiagramLayerSettings( dls );

QgsLayerTreeGroup* root = new QgsLayerTreeGroup();
std::unique_ptr< QgsLayerTreeGroup > root( new QgsLayerTreeGroup() );
root->addLayer( vl4 );
QgsLayerTreeModel legendModel( root );
QgsLayerTreeModel legendModel( root.get() );

QgsLegendSettings settings;
_setStandardTestFont( settings, QStringLiteral( "Bold" ) );
Expand Down Expand Up @@ -713,9 +713,9 @@ void TestQgsLegendRenderer::testDiagramSizeLegend()
dls.setShowAllDiagrams( true );
vl4->setDiagramLayerSettings( dls );

QgsLayerTreeGroup* root = new QgsLayerTreeGroup();
std::unique_ptr< QgsLayerTreeGroup > root( new QgsLayerTreeGroup() );
root->addLayer( vl4 );
QgsLayerTreeModel legendModel( root );
QgsLayerTreeModel legendModel( root.get() );

QgsLegendSettings settings;
_setStandardTestFont( settings, QStringLiteral( "Bold" ) );
Expand Down
6 changes: 6 additions & 0 deletions tests/src/core/testqgsmapsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class TestQgsMapSettings: public QObject
Q_OBJECT
private slots:
void initTestCase();
void cleanupTestCase();
void visibleExtent();
void mapUnitsPerPixel();
void visiblePolygon();
Expand All @@ -49,6 +50,11 @@ void TestQgsMapSettings::initTestCase()
QgsApplication::showSettings();
}

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

QString TestQgsMapSettings::toString( const QPolygonF& p, int dec ) const
{
QString s;
Expand Down
9 changes: 6 additions & 3 deletions tests/src/core/testqgspainteffectregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ class TestQgsPaintEffectRegistry : public QObject

void TestQgsPaintEffectRegistry::initTestCase()
{

QgsApplication::init(); // init paths for CRS lookup
QgsApplication::initQgis();
}

void TestQgsPaintEffectRegistry::cleanupTestCase()
{

QgsApplication::exitQgis();
}

void TestQgsPaintEffectRegistry::init()
Expand Down Expand Up @@ -116,8 +117,10 @@ void TestQgsPaintEffectRegistry::addEffect()
registry->addEffectType( new QgsPaintEffectMetadata( QStringLiteral( "Dummy" ), QStringLiteral( "Dummy effect" ), DummyPaintEffect::create ) );
QCOMPARE( registry->effects().length(), previousCount + 1 );
//try adding again, should have no effect
registry->addEffectType( new QgsPaintEffectMetadata( QStringLiteral( "Dummy" ), QStringLiteral( "Dummy effect" ), DummyPaintEffect::create ) );
QgsPaintEffectMetadata* dupe = new QgsPaintEffectMetadata( QStringLiteral( "Dummy" ), QStringLiteral( "Dummy effect" ), DummyPaintEffect::create );
QVERIFY( ! registry->addEffectType( dupe ) );
QCOMPARE( registry->effects().length(), previousCount + 1 );
delete dupe;

//try adding empty metadata
registry->addEffectType( nullptr );
Expand Down
1 change: 1 addition & 0 deletions tests/src/core/testqgsprocessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ void TestQgsProcessing::addProvider()
QVERIFY( !r.addProvider( p3 ) );
QCOMPARE( r.providers().toSet(), QSet< QgsProcessingProvider* >() << p << p2 );
QCOMPARE( spyProviderAdded.count(), 2 );
delete p3;
}

void TestQgsProcessing::providerById()
Expand Down
18 changes: 12 additions & 6 deletions tests/src/core/testqgsstyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,12 @@ void TestStyle::testFavorites()
int count = favorites.count();

// add some symbols to favorites
mStyle->saveSymbol( "symbolA", QgsMarkerSymbol::createSimple( QgsStringMap() ), true, QStringList() );
mStyle->saveSymbol( "symbolB", QgsMarkerSymbol::createSimple( QgsStringMap() ), false, QStringList() );
mStyle->saveSymbol( "symbolC", QgsMarkerSymbol::createSimple( QgsStringMap() ), true, QStringList() );
std::unique_ptr< QgsMarkerSymbol > sym1( QgsMarkerSymbol::createSimple( QgsStringMap() ) );
std::unique_ptr< QgsMarkerSymbol > sym2( QgsMarkerSymbol::createSimple( QgsStringMap() ) );
std::unique_ptr< QgsMarkerSymbol > sym3( QgsMarkerSymbol::createSimple( QgsStringMap() ) );
mStyle->saveSymbol( "symbolA", sym1.get(), true, QStringList() );
mStyle->saveSymbol( "symbolB", sym2.get(), false, QStringList() );
mStyle->saveSymbol( "symbolC", sym3.get(), true, QStringList() );

// check for added symbols to favorites
favorites = mStyle->symbolsOfFavorite( QgsStyle::SymbolEntity );
Expand Down Expand Up @@ -307,9 +310,12 @@ void TestStyle::testTags()
QVERIFY( !tags.contains( "purple" ) );

//add some symbols
QVERIFY( mStyle->saveSymbol( "symbol1", QgsMarkerSymbol::createSimple( QgsStringMap() ), false, QStringList() << "red" << "starry" ) );
mStyle->addSymbol( QStringLiteral( "blue starry" ), QgsMarkerSymbol::createSimple( QgsStringMap() ), true );
mStyle->addSymbol( QStringLiteral( "red circle" ), QgsMarkerSymbol::createSimple( QgsStringMap() ), true );
std::unique_ptr< QgsMarkerSymbol> sym1( QgsMarkerSymbol::createSimple( QgsStringMap() ) );
std::unique_ptr< QgsMarkerSymbol> sym2( QgsMarkerSymbol::createSimple( QgsStringMap() ) );
std::unique_ptr< QgsMarkerSymbol> sym3( QgsMarkerSymbol::createSimple( QgsStringMap() ) );
QVERIFY( mStyle->saveSymbol( "symbol1", sym1.get() , false, QStringList() << "red" << "starry" ) );
mStyle->addSymbol( QStringLiteral( "blue starry" ), sym2.release(), true );
mStyle->addSymbol( QStringLiteral( "red circle" ), sym3.release(), true );

//tag them
QVERIFY( mStyle->tagSymbol( QgsStyle::SymbolEntity, "blue starry", QStringList() << "blue" << "starry" ) );
Expand Down
1 change: 1 addition & 0 deletions tests/src/gui/testqgsmapcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ void TestQgsMapCanvas::initTestCase()

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


Expand Down

0 comments on commit a80258f

Please sign in to comment.