Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup c++ layout tests #54824

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/core/qgsmultirenderchecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ bool QgsLayoutChecker::testLayout( QString &checkedReport, int page, int pixelDi
p.end();

QString renderedFilePath = QDir::tempPath() + '/' + QFileInfo( mTestName ).baseName() + "_rendered.png";
if ( QFile::exists( renderedFilePath ) )
QFile::remove( renderedFilePath );

outputImage.save( renderedFilePath, "PNG" );

setRenderedImage( renderedFilePath );
Expand Down
6 changes: 5 additions & 1 deletion src/test/qgstest.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,14 @@ class TEST_EXPORT QgsTest : public QObject
return result;
}

bool layoutCheck( const QString &name, QgsLayout *layout, int page = 0, int allowedMismatch = 0 )
bool layoutCheck( const QString &name, QgsLayout *layout, int page = 0, int allowedMismatch = 0, const QSize size = QSize(), int colorTolerance = 0 )
{
QgsLayoutChecker checker( name, layout );
checker.setControlPathPrefix( mControlPathPrefix );
if ( size.isValid() )
checker.setSize( size );
if ( colorTolerance > 0 )
checker.setColorTolerance( colorTolerance );

QString report;
const bool result = checker.testLayout( report, page, allowedMismatch );
Expand Down
40 changes: 13 additions & 27 deletions tests/src/core/testqgslayoutatlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
***************************************************************************/

#include "qgsapplication.h"
#include "qgsmultirenderchecker.h"
#include "qgslayoutitemmap.h"
#include "qgslayoutitemmapoverview.h"
#include "qgslayoutatlas.h"
Expand All @@ -39,13 +38,14 @@ class TestQgsLayoutAtlas : public QgsTest
Q_OBJECT

public:
TestQgsLayoutAtlas() : QgsTest( QStringLiteral( "Layout Atlas Tests" ) ) {}
TestQgsLayoutAtlas()
: QgsTest( QStringLiteral( "Layout Atlas Tests" ), QStringLiteral( "atlas" ) ) {}

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 initTestCase();
void cleanupTestCase();
void init();
void cleanup();

// test filename pattern evaluation
void filename();
Expand Down Expand Up @@ -215,9 +215,7 @@ void TestQgsLayoutAtlas::autoscale_render()
mAtlas->seekTo( fit );
mLabel1->adjustSizeToText();

QgsLayoutChecker checker( QStringLiteral( "atlas_autoscale%1" ).arg( ( ( int )fit ) + 1 ), mLayout );
checker.setControlPathPrefix( QStringLiteral( "atlas" ) );
QVERIFY( checker.testLayout( mReport, 0, 100 ) );
QVERIFY( layoutCheck( QStringLiteral( "atlas_autoscale%1" ).arg( ( ( int )fit ) + 1 ), mLayout, 0, 100 ) );
}
mAtlas->endRender();
}
Expand All @@ -237,9 +235,7 @@ void TestQgsLayoutAtlas::fixedscale_render()
mAtlas->seekTo( fit );
mLabel1->adjustSizeToText();

QgsLayoutChecker checker( QStringLiteral( "atlas_fixedscale%1" ).arg( ( ( int )fit ) + 1 ), mLayout );
checker.setControlPathPrefix( QStringLiteral( "atlas" ) );
QVERIFY( checker.testLayout( mReport, 0, 100 ) );
QVERIFY( layoutCheck( QStringLiteral( "atlas_fixedscale%1" ).arg( ( ( int )fit ) + 1 ), mLayout, 0, 100 ) );
}
mAtlas->endRender();
}
Expand Down Expand Up @@ -271,9 +267,7 @@ void TestQgsLayoutAtlas::predefinedscales_render()
mAtlas->seekTo( fit );
mLabel1->adjustSizeToText();

QgsLayoutChecker checker( QStringLiteral( "atlas_predefinedscales%1" ).arg( ( ( int )fit ) + 1 ), mLayout );
checker.setControlPathPrefix( QStringLiteral( "atlas" ) );
QVERIFY( checker.testLayout( mReport, 0, 100 ) );
QVERIFY( layoutCheck( QStringLiteral( "atlas_predefinedscales%1" ).arg( ( ( int )fit ) + 1 ), mLayout, 0, 100 ) );
}
mAtlas->endRender();
}
Expand All @@ -295,9 +289,7 @@ void TestQgsLayoutAtlas::two_map_autoscale_render()
mAtlas->seekTo( fit );
mLabel1->adjustSizeToText();

QgsLayoutChecker checker( QStringLiteral( "atlas_two_maps%1" ).arg( ( ( int )fit ) + 1 ), mLayout );
checker.setControlPathPrefix( QStringLiteral( "atlas" ) );
QVERIFY( checker.testLayout( mReport, 0, 100 ) );
QVERIFY( layoutCheck( QStringLiteral( "atlas_two_maps%1" ).arg( ( ( int )fit ) + 1 ), mLayout, 0, 100 ) );
}
mAtlas->endRender();
}
Expand All @@ -316,9 +308,7 @@ void TestQgsLayoutAtlas::hiding_render()
mAtlas->seekTo( fit );
mLabel1->adjustSizeToText();

QgsLayoutChecker checker( QStringLiteral( "atlas_hiding%1" ).arg( ( ( int )fit ) + 1 ), mLayout );
checker.setControlPathPrefix( QStringLiteral( "atlas" ) );
QVERIFY( checker.testLayout( mReport, 0, 100 ) );
QVERIFY( layoutCheck( QStringLiteral( "atlas_hiding%1" ).arg( ( ( int )fit ) + 1 ), mLayout, 0, 100 ) );
}
mAtlas->endRender();
}
Expand All @@ -341,9 +331,7 @@ void TestQgsLayoutAtlas::sorting_render()
mAtlas->seekTo( fit );
mLabel1->adjustSizeToText();

QgsLayoutChecker checker( QStringLiteral( "atlas_sorting%1" ).arg( ( ( int )fit ) + 1 ), mLayout );
checker.setControlPathPrefix( QStringLiteral( "atlas" ) );
QVERIFY( checker.testLayout( mReport, 0, 100 ) );
QVERIFY( layoutCheck( QStringLiteral( "atlas_sorting%1" ).arg( ( ( int )fit ) + 1 ), mLayout, 0, 100 ) );
}
mAtlas->endRender();
}
Expand All @@ -368,9 +356,7 @@ void TestQgsLayoutAtlas::filtering_render()
mAtlas->seekTo( fit );
mLabel1->adjustSizeToText();

QgsLayoutChecker checker( QStringLiteral( "atlas_filtering%1" ).arg( ( ( int )fit ) + 1 ), mLayout );
checker.setControlPathPrefix( QStringLiteral( "atlas" ) );
QVERIFY( checker.testLayout( mReport, 0, 100 ) );
QVERIFY( layoutCheck( QStringLiteral( "atlas_filtering%1" ).arg( ( ( int )fit ) + 1 ), mLayout, 0, 100 ) );
}
mAtlas->endRender();
}
Expand Down
6 changes: 6 additions & 0 deletions tests/src/core/testqgslayoutcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class TestQgsLayoutContext: public QgsTest

private slots:

void cleanupTestCase();
void creation(); //test creation of QgsLayout
void flags(); //test QgsLayout flags
void feature();
Expand All @@ -51,6 +52,11 @@ class TestQgsLayoutContext: public QgsTest

};

void TestQgsLayoutContext::cleanupTestCase()
{
QgsApplication::exitQgis();
}

void TestQgsLayoutContext::creation()
{
QgsLayoutRenderContext *context = new QgsLayoutRenderContext( nullptr );
Expand Down
15 changes: 10 additions & 5 deletions tests/src/core/testqgslayoutexporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@
#include "qgsvectorlayer.h"
#include "qgslayoutitemlegend.h"

class TestQgsLayoutExporter: public QObject
class TestQgsLayoutExporter: public QgsTest
{
Q_OBJECT

public:
TestQgsLayoutExporter()
: QgsTest( QStringLiteral( "Layout Exporter Tests" ) ) {}

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 initTestCase();
void cleanupTestCase();
void init();
void cleanup();
void testHandleLayeredExport();

};
Expand All @@ -47,6 +51,7 @@ void TestQgsLayoutExporter::initTestCase()

void TestQgsLayoutExporter::cleanupTestCase()
{
QgsApplication::exitQgis();
}

void TestQgsLayoutExporter::init()
Expand Down
53 changes: 11 additions & 42 deletions tests/src/core/testqgslayouthtml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "qgsapplication.h"
#include "qgslayoutitemhtml.h"
#include "qgslayoutframe.h"
#include "qgsmultirenderchecker.h"
#include "qgsfontutils.h"
#include "qgsvectorlayer.h"
#include "qgsrelationmanager.h"
Expand All @@ -35,7 +34,7 @@ class TestQgsLayoutHtml : public QgsTest
Q_OBJECT

public:
TestQgsLayoutHtml() : QgsTest( QStringLiteral( "Layout HTML Tests" ) ) {}
TestQgsLayoutHtml() : QgsTest( QStringLiteral( "Layout HTML Tests" ), QStringLiteral( "composer_html" ) ) {}

private slots:
void initTestCase();// will be called before the first testfunction is executed.
Expand Down Expand Up @@ -80,10 +79,7 @@ void TestQgsLayoutHtml::sourceMode()
htmlItem->setHtml( QStringLiteral( "<body style=\"margin: 10px;\"><div style=\"width: 100px; height: 50px; background-color: red;\"></div></body>" ) );
htmlItem->loadHtml();

QgsLayoutChecker checker( QStringLiteral( "composerhtml_manual" ), &l );
checker.setControlPathPrefix( QStringLiteral( "composer_html" ) );
const bool result = checker.testLayout( mReport, 0, 100 );
QVERIFY( result );
QVERIFY( layoutCheck( QStringLiteral( "composerhtml_manual" ), &l, 0, 100 ) );
}

void TestQgsLayoutHtml::userStylesheets()
Expand All @@ -103,10 +99,7 @@ void TestQgsLayoutHtml::userStylesheets()
//setting user stylesheet enabled automatically loads html
htmlItem->setUserStylesheetEnabled( true );

QgsLayoutChecker checker( QStringLiteral( "composerhtml_userstylesheet" ), &l );
checker.setControlPathPrefix( QStringLiteral( "composer_html" ) );
const bool result = checker.testLayout( mReport, 0, 100 );
QVERIFY( result );
QVERIFY( layoutCheck( QStringLiteral( "composerhtml_userstylesheet" ), &l, 0, 100 ) );
}

void TestQgsLayoutHtml::evalExpressions()
Expand All @@ -124,10 +117,7 @@ void TestQgsLayoutHtml::evalExpressions()

htmlItem->loadHtml();

QgsLayoutChecker checker( QStringLiteral( "composerhtml_expressions_enabled" ), &l );
checker.setControlPathPrefix( QStringLiteral( "composer_html" ) );
const bool result = checker.testLayout( mReport );
QVERIFY( result );
QVERIFY( layoutCheck( QStringLiteral( "composerhtml_expressions_enabled" ), &l ) );
}

void TestQgsLayoutHtml::evalExpressionsOff()
Expand All @@ -143,10 +133,7 @@ void TestQgsLayoutHtml::evalExpressionsOff()
htmlItem->setHtml( QStringLiteral( "<body style=\"margin: 10px;\"><div style=\"width: [% 10 * 10 %]px; height: [% 30 + 20 %]px; background-color: [% 'yel' || 'low' %];\"></div></body>" ) );
htmlItem->loadHtml();

QgsLayoutChecker checker( QStringLiteral( "composerhtml_expressions_disabled" ), &l );
checker.setControlPathPrefix( QStringLiteral( "composer_html" ) );
const bool result = checker.testLayout( mReport );
QVERIFY( result );
QVERIFY( layoutCheck( QStringLiteral( "composerhtml_expressions_disabled" ), &l ) );
}

void TestQgsLayoutHtml::table()
Expand All @@ -159,10 +146,7 @@ void TestQgsLayoutHtml::table()
htmlItem->addFrame( htmlFrame );
htmlItem->setUrl( QUrl( QStringLiteral( "file:///%1/test_html.html" ).arg( TEST_DATA_DIR ) ) );

QgsLayoutChecker checker( QStringLiteral( "composerhtml_table" ), &l );
checker.setControlPathPrefix( QStringLiteral( "composer_html" ) );
const bool result = checker.testLayout( mReport );
QVERIFY( result );
QVERIFY( layoutCheck( QStringLiteral( "composerhtml_table" ), &l ) );
}

void TestQgsLayoutHtml::tableMultiFrame()
Expand All @@ -179,16 +163,10 @@ void TestQgsLayoutHtml::tableMultiFrame()
//page1
htmlItem->setUrl( QUrl( QStringLiteral( "file:///%1/test_html.html" ).arg( TEST_DATA_DIR ) ) );
htmlItem->frame( 0 )->setFrameEnabled( true );
QgsLayoutChecker checker1( QStringLiteral( "composerhtml_multiframe1" ), &l );
checker1.setControlPathPrefix( QStringLiteral( "composer_html" ) );
bool result = checker1.testLayout( mReport );
QVERIFY( layoutCheck( QStringLiteral( "composerhtml_multiframe1" ), &l ) );

//page2
QgsLayoutChecker checker2( QStringLiteral( "composerhtml_multiframe2" ), &l );
checker2.setControlPathPrefix( QStringLiteral( "composer_html" ) );
result = checker2.testLayout( mReport, 1 ) && result;

QVERIFY( result );
QVERIFY( layoutCheck( QStringLiteral( "composerhtml_multiframe2" ), &l, 1 ) );
}

void TestQgsLayoutHtml::htmlMultiFrameSmartBreak()
Expand All @@ -205,16 +183,10 @@ void TestQgsLayoutHtml::htmlMultiFrameSmartBreak()
//page1
htmlItem->setUrl( QUrl( QStringLiteral( "file:///%1/test_html.html" ).arg( TEST_DATA_DIR ) ) );
htmlItem->frame( 0 )->setFrameEnabled( true );
QgsLayoutChecker checker1( QStringLiteral( "composerhtml_smartbreaks1" ), &l );
checker1.setControlPathPrefix( QStringLiteral( "composer_html" ) );
bool result = checker1.testLayout( mReport, 0, 200 );
QVERIFY( layoutCheck( QStringLiteral( "composerhtml_smartbreaks1" ), &l, 0, 200 ) );

//page2
QgsLayoutChecker checker2( QStringLiteral( "composerhtml_smartbreaks2" ), &l );
checker2.setControlPathPrefix( QStringLiteral( "composer_html" ) );
result = checker2.testLayout( mReport, 1, 200 ) && result;

QVERIFY( result );
QVERIFY( layoutCheck( QStringLiteral( "composerhtml_smartbreaks2" ), &l, 1, 200 ) );
}

void TestQgsLayoutHtml::javascriptSetFeature()
Expand Down Expand Up @@ -285,10 +257,7 @@ void TestQgsLayoutHtml::javascriptSetFeature()

htmlItem->loadHtml();

QgsLayoutChecker checker( QStringLiteral( "composerhtml_setfeature" ), &l );
checker.setControlPathPrefix( QStringLiteral( "composer_html" ) );
const bool result = checker.testLayout( mReport );
QVERIFY( result );
QVERIFY( layoutCheck( QStringLiteral( "composerhtml_setfeature" ), &l ) );

QgsProject::instance()->removeMapLayers( QList<QgsMapLayer *>() << childLayer << parentLayer );
}
Expand Down
Loading
Loading