Skip to content
Permalink
Browse files

Add QgsProcessingParameterType tests

  • Loading branch information
m-kuhn authored and nyalldawson committed Mar 5, 2018
1 parent eeb6f44 commit 542910e9dabc24565f3ce670f0fdbf0b5152b775
Showing with 78 additions and 0 deletions.
  1. +78 −0 tests/src/analysis/testqgsprocessing.cpp
@@ -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"

0 comments on commit 542910e

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