Skip to content

Commit d070558

Browse files
committedApr 28, 2014
[composer] Start test suite for composer tables.
1 parent e0c6402 commit d070558

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed
 

‎tests/src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ ADD_QGIS_TEST(composershapestest testqgscomposershapes.cpp)
109109
ADD_QGIS_TEST(composerrotationtest testqgscomposerrotation.cpp)
110110
ADD_QGIS_TEST(atlascompositiontest testqgsatlascomposition.cpp)
111111
ADD_QGIS_TEST(composerlabeltest testqgscomposerlabel.cpp)
112+
ADD_QGIS_TEST(composertabletest testqgscomposertable.cpp)
112113
ADD_QGIS_TEST(stylev2test testqgsstylev2.cpp)
113114
ADD_QGIS_TEST(composerhtmltest testqgscomposerhtml.cpp )
114115
ADD_QGIS_TEST(rectangletest testqgsrectangle.cpp)
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/***************************************************************************
2+
testqgscomposertable.cpp
3+
----------------------
4+
begin : April 2014
5+
copyright : (C) 2014 by Nyall Dawson
6+
email : nyall dot dawson at gmail dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgsapplication.h"
19+
#include "qgscomposition.h"
20+
#include "qgscomposertexttable.h"
21+
#include "qgscomposerattributetable.h"
22+
#include "qgsmapsettings.h"
23+
#include "qgsvectorlayer.h"
24+
#include "qgsvectordataprovider.h"
25+
26+
#include <QObject>
27+
#include <QtTest>
28+
29+
class TestQgsComposerTable: public QObject
30+
{
31+
Q_OBJECT;
32+
private slots:
33+
void initTestCase();// will be called before the first testfunction is executed.
34+
void cleanupTestCase();// will be called after the last testfunction was executed.
35+
void init();// will be called before each testfunction is executed.
36+
void cleanup();// will be called after every testfunction.
37+
38+
void textTableHeadings(); //test setting/retrieving text table headers
39+
40+
private:
41+
QgsComposition* mComposition;
42+
QgsComposerTextTable* mComposerTextTable;
43+
QgsMapSettings mMapSettings;
44+
QgsVectorLayer* mVectorLayer;
45+
};
46+
47+
void TestQgsComposerTable::initTestCase()
48+
{
49+
QgsApplication::init();
50+
QgsApplication::initQgis();
51+
52+
//create maplayers from testdata and add to layer registry
53+
QFileInfo vectorFileInfo( QString( TEST_DATA_DIR ) + QDir::separator() + "france_parts.shp" );
54+
mVectorLayer = new QgsVectorLayer( vectorFileInfo.filePath(),
55+
vectorFileInfo.completeBaseName(),
56+
"ogr" );
57+
58+
//create composition with composer map
59+
mMapSettings.setLayers( QStringList() << mVectorLayer->id() );
60+
mMapSettings.setCrsTransformEnabled( false );
61+
mComposition = new QgsComposition( mMapSettings );
62+
mComposition->setPaperSize( 297, 210 ); //A4 landscape
63+
64+
mComposerTextTable = new QgsComposerTextTable( mComposition );
65+
mComposition->addItem( mComposerTextTable );
66+
67+
}
68+
69+
void TestQgsComposerTable::cleanupTestCase()
70+
{
71+
delete mComposition;
72+
delete mVectorLayer;
73+
}
74+
75+
void TestQgsComposerTable::init()
76+
{
77+
}
78+
79+
void TestQgsComposerTable::cleanup()
80+
{
81+
}
82+
83+
void TestQgsComposerTable::textTableHeadings()
84+
{
85+
//test setting/retrieving text table headers
86+
QStringList headers;
87+
headers << "a" << "b" << "c";
88+
mComposerTextTable->setHeaderLabels( headers );
89+
90+
//get header labels and compare
91+
QMap<int, QString> headerMap = mComposerTextTable->headerLabels();
92+
QMap<int, QString>::const_iterator headerIt = headerMap.constBegin();
93+
int col = 0;
94+
QString expected;
95+
QString evaluated;
96+
for ( ; headerIt != headerMap.constEnd(); ++headerIt )
97+
{
98+
col = headerIt.key();
99+
evaluated = headerIt.value();
100+
expected = headers.at( col );
101+
QCOMPARE( evaluated, expected );
102+
}
103+
}
104+
105+
QTEST_MAIN( TestQgsComposerTable )
106+
#include "moc_testqgscomposertable.cxx"

0 commit comments

Comments
 (0)
Please sign in to comment.