[composer] Move composer picture related tests into their own seperate test suite (sponsored by City of Uster, Switzerland)

This commit is contained in:
Nyall Dawson 2014-04-28 19:30:32 +10:00
parent 23b660ec74
commit 53cda0a9c7
6 changed files with 130 additions and 51 deletions

View File

@ -107,6 +107,7 @@ ADD_QGIS_TEST(composermaptest testqgscomposermap.cpp)
ADD_QGIS_TEST(composereffectstest testqgscomposereffects.cpp)
ADD_QGIS_TEST(composershapestest testqgscomposershapes.cpp)
ADD_QGIS_TEST(composerrotationtest testqgscomposerrotation.cpp)
ADD_QGIS_TEST(composerpicturetest testqgscomposerpicture.cpp)
ADD_QGIS_TEST(atlascompositiontest testqgsatlascomposition.cpp)
ADD_QGIS_TEST(composerlabeltest testqgscomposerlabel.cpp)
ADD_QGIS_TEST(composertabletest testqgscomposertable.cpp)

View File

@ -0,0 +1,129 @@
/***************************************************************************
testqgscomposerpicture.cpp
----------------------
begin : April 2014
copyright : (C) 2014 by Nyall Dawson
email : nyall dot dawson at gmail.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 "qgscomposerpicture.h"
#include <QObject>
#include <QtTest>
#include <QColor>
#include <QPainter>
class TestQgsComposerPicture: 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 pictureRotation(); //test if picture pictureRotation is functioning
void pictureItemRotation(); //test if composer picture item rotation is functioning
//void oldPictureRotationApi(); //test if old deprectated composer picture rotation api is functioning
private:
QgsComposition* mComposition;
QgsComposerPicture* mComposerPicture;
QgsMapSettings mMapSettings;
QString mReport;
};
void TestQgsComposerPicture::initTestCase()
{
QgsApplication::init();
QgsApplication::initQgis();
mComposition = new QgsComposition( mMapSettings );
mComposition->setPaperSize( 297, 210 ); //A4 landscape
mComposerPicture = new QgsComposerPicture( mComposition );
mComposerPicture->setPictureFile( QString( TEST_DATA_DIR ) + QDir::separator() + "sample_image.png" );
mComposerPicture->setSceneRect( QRectF( 70, 70, 100, 100 ) );
mComposerPicture->setFrameEnabled( true );
mReport = "<h1>Composer Picture Tests</h1>\n";
}
void TestQgsComposerPicture::cleanupTestCase()
{
delete mComposition;
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 TestQgsComposerPicture::init()
{
}
void TestQgsComposerPicture::cleanup()
{
}
void TestQgsComposerPicture::pictureRotation()
{
//test picture rotation
mComposition->addComposerPicture( mComposerPicture );
mComposerPicture->setPictureRotation( 45 );
QgsCompositionChecker checker( "composerpicture_rotation", mComposition );
QVERIFY( checker.testComposition( mReport, 0, 100 ) );
mComposition->removeItem( mComposerPicture );
mComposerPicture->setPictureRotation( 0 );
}
void TestQgsComposerPicture::pictureItemRotation()
{
//test picture item rotation
mComposition->addComposerPicture( mComposerPicture );
mComposerPicture->setItemRotation( 45, true );
QgsCompositionChecker checker( "composerpicture_itemrotation", mComposition );
QVERIFY( checker.testComposition( mReport, 0, 100 ) );
mComposition->removeItem( mComposerPicture );
mComposerPicture->setItemRotation( 0, true );
}
#if 0
void TestQgsComposerPicture::oldPictureRotationApi()
{
//test old style deprecated rotation api - remove test after 2.0 series
mComposition->addComposerPicture( mComposerPicture );
mComposerPicture->setRotation( 45 );
QgsCompositionChecker checker( "composerpicture_rotation_oldapi", mComposition );
QVERIFY( checker.testComposition( mReport ) );
mComposition->removeItem( mComposerPicture );
mComposerPicture->setRotation( 0 );
}
#endif
QTEST_MAIN( TestQgsComposerPicture )
#include "moc_testqgscomposerpicture.cxx"

View File

@ -21,7 +21,6 @@
#include "qgscomposershape.h"
#include "qgscomposermap.h"
#include "qgscomposerlabel.h"
#include "qgscomposerpicture.h"
#include "qgsmultibandcolorrenderer.h"
#include "qgsmaprenderer.h"
#include "qgsrasterlayer.h"
@ -50,9 +49,6 @@ class TestQgsComposerRotation: public QObject
void mapRotation(); //test if composer map mapRotation is functioning
void mapItemRotation(); //test if composer map item rotation is functioning
//void oldMapRotationApi(); //test if old deprectated composer map rotation api is functioning
void pictureRotation(); //test if picture pictureRotation is functioning
void pictureItemRotation(); //test if composer picture item rotation is functioning
//void oldPictureRotationApi(); //test if old deprectated composer picture rotation api is functioning
private:
QgsComposition* mComposition;
@ -61,7 +57,6 @@ class TestQgsComposerRotation: public QObject
QgsMapRenderer* mMapRenderer;
QgsComposerMap* mComposerMap;
QgsMapSettings mMapSettings;
QgsComposerPicture* mComposerPicture;
QgsRasterLayer* mRasterLayer;
QString mReport;
};
@ -97,11 +92,6 @@ void TestQgsComposerRotation::initTestCase()
mComposerLabel->adjustSizeToText();
mComposerLabel->setBackgroundColor( QColor::fromRgb( 255, 150, 0 ) );
mComposerPicture = new QgsComposerPicture( mComposition );
mComposerPicture->setPictureFile( QString( TEST_DATA_DIR ) + QDir::separator() + "sample_image.png" );
mComposerPicture->setSceneRect( QRectF( 70, 70, 100, 100 ) );
mComposerPicture->setFrameEnabled( true );
mComposerMap = new QgsComposerMap( mComposition, 20, 20, 200, 100 );
mComposerMap->setFrameEnabled( true );
@ -232,46 +222,5 @@ void TestQgsComposerRotation::oldMapRotationApi()
}
#endif
void TestQgsComposerRotation::pictureRotation()
{
//test picture rotation
mComposition->addComposerPicture( mComposerPicture );
mComposerPicture->setPictureRotation( 45 );
QgsCompositionChecker checker( "composerrotation_picturerotation", mComposition );
QVERIFY( checker.testComposition( mReport, 0, 100 ) );
mComposition->removeItem( mComposerPicture );
mComposerPicture->setPictureRotation( 0 );
}
void TestQgsComposerRotation::pictureItemRotation()
{
//test picture item rotation
mComposition->addComposerPicture( mComposerPicture );
mComposerPicture->setItemRotation( 45, true );
QgsCompositionChecker checker( "composerrotation_pictureitemrotation", mComposition );
QVERIFY( checker.testComposition( mReport, 0, 100 ) );
mComposition->removeItem( mComposerPicture );
mComposerPicture->setItemRotation( 0, true );
}
#if 0
void TestQgsComposerRotation::oldPictureRotationApi()
{
//test old style deprecated rotation api - remove test after 2.0 series
mComposition->addComposerPicture( mComposerPicture );
mComposerPicture->setRotation( 45 );
QgsCompositionChecker checker( "composerrotation_picturerotation_oldapi", mComposition );
QVERIFY( checker.testComposition( mReport ) );
mComposition->removeItem( mComposerPicture );
mComposerPicture->setRotation( 0 );
}
#endif
QTEST_MAIN( TestQgsComposerRotation )
#include "moc_testqgscomposerrotation.cxx"