Skip to content
Permalink
Browse files

Add test

  • Loading branch information
nyalldawson committed Jun 28, 2020
1 parent ea420df commit 38154380131e3c4cb840cf507d5feee04fbae123
Showing with 31 additions and 0 deletions.
  1. +31 −0 tests/src/analysis/testqgsprocessingalgs.cpp
@@ -52,6 +52,7 @@
#include "qgsvectorlayerlabeling.h"
#include "qgsstyle.h"
#include "qgsbookmarkmanager.h"
#include "qgsexpressioncontextutils.h"

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

void saveLog();
void setProjectVariable();

private:

@@ -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.
You can’t perform that action at this time.