Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add rendering tests for HiDPI (device pixel ratio)
- Loading branch information
Showing
6 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/*************************************************************************** | ||
TestQgsMapDevicePixelRatio.cpp | ||
-------------------------------------- | ||
Date : October 2018 | ||
Copyright : (C) 2018 by Denis Rouzaud | ||
Email : denis@opengis.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 <QObject> | ||
#include <QString> | ||
#include <QStringList> | ||
#include <QApplication> | ||
#include <QFileInfo> | ||
#include <QDir> | ||
#include <QFile> | ||
#include <QIODevice> | ||
|
||
#include "qgstest.h" | ||
#include "qgsvectorlayer.h" | ||
#include "qgsfontutils.h" | ||
#include "qgsmapsettings.h" | ||
|
||
//qgis unit test includes | ||
#include <qgsrenderchecker.h> | ||
|
||
/** | ||
* \ingroup UnitTests | ||
* This is a unit test for the map rotation feature | ||
*/ | ||
class TestQgsMapDevicePixelRatio : public QObject | ||
{ | ||
Q_OBJECT | ||
public: | ||
TestQgsMapDevicePixelRatio() | ||
{ | ||
mTestDataDir = QStringLiteral( TEST_DATA_DIR ) + '/'; | ||
} | ||
|
||
~TestQgsMapDevicePixelRatio() override; | ||
|
||
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 pointsLayer(); | ||
|
||
private: | ||
bool render( const QString &fileName, float dpr ); | ||
|
||
QString mTestDataDir; | ||
QgsVectorLayer *mPointsLayer = nullptr; | ||
QgsMapSettings *mMapSettings = nullptr; | ||
QString mReport; | ||
}; | ||
|
||
//runs before all tests | ||
void TestQgsMapDevicePixelRatio::initTestCase() | ||
{ | ||
// init QGIS's paths - true means that all path will be inited from prefix | ||
QgsApplication::init(); | ||
QgsApplication::initQgis(); | ||
|
||
mMapSettings = new QgsMapSettings(); | ||
|
||
//create a point layer that will be used in all tests... | ||
QString myPointsFileName = mTestDataDir + "points.shp"; | ||
QFileInfo myPointFileInfo( myPointsFileName ); | ||
mPointsLayer = new QgsVectorLayer( myPointFileInfo.filePath(), | ||
myPointFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); | ||
|
||
mReport += QLatin1String( "<h1>Map Device Pixel Ratio Tests</h1>\n" ); | ||
|
||
QgsFontUtils::loadStandardTestFonts( QStringList() << QStringLiteral( "Bold" ) ); | ||
} | ||
|
||
TestQgsMapDevicePixelRatio::~TestQgsMapDevicePixelRatio() = default; | ||
|
||
//runs after all tests | ||
void TestQgsMapDevicePixelRatio::cleanupTestCase() | ||
{ | ||
delete mMapSettings; | ||
delete mPointsLayer; | ||
QgsApplication::exitQgis(); | ||
|
||
QString myReportFile = QDir::tempPath() + "/qgistest.html"; | ||
QFile myFile( myReportFile ); | ||
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) ) | ||
{ | ||
QTextStream myQTextStream( &myFile ); | ||
myQTextStream << mReport; | ||
myFile.close(); | ||
} | ||
} | ||
|
||
void TestQgsMapDevicePixelRatio::pointsLayer() | ||
{ | ||
mMapSettings->setLayers( QList<QgsMapLayer *>() << mPointsLayer ); | ||
|
||
QString qml = mTestDataDir + "points.qml"; | ||
bool success = false; | ||
mPointsLayer->loadNamedStyle( qml, success ); | ||
QVERIFY( success ); | ||
QVERIFY( render( "dpr-normal", 1 ) ); | ||
QVERIFY( render( "dpr-2", 2 ) ); | ||
QVERIFY( render( "dpr-float", 2.5 ) ); | ||
} | ||
|
||
|
||
bool TestQgsMapDevicePixelRatio::render( const QString &testType, float dpr ) | ||
{ | ||
mReport += "<h2>" + testType + "</h2>\n"; | ||
mMapSettings->setOutputSize( QSize( 256, 256 ) ); | ||
mMapSettings->setOutputDpi( 96 ); | ||
mMapSettings->setDevicePixelRatio( dpr ); | ||
mMapSettings->setExtent( QgsRectangle( -105.5, 37, -97.5, 45 ) ); | ||
qDebug() << "scale" << QString::number( mMapSettings->scale(), 'f' ); | ||
QgsRenderChecker checker; | ||
checker.setControlPathPrefix( QStringLiteral( "mapdevicepixelratio" ) ); | ||
checker.setControlName( "expected_" + testType ); | ||
checker.setMapSettings( *mMapSettings ); | ||
bool result = checker.runTest( testType ); | ||
mReport += "\n\n\n" + checker.report(); | ||
return result; | ||
} | ||
|
||
QGSTEST_MAIN( TestQgsMapDevicePixelRatio ) | ||
#include "testqgsmapdevicepixelratio.moc" |
Binary file added
BIN
+68.6 KB
...s/testdata/control_images/mapdevicepixelratio/expected_dpr-2/expected_dpr-2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+105 KB
...ta/control_images/mapdevicepixelratio/expected_dpr-float/expected_dpr-float.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+20.6 KB
.../control_images/mapdevicepixelratio/expected_dpr-normal/expected_dpr-normal.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.