Skip to content

Commit

Permalink
[tests] Fix composer tests. Rebuild images following MTR rendering ch…
Browse files Browse the repository at this point in the history
…anges. Switch tests to use standard test font.
  • Loading branch information
nyalldawson committed Apr 3, 2014
1 parent 6d73593 commit 0b32f2a
Show file tree
Hide file tree
Showing 79 changed files with 59 additions and 47 deletions.
29 changes: 16 additions & 13 deletions tests/src/core/testqgsatlascomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "qgsvectordataprovider.h"
#include "qgssymbolv2.h"
#include "qgssinglesymbolrendererv2.h"
#include "qgsfontutils.h"
#include <QObject>
#include <QSignalSpy>
#include <QtTest>
Expand Down Expand Up @@ -134,14 +135,16 @@ void TestQgsAtlasComposition::initTestCase()
mLabel1 = new QgsComposerLabel( mComposition );
mComposition->addComposerLabel( mLabel1 );
mLabel1->setText( "[% \"NAME_1\" %] area" );
//next to explicetly set width, since expression isn't yet evaulated against
//an atlas feature and will be shorter then required
mLabel1->setFont( QgsFontUtils::getStandardTestFont() );
//need to explictly set width, since expression hasn't been evaluated against
//an atlas feature yet and will be shorter than required
mLabel1->setSceneRect( QRectF( 150, 5, 60, 15 ) );

// feature number label
mLabel2 = new QgsComposerLabel( mComposition );
mComposition->addComposerLabel( mLabel2 );
mLabel2->setText( "# [%$feature || ' / ' || $numfeatures%]" );
mLabel2->setFont( QgsFontUtils::getStandardTestFont() );
mLabel2->setSceneRect( QRectF( 150, 200, 60, 15 ) );

qWarning() << "header label font: " << mLabel1->font().toString() << " exactMatch:" << mLabel1->font().exactMatch();
Expand Down Expand Up @@ -201,7 +204,7 @@ void TestQgsAtlasComposition::autoscale_render()
mLabel1->adjustSizeToText();

QgsCompositionChecker checker( QString( "atlas_autoscale%1" ).arg((( int )fit ) + 1 ), mComposition );
QVERIFY( checker.testComposition( mReport, 0, 10 ) );
QVERIFY( checker.testComposition( mReport, 0, 200 ) );
}
mAtlas->endRender();
mAtlasMap->setAtlasDriven( false );
Expand All @@ -223,7 +226,7 @@ void TestQgsAtlasComposition::autoscale_render_2_0_api()
mLabel1->adjustSizeToText();

QgsCompositionChecker checker( QString( "atlas_autoscale_old_api%1" ).arg((( int )fit ) + 1 ), mComposition );
QVERIFY( checker.testComposition( mReport, 0 ) );
QVERIFY( checker.testComposition( mReport, 0, 200 ) );
}
mAtlas->endRender();
mAtlas->setComposerMap( 0 );
Expand All @@ -245,7 +248,7 @@ void TestQgsAtlasComposition::fixedscale_render()
mLabel1->adjustSizeToText();

QgsCompositionChecker checker( QString( "atlas_fixedscale%1" ).arg((( int )fit ) + 1 ), mComposition );
QVERIFY( checker.testComposition( mReport, 0 ) );
QVERIFY( checker.testComposition( mReport, 0, 200 ) );
}
mAtlas->endRender();

Expand All @@ -266,7 +269,7 @@ void TestQgsAtlasComposition::fixedscale_render_2_0_api()
mLabel1->adjustSizeToText();

QgsCompositionChecker checker( QString( "atlas_fixedscale_old_api%1" ).arg((( int )fit ) + 1 ), mComposition );
QVERIFY( checker.testComposition( mReport, 0 ) );
QVERIFY( checker.testComposition( mReport, 0, 200 ) );
}
mAtlas->endRender();
mAtlas->setComposerMap( 0 );
Expand All @@ -290,7 +293,7 @@ void TestQgsAtlasComposition::two_map_autoscale_render()
mLabel1->adjustSizeToText();

QgsCompositionChecker checker( QString( "atlas_two_maps%1" ).arg((( int )fit ) + 1 ), mComposition );
QVERIFY( checker.testComposition( mReport, 0, 10 ) );
QVERIFY( checker.testComposition( mReport, 0, 200 ) );
}
mAtlas->endRender();
mAtlasMap->setAtlasDriven( false );
Expand All @@ -314,7 +317,7 @@ void TestQgsAtlasComposition::hiding_render()
mLabel1->adjustSizeToText();

QgsCompositionChecker checker( QString( "atlas_hiding%1" ).arg((( int )fit ) + 1 ), mComposition );
QVERIFY( checker.testComposition( mReport, 0 ) );
QVERIFY( checker.testComposition( mReport, 0, 200 ) );
}
mAtlas->endRender();
}
Expand All @@ -338,7 +341,7 @@ void TestQgsAtlasComposition::sorting_render()
mLabel1->adjustSizeToText();

QgsCompositionChecker checker( QString( "atlas_sorting%1" ).arg((( int )fit ) + 1 ), mComposition );
QVERIFY( checker.testComposition( mReport, 0 ) );
QVERIFY( checker.testComposition( mReport, 0, 200 ) );
}
mAtlas->endRender();
}
Expand All @@ -363,7 +366,7 @@ void TestQgsAtlasComposition::filtering_render()
mLabel1->adjustSizeToText();

QgsCompositionChecker checker( QString( "atlas_filtering%1" ).arg((( int )fit ) + 1 ), mComposition );
QVERIFY( checker.testComposition( mReport, 0 ) );
QVERIFY( checker.testComposition( mReport, 0, 200 ) );
}
mAtlas->endRender();
}
Expand All @@ -377,9 +380,9 @@ void TestQgsAtlasComposition::test_signals()
mAtlas->setSortFeatures( false );
mAtlas->setFilterFeatures( false );

QSignalSpy spyRenderBegun( mAtlas, SIGNAL(renderBegun()) );
QSignalSpy spyRenderEnded( mAtlas, SIGNAL(renderEnded()) );
QSignalSpy spyPreparedForAtlas( mAtlasMap, SIGNAL(preparedForAtlas()) );
QSignalSpy spyRenderBegun( mAtlas, SIGNAL( renderBegun() ) );
QSignalSpy spyRenderEnded( mAtlas, SIGNAL( renderEnded() ) );
QSignalSpy spyPreparedForAtlas( mAtlasMap, SIGNAL( preparedForAtlas() ) );
mAtlas->beginRender();

QVERIFY( spyRenderBegun.count() == 1 );
Expand Down
22 changes: 10 additions & 12 deletions tests/src/core/testqgscomposermap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "qgsmaprenderer.h"
#include "qgsmultibandcolorrenderer.h"
#include "qgsrasterlayer.h"
#include "qgsfontutils.h"
#include <QObject>
#include <QtTest>

Expand Down Expand Up @@ -107,7 +108,7 @@ void TestQgsComposerMap::render()
mComposerMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3345223.125 ) );
QgsCompositionChecker checker( "composermap_render", mComposition );

QVERIFY( checker.testComposition( mReport ) );
QVERIFY( checker.testComposition( mReport, 0, 100 ) );
}

void TestQgsComposerMap::grid()
Expand All @@ -116,12 +117,10 @@ void TestQgsComposerMap::grid()
mComposerMap->setGridEnabled( true );
mComposerMap->setGridIntervalX( 2000 );
mComposerMap->setGridIntervalY( 2000 );
// Anotation is disabled because fonts are different on each platform
// TODO: ship a test font with QGIS and use it here
//mComposerMap->setShowGridAnnotation( true );
mComposerMap->setShowGridAnnotation( true );
mComposerMap->setGridPenWidth( 0.5 );
mComposerMap->setGridPenColor( QColor( 0, 255, 0 ) );
#if 0
mComposerMap->setGridAnnotationFont( QgsFontUtils::getStandardTestFont() );
mComposerMap->setGridAnnotationPrecision( 0 );
mComposerMap->setGridAnnotationPosition( QgsComposerMap::Disabled, QgsComposerMap::Left );
mComposerMap->setGridAnnotationPosition( QgsComposerMap::OutsideMapFrame, QgsComposerMap::Right );
Expand All @@ -130,12 +129,11 @@ void TestQgsComposerMap::grid()
mComposerMap->setGridAnnotationDirection( QgsComposerMap::Horizontal, QgsComposerMap::Right );
mComposerMap->setGridAnnotationDirection( QgsComposerMap::Horizontal, QgsComposerMap::Bottom );
mComposerMap->setAnnotationFontColor( QColor( 255, 0, 0, 150 ) );
#endif
mComposerMap->setGridBlendMode( QPainter::CompositionMode_Overlay );
qWarning() << "grid annotation font: " << mComposerMap->gridAnnotationFont().toString() << " exactMatch:" << mComposerMap->gridAnnotationFont().exactMatch();
QgsCompositionChecker checker( "composermap_grid", mComposition );

bool testResult = checker.testComposition( mReport );
bool testResult = checker.testComposition( mReport, 0, 100 );
mComposerMap->setGridEnabled( false );
mComposerMap->setShowGridAnnotation( false );
QVERIFY( testResult );
Expand All @@ -151,7 +149,7 @@ void TestQgsComposerMap::overviewMap()
overviewMap->setOverviewFrameMap( mComposerMap->id() );
QgsCompositionChecker checker( "composermap_overview", mComposition );

bool testResult = checker.testComposition( mReport );
bool testResult = checker.testComposition( mReport, 0, 100 );
mComposition->removeComposerItem( overviewMap );
QVERIFY( testResult );
}
Expand All @@ -168,7 +166,7 @@ void TestQgsComposerMap::overviewMapBlending()

QgsCompositionChecker checker( "composermap_overview_blending", mComposition );

bool testResult = checker.testComposition( mReport );
bool testResult = checker.testComposition( mReport, 0, 100 );
mComposition->removeComposerItem( overviewMapBlend );
QVERIFY( testResult );
}
Expand All @@ -185,7 +183,7 @@ void TestQgsComposerMap::overviewMapInvert()

QgsCompositionChecker checker( "composermap_overview_invert", mComposition );

bool testResult = checker.testComposition( mReport );
bool testResult = checker.testComposition( mReport, 0, 100 );
mComposition->removeComposerItem( overviewMapInvert );
QVERIFY( testResult );
}
Expand Down Expand Up @@ -233,7 +231,7 @@ void TestQgsComposerMap::zebraStyle()

QgsCompositionChecker checker( "composermap_zebrastyle", mComposition );

bool testResult = checker.testComposition( mReport );
bool testResult = checker.testComposition( mReport, 0, 100 );
QVERIFY( testResult );
}

Expand All @@ -250,7 +248,7 @@ void TestQgsComposerMap::overviewMapCenter()

QgsCompositionChecker checker( "composermap_overview_center", mComposition );

bool testResult = checker.testComposition( mReport );
bool testResult = checker.testComposition( mReport, 0, 100 );
mComposition->removeComposerItem( overviewMapCenter );
QVERIFY( testResult );
}
Expand Down
22 changes: 13 additions & 9 deletions tests/src/core/testqgscomposerrotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "qgsmaprenderer.h"
#include "qgsrasterlayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsfontutils.h"
#include <QObject>
#include <QtTest>
#include <QColor>
Expand All @@ -44,7 +45,7 @@ class TestQgsComposerRotation: public QObject
// Label tests disabled because are platform dependent (font)
void shapeRotation(); //test if composer shape rotation is functioning
//void oldShapeRotationApi(); //test if old deprecated composer shape rotation api is functioning
//void labelRotation(); //test if composer label rotation is functioning
void labelRotation(); //test if composer label rotation is functioning
//void oldLabelRotationApi(); //test if old deprectated composer label rotation api is functioning
void mapRotation(); //test if composer map mapRotation is functioning
void mapItemRotation(); //test if composer map item rotation is functioning
Expand All @@ -59,6 +60,7 @@ class TestQgsComposerRotation: public QObject
QgsComposerLabel* mComposerLabel;
QgsMapRenderer* mMapRenderer;
QgsComposerMap* mComposerMap;
QgsMapSettings mMapSettings;
QgsComposerPicture* mComposerPicture;
QgsRasterLayer* mRasterLayer;
QString mReport;
Expand All @@ -78,11 +80,10 @@ void TestQgsComposerRotation::initTestCase()

QgsMapLayerRegistry::instance()->addMapLayers( QList<QgsMapLayer*>() << mRasterLayer );

QgsMapSettings settings;
settings.setLayers( QStringList() << mRasterLayer->id() );
settings.setCrsTransformEnabled( false );
mMapSettings.setLayers( QStringList() << mRasterLayer->id() );
mMapSettings.setCrsTransformEnabled( false );

mComposition = new QgsComposition( settings );
mComposition = new QgsComposition( mMapSettings );
mComposition->setPaperSize( 297, 210 ); //A4 landscape

mComposerRect = new QgsComposerShape( 70, 70, 150, 100, mComposition );
Expand All @@ -91,6 +92,7 @@ void TestQgsComposerRotation::initTestCase()

mComposerLabel = new QgsComposerLabel( mComposition );
mComposerLabel->setText( "test label" );
mComposerLabel->setFont( QgsFontUtils::getStandardTestFont() );
mComposerLabel->setPos( 70, 70 );
mComposerLabel->adjustSizeToText();
mComposerLabel->setBackgroundColor( QColor::fromRgb( 255, 150, 0 ) );
Expand Down Expand Up @@ -155,21 +157,23 @@ void TestQgsComposerRotation::oldShapeRotationApi()

mComposition->removeItem( mComposerRect );
}
#endif

void TestQgsComposerRotation::labelRotation()
{
mComposition->addComposerLabel( mComposerLabel );
mComposerLabel->setItemRotation( 135, true );

QgsCompositionChecker checker( "composerrotation_label", mComposition );
QVERIFY( checker.testComposition( mReport ) );
QVERIFY( checker.testComposition( mReport, 0, 20 ) );

// removeItem() for label does not work, the label is rendered in the next test
// cannot find why, other items are removed correctly
mComposition->removeItem( mComposerLabel );
mComposerLabel->setItemRotation( 0, true );
}

#if 0
void TestQgsComposerRotation::oldLabelRotationApi()
{
//test old style deprecated rotation api - remove test after 2.0 series
Expand All @@ -192,7 +196,7 @@ void TestQgsComposerRotation::mapRotation()
mComposerMap->setMapRotation( 90 );

QgsCompositionChecker checker( "composerrotation_maprotation", mComposition );
QVERIFY( checker.testComposition( mReport ) );
QVERIFY( checker.testComposition( mReport, 0, 100 ) );

mComposition->removeItem( mComposerMap );
mComposerMap->setMapRotation( 0 );
Expand Down Expand Up @@ -235,7 +239,7 @@ void TestQgsComposerRotation::pictureRotation()
mComposerPicture->setPictureRotation( 45 );

QgsCompositionChecker checker( "composerrotation_picturerotation", mComposition );
QVERIFY( checker.testComposition( mReport ) );
QVERIFY( checker.testComposition( mReport, 0, 100 ) );

mComposition->removeItem( mComposerPicture );
mComposerPicture->setPictureRotation( 0 );
Expand All @@ -248,7 +252,7 @@ void TestQgsComposerRotation::pictureItemRotation()
mComposerPicture->setItemRotation( 45, true );

QgsCompositionChecker checker( "composerrotation_pictureitemrotation", mComposition );
QVERIFY( checker.testComposition( mReport ) );
QVERIFY( checker.testComposition( mReport, 0, 100 ) );

mComposition->removeItem( mComposerPicture );
mComposerPicture->setItemRotation( 0, true );
Expand Down
14 changes: 9 additions & 5 deletions tests/src/core/testqgscomposerscalebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "qgsmaprenderer.h"
#include "qgsmultibandcolorrenderer.h"
#include "qgsrasterlayer.h"
#include "qgsfontutils.h"
#include <QObject>
#include <QtTest>

Expand Down Expand Up @@ -80,15 +81,17 @@ void TestQgsComposerScaleBar::initTestCase()
mComposerMap->setNewExtent( QgsRectangle( 17.923, 30.160, 18.023, 30.260 ) );

mComposerScaleBar = new QgsComposerScaleBar( mComposition );
mComposerScaleBar->setSceneRect( QRectF( 20, 180, 20, 20 ) );
mComposerScaleBar->setSceneRect( QRectF( 20, 180, 50, 20 ) );
mComposition->addComposerScaleBar( mComposerScaleBar );
mComposerScaleBar->setComposerMap( mComposerMap );
mComposerScaleBar->setFont( QgsFontUtils::getStandardTestFont() );
mComposerScaleBar->setUnits( QgsComposerScaleBar::Meters );
mComposerScaleBar->setNumUnitsPerSegment( 2000 );
mComposerScaleBar->setNumSegmentsLeft( 0 );
mComposerScaleBar->setNumSegments( 2 );
mComposerScaleBar->setHeight( 5 );


qWarning() << "scalebar font: " << mComposerScaleBar->font().toString() << " exactMatch:" << mComposerScaleBar->font().exactMatch();

mReport = "<h1>Composer Scalebar Tests</h1>\n";
Expand Down Expand Up @@ -123,28 +126,29 @@ void TestQgsComposerScaleBar::singleBox()
{
mComposerScaleBar->setStyle( "Single Box" );
QgsCompositionChecker checker( "composerscalebar_singlebox", mComposition );
QVERIFY( checker.testComposition( mReport ) );
QVERIFY( checker.testComposition( mReport, 0, 20 ) );
};

void TestQgsComposerScaleBar::doubleBox()
{
mComposerScaleBar->setStyle( "Double Box" );
QgsCompositionChecker checker( "composerscalebar_doublebox", mComposition );
QVERIFY( checker.testComposition( mReport ) );
QVERIFY( checker.testComposition( mReport, 0, 20 ) );
};

void TestQgsComposerScaleBar::numeric()
{
mComposerScaleBar->setStyle( "Numeric" );
mComposerScaleBar->setSceneRect( QRectF( 20, 180, 50, 20 ) );
QgsCompositionChecker checker( "composerscalebar_numeric", mComposition );
QVERIFY( checker.testComposition( mReport ) );
QVERIFY( checker.testComposition( mReport, 0, 20 ) );
};

void TestQgsComposerScaleBar::tick()
{
mComposerScaleBar->setStyle( "Line Ticks Up" );
QgsCompositionChecker checker( "composerscalebar_tick", mComposition );
QVERIFY( checker.testComposition( mReport ) );
QVERIFY( checker.testComposition( mReport, 0, 20 ) );
};

QTEST_MAIN( TestQgsComposerScaleBar )
Expand Down
Loading

0 comments on commit 0b32f2a

Please sign in to comment.