Add QgsProcessingParameterType tests

This commit is contained in:
Matthias Kuhn 2018-03-05 12:46:38 -05:00 committed by Nyall Dawson
parent eeb6f44df7
commit 542910e9da

View File

@ -20,6 +20,7 @@
#include "qgsprocessingutils.h"
#include "qgsprocessingalgorithm.h"
#include "qgsprocessingcontext.h"
#include "qgsprocessingparametertype.h"
#include "qgsprocessingmodelalgorithm.h"
#include "qgsnativealgorithms.h"
#include <QObject>
@ -380,6 +381,33 @@ class DummyProvider3 : public QgsProcessingProvider
};
class DummyParameterType : public QgsProcessingParameterType
{
// QgsProcessingParameterType interface
public:
QgsProcessingParameterDefinition *create( const QString &name ) const
{
return new QgsProcessingParameterString( name );
}
QString description() const
{
return QStringLiteral( "Description" );
}
QString name() const
{
return QStringLiteral( "ParamType" );
}
QString id() const
{
return QStringLiteral( "paramType" );
}
};
class TestQgsProcessing: public QObject
{
Q_OBJECT
@ -450,6 +478,10 @@ class TestQgsProcessing: public QObject
void stringToPythonLiteral();
void defaultExtensionsForProvider();
void supportsNonFileBasedOutput();
void addParameterType();
void removeParameterType();
void parameterTypes();
void parameterType();
private:
@ -5971,5 +6003,51 @@ void TestQgsProcessing::supportsNonFileBasedOutput()
QVERIFY( !static_cast< const QgsProcessingDestinationParameter * >( alg2.destinationParameterDefinitions().at( 1 ) )->supportsNonFileBasedOutput() );
}
void TestQgsProcessing::addParameterType()
{
QgsProcessingRegistry reg;
QSignalSpy spy( &reg, &QgsProcessingRegistry::parameterTypeAdded );
reg.addParameterType( new DummyParameterType() );
QCOMPARE( spy.count(), 1 );
}
void TestQgsProcessing::removeParameterType()
{
QgsProcessingRegistry reg;
auto paramType = new DummyParameterType();
reg.addParameterType( paramType );
QSignalSpy spy( &reg, &QgsProcessingRegistry::parameterTypeRemoved );
reg.removeParameterType( paramType );
QCOMPARE( spy.count(), 1 );
}
void TestQgsProcessing::parameterTypes()
{
QgsProcessingRegistry reg;
int coreParamCount = reg.parameterTypes().count();
QVERIFY( coreParamCount > 5 );
auto paramType = new DummyParameterType();
reg.addParameterType( paramType );
QCOMPARE( reg.parameterTypes().count(), coreParamCount + 1 );
QVERIFY( reg.parameterTypes().contains( paramType ) );
}
void TestQgsProcessing::parameterType()
{
QgsProcessingRegistry reg;
QVERIFY( reg.parameterType( QStringLiteral( "string" ) ) );
QVERIFY( !reg.parameterType( QStringLiteral( "borken" ) ) );
auto paramType = new DummyParameterType();
reg.addParameterType( paramType );
QCOMPARE( reg.parameterType( QStringLiteral( "paramType" ) ), paramType );
}
QGSTEST_MAIN( TestQgsProcessing )
#include "testqgsprocessing.moc"