Skip to content

Commit

Permalink
Test fixes and further QgsProject::instance() removals
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Dec 10, 2016
1 parent 5fc10d6 commit 483c7f4
Show file tree
Hide file tree
Showing 32 changed files with 63 additions and 96 deletions.
8 changes: 3 additions & 5 deletions tests/src/core/testqgscomposermap.cpp
Expand Up @@ -90,6 +90,9 @@ void TestQgsComposerMap::initTestCase()
QFileInfo lineFileInfo( QStringLiteral( TEST_DATA_DIR ) + "/lines.shp" );
mLinesLayer = new QgsVectorLayer( lineFileInfo.filePath(),
lineFileInfo.completeBaseName(), QStringLiteral( "ogr" ) );

// some layers need to be in project for data-defined layers functionality
QgsProject::instance()->addMapLayers( QList<QgsMapLayer*>() << mRasterLayer << mPointsLayer << mPolysLayer << mLinesLayer );
}

void TestQgsComposerMap::cleanupTestCase()
Expand All @@ -103,11 +106,6 @@ void TestQgsComposerMap::cleanupTestCase()
myFile.close();
}

delete mRasterLayer;
delete mPointsLayer;
delete mPolysLayer;
delete mLinesLayer;

QgsApplication::exitQgis();
}

Expand Down
3 changes: 1 addition & 2 deletions tests/src/core/testqgscomposermapoverview.cpp
Expand Up @@ -74,8 +74,6 @@ void TestQgsComposerMapOverview::initTestCase()
QgsMultiBandColorRenderer* rasterRenderer = new QgsMultiBandColorRenderer( mRasterLayer->dataProvider(), 1, 2, 3 );
mRasterLayer->setRenderer( rasterRenderer );

QgsProject::instance()->addMapLayers( QList<QgsMapLayer*>() << mRasterLayer );

//create composition with composer map
mMapSettings->setLayers( QList<QgsMapLayer*>() << mRasterLayer );
mMapSettings->setCrsTransformEnabled( false );
Expand All @@ -92,6 +90,7 @@ void TestQgsComposerMapOverview::cleanupTestCase()
{
delete mComposition;
delete mMapSettings;
delete mRasterLayer;

QString myReportFile = QDir::tempPath() + "/qgistest.html";
QFile myFile( myReportFile );
Expand Down
3 changes: 1 addition & 2 deletions tests/src/core/testqgscomposerrotation.cpp
Expand Up @@ -80,8 +80,6 @@ void TestQgsComposerRotation::initTestCase()
QgsMultiBandColorRenderer* rasterRenderer = new QgsMultiBandColorRenderer( mRasterLayer->dataProvider(), 1, 2, 3 );
mRasterLayer->setRenderer( rasterRenderer );

QgsProject::instance()->addMapLayers( QList<QgsMapLayer*>() << mRasterLayer );

mMapSettings->setLayers( QList<QgsMapLayer*>() << mRasterLayer );
mMapSettings->setCrsTransformEnabled( false );

Expand Down Expand Up @@ -115,6 +113,7 @@ void TestQgsComposerRotation::cleanupTestCase()
delete mComposerRect;
delete mComposition;
delete mMapSettings;
delete mRasterLayer;

QString myReportFile = QDir::tempPath() + "/qgistest.html";
QFile myFile( myReportFile );
Expand Down
3 changes: 1 addition & 2 deletions tests/src/core/testqgscomposerscalebar.cpp
Expand Up @@ -86,8 +86,6 @@ void TestQgsComposerScaleBar::initTestCase()
QgsMultiBandColorRenderer* rasterRenderer = new QgsMultiBandColorRenderer( mRasterLayer->dataProvider(), 2, 3, 4 );
mRasterLayer->setRenderer( rasterRenderer );

QgsProject::instance()->addMapLayers( QList<QgsMapLayer*>() << mRasterLayer );

//create composition with composer map
mMapSettings->setLayers( QList<QgsMapLayer*>() << mRasterLayer );

Expand Down Expand Up @@ -127,6 +125,7 @@ void TestQgsComposerScaleBar::cleanupTestCase()
{
delete mComposition;
delete mMapSettings;
delete mRasterLayer;

QString myReportFile = QDir::tempPath() + "/qgistest.html";
QFile myFile( myReportFile );
Expand Down
4 changes: 1 addition & 3 deletions tests/src/core/testqgsdiagram.cpp
Expand Up @@ -87,9 +87,6 @@ class TestQgsDiagram : public QObject
mPointsLayer = new QgsVectorLayer( myPointFileInfo.filePath(),
myPointFileInfo.completeBaseName(), QStringLiteral( "ogr" ) );

// Register the layer with the registry
QgsProject::instance()->addMapLayer( mPointsLayer );

// Create map composition to draw on
mMapSettings->setLayers( QList<QgsMapLayer*>() << mPointsLayer );

Expand All @@ -100,6 +97,7 @@ class TestQgsDiagram : public QObject
void cleanupTestCase()
{
delete mMapSettings;
delete mPointsLayer;

QString myReportFile = QDir::tempPath() + "/qgistest.html";
QFile myFile( myReportFile );
Expand Down
6 changes: 2 additions & 4 deletions tests/src/core/testqgsellipsemarker.cpp
Expand Up @@ -98,10 +98,6 @@ void TestQgsEllipseMarkerSymbol::initTestCase()
mpPointsLayer = new QgsVectorLayer( pointFileInfo.filePath(),
pointFileInfo.completeBaseName(), QStringLiteral( "ogr" ) );

// Register the layer with the registry
QgsProject::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpPointsLayer );

//setup symbol
mEllipseMarkerLayer = new QgsEllipseSymbolLayer();
mMarkerSymbol = new QgsMarkerSymbol();
Expand All @@ -128,6 +124,8 @@ void TestQgsEllipseMarkerSymbol::cleanupTestCase()
myFile.close();
}

delete mpPointsLayer;

QgsApplication::exitQgis();
}

Expand Down
6 changes: 2 additions & 4 deletions tests/src/core/testqgsfilledmarker.cpp
Expand Up @@ -96,10 +96,6 @@ void TestQgsFilledMarkerSymbol::initTestCase()
mpPointsLayer = new QgsVectorLayer( pointFileInfo.filePath(),
pointFileInfo.completeBaseName(), QStringLiteral( "ogr" ) );

// Register the layer with the registry
QgsProject::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpPointsLayer );

//setup symbol
QgsGradientFillSymbolLayer* gradientFill = new QgsGradientFillSymbolLayer();
gradientFill->setColor( QColor( "red" ) );
Expand Down Expand Up @@ -139,6 +135,8 @@ void TestQgsFilledMarkerSymbol::cleanupTestCase()
myFile.close();
}

delete mpPointsLayer;

QgsApplication::exitQgis();
}

Expand Down
6 changes: 2 additions & 4 deletions tests/src/core/testqgsfontmarker.cpp
Expand Up @@ -96,10 +96,6 @@ void TestQgsFontMarkerSymbol::initTestCase()
mpPointsLayer = new QgsVectorLayer( pointFileInfo.filePath(),
pointFileInfo.completeBaseName(), QStringLiteral( "ogr" ) );

// Register the layer with the registry
QgsProject::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpPointsLayer );

//setup symbol
mFontMarkerLayer = new QgsFontMarkerSymbolLayer();
mMarkerSymbol = new QgsMarkerSymbol();
Expand All @@ -126,6 +122,8 @@ void TestQgsFontMarkerSymbol::cleanupTestCase()
myFile.close();
}

delete mpPointsLayer;

QgsApplication::exitQgis();
}

Expand Down
6 changes: 2 additions & 4 deletions tests/src/core/testqgsgradients.cpp
Expand Up @@ -106,10 +106,6 @@ void TestQgsGradients::initTestCase()
simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification );
mpPolysLayer->setSimplifyMethod( simplifyMethod );

// Register the layer with the registry
QgsProject::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpPolysLayer );

//setup gradient fill
mGradientFill = new QgsGradientFillSymbolLayer();
mFillSymbol = new QgsFillSymbol();
Expand All @@ -136,6 +132,8 @@ void TestQgsGradients::cleanupTestCase()
myFile.close();
}

delete mpPolysLayer;

QgsApplication::exitQgis();
}

Expand Down
5 changes: 2 additions & 3 deletions tests/src/core/testqgsinvertedpolygonrenderer.cpp
Expand Up @@ -94,9 +94,6 @@ void TestQgsInvertedPolygon::initTestCase()
simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification );
mpPolysLayer->setSimplifyMethod( simplifyMethod );

// Register the layer with the registry
QgsProject::instance()->addMapLayers( QList<QgsMapLayer *>() << mpPolysLayer );

mMapSettings.setLayers( QList<QgsMapLayer*>() << mpPolysLayer );
mReport += QLatin1String( "<h1>Inverted Polygon Renderer Tests</h1>\n" );
}
Expand All @@ -112,6 +109,8 @@ void TestQgsInvertedPolygon::cleanupTestCase()
myFile.close();
}

delete mpPolysLayer;

QgsApplication::exitQgis();
}

Expand Down
6 changes: 2 additions & 4 deletions tests/src/core/testqgslinefillsymbol.cpp
Expand Up @@ -99,10 +99,6 @@ void TestQgsLineFillSymbol::initTestCase()
simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification );
mpPolysLayer->setSimplifyMethod( simplifyMethod );

// Register the layer with the registry
QgsProject::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpPolysLayer );

//setup gradient fill
mLineFill = new QgsLinePatternFillSymbolLayer();
mFillSymbol = new QgsFillSymbol();
Expand All @@ -129,6 +125,8 @@ void TestQgsLineFillSymbol::cleanupTestCase()
myFile.close();
}

delete mpPolysLayer;

QgsApplication::exitQgis();
}

Expand Down
11 changes: 3 additions & 8 deletions tests/src/core/testqgsmaprotation.cpp
Expand Up @@ -82,32 +82,24 @@ void TestQgsMapRotation::initTestCase()

mMapSettings = new QgsMapSettings();

QList<QgsMapLayer *> mapLayers;

//create a raster layer that will be used in all tests...
QFileInfo rasterFileInfo( mTestDataDir + "rgb256x256.png" );
mRasterLayer = new QgsRasterLayer( rasterFileInfo.filePath(),
rasterFileInfo.completeBaseName() );
QgsMultiBandColorRenderer* rasterRenderer = new QgsMultiBandColorRenderer( mRasterLayer->dataProvider(), 1, 2, 3 );
mRasterLayer->setRenderer( rasterRenderer );
mapLayers << mRasterLayer;

//create a point layer that will be used in all tests...
QString myPointsFileName = mTestDataDir + "points.shp";
QFileInfo myPointFileInfo( myPointsFileName );
mPointsLayer = new QgsVectorLayer( myPointFileInfo.filePath(),
myPointFileInfo.completeBaseName(), QStringLiteral( "ogr" ) );
mapLayers << mPointsLayer;

//create a line layer that will be used in all tests...
QString myLinesFileName = mTestDataDir + "lines_cardinals.shp";
QFileInfo myLinesFileInfo( myLinesFileName );
mLinesLayer = new QgsVectorLayer( myLinesFileInfo.filePath(),
myLinesFileInfo.completeBaseName(), QStringLiteral( "ogr" ) );
mapLayers << mLinesLayer;

// Register all layers with the registry
QgsProject::instance()->addMapLayers( mapLayers );

// This is needed to correctly set rotation center,
// the actual size doesn't matter as QgsRenderChecker will
Expand All @@ -128,6 +120,9 @@ TestQgsMapRotation::~TestQgsMapRotation()
void TestQgsMapRotation::cleanupTestCase()
{
delete mMapSettings;
delete mPointsLayer;
delete mLinesLayer;
delete mRasterLayer;
QgsApplication::exitQgis();

QString myReportFile = QDir::tempPath() + "/qgistest.html";
Expand Down
12 changes: 6 additions & 6 deletions tests/src/core/testqgspainteffect.cpp
Expand Up @@ -702,7 +702,6 @@ void TestQgsPaintEffect::layerEffectPolygon()
QgsVectorSimplifyMethod simplifyMethod;
simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification );
polysLayer->setSimplifyMethod( simplifyMethod );
QgsProject::instance()->addMapLayers( QList<QgsMapLayer *>() << polysLayer );

QgsMapSettings ms;
QgsSimpleFillSymbolLayer* fill = new QgsSimpleFillSymbolLayer;
Expand All @@ -721,6 +720,7 @@ void TestQgsPaintEffect::layerEffectPolygon()
mReport += QLatin1String( "<h2>Paint effect symbol layer test (polygon)</h2>\n" );
bool result = mapRenderCheck( QStringLiteral( "painteffect_poly" ), ms );
QVERIFY( result );
delete polysLayer;
}

void TestQgsPaintEffect::layerEffectLine()
Expand All @@ -733,7 +733,6 @@ void TestQgsPaintEffect::layerEffectLine()
QgsVectorSimplifyMethod simplifyMethod;
simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification );
lineLayer->setSimplifyMethod( simplifyMethod );
QgsProject::instance()->addMapLayers( QList<QgsMapLayer *>() << lineLayer );

QgsMapSettings ms;
QgsSimpleLineSymbolLayer* line = new QgsSimpleLineSymbolLayer;
Expand All @@ -753,6 +752,7 @@ void TestQgsPaintEffect::layerEffectLine()
mReport += QLatin1String( "<h2>Paint effect symbol layer test (line)</h2>\n" );
bool result = mapRenderCheck( QStringLiteral( "painteffect_line" ), ms );
QVERIFY( result );
delete lineLayer;
}

void TestQgsPaintEffect::layerEffectMarker()
Expand All @@ -762,7 +762,6 @@ void TestQgsPaintEffect::layerEffectMarker()
QFileInfo pointFileInfo( pointFileName );
QgsVectorLayer* pointLayer = new QgsVectorLayer( pointFileInfo.filePath(),
pointFileInfo.completeBaseName(), QStringLiteral( "ogr" ) );
QgsProject::instance()->addMapLayers( QList<QgsMapLayer *>() << pointLayer );

QgsMapSettings ms;
QgsSimpleMarkerSymbolLayer* marker = new QgsSimpleMarkerSymbolLayer;
Expand All @@ -781,6 +780,7 @@ void TestQgsPaintEffect::layerEffectMarker()
mReport += QLatin1String( "<h2>Paint effect symbol layer test (point)</h2>\n" );
bool result = mapRenderCheck( QStringLiteral( "painteffect_marker" ), ms );
QVERIFY( result );
delete pointLayer;
}

void TestQgsPaintEffect::vectorLayerEffect()
Expand All @@ -793,7 +793,6 @@ void TestQgsPaintEffect::vectorLayerEffect()
QgsVectorSimplifyMethod simplifyMethod;
simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification );
polysLayer->setSimplifyMethod( simplifyMethod );
QgsProject::instance()->addMapLayers( QList<QgsMapLayer *>() << polysLayer );

QgsMapSettings ms;
QgsSimpleFillSymbolLayer* fill = new QgsSimpleFillSymbolLayer;
Expand All @@ -816,6 +815,7 @@ void TestQgsPaintEffect::vectorLayerEffect()
mReport += QLatin1String( "<h2>Paint effect layer test</h2>\n" );
bool result = mapRenderCheck( QStringLiteral( "painteffect_layer" ), ms );
QVERIFY( result );
delete polysLayer;
}

void TestQgsPaintEffect::mapUnits()
Expand All @@ -828,7 +828,6 @@ void TestQgsPaintEffect::mapUnits()
QgsVectorSimplifyMethod simplifyMethod;
simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification );
lineLayer->setSimplifyMethod( simplifyMethod );
QgsProject::instance()->addMapLayers( QList<QgsMapLayer *>() << lineLayer );

QgsMapSettings ms;
QgsSimpleLineSymbolLayer* line = new QgsSimpleLineSymbolLayer;
Expand All @@ -851,6 +850,7 @@ void TestQgsPaintEffect::mapUnits()
mReport += QLatin1String( "<h2>Paint effect map units test</h2>\n" );
bool result = mapRenderCheck( QStringLiteral( "painteffect_mapunits" ), ms );
QVERIFY( result );
delete lineLayer;
}

void TestQgsPaintEffect::composer()
Expand All @@ -864,7 +864,6 @@ void TestQgsPaintEffect::composer()
QgsVectorSimplifyMethod simplifyMethod;
simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification );
lineLayer->setSimplifyMethod( simplifyMethod );
QgsProject::instance()->addMapLayers( QList<QgsMapLayer *>() << lineLayer );

QgsMapSettings ms;
QgsSimpleLineSymbolLayer* line = new QgsSimpleLineSymbolLayer;
Expand Down Expand Up @@ -902,6 +901,7 @@ void TestQgsPaintEffect::composer()
bool result = imageCheck( QStringLiteral( "painteffect_composer" ), outputImage );
delete composition;
QVERIFY( result );
delete lineLayer;
}


Expand Down
8 changes: 4 additions & 4 deletions tests/src/python/test_qgsarrowsymbollayer.py
Expand Up @@ -88,7 +88,7 @@ def test_1(self):
sym_layer.setSubSymbol(fill_sym)
sym.changeSymbolLayer(0, sym_layer)

rendered_layers = [self.lines_layer.id()]
rendered_layers = [self.lines_layer]
self.mapsettings.setLayers(rendered_layers)

renderchecker = QgsMultiRenderChecker()
Expand All @@ -104,7 +104,7 @@ def test_2(self):
sym_layer.setSubSymbol(fill_sym)
sym.changeSymbolLayer(0, sym_layer)

rendered_layers = [self.lines_layer.id()]
rendered_layers = [self.lines_layer]
self.mapsettings.setLayers(rendered_layers)

renderchecker = QgsMultiRenderChecker()
Expand All @@ -120,7 +120,7 @@ def test_3(self):
sym_layer.setSubSymbol(fill_sym)
sym.changeSymbolLayer(0, sym_layer)

rendered_layers = [self.lines_layer.id()]
rendered_layers = [self.lines_layer]
self.mapsettings.setLayers(rendered_layers)

renderchecker = QgsMultiRenderChecker()
Expand All @@ -140,7 +140,7 @@ def test_unrepeated(self):
sym_layer.setSubSymbol(fill_sym)
sym.changeSymbolLayer(0, sym_layer)

rendered_layers = [self.lines_layer.id()]
rendered_layers = [self.lines_layer]
self.mapsettings.setLayers(rendered_layers)

renderchecker = QgsMultiRenderChecker()
Expand Down

0 comments on commit 483c7f4

Please sign in to comment.