Skip to content

Commit

Permalink
test for dxf layers parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Nov 2, 2020
1 parent b7997e0 commit 7e798d4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tests/src/analysis/CMakeLists.txt
Expand Up @@ -10,6 +10,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src/core ${CMAKE_SOURCE_DIR}/src/core
${CMAKE_SOURCE_DIR}/src/core/auth ${CMAKE_SOURCE_DIR}/src/core/auth
${CMAKE_SOURCE_DIR}/src/core/expression ${CMAKE_SOURCE_DIR}/src/core/expression
${CMAKE_SOURCE_DIR}/src/core/dxf
${CMAKE_SOURCE_DIR}/src/core/geometry ${CMAKE_SOURCE_DIR}/src/core/geometry
${CMAKE_SOURCE_DIR}/src/core/labeling ${CMAKE_SOURCE_DIR}/src/core/labeling
${CMAKE_SOURCE_DIR}/src/core/layout ${CMAKE_SOURCE_DIR}/src/core/layout
Expand Down Expand Up @@ -89,7 +90,7 @@ SET(TESTS
testqgsreclassifyutils.cpp testqgsreclassifyutils.cpp
testqgsalignraster.cpp testqgsalignraster.cpp
testqgsnetworkanalysis.cpp testqgsnetworkanalysis.cpp
testqgsninecellfilters.cpp testqgsninecellfilters.cpp
testqgsmeshcalculator.cpp testqgsmeshcalculator.cpp
testqgsmeshcontours.cpp testqgsmeshcontours.cpp
testqgstriangulation.cpp testqgstriangulation.cpp
Expand Down
42 changes: 42 additions & 0 deletions tests/src/analysis/testqgsprocessing.cpp
Expand Up @@ -51,6 +51,7 @@
#include "qgsprocessingparameterfieldmap.h" #include "qgsprocessingparameterfieldmap.h"
#include "qgsprocessingparameteraggregate.h" #include "qgsprocessingparameteraggregate.h"
#include "qgsprocessingparametertininputlayers.h" #include "qgsprocessingparametertininputlayers.h"
#include "qgsprocessingparameterdxflayers.h"


class DummyAlgorithm : public QgsProcessingAlgorithm class DummyAlgorithm : public QgsProcessingAlgorithm
{ {
Expand Down Expand Up @@ -603,6 +604,7 @@ class TestQgsProcessing: public QObject
void parameterFieldMapping(); void parameterFieldMapping();
void parameterAggregate(); void parameterAggregate();
void parameterTinInputLayers(); void parameterTinInputLayers();
void parameterDxfLayers();
void checkParamValues(); void checkParamValues();
void combineLayerExtent(); void combineLayerExtent();
void processingFeatureSource(); void processingFeatureSource();
Expand Down Expand Up @@ -8364,6 +8366,46 @@ void TestQgsProcessing::parameterDateTime()
QVERIFY( !fromCode->defaultValue().isValid() ); 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() void TestQgsProcessing::checkParamValues()
{ {
DummyAlgorithm a( "asd" ); DummyAlgorithm a( "asd" );
Expand Down

0 comments on commit 7e798d4

Please sign in to comment.