Skip to content

Commit

Permalink
[composer] Add test for text table cell values
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 28, 2014
1 parent ebb31de commit 9f84e9f
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/src/core/testqgscomposertable.cpp
Expand Up @@ -22,6 +22,7 @@
#include "qgsmapsettings.h"
#include "qgsvectorlayer.h"
#include "qgsvectordataprovider.h"
#include "qgsfeature.h"

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

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

private:
QgsComposition* mComposition;
Expand Down Expand Up @@ -102,5 +104,48 @@ void TestQgsComposerTable::textTableHeadings()
}
}

void TestQgsComposerTable::textTableRows()
{
//test adding and retrieving text table rows

//add some rows to the table
QList<QStringList> rows;
QStringList row;
row << "a1" << "b1" << "c1";
rows.append( row );
row.clear();
row << "a2" << "b2" << "c2";
rows.append( row );
row.clear();
row << "a3" << "b3" << "c3";
rows.append( row );
QList<QStringList>::const_iterator rowIt = rows.constBegin();
for ( ; rowIt != rows.constEnd(); ++rowIt )
{
mComposerTextTable->addRow( *rowIt );
}

//now retrieve rows and check
QList<QgsAttributeMap> evaluatedRows;
bool result = mComposerTextTable->getFeatureAttributes( evaluatedRows );
QCOMPARE( result, true );

QList<QgsAttributeMap>::const_iterator resultIt = evaluatedRows.constBegin();
int rowNumber = 0;
int colNumber = 0;
for ( ; resultIt != evaluatedRows.constEnd(); ++resultIt )
{
colNumber = 0;
QgsAttributeMap::const_iterator cellIt = ( *resultIt ).constBegin();
for ( ; cellIt != ( *resultIt ).constEnd(); ++cellIt )
{
QCOMPARE(( *cellIt ).toString(), rows.at( rowNumber ).at( colNumber ) );
colNumber++;
}
rowNumber++;
}

}

QTEST_MAIN( TestQgsComposerTable )
#include "moc_testqgscomposertable.cxx"

0 comments on commit 9f84e9f

Please sign in to comment.