Skip to content

Commit 6c7eb5b

Browse files
committed
Add some GDAL provider unit tests...
(...doing penance for my 2.8 sins)
1 parent 9490d66 commit 6c7eb5b

File tree

5 files changed

+138
-0
lines changed

5 files changed

+138
-0
lines changed

tests/src/providers/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ ENDMACRO (ADD_QGIS_TEST)
7474
# Tests:
7575

7676
ADD_QGIS_TEST(wcsprovidertest testqgswcsprovider.cpp)
77+
ADD_QGIS_TEST(gdalprovidertest testqgsgdalprovider.cpp)
7778

7879
#############################################################
7980
# WCS public servers test:
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/***************************************************************************
2+
testqgsgdalprovider.cpp
3+
--------------------------------------
4+
Date : March 2015
5+
Copyright : (C) 2015 by Nyall Dawson
6+
Email : nyall.dawson@gmail.com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
#include <QtTest/QtTest>
16+
#include <QObject>
17+
#include <QString>
18+
#include <QStringList>
19+
#include <QObject>
20+
#include <QApplication>
21+
#include <QFileInfo>
22+
#include <QDir>
23+
24+
//qgis includes...
25+
#include <qgis.h>
26+
#include <qgsapplication.h>
27+
#include <qgsproviderregistry.h>
28+
#include <qgsrasterdataprovider.h>
29+
#include <qgsrectangle.h>
30+
31+
/** \ingroup UnitTests
32+
* This is a unit test for the gdal provider
33+
*/
34+
class TestQgsGdalProvider : public QObject
35+
{
36+
Q_OBJECT
37+
38+
private slots:
39+
void initTestCase();// will be called before the first testfunction is executed.
40+
void cleanupTestCase();// will be called after the last testfunction was executed.
41+
void init() {}// will be called before each testfunction is executed.
42+
void cleanup() {}// will be called after every testfunction.
43+
44+
void scaleDataType(); //test resultant data types for int raster with float scale (#11573)
45+
void warpedVrt(); //test loading raster which requires a warped vrt
46+
47+
private:
48+
QString mTestDataDir;
49+
QString mReport;
50+
};
51+
52+
//runs before all tests
53+
void TestQgsGdalProvider::initTestCase()
54+
{
55+
// init QGIS's paths - true means that all path will be inited from prefix
56+
QgsApplication::init();
57+
QgsApplication::initQgis();
58+
59+
mTestDataDir = QString( TEST_DATA_DIR ) + QDir::separator(); //defined in CmakeLists.txt
60+
mReport = "<h1>GDAL Provider Tests</h1>\n";
61+
}
62+
63+
//runs after all tests
64+
void TestQgsGdalProvider::cleanupTestCase()
65+
{
66+
QgsApplication::exitQgis();
67+
QString myReportFile = QDir::tempPath() + QDir::separator() + "qgistest.html";
68+
QFile myFile( myReportFile );
69+
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
70+
{
71+
QTextStream myQTextStream( &myFile );
72+
myQTextStream << mReport;
73+
myFile.close();
74+
}
75+
}
76+
77+
void TestQgsGdalProvider::scaleDataType()
78+
{
79+
QString rasterWithOffset = QString( TEST_DATA_DIR ) + QDir::separator() + "int_raster_with_scale.tif";
80+
QgsDataProvider* provider = QgsProviderRegistry::instance()->provider( "gdal", rasterWithOffset );
81+
QgsRasterDataProvider* rp = dynamic_cast< QgsRasterDataProvider* >( provider );
82+
QVERIFY( rp );
83+
//raster is an integer data type, but has a scale < 1, so data type must be float
84+
QCOMPARE( rp->dataType( 1 ), QGis::Float32 );
85+
QCOMPARE( rp->srcDataType( 1 ), QGis::Float32 );
86+
}
87+
88+
void TestQgsGdalProvider::warpedVrt()
89+
{
90+
QString raster = QString( TEST_DATA_DIR ) + QDir::separator() + "requires_warped_vrt.tif";
91+
QgsDataProvider* provider = QgsProviderRegistry::instance()->provider( "gdal", raster );
92+
QgsRasterDataProvider* rp = dynamic_cast< QgsRasterDataProvider* >( provider );
93+
QVERIFY( rp );
94+
95+
qDebug() << "x min: " << rp->extent().xMinimum();
96+
qDebug() << "x max: " << rp->extent().xMaximum();
97+
qDebug() << "y min: " << rp->extent().yMinimum();
98+
qDebug() << "y max: " << rp->extent().yMaximum();
99+
100+
QVERIFY( qgsDoubleNear( rp->extent().xMinimum(), 2058589, 1 ) );
101+
QVERIFY( qgsDoubleNear( rp->extent().xMaximum(), 3118999, 1 ) );
102+
QVERIFY( qgsDoubleNear( rp->extent().yMinimum(), 2281355, 1 ) );
103+
QVERIFY( qgsDoubleNear( rp->extent().yMaximum(), 3129683, 1 ) );
104+
}
105+
106+
QTEST_MAIN( TestQgsGdalProvider )
107+
#include "testqgsgdalprovider.moc"
1022 Bytes
Binary file not shown.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<PAMDataset>
2+
<Metadata>
3+
<MDI key="AOD Source">MODIS (MOD08_D3)</MDI>
4+
<MDI key="AOD Value">0.069</MDI>
5+
<MDI key="GIPPY Version">1.0.2</MDI>
6+
<MDI key="GIPS Version">0.7.1</MDI>
7+
<MDI key="GIPS-landsat Version">0.9.0</MDI>
8+
</Metadata>
9+
<PAMRasterBand band="1">
10+
<Description>ndvi</Description>
11+
<UnitType>other</UnitType>
12+
<Scale>9.999999747378752e-05</Scale>
13+
<Histograms>
14+
<HistItem>
15+
<HistMin>7091</HistMin>
16+
<HistMax>8573</HistMax>
17+
<BucketCount>2</BucketCount>
18+
<IncludeOutOfRange>0</IncludeOutOfRange>
19+
<Approximate>0</Approximate>
20+
<HistCounts>23|33</HistCounts>
21+
</HistItem>
22+
</Histograms>
23+
<Metadata>
24+
<MDI key="STATISTICS_MAXIMUM">8326</MDI>
25+
<MDI key="STATISTICS_MEAN">7873.3214285714</MDI>
26+
<MDI key="STATISTICS_MINIMUM">7338</MDI>
27+
<MDI key="STATISTICS_STDDEV">261.16183455194</MDI>
28+
</Metadata>
29+
</PAMRasterBand>
30+
</PAMDataset>
978 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)