Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some GDAL provider unit tests...
(...doing penance for my 2.8 sins)
- Loading branch information
1 parent
9490d66
commit 6c7eb5b
Showing
5 changed files
with
138 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/*************************************************************************** | ||
testqgsgdalprovider.cpp | ||
-------------------------------------- | ||
Date : March 2015 | ||
Copyright : (C) 2015 by Nyall Dawson | ||
Email : nyall.dawson@gmail.com | ||
*************************************************************************** | ||
* * | ||
* 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 <QtTest/QtTest> | ||
#include <QObject> | ||
#include <QString> | ||
#include <QStringList> | ||
#include <QObject> | ||
#include <QApplication> | ||
#include <QFileInfo> | ||
#include <QDir> | ||
|
||
//qgis includes... | ||
#include <qgis.h> | ||
#include <qgsapplication.h> | ||
#include <qgsproviderregistry.h> | ||
#include <qgsrasterdataprovider.h> | ||
#include <qgsrectangle.h> | ||
|
||
/** \ingroup UnitTests | ||
* This is a unit test for the gdal provider | ||
*/ | ||
class TestQgsGdalProvider : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
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 scaleDataType(); //test resultant data types for int raster with float scale (#11573) | ||
void warpedVrt(); //test loading raster which requires a warped vrt | ||
|
||
private: | ||
QString mTestDataDir; | ||
QString mReport; | ||
}; | ||
|
||
//runs before all tests | ||
void TestQgsGdalProvider::initTestCase() | ||
{ | ||
// init QGIS's paths - true means that all path will be inited from prefix | ||
QgsApplication::init(); | ||
QgsApplication::initQgis(); | ||
|
||
mTestDataDir = QString( TEST_DATA_DIR ) + QDir::separator(); //defined in CmakeLists.txt | ||
mReport = "<h1>GDAL Provider Tests</h1>\n"; | ||
} | ||
|
||
//runs after all tests | ||
void TestQgsGdalProvider::cleanupTestCase() | ||
{ | ||
QgsApplication::exitQgis(); | ||
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 TestQgsGdalProvider::scaleDataType() | ||
{ | ||
QString rasterWithOffset = QString( TEST_DATA_DIR ) + QDir::separator() + "int_raster_with_scale.tif"; | ||
QgsDataProvider* provider = QgsProviderRegistry::instance()->provider( "gdal", rasterWithOffset ); | ||
QgsRasterDataProvider* rp = dynamic_cast< QgsRasterDataProvider* >( provider ); | ||
QVERIFY( rp ); | ||
//raster is an integer data type, but has a scale < 1, so data type must be float | ||
QCOMPARE( rp->dataType( 1 ), QGis::Float32 ); | ||
QCOMPARE( rp->srcDataType( 1 ), QGis::Float32 ); | ||
} | ||
|
||
void TestQgsGdalProvider::warpedVrt() | ||
{ | ||
QString raster = QString( TEST_DATA_DIR ) + QDir::separator() + "requires_warped_vrt.tif"; | ||
QgsDataProvider* provider = QgsProviderRegistry::instance()->provider( "gdal", raster ); | ||
QgsRasterDataProvider* rp = dynamic_cast< QgsRasterDataProvider* >( provider ); | ||
QVERIFY( rp ); | ||
|
||
qDebug() << "x min: " << rp->extent().xMinimum(); | ||
qDebug() << "x max: " << rp->extent().xMaximum(); | ||
qDebug() << "y min: " << rp->extent().yMinimum(); | ||
qDebug() << "y max: " << rp->extent().yMaximum(); | ||
|
||
QVERIFY( qgsDoubleNear( rp->extent().xMinimum(), 2058589, 1 ) ); | ||
QVERIFY( qgsDoubleNear( rp->extent().xMaximum(), 3118999, 1 ) ); | ||
QVERIFY( qgsDoubleNear( rp->extent().yMinimum(), 2281355, 1 ) ); | ||
QVERIFY( qgsDoubleNear( rp->extent().yMaximum(), 3129683, 1 ) ); | ||
} | ||
|
||
QTEST_MAIN( TestQgsGdalProvider ) | ||
#include "testqgsgdalprovider.moc" |
Binary file not shown.
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,30 @@ | ||
<PAMDataset> | ||
<Metadata> | ||
<MDI key="AOD Source">MODIS (MOD08_D3)</MDI> | ||
<MDI key="AOD Value">0.069</MDI> | ||
<MDI key="GIPPY Version">1.0.2</MDI> | ||
<MDI key="GIPS Version">0.7.1</MDI> | ||
<MDI key="GIPS-landsat Version">0.9.0</MDI> | ||
</Metadata> | ||
<PAMRasterBand band="1"> | ||
<Description>ndvi</Description> | ||
<UnitType>other</UnitType> | ||
<Scale>9.999999747378752e-05</Scale> | ||
<Histograms> | ||
<HistItem> | ||
<HistMin>7091</HistMin> | ||
<HistMax>8573</HistMax> | ||
<BucketCount>2</BucketCount> | ||
<IncludeOutOfRange>0</IncludeOutOfRange> | ||
<Approximate>0</Approximate> | ||
<HistCounts>23|33</HistCounts> | ||
</HistItem> | ||
</Histograms> | ||
<Metadata> | ||
<MDI key="STATISTICS_MAXIMUM">8326</MDI> | ||
<MDI key="STATISTICS_MEAN">7873.3214285714</MDI> | ||
<MDI key="STATISTICS_MINIMUM">7338</MDI> | ||
<MDI key="STATISTICS_STDDEV">261.16183455194</MDI> | ||
</Metadata> | ||
</PAMRasterBand> | ||
</PAMDataset> |
Binary file not shown.