From d070558bb2334d28b4fba12e92a9e562997306a5 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Mon, 28 Apr 2014 19:01:21 +1000 Subject: [PATCH] [composer] Start test suite for composer tables. --- tests/src/core/CMakeLists.txt | 1 + tests/src/core/testqgscomposertable.cpp | 106 ++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 tests/src/core/testqgscomposertable.cpp diff --git a/tests/src/core/CMakeLists.txt b/tests/src/core/CMakeLists.txt index 1d5f5f3986ea..28d567696c48 100644 --- a/tests/src/core/CMakeLists.txt +++ b/tests/src/core/CMakeLists.txt @@ -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) diff --git a/tests/src/core/testqgscomposertable.cpp b/tests/src/core/testqgscomposertable.cpp new file mode 100644 index 000000000000..02c2729614c8 --- /dev/null +++ b/tests/src/core/testqgscomposertable.cpp @@ -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 +#include + +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 headerMap = mComposerTextTable->headerLabels(); + QMap::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"