Skip to content

Commit 9f84e9f

Browse files
committedApr 28, 2014
[composer] Add test for text table cell values
1 parent ebb31de commit 9f84e9f

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
 

‎tests/src/core/testqgscomposertable.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "qgsmapsettings.h"
2323
#include "qgsvectorlayer.h"
2424
#include "qgsvectordataprovider.h"
25+
#include "qgsfeature.h"
2526

2627
#include <QObject>
2728
#include <QtTest>
@@ -36,6 +37,7 @@ class TestQgsComposerTable: public QObject
3637
void cleanup();// will be called after every testfunction.
3738

3839
void textTableHeadings(); //test setting/retrieving text table headers
40+
void textTableRows(); //test adding and retrieving text table rows
3941

4042
private:
4143
QgsComposition* mComposition;
@@ -102,5 +104,48 @@ void TestQgsComposerTable::textTableHeadings()
102104
}
103105
}
104106

107+
void TestQgsComposerTable::textTableRows()
108+
{
109+
//test adding and retrieving text table rows
110+
111+
//add some rows to the table
112+
QList<QStringList> rows;
113+
QStringList row;
114+
row << "a1" << "b1" << "c1";
115+
rows.append( row );
116+
row.clear();
117+
row << "a2" << "b2" << "c2";
118+
rows.append( row );
119+
row.clear();
120+
row << "a3" << "b3" << "c3";
121+
rows.append( row );
122+
QList<QStringList>::const_iterator rowIt = rows.constBegin();
123+
for ( ; rowIt != rows.constEnd(); ++rowIt )
124+
{
125+
mComposerTextTable->addRow( *rowIt );
126+
}
127+
128+
//now retrieve rows and check
129+
QList<QgsAttributeMap> evaluatedRows;
130+
bool result = mComposerTextTable->getFeatureAttributes( evaluatedRows );
131+
QCOMPARE( result, true );
132+
133+
QList<QgsAttributeMap>::const_iterator resultIt = evaluatedRows.constBegin();
134+
int rowNumber = 0;
135+
int colNumber = 0;
136+
for ( ; resultIt != evaluatedRows.constEnd(); ++resultIt )
137+
{
138+
colNumber = 0;
139+
QgsAttributeMap::const_iterator cellIt = ( *resultIt ).constBegin();
140+
for ( ; cellIt != ( *resultIt ).constEnd(); ++cellIt )
141+
{
142+
QCOMPARE(( *cellIt ).toString(), rows.at( rowNumber ).at( colNumber ) );
143+
colNumber++;
144+
}
145+
rowNumber++;
146+
}
147+
148+
}
149+
105150
QTEST_MAIN( TestQgsComposerTable )
106151
#include "moc_testqgscomposertable.cxx"

0 commit comments

Comments
 (0)
Please sign in to comment.