Skip to content

Commit

Permalink
Add QgsProcessingParameterType tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn authored and nyalldawson committed Mar 6, 2018
1 parent eeb6f44 commit 542910e
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions tests/src/analysis/testqgsprocessing.cpp
Expand Up @@ -20,6 +20,7 @@
#include "qgsprocessingutils.h"
#include "qgsprocessingalgorithm.h"
#include "qgsprocessingcontext.h"
#include "qgsprocessingparametertype.h"
#include "qgsprocessingmodelalgorithm.h"
#include "qgsnativealgorithms.h"
#include <QObject>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -450,6 +478,10 @@ class TestQgsProcessing: public QObject
void stringToPythonLiteral();
void defaultExtensionsForProvider();
void supportsNonFileBasedOutput();
void addParameterType();
void removeParameterType();
void parameterTypes();
void parameterType();

private:

Expand Down Expand Up @@ -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"

0 comments on commit 542910e

Please sign in to comment.