mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
[tests] Add test for composer paper styles
This commit is contained in:
parent
aae492fa43
commit
31e37af4f3
@ -101,6 +101,7 @@ ADD_QGIS_TEST(vectorlayertest testqgsvectorlayer.cpp)
|
||||
ADD_QGIS_TEST(rulebasedrenderertest testqgsrulebasedrenderer.cpp)
|
||||
ADD_QGIS_TEST(ziplayertest testziplayer.cpp)
|
||||
ADD_QGIS_TEST(dataitemtest testqgsdataitem.cpp)
|
||||
ADD_QGIS_TEST(composerpapertest testqgscomposerpaper.cpp)
|
||||
ADD_QGIS_TEST(composermaptest testqgscomposermap.cpp)
|
||||
ADD_QGIS_TEST(composereffectstest testqgscomposereffects.cpp)
|
||||
ADD_QGIS_TEST(composershapestest testqgscomposershapes.cpp)
|
||||
|
134
tests/src/core/testqgscomposerpaper.cpp
Normal file
134
tests/src/core/testqgscomposerpaper.cpp
Normal file
@ -0,0 +1,134 @@
|
||||
/***************************************************************************
|
||||
testqgscomposerpaper.cpp
|
||||
----------------------
|
||||
begin : January 2014
|
||||
copyright : (C) 2014 by Marco Hugentobler, 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 "qgscomposershape.h"
|
||||
#include "qgssymbolv2.h"
|
||||
#include "qgssinglesymbolrendererv2.h"
|
||||
#include "qgsfillsymbollayerv2.h"
|
||||
#include "qgslinesymbollayerv2.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QtTest>
|
||||
#include <QColor>
|
||||
#include <QPainter>
|
||||
|
||||
class TestQgsComposerPaper: 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 defaultPaper(); //test default paper style
|
||||
void transparentPaper(); //test totally transparent paper style
|
||||
void borderedPaper(); //test page with border
|
||||
void markerLinePaper(); //test page with marker line border
|
||||
|
||||
private:
|
||||
QgsComposition* mComposition;
|
||||
QString mReport;
|
||||
QgsSimpleFillSymbolLayerV2* mSimpleFill;
|
||||
QgsMarkerLineSymbolLayerV2* mMarkerLine;
|
||||
QgsFillSymbolV2* mFillSymbol;
|
||||
QgsFillSymbolV2* mMarkerLineSymbol;
|
||||
QgsSingleSymbolRendererV2* mSymbolRenderer;
|
||||
|
||||
};
|
||||
|
||||
void TestQgsComposerPaper::initTestCase()
|
||||
{
|
||||
QgsApplication::init();
|
||||
QgsApplication::initQgis();
|
||||
|
||||
//create empty composition
|
||||
mComposition = new QgsComposition( 0 );
|
||||
mComposition->setPaperSize( 297, 210 ); //A4 landscape
|
||||
|
||||
//setup simple fill
|
||||
mSimpleFill = new QgsSimpleFillSymbolLayerV2();
|
||||
mFillSymbol = new QgsFillSymbolV2();
|
||||
mFillSymbol->changeSymbolLayer( 0, mSimpleFill );
|
||||
|
||||
//setup marker line fill
|
||||
mMarkerLine = new QgsMarkerLineSymbolLayerV2();
|
||||
mMarkerLineSymbol = new QgsFillSymbolV2();
|
||||
mMarkerLineSymbol->changeSymbolLayer( 0, mMarkerLine );
|
||||
|
||||
mReport = "<h1>Composer Paper Tests</h1>\n";
|
||||
}
|
||||
|
||||
void TestQgsComposerPaper::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 TestQgsComposerPaper::init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TestQgsComposerPaper::cleanup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TestQgsComposerPaper::defaultPaper()
|
||||
{
|
||||
QgsCompositionChecker checker( "composerpaper_default", mComposition );
|
||||
QVERIFY( checker.testComposition( mReport ) );
|
||||
}
|
||||
|
||||
void TestQgsComposerPaper::transparentPaper()
|
||||
{
|
||||
mSimpleFill->setColor( Qt::transparent );
|
||||
mSimpleFill->setBorderColor( Qt::transparent );
|
||||
mComposition->setPageStyleSymbol( mFillSymbol );
|
||||
QgsCompositionChecker checker( "composerpaper_transparent", mComposition );
|
||||
QVERIFY( checker.testComposition( mReport ) );
|
||||
}
|
||||
|
||||
void TestQgsComposerPaper::borderedPaper()
|
||||
{
|
||||
mSimpleFill->setColor( Qt::white );
|
||||
mSimpleFill->setBorderColor( Qt::black );
|
||||
mSimpleFill->setBorderWidth( 6 );
|
||||
QgsCompositionChecker checker( "composerpaper_bordered", mComposition );
|
||||
QVERIFY( checker.testComposition( mReport ) );
|
||||
}
|
||||
|
||||
void TestQgsComposerPaper::markerLinePaper()
|
||||
{
|
||||
mComposition->setPageStyleSymbol( mMarkerLineSymbol );
|
||||
QgsCompositionChecker checker( "composerpaper_markerborder", mComposition );
|
||||
QVERIFY( checker.testComposition( mReport ) );
|
||||
}
|
||||
|
||||
QTEST_MAIN( TestQgsComposerPaper )
|
||||
#include "moc_testqgscomposerpaper.cxx"
|
BIN
tests/testdata/control_images/expected_composerpaper_bordered/expected_composerpaper_bordered.png
vendored
Normal file
BIN
tests/testdata/control_images/expected_composerpaper_bordered/expected_composerpaper_bordered.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 39 KiB |
BIN
tests/testdata/control_images/expected_composerpaper_default/expected_composerpaper_default.png
vendored
Normal file
BIN
tests/testdata/control_images/expected_composerpaper_default/expected_composerpaper_default.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 39 KiB |
Binary file not shown.
After Width: | Height: | Size: 130 KiB |
Binary file not shown.
After Width: | Height: | Size: 33 KiB |
Loading…
x
Reference in New Issue
Block a user