31
#include <qgsrasterlayer.h>
32
#include <qgsrasterbandstats.h>
33
#include <qgsmaplayerregistry.h>
31
#include <qgsrasterlayer.h>
32
#include <qgsrasterbandstats.h>
33
#include <qgsmaplayerregistry.h>
34
34
#include <qgsapplication.h>
35
#include <qgsmaprenderer.h>
35
#include <qgsmaprenderer.h>
37
37
//qgis unit test includes
38
38
#include <qgsrenderchecker.h>
44
44
class Regression992: public QObject
48
48
void initTestCase();// will be called before the first testfunction is executed.
49
49
void cleanupTestCase();// will be called after the last testfunction was executed.
50
void init(){};// will be called before each testfunction is executed.
51
void cleanup(){};// will be called after every testfunction.
50
void init() {};// will be called before each testfunction is executed.
51
void cleanup() {};// will be called after every testfunction.
53
53
void regression992();
55
bool render(QString theFileName);
55
bool render( QString theFileName );
56
56
QString mTestDataDir;
57
57
QgsRasterLayer * mpRasterLayer;
58
58
QgsMapRenderer * mpMapRenderer;
63
63
void Regression992::initTestCase()
65
65
// init QGIS's paths - true means that all path will be inited from prefix
66
QString qgisPath = QCoreApplication::applicationDirPath ();
67
QgsApplication::setPrefixPath(INSTALL_PREFIX, true);
66
QString qgisPath = QCoreApplication::applicationDirPath();
67
QgsApplication::setPrefixPath( INSTALL_PREFIX, true );
68
68
QgsApplication::showSettings();
69
69
//create some objects that will be used in all tests...
70
70
//create a raster layer that will be used in all tests...
71
mTestDataDir = QString(TEST_DATA_DIR) + QDir::separator(); //defined in CMakeLists.txt
71
mTestDataDir = QString( TEST_DATA_DIR ) + QDir::separator(); //defined in CMakeLists.txt
72
72
QString myFileName = mTestDataDir + "rgbwcmyk01_YeGeo.jp2";
73
QFileInfo myRasterFileInfo ( myFileName );
74
mpRasterLayer = new QgsRasterLayer ( myRasterFileInfo.filePath(),
75
myRasterFileInfo.completeBaseName() );
73
QFileInfo myRasterFileInfo( myFileName );
74
mpRasterLayer = new QgsRasterLayer( myRasterFileInfo.filePath(),
75
myRasterFileInfo.completeBaseName() );
76
76
// Register the layer with the registry
77
QgsMapLayerRegistry::instance()->addMapLayer(mpRasterLayer);
77
QgsMapLayerRegistry::instance()->addMapLayer( mpRasterLayer );
78
78
// add the test layer to the maprender
79
79
mpMapRenderer = new QgsMapRenderer();
80
80
QStringList myLayers;
81
myLayers << mpRasterLayer->getLayerID();
82
mpMapRenderer->setLayerSet(myLayers);
81
myLayers << mpRasterLayer->id();
82
mpMapRenderer->setLayerSet( myLayers );
83
83
mReport += "<h1>Regression 992 Test</h1>\n";
84
84
mReport += "<p>See <a href=\"https://trac.osgeo.org/qgis/ticket/992\">"
85
"trac ticket 992</a> for more details.</p>";
85
"trac ticket 992</a> for more details.</p>";
87
87
//runs after all tests
88
88
void Regression992::cleanupTestCase()
90
90
QString myReportFile = QDir::tempPath() + QDir::separator() + "regression992.html";
91
QFile myFile ( myReportFile);
92
if ( myFile.open ( QIODevice::WriteOnly ) )
91
QFile myFile( myReportFile );
92
if ( myFile.open( QIODevice::WriteOnly ) )
94
QTextStream myQTextStream ( &myFile );
94
QTextStream myQTextStream( &myFile );
95
95
myQTextStream << mReport;
97
QDesktopServices::openUrl("file://"+myReportFile);
97
QDesktopServices::openUrl( "file://" + myReportFile );
101
101
void Regression992::regression992()
103
QVERIFY ( mpRasterLayer->isValid() );
104
mpMapRenderer->setExtent(mpRasterLayer->extent());
105
QString myDataDir (TEST_DATA_DIR); //defined in CmakeLists.txt
103
QVERIFY( mpRasterLayer->isValid() );
104
mpMapRenderer->setExtent( mpRasterLayer->extent() );
105
QString myDataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt
106
106
QString myTestDataDir = myDataDir + QDir::separator();
107
107
QgsRenderChecker myChecker;
108
myChecker.setExpectedImage ( myTestDataDir + "expected_rgbwcmyk01_YeGeo.jp2.png" );
109
myChecker.setMapRenderer ( mpMapRenderer );
110
bool myResultFlag = myChecker.runTest("regression992");
108
myChecker.setExpectedImage( myTestDataDir + "expected_rgbwcmyk01_YeGeo.jp2.png" );
109
myChecker.setMapRenderer( mpMapRenderer );
110
bool myResultFlag = myChecker.runTest( "regression992" );
111
111
mReport += "\n\n\n" + myChecker.report();
112
QVERIFY(myResultFlag);
112
QVERIFY( myResultFlag );
115
QTEST_MAIN(Regression992)
115
QTEST_MAIN( Regression992 )
116
116
#include "moc_regression992.cxx"