Skip to content

Commit

Permalink
add test for createMultiBandRaster
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed May 23, 2017
1 parent fa6b5b0 commit ca7cd63
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/src/core/testqgsrasterfilewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class TestQgsRasterFileWriter: public QObject

void writeTest();
void testCreateOneBandRaster();
void testCreateMultiBandRaster();
private:
bool writeTest( const QString &rasterName );
void log( const QString &msg );
Expand Down Expand Up @@ -211,6 +212,63 @@ void TestQgsRasterFileWriter::testCreateOneBandRaster()
delete rlayer;
}

void TestQgsRasterFileWriter::testCreateMultiBandRaster()
{
// generate unique filename (need to open the file first to generate it)
QTemporaryFile tmpFile;
tmpFile.open();
tmpFile.close();
QString filename = tmpFile.fileName();

QgsRectangle extent( 106.7, -6.2, 106.9, -6.1 );
int width = 200, height = 100, nBands = 1;

QgsRasterFileWriter writer( filename );
QgsRasterDataProvider *dp = writer.createMultiBandRaster( Qgis::Byte, width, height, extent, QgsCoordinateReferenceSystem( "EPSG:4326" ), nBands );
QVERIFY( dp );
QCOMPARE( dp->xSize(), width );
QCOMPARE( dp->ySize(), height );
QCOMPARE( dp->extent(), extent );
QCOMPARE( dp->bandCount(), 1 );
QCOMPARE( dp->dataType( 1 ), Qgis::Byte );
QVERIFY( dp->isEditable() );
delete dp;

QgsRasterLayer *rlayer = new QgsRasterLayer( filename, "tmp", "gdal" );
QVERIFY( rlayer->isValid() );
QCOMPARE( rlayer->width(), width );
QCOMPARE( rlayer->height(), height );
QCOMPARE( rlayer->extent(), extent );
QCOMPARE( rlayer->bandCount(), 1 );
QCOMPARE( rlayer->dataProvider()->dataType( 1 ), Qgis::Byte );
delete rlayer;

nBands = 3;
dp = writer.createMultiBandRaster( Qgis::Byte, width, height, extent, QgsCoordinateReferenceSystem( "EPSG:4326" ), nBands );
QVERIFY( dp );
QCOMPARE( dp->xSize(), width );
QCOMPARE( dp->ySize(), height );
QCOMPARE( dp->extent(), extent );
QCOMPARE( dp->bandCount(), nBands );
for ( int i = 1; i <= nBands; i++ )
{
QCOMPARE( dp->dataType( i ), Qgis::Byte );
}
QVERIFY( dp->isEditable() );
delete dp;

rlayer = new QgsRasterLayer( filename, "tmp", "gdal" );
QVERIFY( rlayer->isValid() );
QCOMPARE( rlayer->width(), width );
QCOMPARE( rlayer->height(), height );
QCOMPARE( rlayer->extent(), extent );
QCOMPARE( rlayer->bandCount(), nBands );
for ( int i = 1; i <= nBands; i++ )
{
QCOMPARE( rlayer->dataProvider()->dataType( i ), Qgis::Byte );
}
delete rlayer;
}

void TestQgsRasterFileWriter::log( const QString &msg )
{
Expand Down

0 comments on commit ca7cd63

Please sign in to comment.