Skip to content

Commit

Permalink
Add composer html test
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Aug 7, 2012
1 parent 8719ef9 commit 95e7832
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/src/core/CMakeLists.txt
Expand Up @@ -97,3 +97,4 @@ ADD_QGIS_TEST(rulebasedrenderertest testqgsrulebasedrenderer.cpp)
ADD_QGIS_TEST(ziplayertest testziplayer.cpp)
ADD_QGIS_TEST(dataitemtest testqgsdataitem.cpp)
ADD_QGIS_TEST(composermaptest testqgscomposermap.cpp)
ADD_QGIS_TEST(composerhtmltest testqgscomposerhtml.cpp )
2 changes: 1 addition & 1 deletion tests/src/core/qgscompositionchecker.cpp
Expand Up @@ -53,7 +53,7 @@ bool QgsCompositionChecker::testComposition( int page )
QRectF targetArea( 0, 0, 3507, 2480 );
mComposition->render( &p, targetArea, sourceArea );
p.end();
outputImage.save( "/tmp/composermap_control.png", "PNG" );
outputImage.save( "/tmp/composerhtml_table_control.png", "PNG" );
return false;
#endif //0

Expand Down
70 changes: 70 additions & 0 deletions tests/src/core/testqgscomposerhtml.cpp
@@ -0,0 +1,70 @@
/***************************************************************************
testqgscomposerhtml.cpp
-----------------------
begin : August 2012
copyright : (C) 2012 by Marco Hugentobler
email : marco at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* 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 "qgscomposerhtml.h"
#include "qgscomposition.h"
#include "qgscompositionchecker.h"
#include <QObject>
#include <QtTest>

class TestQgsComposerHtml: 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 table(); //test if rendering of the composition with composr map is correct

private:
QgsComposition* mComposition;
};

void TestQgsComposerHtml::initTestCase()
{
mComposition = new QgsComposition( 0 );
mComposition->setPaperSize( 297, 210 ); //A4 landscape
}

void TestQgsComposerHtml::cleanupTestCase()
{
delete mComposition;
}

void TestQgsComposerHtml::init()
{

}

void TestQgsComposerHtml::cleanup()
{

}

void TestQgsComposerHtml::table()
{
QgsComposerHtml* htmlItem = new QgsComposerHtml( mComposition, 0, 0, 100, 200 );
htmlItem->setUrl( QUrl( QString( "file:///%1" ).arg( QString( TEST_DATA_DIR ) + QDir::separator() + "html_table.html" ) ) );
QgsCompositionChecker checker( "Composer html table", mComposition, QString( QString( TEST_DATA_DIR ) + QDir::separator() +
"control_images" + QDir::separator() + "expected_composerhtml" + QDir::separator() + "composerhtml_table.png" ) );
QVERIFY( checker.testComposition() );
}


QTEST_MAIN( TestQgsComposerHtml )
#include "moc_testqgscomposerhtml.cxx"
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions tests/testdata/html_table.html
@@ -0,0 +1,10 @@
<table border="1" style="font-size:12pt; ">
<tbody>
<tr><td>1 Foo data</td><td>Bar data</td></tr>
<tr><td>2 Foo data</td><td>Bar data</td></tr>
<tr><td>3 Foo data</td><td>Bar data</td></tr>
<tr><td>4 Foo data</td><td>Bar data</td></tr>
<tr><td>5 Foo data</td><td>Bar data</td></tr>
</tbody>
</table>
<table>

0 comments on commit 95e7832

Please sign in to comment.