Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent authored and nyalldawson committed Sep 12, 2023
1 parent 8f8cfa9 commit f64b53c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/src/analysis/testqgsprocessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ class TestQgsProcessing: public QObject
void sourceTypeToString();
void formatHelp();
void preprocessParameters();
void guiDefaultParameterValues();

private:

Expand Down Expand Up @@ -12659,5 +12660,26 @@ void TestQgsProcessing::preprocessParameters()
QCOMPARE( outputs.value( QStringLiteral( "DISTANCE" ) ).value< QgsProperty >().expressionString(), QStringLiteral( "A_FIELD * 200" ) );
}

void TestQgsProcessing::guiDefaultParameterValues()
{
DummyAlgorithm alg( "testAlgorithm" );
QgsProcessingParameterNumber *intTestParam = new QgsProcessingParameterNumber( QStringLiteral( "testIntegerParameter" ), QStringLiteral( "A test parameter" ), QgsProcessingParameterNumber::Integer, 10 );
alg.addParameter( intTestParam );
QgsProcessingParameterString *stringTestParam = new QgsProcessingParameterString( QStringLiteral( "testStringParameter" ), QStringLiteral( "A test parameter" ), QStringLiteral( "test, test, test" ) );
alg.addParameter( stringTestParam );

QgsSettings s;
s.setValue( QStringLiteral( "/Processing/DefaultGuiParam/testAlgorithm/testIntegerParameter" ), 42 );
s.setValue( QStringLiteral( "/Processing/DefaultGuiParam/testAlgorithm/testStringParameter" ), QStringLiteral( "defaultString" ) );

QCOMPARE( intTestParam->defaultValueForGui(), 42 );
QCOMPARE( intTestParam->guiDefaultValueOverride(), 42 );
QCOMPARE( stringTestParam->defaultValueForGui(), QStringLiteral( "defaultString" ) );
QCOMPARE( stringTestParam->guiDefaultValueOverride(), QStringLiteral( "defaultString" ) );

s.remove( QStringLiteral( "/Processing/DefaultGuiParam/testAlgorithm/testIntegerParameter" ) );
s.remove( QStringLiteral( "/Processing/DefaultGuiParam/testAlgorithm/testStringParameter" ) );
}

QGSTEST_MAIN( TestQgsProcessing )
#include "testqgsprocessing.moc"

0 comments on commit f64b53c

Please sign in to comment.