Skip to content
Permalink
Browse files

Split composer map overview tests off into their own test suite

  • Loading branch information
nyalldawson committed Sep 20, 2014
1 parent ccad38b commit 97ea6f68c998b30c6206cde55208f899f085ba44
Showing with 205 additions and 109 deletions.
  1. +1 −0 tests/src/core/CMakeLists.txt
  2. +0 −109 tests/src/core/testqgscomposermap.cpp
  3. +204 −0 tests/src/core/testqgscomposermapoverview.cpp
@@ -110,6 +110,7 @@ ADD_QGIS_TEST(composerutils testqgscomposerutils.cpp)
ADD_QGIS_TEST(composerpapertest testqgscomposerpaper.cpp)
ADD_QGIS_TEST(composermaptest testqgscomposermap.cpp)
ADD_QGIS_TEST(composermapgridtest testqgscomposermapgrid.cpp)
ADD_QGIS_TEST(composermapoverviewtest testqgscomposermapoverview.cpp)
ADD_QGIS_TEST(composereffectstest testqgscomposereffects.cpp)
ADD_QGIS_TEST(composershapestest testqgscomposershapes.cpp)
ADD_QGIS_TEST(composerrotationtest testqgscomposerrotation.cpp)
@@ -19,13 +19,10 @@
#include "qgscomposition.h"
#include "qgscompositionchecker.h"
#include "qgscomposermap.h"
#include "qgscomposermapoverview.h"
#include "qgscomposermapgrid.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaprenderer.h"
#include "qgsmultibandcolorrenderer.h"
#include "qgsrasterlayer.h"
#include "qgsfontutils.h"
#include <QObject>
#include <QtTest>

@@ -38,13 +35,7 @@ class TestQgsComposerMap: public QObject
void init();// will be called before each testfunction is executed.
void cleanup();// will be called after every testfunction.
void render(); //test if rendering of the composition with composr map is correct
void overviewMap(); //test if overview map frame works
void overviewMapRotated(); //test if overview map frame works with rotated overview
void overviewMapRotated2(); //test if overview map frame works with rotated map
void overviewMapBlending(); //test if blend modes with overview map frame works
void overviewMapInvert(); //test if invert of overview map frame works
void uniqueId(); //test if map id is adapted when doing copy paste
void overviewMapCenter(); //test if centering of overview map frame works
void worldFileGeneration(); // test world file generation
void mapPolygonVertices(); // test mapPolygon function with no map rotation

@@ -114,88 +105,6 @@ void TestQgsComposerMap::render()
QVERIFY( checker.testComposition( mReport, 0, 100 ) );
}

void TestQgsComposerMap::overviewMap()
{
QgsComposerMap* overviewMap = new QgsComposerMap( mComposition, 20, 130, 70, 70 );
overviewMap->setFrameEnabled( true );
mComposition->addComposerMap( overviewMap );
mComposerMap->setNewExtent( QgsRectangle( 785462.375, 3341423.125, 789262.375, 3343323.125 ) ); //zoom in
overviewMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3350923.125 ) );
overviewMap->overview()->setFrameMap( mComposerMap->id() );
QgsCompositionChecker checker( "composermap_overview", mComposition );

bool testResult = checker.testComposition( mReport, 0, 100 );
mComposition->removeComposerItem( overviewMap );
QVERIFY( testResult );
}

void TestQgsComposerMap::overviewMapRotated()
{
QgsComposerMap* overviewMap = new QgsComposerMap( mComposition, 20, 130, 70, 70 );
overviewMap->setFrameEnabled( true );
mComposition->addComposerMap( overviewMap );
mComposerMap->setNewExtent( QgsRectangle( 785462.375, 3341423.125, 789262.375, 3343323.125 ) ); //zoom in
mComposerMap->setMapRotation( 30 );
overviewMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3350923.125 ) );
overviewMap->overview()->setFrameMap( mComposerMap->id() );
QgsCompositionChecker checker( "composermap_overview_rotated", mComposition );

bool testResult = checker.testComposition( mReport, 0, 100 );
mComposition->removeComposerItem( overviewMap );
mComposerMap->setMapRotation( 0 );
QVERIFY( testResult );
}

void TestQgsComposerMap::overviewMapRotated2()
{
QgsComposerMap* overviewMap = new QgsComposerMap( mComposition, 20, 130, 70, 70 );
overviewMap->setFrameEnabled( true );
mComposition->addComposerMap( overviewMap );
mComposerMap->setNewExtent( QgsRectangle( 785462.375, 3341423.125, 789262.375, 3343323.125 ) ); //zoom in
overviewMap->setMapRotation( 30 );
overviewMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3350923.125 ) );
overviewMap->overview()->setFrameMap( mComposerMap->id() );
QgsCompositionChecker checker( "composermap_overview_rotated2", mComposition );

bool testResult = checker.testComposition( mReport, 0, 100 );
mComposition->removeComposerItem( overviewMap );
QVERIFY( testResult );
}

void TestQgsComposerMap::overviewMapBlending()
{
QgsComposerMap* overviewMapBlend = new QgsComposerMap( mComposition, 20, 130, 70, 70 );
overviewMapBlend->setFrameEnabled( true );
mComposition->addComposerMap( overviewMapBlend );
mComposerMap->setNewExtent( QgsRectangle( 785462.375, 3341423.125, 789262.375, 3343323.125 ) ); //zoom in
overviewMapBlend->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3350923.125 ) );
overviewMapBlend->overview()->setFrameMap( mComposerMap->id() );
overviewMapBlend->overview()->setBlendMode( QPainter::CompositionMode_Multiply );

QgsCompositionChecker checker( "composermap_overview_blending", mComposition );

bool testResult = checker.testComposition( mReport, 0, 100 );
mComposition->removeComposerItem( overviewMapBlend );
QVERIFY( testResult );
}

void TestQgsComposerMap::overviewMapInvert()
{
QgsComposerMap* overviewMapInvert = new QgsComposerMap( mComposition, 20, 130, 70, 70 );
overviewMapInvert->setFrameEnabled( true );
mComposition->addComposerMap( overviewMapInvert );
mComposerMap->setNewExtent( QgsRectangle( 785462.375, 3341423.125, 789262.375, 3343323.125 ) ); //zoom in
overviewMapInvert->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3350923.125 ) );
overviewMapInvert->overview()->setFrameMap( mComposerMap->id() );
overviewMapInvert->overview()->setInverted( true );

QgsCompositionChecker checker( "composermap_overview_invert", mComposition );

bool testResult = checker.testComposition( mReport, 0, 100 );
mComposition->removeComposerItem( overviewMapInvert );
QVERIFY( testResult );
}

void TestQgsComposerMap::uniqueId()
{
QDomDocument doc;
@@ -223,24 +132,6 @@ void TestQgsComposerMap::uniqueId()
QVERIFY( oldId != newId );
}

void TestQgsComposerMap::overviewMapCenter()
{
QgsComposerMap* overviewMapCenter = new QgsComposerMap( mComposition, 20, 130, 70, 70 );
overviewMapCenter->setFrameEnabled( true );
mComposition->addComposerMap( overviewMapCenter );
mComposerMap->setNewExtent( QgsRectangle( 785462.375 + 5000, 3341423.125, 789262.375 + 5000, 3343323.125 ) ); //zoom in
mComposerMap->grid()->setEnabled( false );
overviewMapCenter->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3350923.125 ) );
overviewMapCenter->overview()->setFrameMap( mComposerMap->id() );
overviewMapCenter->overview()->setCentered( true );

QgsCompositionChecker checker( "composermap_overview_center", mComposition );

bool testResult = checker.testComposition( mReport, 0, 100 );
mComposition->removeComposerItem( overviewMapCenter );
QVERIFY( testResult );
}

void TestQgsComposerMap::worldFileGeneration()
{
mComposerMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3345223.125 ) );
@@ -0,0 +1,204 @@
/***************************************************************************
testqgscomposermapoverview.cpp
----------------------
begin : September 2014
copyright : (C) 2014 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsapplication.h"
#include "qgscomposition.h"
#include "qgscompositionchecker.h"
#include "qgscomposermap.h"
#include "qgscomposermapoverview.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaprenderer.h"
#include "qgsmultibandcolorrenderer.h"
#include "qgsrasterlayer.h"
#include "qgsfontutils.h"
#include <QObject>
#include <QtTest>

class TestQgsComposerMapOverview: public QObject
{
Q_OBJECT;
private slots:
void initTestCase();// will be called before the first testfunction is executed.
void cleanupTestCase();// will be called after the last testfunction was executed.
void init();// will be called before each testfunction is executed.
void cleanup();// will be called after every testfunction.
void overviewMap(); //test if overview map frame works
void overviewMapRotated(); //test if overview map frame works with rotated overview
void overviewMapRotated2(); //test if overview map frame works with rotated map
void overviewMapBlending(); //test if blend modes with overview map frame works
void overviewMapInvert(); //test if invert of overview map frame works
void overviewMapCenter(); //test if centering of overview map frame works

private:
QgsComposition* mComposition;
QgsComposerMap* mComposerMap;
QgsMapSettings mMapSettings;
QgsRasterLayer* mRasterLayer;
QString mReport;
};

void TestQgsComposerMapOverview::initTestCase()
{
QgsApplication::init();
QgsApplication::initQgis();

//create maplayers from testdata and add to layer registry
QFileInfo rasterFileInfo( QString( TEST_DATA_DIR ) + QDir::separator() + "landsat.tif" );
mRasterLayer = new QgsRasterLayer( rasterFileInfo.filePath(),
rasterFileInfo.completeBaseName() );
QgsMultiBandColorRenderer* rasterRenderer = new QgsMultiBandColorRenderer( mRasterLayer->dataProvider(), 2, 3, 4 );
mRasterLayer->setRenderer( rasterRenderer );

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

//create composition with composer map
mMapSettings.setLayers( QStringList() << mRasterLayer->id() );
mMapSettings.setCrsTransformEnabled( false );
mComposition = new QgsComposition( mMapSettings );
mComposition->setPaperSize( 297, 210 ); //A4 landscape
mComposerMap = new QgsComposerMap( mComposition, 20, 20, 200, 100 );
mComposerMap->setFrameEnabled( true );
mComposition->addComposerMap( mComposerMap );

mReport = "<h1>Composer Map Overview Tests</h1>\n";
}

void TestQgsComposerMapOverview::cleanupTestCase()
{
delete mComposition;
delete mRasterLayer;

QString myReportFile = QDir::tempPath() + QDir::separator() + "qgistest.html";
QFile myFile( myReportFile );
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
{
QTextStream myQTextStream( &myFile );
myQTextStream << mReport;
myFile.close();
}
}

void TestQgsComposerMapOverview::init()
{
}

void TestQgsComposerMapOverview::cleanup()
{

}

void TestQgsComposerMapOverview::overviewMap()
{
QgsComposerMap* overviewMap = new QgsComposerMap( mComposition, 20, 130, 70, 70 );
overviewMap->setFrameEnabled( true );
mComposition->addComposerMap( overviewMap );
mComposerMap->setNewExtent( QgsRectangle( 785462.375, 3341423.125, 789262.375, 3343323.125 ) ); //zoom in
overviewMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3350923.125 ) );
overviewMap->overview()->setFrameMap( mComposerMap->id() );
QgsCompositionChecker checker( "composermap_overview", mComposition );

bool testResult = checker.testComposition( mReport, 0, 100 );
mComposition->removeComposerItem( overviewMap );
QVERIFY( testResult );
}

void TestQgsComposerMapOverview::overviewMapRotated()
{
QgsComposerMap* overviewMap = new QgsComposerMap( mComposition, 20, 130, 70, 70 );
overviewMap->setFrameEnabled( true );
mComposition->addComposerMap( overviewMap );
mComposerMap->setNewExtent( QgsRectangle( 785462.375, 3341423.125, 789262.375, 3343323.125 ) ); //zoom in
mComposerMap->setMapRotation( 30 );
overviewMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3350923.125 ) );
overviewMap->overview()->setFrameMap( mComposerMap->id() );
QgsCompositionChecker checker( "composermap_overview_rotated", mComposition );

bool testResult = checker.testComposition( mReport, 0, 100 );
mComposition->removeComposerItem( overviewMap );
mComposerMap->setMapRotation( 0 );
QVERIFY( testResult );
}

void TestQgsComposerMapOverview::overviewMapRotated2()
{
QgsComposerMap* overviewMap = new QgsComposerMap( mComposition, 20, 130, 70, 70 );
overviewMap->setFrameEnabled( true );
mComposition->addComposerMap( overviewMap );
mComposerMap->setNewExtent( QgsRectangle( 785462.375, 3341423.125, 789262.375, 3343323.125 ) ); //zoom in
overviewMap->setMapRotation( 30 );
overviewMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3350923.125 ) );
overviewMap->overview()->setFrameMap( mComposerMap->id() );
QgsCompositionChecker checker( "composermap_overview_rotated2", mComposition );

bool testResult = checker.testComposition( mReport, 0, 100 );
mComposition->removeComposerItem( overviewMap );
QVERIFY( testResult );
}

void TestQgsComposerMapOverview::overviewMapBlending()
{
QgsComposerMap* overviewMapBlend = new QgsComposerMap( mComposition, 20, 130, 70, 70 );
overviewMapBlend->setFrameEnabled( true );
mComposition->addComposerMap( overviewMapBlend );
mComposerMap->setNewExtent( QgsRectangle( 785462.375, 3341423.125, 789262.375, 3343323.125 ) ); //zoom in
overviewMapBlend->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3350923.125 ) );
overviewMapBlend->overview()->setFrameMap( mComposerMap->id() );
overviewMapBlend->overview()->setBlendMode( QPainter::CompositionMode_Multiply );

QgsCompositionChecker checker( "composermap_overview_blending", mComposition );

bool testResult = checker.testComposition( mReport, 0, 100 );
mComposition->removeComposerItem( overviewMapBlend );
QVERIFY( testResult );
}

void TestQgsComposerMapOverview::overviewMapInvert()
{
QgsComposerMap* overviewMapInvert = new QgsComposerMap( mComposition, 20, 130, 70, 70 );
overviewMapInvert->setFrameEnabled( true );
mComposition->addComposerMap( overviewMapInvert );
mComposerMap->setNewExtent( QgsRectangle( 785462.375, 3341423.125, 789262.375, 3343323.125 ) ); //zoom in
overviewMapInvert->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3350923.125 ) );
overviewMapInvert->overview()->setFrameMap( mComposerMap->id() );
overviewMapInvert->overview()->setInverted( true );

QgsCompositionChecker checker( "composermap_overview_invert", mComposition );

bool testResult = checker.testComposition( mReport, 0, 100 );
mComposition->removeComposerItem( overviewMapInvert );
QVERIFY( testResult );
}

void TestQgsComposerMapOverview::overviewMapCenter()
{
QgsComposerMap* overviewMapCenter = new QgsComposerMap( mComposition, 20, 130, 70, 70 );
overviewMapCenter->setFrameEnabled( true );
mComposition->addComposerMap( overviewMapCenter );
mComposerMap->setNewExtent( QgsRectangle( 785462.375 + 5000, 3341423.125, 789262.375 + 5000, 3343323.125 ) ); //zoom in
overviewMapCenter->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3350923.125 ) );
overviewMapCenter->overview()->setFrameMap( mComposerMap->id() );
overviewMapCenter->overview()->setCentered( true );

QgsCompositionChecker checker( "composermap_overview_center", mComposition );

bool testResult = checker.testComposition( mReport, 0, 100 );
mComposition->removeComposerItem( overviewMapCenter );
QVERIFY( testResult );
}

QTEST_MAIN( TestQgsComposerMapOverview )
#include "moc_testqgscomposermapoverview.cxx"

0 comments on commit 97ea6f6

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