Skip to content
Permalink
Browse files

Fix some clazy warnings in tests

  • Loading branch information
nyalldawson committed Apr 3, 2018
1 parent e2d75d5 commit c2af8ca4bc7d7d2f38dce774dfcadd4f15da935a
Showing with 34 additions and 29 deletions.
  1. +34 −29 tests/src/core/testqgscompositionconverter.cpp
@@ -150,9 +150,9 @@ class TestQgsCompositionConverter: public QObject

private:

void checkRenderedImage( QgsLayout *layout, const QString testName, const int pageNumber = 0 );
void checkRenderedImage( QgsLayout *layout, const QString &testName, const int pageNumber = 0 );

QDomElement loadComposer( const QString name );
QDomElement loadComposer( const QString &name );

QString mReport;

@@ -192,7 +192,7 @@ void TestQgsCompositionConverter::cleanup()

void TestQgsCompositionConverter::importComposerTemplateLabel()
{
QDomElement composerElem( loadComposer( "2x_template_label.qpt" ) );
QDomElement composerElem( loadComposer( QStringLiteral( "2x_template_label.qpt" ) ) );
QgsProject project;
project.read( QStringLiteral( TEST_DATA_DIR ) + "/layouts/sample_project.qgs" );
QDomElement docElem = composerElem.elementsByTagName( QStringLiteral( "Composition" ) ).at( 0 ).toElement();
@@ -225,7 +225,7 @@ void TestQgsCompositionConverter::importComposerTemplateLabel()

void TestQgsCompositionConverter::importComposerTemplateShape()
{
QDomElement composerElem( loadComposer( "2x_template_shape.qpt" ) );
QDomElement composerElem( loadComposer( QStringLiteral( "2x_template_shape.qpt" ) ) );
QgsProject project;
project.read( QStringLiteral( TEST_DATA_DIR ) + "/layouts/sample_project.qgs" );
QDomElement docElem = composerElem.elementsByTagName( QStringLiteral( "Composition" ) ).at( 0 ).toElement();
@@ -261,7 +261,7 @@ void TestQgsCompositionConverter::importComposerTemplateShape()

void TestQgsCompositionConverter::importComposerTemplatePicture()
{
QDomElement composerElem( loadComposer( "2x_template_pictures.qpt" ) );
QDomElement composerElem( loadComposer( QStringLiteral( "2x_template_pictures.qpt" ) ) );
QVERIFY( !composerElem.isNull() );
QgsProject project;
project.read( QStringLiteral( TEST_DATA_DIR ) + "/layouts/sample_project.qgs" );
@@ -293,7 +293,7 @@ void TestQgsCompositionConverter::importComposerTemplatePicture()

void TestQgsCompositionConverter::importComposerTemplatePolygon()
{
QDomElement composerElem( loadComposer( "2x_template_polygon.qpt" ) );
QDomElement composerElem( loadComposer( QStringLiteral( "2x_template_polygon.qpt" ) ) );
QVERIFY( !composerElem.isNull() );
QgsProject project;
project.read( QStringLiteral( TEST_DATA_DIR ) + "/layouts/sample_project.qgs" );
@@ -319,7 +319,7 @@ void TestQgsCompositionConverter::importComposerTemplatePolygon()

void TestQgsCompositionConverter::importComposerTemplatePolyline()
{
QDomElement composerElem( loadComposer( "2x_template_polyline.qpt" ) );
QDomElement composerElem( loadComposer( QStringLiteral( "2x_template_polyline.qpt" ) ) );
QVERIFY( !composerElem.isNull() );
QgsProject project;
project.read( QStringLiteral( TEST_DATA_DIR ) + "/layouts/sample_project.qgs" );
@@ -347,7 +347,7 @@ void TestQgsCompositionConverter::importComposerTemplatePolyline()

void TestQgsCompositionConverter::importComposerTemplateArrow()
{
QDomElement composerElem( loadComposer( "2x_template_arrow.qpt" ) );
QDomElement composerElem( loadComposer( QStringLiteral( "2x_template_arrow.qpt" ) ) );
QVERIFY( !composerElem.isNull() );
QgsProject project;
project.read( QStringLiteral( TEST_DATA_DIR ) + "/layouts/sample_project.qgs" );
@@ -376,7 +376,7 @@ void TestQgsCompositionConverter::importComposerTemplateArrow()

void TestQgsCompositionConverter::importComposerTemplateMap()
{
QDomElement composerElem( loadComposer( "2x_template_map_overview.qpt" ) );
QDomElement composerElem( loadComposer( QStringLiteral( "2x_template_map_overview.qpt" ) ) );
QVERIFY( !composerElem.isNull() );
QgsProject project;
project.read( QStringLiteral( TEST_DATA_DIR ) + "/layouts/sample_project.qgs" );
@@ -410,6 +410,7 @@ void TestQgsCompositionConverter::importComposerTemplateMap()
QStringList mapUuids;
QList<QgsLayoutItemMap *> mapItems;
layout->layoutItems<QgsLayoutItemMap>( mapItems );
mapUuids.reserve( mapItems.count() );
for ( auto const &item : mapItems )
{
mapUuids << item->uuid();
@@ -419,9 +420,10 @@ void TestQgsCompositionConverter::importComposerTemplateMap()
int count = 0;
QList<QgsLayoutItemMap *> items;
layout->layoutItems<QgsLayoutItemMap>( items );
for ( auto const &mapItem : items )
for ( auto const &mapItem : qgis::as_const( items ) )
{
for ( auto const &item : mapItem->overviews()->asList() )
const auto overviewItems = mapItem->overviews()->asList();
for ( auto const &item : overviewItems )
{
if ( ! item->map( )->uuid().isEmpty( ) )
{
@@ -443,7 +445,7 @@ void TestQgsCompositionConverter::importComposerTemplateMap()

void TestQgsCompositionConverter::importComposerTemplateLegend()
{
QDomElement composerElem( loadComposer( "2x_template_legend.qpt" ) );
QDomElement composerElem( loadComposer( QStringLiteral( "2x_template_legend.qpt" ) ) );
QVERIFY( !composerElem.isNull() );
QgsProject project;
project.read( QStringLiteral( TEST_DATA_DIR ) + "/layouts/sample_project.qgs" );
@@ -469,7 +471,7 @@ void TestQgsCompositionConverter::importComposerTemplateLegend()

void TestQgsCompositionConverter::importComposerTemplateAttributeTable()
{
QDomElement composerElem( loadComposer( "2x_template_attributetable.qpt" ) );
QDomElement composerElem( loadComposer( QStringLiteral( "2x_template_attributetable.qpt" ) ) );
QgsProject project;
project.read( QStringLiteral( TEST_DATA_DIR ) + "/layouts/sample_project.qgs" );
QDomElement docElem = composerElem.elementsByTagName( QStringLiteral( "Composition" ) ).at( 0 ).toElement();
@@ -493,7 +495,7 @@ void TestQgsCompositionConverter::importComposerTemplateAttributeTable()

void TestQgsCompositionConverter::importComposerTemplateHtml()
{
QDomElement composerElem( loadComposer( "2x_template_html.qpt" ) );
QDomElement composerElem( loadComposer( QStringLiteral( "2x_template_html.qpt" ) ) );
QgsProject project;
project.read( QStringLiteral( TEST_DATA_DIR ) + "/layouts/sample_project.qgs" );
QDomElement docElem = composerElem.elementsByTagName( QStringLiteral( "Composition" ) ).at( 0 ).toElement();
@@ -517,7 +519,7 @@ void TestQgsCompositionConverter::importComposerTemplateHtml()

void TestQgsCompositionConverter::importComposerTemplateScaleBar()
{
QDomElement composerElem( loadComposer( "2x_template_scalebar.qpt" ) );
QDomElement composerElem( loadComposer( QStringLiteral( "2x_template_scalebar.qpt" ) ) );
QVERIFY( !composerElem.isNull() );
QgsProject project;
project.read( QStringLiteral( TEST_DATA_DIR ) + "/layouts/sample_project.qgs" );
@@ -564,7 +566,7 @@ void TestQgsCompositionConverter::convertComposition()
void TestQgsCompositionConverter::isCompositionTemplate()
{
QString templatePath( QStringLiteral( TEST_DATA_DIR ) + "/layouts/2x_template.qpt" );
QDomDocument doc( "mydocument" );
QDomDocument doc( QStringLiteral( "mydocument" ) );
QFile file( templatePath );
QVERIFY( file.open( QIODevice::ReadOnly ) );
QVERIFY( doc.setContent( &file ) );
@@ -577,7 +579,7 @@ void TestQgsCompositionConverter::isCompositionTemplate()
void TestQgsCompositionConverter::convertCompositionTemplate()
{
QString templatePath( QStringLiteral( TEST_DATA_DIR ) + "/layouts/2x_template.qpt" );
QDomDocument doc( "mydocument" );
QDomDocument doc( QStringLiteral( "mydocument" ) );
QFile file( templatePath );
QVERIFY( file.open( QIODevice::ReadOnly ) );
QVERIFY( doc.setContent( &file ) );
@@ -599,7 +601,7 @@ void TestQgsCompositionConverter::convertCompositionTemplate()

void TestQgsCompositionConverter::importComposerTemplate()
{
QDomElement composerElem( loadComposer( "2x_template.qpt" ) );
QDomElement composerElem( loadComposer( QStringLiteral( "2x_template.qpt" ) ) );
QgsProject project;
project.read( QStringLiteral( TEST_DATA_DIR ) + "/layouts/sample_project.qgs" );
QDomElement docElem = composerElem.elementsByTagName( QStringLiteral( "Composition" ) ).at( 0 ).toElement();
@@ -614,7 +616,8 @@ void TestQgsCompositionConverter::importComposerTemplate()
QStringList mapUuids;
QList<QgsLayoutItemMap *> mapItems;
layout->layoutItems<QgsLayoutItemMap>( mapItems );
for ( auto const &item : mapItems )
mapUuids.reserve( mapItems.count() );
for ( auto const &item : qgis::as_const( mapItems ) )
{
mapUuids << item->uuid();
}
@@ -624,7 +627,7 @@ void TestQgsCompositionConverter::importComposerTemplate()
int count = 0;
QList<QgsLayoutItemPicture *> items;
layout->layoutItems<QgsLayoutItemPicture>( items );
for ( auto const &item : items )
for ( auto const &item : qgis::as_const( items ) )
{
if ( item->linkedMap() )
{
@@ -642,7 +645,7 @@ void TestQgsCompositionConverter::importComposerTemplate()
int count = 0;
QList<QgsLayoutItemLegend *> items;
layout->layoutItems<QgsLayoutItemLegend>( items );
for ( auto const &item : items )
for ( auto const &item : qgis::as_const( items ) )
{
if ( item->linkedMap() )
{
@@ -659,7 +662,7 @@ void TestQgsCompositionConverter::importComposerTemplate()
int count = 0;
QList<QgsLayoutItemScaleBar *> items;
layout->layoutItems<QgsLayoutItemScaleBar>( items );
for ( auto const &item : items )
for ( auto const &item : qgis::as_const( items ) )
{
if ( item->linkedMap( ) )
{
@@ -678,7 +681,7 @@ void TestQgsCompositionConverter::importComposerTemplate()

void TestQgsCompositionConverter::importComposerAtlas()
{
QDomElement composerElem( loadComposer( "2x_template_atlas.qpt" ) );
QDomElement composerElem( loadComposer( QStringLiteral( "2x_template_atlas.qpt" ) ) );
QVERIFY( !composerElem.isNull() );
QVERIFY( !composerElem.attribute( QStringLiteral( "title" ) ).isEmpty() );
QgsProject project;
@@ -696,23 +699,25 @@ void TestQgsCompositionConverter::importComposerAtlas()

}

void TestQgsCompositionConverter::checkRenderedImage( QgsLayout *layout, const QString testName, const int pageNumber )
void TestQgsCompositionConverter::checkRenderedImage( QgsLayout *layout, const QString &testName, const int pageNumber )
{
QgsLayoutChecker checker( testName + "_" + QString::number( pageNumber ), layout );
QgsLayoutChecker checker( testName + '_' + QString::number( pageNumber ), layout );
QSize size( layout->pageCollection()->page( pageNumber )->sizeWithUnits().width() * 3.77, layout->pageCollection()->page( pageNumber )->sizeWithUnits().height() * 3.77 );
checker.setSize( size );
checker.setControlPathPrefix( QStringLiteral( "compositionconverter" ) );
QVERIFY( checker.testLayout( mReport, pageNumber, 0, false ) );
}


QDomElement TestQgsCompositionConverter::loadComposer( const QString name )
QDomElement TestQgsCompositionConverter::loadComposer( const QString &name )
{
QString templatePath( QStringLiteral( TEST_DATA_DIR ) + "/layouts/" + name );
QDomDocument doc( "mydocument" );
QDomDocument doc( QStringLiteral( "mydocument" ) );
QFile file( templatePath );
Q_ASSERT( file.open( QIODevice::ReadOnly ) );
Q_ASSERT( doc.setContent( &file ) );
bool res = file.open( QIODevice::ReadOnly );
Q_ASSERT( res );
res = doc.setContent( &file );
Q_ASSERT( res );
file.close();
QDomNodeList nodes( doc.elementsByTagName( QStringLiteral( "Composer" ) ) );
if ( nodes.length() > 0 )

0 comments on commit c2af8ca

Please sign in to comment.
You can’t perform that action at this time.