Skip to content

Commit

Permalink
add test for world file creation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy authored and nyalldawson committed Sep 29, 2023
1 parent 6efed1d commit 6a563f8
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/src/app/testqgsgeoreferencer.cpp
Expand Up @@ -51,6 +51,7 @@ class TestQgsGeoreferencer : public QObject
void testListModel();
void testListModelCrs();
void testGdalCommands();
void testWorldFile();

private:
QgisApp *mQgisApp = nullptr;
Expand Down Expand Up @@ -876,5 +877,34 @@ void TestQgsGeoreferencer::testGdalCommands()
QStringLiteral( TEST_DATA_DIR ) + QStringLiteral( "/landsat.tif" ) ) );
}

void TestQgsGeoreferencer::testWorldFile()
{
QgsGeoreferencerMainWindow window;
window.openLayer( Qgis::LayerType::Raster, QStringLiteral( TEST_DATA_DIR ) + QStringLiteral( "/landsat.tif" ) );
QString worldFileName = QStringLiteral( TEST_DATA_DIR ) + QStringLiteral( "/landsat.wld" );

QVERIFY( window.writeWorldFile( QgsPointXY( 0, 0 ), 1.0, 1.0, 0 ) );

QFile file( worldFileName );
QVERIFY( file.open( QIODevice::ReadOnly | QIODevice::Text ) );

QTextStream stream( &file );
QVector<double> values;
values.reserve( 6 );
while ( !stream.atEnd() )
{
values << stream.readLine().toDouble();
}
file.close();
QFile::remove( worldFileName );

QCOMPARE( values.at( 0 ), 1.0 );
QCOMPARE( values.at( 1 ), 0 );
QCOMPARE( values.at( 2 ), 0 );
QCOMPARE( values.at( 3 ), -1.0 );
QCOMPARE( values.at( 4 ), 0.5 ); // center of the origin pixel
QCOMPARE( values.at( 5 ), -0.5 );
}

QGSTEST_MAIN( TestQgsGeoreferencer )
#include "testqgsgeoreferencer.moc"

0 comments on commit 6a563f8

Please sign in to comment.