Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 28, 2020
1 parent ea420df commit 3815438
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/src/analysis/testqgsprocessingalgs.cpp
Expand Up @@ -52,6 +52,7 @@
#include "qgsvectorlayerlabeling.h"
#include "qgsstyle.h"
#include "qgsbookmarkmanager.h"
#include "qgsexpressioncontextutils.h"

class TestQgsProcessingAlgs: public QObject
{
Expand Down Expand Up @@ -129,6 +130,7 @@ class TestQgsProcessingAlgs: public QObject
void conditionalBranch();

void saveLog();
void setProjectVariable();

private:

Expand Down Expand Up @@ -3660,5 +3662,34 @@ void TestQgsProcessingAlgs::saveLog()
QCOMPARE( QString( file2.readAll() ), QStringLiteral( "<span style=\"color:red\">test</span><br/>" ) );
}

void TestQgsProcessingAlgs::setProjectVariable()
{
std::unique_ptr< QgsProcessingAlgorithm > alg( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:setprojectvariable" ) ) );
QVERIFY( alg != nullptr );

QVariantMap parameters;
parameters.insert( QStringLiteral( "NAME" ), QStringLiteral( "my_var" ) );
parameters.insert( QStringLiteral( "VALUE" ), 11 );

bool ok = false;
std::unique_ptr< QgsProcessingContext > context = qgis::make_unique< QgsProcessingContext >();
QgsProject p;
context->setProject( &p );
QgsProcessingFeedback feedback;
QVariantMap results;
results = alg->run( parameters, *context, &feedback, &ok );
QVERIFY( ok );

std::unique_ptr< QgsExpressionContextScope > scope( QgsExpressionContextUtils::projectScope( &p ) );
QCOMPARE( scope->variable( QStringLiteral( "my_var" ) ).toInt(), 11 );

//overwrite existing
parameters.insert( QStringLiteral( "VALUE" ), 13 );
results = alg->run( parameters, *context, &feedback, &ok );
QVERIFY( ok );
scope.reset( QgsExpressionContextUtils::projectScope( &p ) );
QCOMPARE( scope->variable( QStringLiteral( "my_var" ) ).toInt(), 13 );
}

QGSTEST_MAIN( TestQgsProcessingAlgs )
#include "testqgsprocessingalgs.moc"

0 comments on commit 3815438

Please sign in to comment.