Skip to content
Permalink
Browse files

test for dxf layers parameter

  • Loading branch information
alexbruy committed Nov 2, 2020
1 parent b7997e0 commit 7e798d40b8178ac14f659c9b8f971593b9e81abb
Showing with 44 additions and 1 deletion.
  1. +2 −1 tests/src/analysis/CMakeLists.txt
  2. +42 −0 tests/src/analysis/testqgsprocessing.cpp
@@ -10,6 +10,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src/core
${CMAKE_SOURCE_DIR}/src/core/auth
${CMAKE_SOURCE_DIR}/src/core/expression
${CMAKE_SOURCE_DIR}/src/core/dxf
${CMAKE_SOURCE_DIR}/src/core/geometry
${CMAKE_SOURCE_DIR}/src/core/labeling
${CMAKE_SOURCE_DIR}/src/core/layout
@@ -89,7 +90,7 @@ SET(TESTS
testqgsreclassifyutils.cpp
testqgsalignraster.cpp
testqgsnetworkanalysis.cpp
testqgsninecellfilters.cpp
testqgsninecellfilters.cpp
testqgsmeshcalculator.cpp
testqgsmeshcontours.cpp
testqgstriangulation.cpp
@@ -51,6 +51,7 @@
#include "qgsprocessingparameterfieldmap.h"
#include "qgsprocessingparameteraggregate.h"
#include "qgsprocessingparametertininputlayers.h"
#include "qgsprocessingparameterdxflayers.h"

class DummyAlgorithm : public QgsProcessingAlgorithm
{
@@ -603,6 +604,7 @@ class TestQgsProcessing: public QObject
void parameterFieldMapping();
void parameterAggregate();
void parameterTinInputLayers();
void parameterDxfLayers();
void checkParamValues();
void combineLayerExtent();
void processingFeatureSource();
@@ -8364,6 +8366,46 @@ void TestQgsProcessing::parameterDateTime()
QVERIFY( !fromCode->defaultValue().isValid() );
}

void TestQgsProcessing::parameterDxfLayers()
{
QgsProcessingContext context;
QgsProject project;
context.setProject( &project );
QgsVectorLayer *vectorLayer = new QgsVectorLayer( QStringLiteral( "Point" ),
QStringLiteral( "PointLayer" ),
QStringLiteral( "memory" ) );
project.addMapLayer( vectorLayer );

std::unique_ptr< QgsProcessingParameterDxfLayers > def( new QgsProcessingParameterDxfLayers( "dxf input layer" ) );
QVERIFY( !def->checkValueIsAcceptable( 1 ) );
QVERIFY( !def->checkValueIsAcceptable( "test" ) );
QVERIFY( !def->checkValueIsAcceptable( "" ) );
QVariantList layerList;
QVERIFY( !def->checkValueIsAcceptable( layerList ) );
QVariantMap layerMap;
layerList.append( layerMap );
QVERIFY( !def->checkValueIsAcceptable( layerList ) );
layerMap["layer"] = "layerName";
layerMap["attributeIndex"] = -1;
layerList[0] = layerMap;
QVERIFY( def->checkValueIsAcceptable( layerList ) );
QVERIFY( !def->checkValueIsAcceptable( layerList, &context ) ); //no corresponding layer in the context's project
layerMap["layer"] = "PointLayer";
layerMap["attributeIndex"] = 1; //change for invalid attribute index
layerList[0] = layerMap;
QVERIFY( !def->checkValueIsAcceptable( layerList, &context ) );

layerMap["attributeIndex"] = -1;
layerList[0] = layerMap;
QVERIFY( def->checkValueIsAcceptable( layerList, &context ) );

QString valueAsPythonString = def->valueAsPythonString( layerList, context );
QCOMPARE( valueAsPythonString, QStringLiteral( "[{'layer': '%1','attributeIndex': -1}]" ).arg( vectorLayer->source() ) );

QString pythonCode = def->asPythonString();
QCOMPARE( pythonCode, QStringLiteral( "QgsProcessingParameterDxfLayers('dxf input layer', '')" ) );
}

void TestQgsProcessing::checkParamValues()
{
DummyAlgorithm a( "asd" );

0 comments on commit 7e798d4

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