Skip to content

Commit

Permalink
[tests] Update composer scalebar tests, fix exception causing test to…
Browse files Browse the repository at this point in the history
… fail
  • Loading branch information
nyalldawson committed Dec 28, 2013
1 parent a1a92cd commit cfd9a66
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/core/composer/qgscomposermap.cpp
Expand Up @@ -279,7 +279,8 @@ void QgsComposerMap::cache( void )
double horizontalVScaleFactor = horizontalViewScaleFactor();
if ( horizontalVScaleFactor < 0 )
{
horizontalVScaleFactor = mLastValidViewScaleFactor;
//make sure scale factor is positive
horizontalVScaleFactor = mLastValidViewScaleFactor > 0 ? mLastValidViewScaleFactor : 1;
}

int w = requestExtent.width() * mapUnitsToMM() * horizontalVScaleFactor;
Expand Down
32 changes: 20 additions & 12 deletions tests/src/core/testqgscomposerscalebar.cpp
Expand Up @@ -46,6 +46,7 @@ class TestQgsComposerScaleBar: public QObject
QgsComposerScaleBar* mComposerScaleBar;
QgsRasterLayer* mRasterLayer;
QgsMapRenderer* mMapRenderer;
QString mReport;
};

void TestQgsComposerScaleBar::initTestCase()
Expand Down Expand Up @@ -90,13 +91,24 @@ void TestQgsComposerScaleBar::initTestCase()
mComposerScaleBar->setHeight( 5 );

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

mReport = "<h1>Composer Scalebar Tests</h1>\n";
}

void TestQgsComposerScaleBar::cleanupTestCase()
{
delete mComposition;
delete mMapRenderer;
delete mRasterLayer;

QString myReportFile = QDir::tempPath() + QDir::separator() + "qgistest.html";
QFile myFile( myReportFile );
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
{
QTextStream myQTextStream( &myFile );
myQTextStream << mReport;
myFile.close();
}
};

void TestQgsComposerScaleBar::init()
Expand All @@ -112,33 +124,29 @@ void TestQgsComposerScaleBar::cleanup()
void TestQgsComposerScaleBar::singleBox()
{
mComposerScaleBar->setStyle( "Single Box" );
QgsCompositionChecker checker( "Composer scalebar singleBox", mComposition, QString( QString( TEST_DATA_DIR ) + QDir::separator() +
"control_images" + QDir::separator() + "expected_composerscalebar" + QDir::separator() + "composerscalebar_singlebox.png" ) );
QVERIFY( checker.testComposition() );
QgsCompositionChecker checker( "composerscalebar_singlebox", mComposition );
QVERIFY( checker.testComposition( mReport ) );
};

void TestQgsComposerScaleBar::doubleBox()
{
mComposerScaleBar->setStyle( "Double Box" );
QgsCompositionChecker checker( "Composer scalebar doubleBox", mComposition, QString( QString( TEST_DATA_DIR ) + QDir::separator() +
"control_images" + QDir::separator() + "expected_composerscalebar" + QDir::separator() + "composerscalebar_doublebox.png" ) );
QVERIFY( checker.testComposition() );
QgsCompositionChecker checker( "composerscalebar_doublebox", mComposition );
QVERIFY( checker.testComposition( mReport ) );
};

void TestQgsComposerScaleBar::numeric()
{
mComposerScaleBar->setStyle( "Numeric" );
QgsCompositionChecker checker( "Composer scalebar numeric", mComposition, QString( QString( TEST_DATA_DIR ) + QDir::separator() +
"control_images" + QDir::separator() + "expected_composerscalebar" + QDir::separator() + "composerscalebar_numeric.png" ) );
QVERIFY( checker.testComposition() );
QgsCompositionChecker checker( "composerscalebar_numeric", mComposition );
QVERIFY( checker.testComposition( mReport ) );
};

void TestQgsComposerScaleBar::tick()
{
mComposerScaleBar->setStyle( "Line Ticks Up" );
QgsCompositionChecker checker( "Composer scalebar tick", mComposition, QString( QString( TEST_DATA_DIR ) + QDir::separator() +
"control_images" + QDir::separator() + "expected_composerscalebar" + QDir::separator() + "composerscalebar_tick.png" ) );
QVERIFY( checker.testComposition() );
QgsCompositionChecker checker( "composerscalebar_tick", mComposition );
QVERIFY( checker.testComposition( mReport ) );
};

QTEST_MAIN( TestQgsComposerScaleBar )
Expand Down
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cfd9a66

Please sign in to comment.