Skip to content
Permalink
Browse files

[processing] More stringent testing of parameter validity

- Check static QgsProperty parameter values
- Properly check QgsProcessingFeatureSourceDefinition and
QgsProcessingOutputLayerDefinition values
  • Loading branch information
nyalldawson committed Apr 27, 2018
1 parent e25fd4c commit c314639e007ccdf3d0a45e8887611564724aa49d
Showing with 86 additions and 9 deletions.
  1. +67 −9 src/core/processing/qgsprocessingparameters.cpp
  2. +19 −0 tests/src/analysis/testqgsprocessing.cpp
@@ -2582,14 +2582,24 @@ QgsProcessingParameterDefinition *QgsProcessingParameterVectorLayer::clone() con
return new QgsProcessingParameterVectorLayer( *this );
}

bool QgsProcessingParameterVectorLayer::checkValueIsAcceptable( const QVariant &var, QgsProcessingContext *context ) const
bool QgsProcessingParameterVectorLayer::checkValueIsAcceptable( const QVariant &v, QgsProcessingContext *context ) const
{
if ( !var.isValid() )
if ( !v.isValid() )
return mFlags & FlagOptional;

QVariant var = v;

if ( var.canConvert<QgsProperty>() )
{
return true;
QgsProperty p = var.value< QgsProperty >();
if ( p.propertyType() == QgsProperty::StaticProperty )
{
var = p.staticValue();
}
else
{
return true;
}
}

if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( var ) ) )
@@ -2899,7 +2909,15 @@ bool QgsProcessingParameterFeatureSource::checkValueIsAcceptable( const QVariant

if ( var.canConvert<QgsProperty>() )
{
return true;
QgsProperty p = var.value< QgsProperty >();
if ( p.propertyType() == QgsProperty::StaticProperty )
{
var = p.staticValue();
}
else
{
return true;
}
}
if ( qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( input ) ) )
{
@@ -3081,7 +3099,15 @@ bool QgsProcessingParameterFeatureSink::checkValueIsAcceptable( const QVariant &

if ( var.canConvert<QgsProperty>() )
{
return true;
QgsProperty p = var.value< QgsProperty >();
if ( p.propertyType() == QgsProperty::StaticProperty )
{
var = p.staticValue();
}
else
{
return true;
}
}

if ( var.type() != QVariant::String )
@@ -3274,7 +3300,15 @@ bool QgsProcessingParameterRasterDestination::checkValueIsAcceptable( const QVar

if ( var.canConvert<QgsProperty>() )
{
return true;
QgsProperty p = var.value< QgsProperty >();
if ( p.propertyType() == QgsProperty::StaticProperty )
{
var = p.staticValue();
}
else
{
return true;
}
}

if ( var.type() != QVariant::String )
@@ -3357,7 +3391,15 @@ bool QgsProcessingParameterFileDestination::checkValueIsAcceptable( const QVaria

if ( var.canConvert<QgsProperty>() )
{
return true;
QgsProperty p = var.value< QgsProperty >();
if ( p.propertyType() == QgsProperty::StaticProperty )
{
var = p.staticValue();
}
else
{
return true;
}
}

if ( var.type() != QVariant::String )
@@ -3465,7 +3507,15 @@ bool QgsProcessingParameterFolderDestination::checkValueIsAcceptable( const QVar

if ( var.canConvert<QgsProperty>() )
{
return true;
QgsProperty p = var.value< QgsProperty >();
if ( p.propertyType() == QgsProperty::StaticProperty )
{
var = p.staticValue();
}
else
{
return true;
}
}

if ( var.type() != QVariant::String )
@@ -3555,7 +3605,15 @@ bool QgsProcessingParameterVectorDestination::checkValueIsAcceptable( const QVar

if ( var.canConvert<QgsProperty>() )
{
return true;
QgsProperty p = var.value< QgsProperty >();
if ( p.propertyType() == QgsProperty::StaticProperty )
{
var = p.staticValue();
}
else
{
return true;
}
}

if ( var.type() != QVariant::String )
@@ -4006,6 +4006,8 @@ void TestQgsProcessing::parameterVectorLayer()
QVERIFY( !def->checkValueIsAcceptable( QgsProcessingFeatureSourceDefinition( "layer1231123" ) ) );
QVERIFY( def->checkValueIsAcceptable( QVariant::fromValue( v1 ) ) );
QVERIFY( !def->checkValueIsAcceptable( QVariant::fromValue( r1 ) ) );
QVERIFY( def->checkValueIsAcceptable( QgsProperty::fromValue( QStringLiteral( "layer12312312" ) ) ) );
QVERIFY( !def->checkValueIsAcceptable( QgsProperty::fromValue( QString() ) ) );

// should be OK
QVERIFY( def->checkValueIsAcceptable( "c:/Users/admin/Desktop/roads_clipped_transformed_v1_reprojected_final_clipped_aAAA.shp" ) );
@@ -4114,8 +4116,11 @@ void TestQgsProcessing::parameterFeatureSource()
QVERIFY( !def->checkValueIsAcceptable( "" ) );
QVERIFY( !def->checkValueIsAcceptable( QVariant() ) );
QVERIFY( def->checkValueIsAcceptable( QgsProcessingFeatureSourceDefinition( "layer1231123" ) ) );
QVERIFY( !def->checkValueIsAcceptable( QgsProcessingFeatureSourceDefinition( "" ) ) );
QVERIFY( def->checkValueIsAcceptable( QVariant::fromValue( v1 ) ) );
QVERIFY( !def->checkValueIsAcceptable( QVariant::fromValue( r1 ) ) );
QVERIFY( def->checkValueIsAcceptable( QgsProperty::fromValue( QStringLiteral( "layer12312312" ) ) ) );
QVERIFY( !def->checkValueIsAcceptable( QgsProperty::fromValue( QString() ) ) );

// should be OK
QVERIFY( def->checkValueIsAcceptable( "c:/Users/admin/Desktop/roads_clipped_transformed_v1_reprojected_final_clipped_aAAA.shp" ) );
@@ -4252,6 +4257,9 @@ void TestQgsProcessing::parameterFeatureSink()
QVERIFY( !def->checkValueIsAcceptable( "" ) );
QVERIFY( !def->checkValueIsAcceptable( QVariant() ) );
QVERIFY( def->checkValueIsAcceptable( QgsProcessingOutputLayerDefinition( "layer1231123" ) ) );
QVERIFY( !def->checkValueIsAcceptable( QgsProcessingOutputLayerDefinition( "" ) ) );
QVERIFY( def->checkValueIsAcceptable( QgsProperty::fromValue( QStringLiteral( "layer12312312" ) ) ) );
QVERIFY( !def->checkValueIsAcceptable( QgsProperty::fromValue( QString() ) ) );

// should be OK with or without context - it's an output layer!
QVERIFY( def->checkValueIsAcceptable( "c:/Users/admin/Desktop/roads_clipped_transformed_v1_reprojected_final_clipped_aAAA.shp" ) );
@@ -4376,6 +4384,9 @@ void TestQgsProcessing::parameterVectorOut()
QVERIFY( !def->checkValueIsAcceptable( "" ) );
QVERIFY( !def->checkValueIsAcceptable( QVariant() ) );
QVERIFY( def->checkValueIsAcceptable( QgsProcessingOutputLayerDefinition( "layer1231123" ) ) );
QVERIFY( !def->checkValueIsAcceptable( QgsProcessingOutputLayerDefinition( "" ) ) );
QVERIFY( def->checkValueIsAcceptable( QgsProperty::fromValue( QStringLiteral( "layer1231123" ) ) ) );
QVERIFY( !def->checkValueIsAcceptable( QgsProperty::fromValue( QString() ) ) );

// should be OK with or without context - it's an output layer!
QVERIFY( def->checkValueIsAcceptable( "c:/Users/admin/Desktop/roads_clipped_transformed_v1_reprojected_final_clipped_aAAA.shp" ) );
@@ -4478,6 +4489,9 @@ void TestQgsProcessing::parameterRasterOut()
QVERIFY( !def->checkValueIsAcceptable( "" ) );
QVERIFY( !def->checkValueIsAcceptable( QVariant() ) );
QVERIFY( def->checkValueIsAcceptable( QgsProcessingOutputLayerDefinition( "layer1231123" ) ) );
QVERIFY( !def->checkValueIsAcceptable( QgsProcessingOutputLayerDefinition( "" ) ) );
QVERIFY( def->checkValueIsAcceptable( QgsProperty::fromValue( QStringLiteral( "layer12312312" ) ) ) );
QVERIFY( !def->checkValueIsAcceptable( QgsProperty::fromValue( QString() ) ) );

// should be OK with or without context - it's an output layer!
QVERIFY( def->checkValueIsAcceptable( "c:/Users/admin/Desktop/roads_clipped_transformed_v1_reprojected_final_clipped_aAAA.tif" ) );
@@ -4601,6 +4615,9 @@ void TestQgsProcessing::parameterFileOut()
QVERIFY( !def->checkValueIsAcceptable( "" ) );
QVERIFY( !def->checkValueIsAcceptable( QVariant() ) );
QVERIFY( def->checkValueIsAcceptable( QgsProcessingOutputLayerDefinition( "layer1231123" ) ) );
QVERIFY( !def->checkValueIsAcceptable( QgsProcessingOutputLayerDefinition( "" ) ) );
QVERIFY( def->checkValueIsAcceptable( QgsProperty::fromValue( QStringLiteral( "layer12312312" ) ) ) );
QVERIFY( !def->checkValueIsAcceptable( QgsProperty::fromValue( QString() ) ) );

// should be OK with or without context - it's an output file!
QVERIFY( def->checkValueIsAcceptable( "c:/Users/admin/Desktop/roads_clipped_transformed_v1_reprojected_final_clipped_aAAA.txt" ) );
@@ -4694,6 +4711,8 @@ void TestQgsProcessing::parameterFolderOut()
QVERIFY( def->checkValueIsAcceptable( "asdasd" ) );
QVERIFY( !def->checkValueIsAcceptable( "" ) );
QVERIFY( !def->checkValueIsAcceptable( QVariant() ) );
QVERIFY( def->checkValueIsAcceptable( QgsProperty::fromValue( QStringLiteral( "asdasdas" ) ) ) );
QVERIFY( !def->checkValueIsAcceptable( QgsProperty::fromValue( QString() ) ) );

// should be OK with or without context - it's an output folder!
QVERIFY( def->checkValueIsAcceptable( "c:/Users/admin/Desktop/" ) );

0 comments on commit c314639

Please sign in to comment.
You can’t perform that action at this time.