Skip to content

Commit

Permalink
[composer] Start test suite for composer tables.
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 28, 2014
1 parent e0c6402 commit d070558
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ ADD_QGIS_TEST(composershapestest testqgscomposershapes.cpp)
ADD_QGIS_TEST(composerrotationtest testqgscomposerrotation.cpp)
ADD_QGIS_TEST(atlascompositiontest testqgsatlascomposition.cpp)
ADD_QGIS_TEST(composerlabeltest testqgscomposerlabel.cpp)
ADD_QGIS_TEST(composertabletest testqgscomposertable.cpp)
ADD_QGIS_TEST(stylev2test testqgsstylev2.cpp)
ADD_QGIS_TEST(composerhtmltest testqgscomposerhtml.cpp )
ADD_QGIS_TEST(rectangletest testqgsrectangle.cpp)
Expand Down
106 changes: 106 additions & 0 deletions tests/src/core/testqgscomposertable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/***************************************************************************
testqgscomposertable.cpp
----------------------
begin : April 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 "qgscomposertexttable.h"
#include "qgscomposerattributetable.h"
#include "qgsmapsettings.h"
#include "qgsvectorlayer.h"
#include "qgsvectordataprovider.h"

#include <QObject>
#include <QtTest>

class TestQgsComposerTable: 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 textTableHeadings(); //test setting/retrieving text table headers

private:
QgsComposition* mComposition;
QgsComposerTextTable* mComposerTextTable;
QgsMapSettings mMapSettings;
QgsVectorLayer* mVectorLayer;
};

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

//create maplayers from testdata and add to layer registry
QFileInfo vectorFileInfo( QString( TEST_DATA_DIR ) + QDir::separator() + "france_parts.shp" );
mVectorLayer = new QgsVectorLayer( vectorFileInfo.filePath(),
vectorFileInfo.completeBaseName(),
"ogr" );

//create composition with composer map
mMapSettings.setLayers( QStringList() << mVectorLayer->id() );
mMapSettings.setCrsTransformEnabled( false );
mComposition = new QgsComposition( mMapSettings );
mComposition->setPaperSize( 297, 210 ); //A4 landscape

mComposerTextTable = new QgsComposerTextTable( mComposition );
mComposition->addItem( mComposerTextTable );

}

void TestQgsComposerTable::cleanupTestCase()
{
delete mComposition;
delete mVectorLayer;
}

void TestQgsComposerTable::init()
{
}

void TestQgsComposerTable::cleanup()
{
}

void TestQgsComposerTable::textTableHeadings()
{
//test setting/retrieving text table headers
QStringList headers;
headers << "a" << "b" << "c";
mComposerTextTable->setHeaderLabels( headers );

//get header labels and compare
QMap<int, QString> headerMap = mComposerTextTable->headerLabels();
QMap<int, QString>::const_iterator headerIt = headerMap.constBegin();
int col = 0;
QString expected;
QString evaluated;
for ( ; headerIt != headerMap.constEnd(); ++headerIt )
{
col = headerIt.key();
evaluated = headerIt.value();
expected = headers.at( col );
QCOMPARE( evaluated, expected );
}
}

QTEST_MAIN( TestQgsComposerTable )
#include "moc_testqgscomposertable.cxx"

0 comments on commit d070558

Please sign in to comment.