Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add tests
  • Loading branch information
alexbruy authored and nyalldawson committed Jul 29, 2021
1 parent 7cb631e commit a94ad63
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 5 deletions.
73 changes: 70 additions & 3 deletions tests/src/analysis/testqgsprocessing.cpp
Expand Up @@ -32,6 +32,7 @@
#include "qgstest.h"
#include "qgsrasterlayer.h"
#include "qgsmeshlayer.h"
#include "qgspluginlayer.h"
#include "qgsproject.h"
#include "qgspoint.h"
#include "qgsgeometry.h"
Expand Down Expand Up @@ -533,6 +534,53 @@ class DummyParameterType : public QgsProcessingParameterType
}
};

class DummyPluginLayer: public QgsPluginLayer
{
public:

DummyPluginLayer( const QString &layerType, const QString &layerName ): QgsPluginLayer( layerType, layerName )
{
mValid = true;
};

DummyPluginLayer *clone() const override { return new DummyPluginLayer( "dummylayer", "test" ); };

QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override
{
Q_UNUSED( rendererContext );
return nullptr;
};

bool writeXml( QDomNode &layerNode, QDomDocument &doc, const QgsReadWriteContext &context ) const override
{
Q_UNUSED( layerNode );
Q_UNUSED( doc );
Q_UNUSED( context );
return true;
};
bool readSymbology( const QDomNode &node, QString &errorMessage,
QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) override
{
Q_UNUSED( node );
Q_UNUSED( errorMessage );
Q_UNUSED( context );
Q_UNUSED( categories );
return true;
};
bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
StyleCategories categories = AllStyleCategories ) const override
{
Q_UNUSED( node );
Q_UNUSED( doc );
Q_UNUSED( errorMessage );
Q_UNUSED( context );
Q_UNUSED( categories );
return true;
};

void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override { Q_UNUSED( transformContext ); };
};

class TestQgsProcessing: public QObject
{
Q_OBJECT
Expand Down Expand Up @@ -806,7 +854,11 @@ void TestQgsProcessing::compatibleLayers()
QVERIFY( m1->isValid() );
QgsMeshLayer *m2 = new QgsMeshLayer( fm.filePath(), "mA", "mdal" );
QVERIFY( m2->isValid() );
p.addMapLayers( QList<QgsMapLayer *>() << r1 << r2 << r3 << v1 << v2 << v3 << v4 << m1 << m2 );

DummyPluginLayer *pl1 = new DummyPluginLayer( "dummylayer", "PX" );
DummyPluginLayer *pl2 = new DummyPluginLayer( "dummylayer", "pA" );

p.addMapLayers( QList<QgsMapLayer *>() << r1 << r2 << r3 << v1 << v2 << v3 << v4 << m1 << m2 << pl1 << pl2 );

// compatibleRasterLayers
QVERIFY( QgsProcessingUtils::compatibleRasterLayers( nullptr ).isEmpty() );
Expand Down Expand Up @@ -854,6 +906,21 @@ void TestQgsProcessing::compatibleLayers()
lIds << vl->name();
QCOMPARE( lIds, QStringList() << "V4" << "v1" << "v3" << "vvvv4" );

// compatiblePluginLayers
QVERIFY( QgsProcessingUtils::compatiblePluginLayers( nullptr ).isEmpty() );

// sorted
lIds.clear();
for ( QgsPluginLayer *pl : QgsProcessingUtils::compatiblePluginLayers( &p ) )
lIds << pl->name();
QCOMPARE( lIds, QStringList() << "pA" << "PX" );

// unsorted
lIds.clear();
for ( QgsPluginLayer *pl : QgsProcessingUtils::compatiblePluginLayers( &p, false ) )
lIds << pl->name();
QCOMPARE( lIds, QStringList() << "PX" << "pA" );

// point only
lIds.clear();
for ( QgsVectorLayer *vl : QgsProcessingUtils::compatibleVectorLayers( &p, QList<int>() << QgsProcessing::TypeVectorPoint ) )
Expand Down Expand Up @@ -897,13 +964,13 @@ void TestQgsProcessing::compatibleLayers()
lIds.clear();
for ( QgsMapLayer *l : QgsProcessingUtils::compatibleLayers( &p ) )
lIds << l->name();
QCOMPARE( lIds, QStringList() << "ar2" << "mA" << "MX" << "R1" << "v1" << "v3" << "V4" << "vvvv4" << "zz" );
QCOMPARE( lIds, QStringList() << "ar2" << "mA" << "MX" << "pA" << "PX" << "R1" << "v1" << "v3" << "V4" << "vvvv4" << "zz" );

// unsorted
lIds.clear();
for ( QgsMapLayer *l : QgsProcessingUtils::compatibleLayers( &p, false ) )
lIds << l->name();
QCOMPARE( lIds, QStringList() << "R1" << "ar2" << "zz" << "V4" << "v1" << "v3" << "vvvv4" << "MX" << "mA" );
QCOMPARE( lIds, QStringList() << "R1" << "ar2" << "zz" << "V4" << "v1" << "v3" << "vvvv4" << "MX" << "mA" << "PX" << "pA" );
}

void TestQgsProcessing::encodeDecodeUriProvider()
Expand Down
61 changes: 59 additions & 2 deletions tests/src/gui/testprocessinggui.cpp
Expand Up @@ -95,6 +95,7 @@
#include "qgsprocessingdxflayerswidgetwrapper.h"
#include "qgsprocessingmeshdatasetwidget.h"
#include "qgsabstractdatabaseproviderconnection.h"
#include "qgspluginlayer.h"


class TestParamType : public QgsProcessingParameterDefinition
Expand Down Expand Up @@ -178,6 +179,52 @@ class TestWidgetFactory : public QgsProcessingParameterWidgetFactoryInterface

};

class DummyPluginLayer: public QgsPluginLayer
{
public:

DummyPluginLayer( const QString &layerType, const QString &layerName ): QgsPluginLayer( layerType, layerName )
{
mValid = true;
};

DummyPluginLayer *clone() const override { return new DummyPluginLayer( "dummylayer", "test" ); };

QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override
{
Q_UNUSED( rendererContext );
return nullptr;
};

bool writeXml( QDomNode &layerNode, QDomDocument &doc, const QgsReadWriteContext &context ) const override
{
Q_UNUSED( layerNode );
Q_UNUSED( doc );
Q_UNUSED( context );
return true;
};
bool readSymbology( const QDomNode &node, QString &errorMessage,
QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) override
{
Q_UNUSED( node );
Q_UNUSED( errorMessage );
Q_UNUSED( context );
Q_UNUSED( categories );
return true;
};
bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
StyleCategories categories = AllStyleCategories ) const override
{
Q_UNUSED( node );
Q_UNUSED( doc );
Q_UNUSED( errorMessage );
Q_UNUSED( context );
Q_UNUSED( categories );
return true;
};

void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override { Q_UNUSED( transformContext ); };
};

class TestProcessingGui : public QObject
{
Expand Down Expand Up @@ -3359,6 +3406,8 @@ void TestProcessingGui::testMultipleFileSelectionDialog()
QgsProject::instance()->addMapLayer( mesh );
QgsRasterLayer *raster = new QgsRasterLayer( QStringLiteral( TEST_DATA_DIR ) + "/raster/band1_byte_ct_epsg4326.tif", QStringLiteral( "raster" ) );
QgsProject::instance()->addMapLayer( raster );
DummyPluginLayer *plugin = new DummyPluginLayer( "dummylayer", "plugin" );
QgsProject::instance()->addMapLayer( plugin );

dlg->setProject( QgsProject::instance() );
// should be filtered to raster layers only
Expand Down Expand Up @@ -3412,6 +3461,14 @@ void TestProcessingGui::testMultipleFileSelectionDialog()
QCOMPARE( dlg->mModel->data( dlg->mModel->index( 0, 0 ) ).toString(), QStringLiteral( "mesh" ) );
QCOMPARE( dlg->mModel->data( dlg->mModel->index( 0, 0 ), Qt::UserRole ).toString(), mesh->id() );

// plugin
param = std::make_unique< QgsProcessingParameterMultipleLayers >( QString(), QString(), QgsProcessing::TypePlugin );
dlg = std::make_unique< QgsProcessingMultipleInputPanelWidget >( param.get(), QVariantList(), QList<QgsProcessingModelChildParameterSource >() );
dlg->setProject( QgsProject::instance() );
QCOMPARE( dlg->mModel->rowCount(), 1 );
QCOMPARE( dlg->mModel->data( dlg->mModel->index( 0, 0 ) ).toString(), QStringLiteral( "plugin" ) );
QCOMPARE( dlg->mModel->data( dlg->mModel->index( 0, 0 ), Qt::UserRole ).toString(), plugin->id() );

// vector points
param = std::make_unique< QgsProcessingParameterMultipleLayers >( QString(), QString(), QgsProcessing::TypeVectorPoint );
dlg = std::make_unique< QgsProcessingMultipleInputPanelWidget >( param.get(), QVariantList(), QList<QgsProcessingModelChildParameterSource >() );
Expand Down Expand Up @@ -3450,12 +3507,12 @@ void TestProcessingGui::testMultipleFileSelectionDialog()
param = std::make_unique< QgsProcessingParameterMultipleLayers >( QString(), QString(), QgsProcessing::TypeMapLayer );
dlg = std::make_unique< QgsProcessingMultipleInputPanelWidget >( param.get(), QVariantList(), QList<QgsProcessingModelChildParameterSource >() );
dlg->setProject( QgsProject::instance() );
QCOMPARE( dlg->mModel->rowCount(), 6 );
QCOMPARE( dlg->mModel->rowCount(), 7 );
titles.clear();
for ( int i = 0; i < dlg->mModel->rowCount(); ++i )
titles << dlg->mModel->data( dlg->mModel->index( i, 0 ) ).toString();
QCOMPARE( titles, QSet<QString>() << QStringLiteral( "polygon [EPSG:4326]" ) << QStringLiteral( "point [EPSG:4326]" ) << QStringLiteral( "line [EPSG:4326]" )
<< QStringLiteral( "nogeom" ) << QStringLiteral( "raster [EPSG:4326]" ) << QStringLiteral( "mesh" ) );
<< QStringLiteral( "nogeom" ) << QStringLiteral( "raster [EPSG:4326]" ) << QStringLiteral( "mesh" ) << QStringLiteral( "plugin" ) );

// files
param = std::make_unique< QgsProcessingParameterMultipleLayers >( QString(), QString(), QgsProcessing::TypeFile );
Expand Down

0 comments on commit a94ad63

Please sign in to comment.