Skip to content
Permalink
Browse files

[composer] Add test for text table cell values

  • Loading branch information
nyalldawson committed Apr 28, 2014
1 parent ebb31de commit 9f84e9fd98f143464d2d8427aa24748d21dcbcc6
Showing with 45 additions and 0 deletions.
  1. +45 −0 tests/src/core/testqgscomposertable.cpp
@@ -22,6 +22,7 @@
#include "qgsmapsettings.h"
#include "qgsvectorlayer.h"
#include "qgsvectordataprovider.h"
#include "qgsfeature.h"

#include <QObject>
#include <QtTest>
@@ -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;
@@ -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.
You can’t perform that action at this time.