Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add test for Create normal raster alg
  • Loading branch information
root676 authored and nyalldawson committed Apr 20, 2020
1 parent c945d97 commit 003ab16
Showing 1 changed file with 97 additions and 0 deletions.
97 changes: 97 additions & 0 deletions tests/src/analysis/testqgsprocessingalgs.cpp
Expand Up @@ -118,6 +118,9 @@ class TestQgsProcessingAlgs: public QObject
void raiseException();
void raiseWarning();

void normalRaster_data();
void normalRaster();

void randomRaster_data();
void randomRaster();

Expand Down Expand Up @@ -3027,6 +3030,100 @@ void TestQgsProcessingAlgs::raiseWarning()
QCOMPARE( feedback.errors, QStringList() << QStringLiteral( "you mighta screwed up boy, but i aint so sure" ) );
}

void TestQgsProcessingAlgs::normalRaster_data()
{
QTest::addColumn<QString>( "inputExtent" );
QTest::addColumn<Qgis::DataType>( "expectedDataType" );
QTest::addColumn<bool>( "succeeds" );
QTest::addColumn<QString>( "crs" );
QTest::addColumn<double>( "pixelSize" );
QTest::addColumn<double>( "mean" );
QTest::addColumn<double>( "stddev" );
QTest::addColumn<int>( "typeId" );

QTest::newRow( "testcase 1" )
<< "-3.000000000,7.000000000,-4.000000000,6.000000000 [EPSG:4326]"
<< Qgis::Float32
<< true
<< "EPSG:4326"
<< 1.0
<< 0.0
<< 12.0
<< 0;


QTest::newRow( "testcase 2" )
<< "-3.000000000,7.000000000,-4.000000000,6.000000000 [EPSG:4326]"
<< Qgis::Float64
<< true
<< "EPSG:4326"
<< 1.0
<< 0.0
<< 1.0
<< 1;
}

void TestQgsProcessingAlgs::normalRaster()
{
//this test only checks if the correct raster data type is chosen
//value by value comparison is not effective for random rasters
QFETCH( QString, inputExtent );
QFETCH( Qgis::DataType, expectedDataType );
QFETCH( bool, succeeds );
QFETCH( QString, crs );
QFETCH( double, pixelSize );
QFETCH( double, mean );
QFETCH( double, stddev );
QFETCH( int, typeId );

//prepare input params
QgsProject p;
std::unique_ptr< QgsProcessingAlgorithm > alg( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:createnormalrasterlayer" ) ) );

QString myDataPath( TEST_DATA_DIR ); //defined in CmakeLists.txt

//set project crs and ellipsoid from input layer
p.setCrs( QgsCoordinateReferenceSystem( crs ), true );

//set project after layer has been added so that transform context/ellipsoid from crs is also set
std::unique_ptr< QgsProcessingContext > context = qgis::make_unique< QgsProcessingContext >();
context->setProject( &p );

QVariantMap parameters;

parameters.insert( QStringLiteral( "EXTENT" ), inputExtent );
parameters.insert( QStringLiteral( "TARGET_CRS" ), QgsCoordinateReferenceSystem( crs ) );
parameters.insert( QStringLiteral( "PIXEL_SIZE" ), pixelSize );
parameters.insert( QStringLiteral( "OUTPUT_TYPE" ), typeId );
parameters.insert( QStringLiteral( "MEAN" ), mean );
parameters.insert( QStringLiteral( "STDDEV" ), stddev );
parameters.insert( QStringLiteral( "OUTPUT" ), QgsProcessing::TEMPORARY_OUTPUT );

bool ok = false;
QgsProcessingFeedback feedback;
QVariantMap results;

if ( !succeeds )
{
//verify if user feedback for unacceptable values are thrown
alg->run( parameters, *context, &feedback, &ok );
QCOMPARE( ok, succeeds );
}
else
{
//run alg...
results = alg->run( parameters, *context, &feedback, &ok );
QVERIFY( ok );

//...and check results with expected datasets
std::unique_ptr<QgsRasterLayer> outputRaster = qgis::make_unique< QgsRasterLayer >( results.value( QStringLiteral( "OUTPUT" ) ).toString(), "output", "gdal" );
std::unique_ptr< QgsRasterInterface > outputInterface( outputRaster->dataProvider()->clone() );

QCOMPARE( outputInterface->dataType( 1 ), expectedDataType );
}

}


void TestQgsProcessingAlgs::randomRaster_data()
{
Expand Down

0 comments on commit 003ab16

Please sign in to comment.