mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Add test for QgsExpressionContextScope::takeScopes
This commit is contained in:
parent
abe1a9b661
commit
aaf70de71e
@ -43,6 +43,7 @@ class TestQgsExpressionContext : public QObject
|
||||
void evaluate();
|
||||
void setFeature();
|
||||
void setFields();
|
||||
void takeScopes();
|
||||
|
||||
void globalScope();
|
||||
void projectScope();
|
||||
@ -511,6 +512,36 @@ void TestQgsExpressionContext::setFields()
|
||||
QCOMPARE( contextWithScope.fields().at( 0 ).name(), QString( "testfield" ) );
|
||||
}
|
||||
|
||||
void TestQgsExpressionContext::takeScopes()
|
||||
{
|
||||
QgsExpressionContextUtils::setGlobalVariable( QStringLiteral( "test_global" ), "testval" );
|
||||
|
||||
QgsProject *project = QgsProject::instance();
|
||||
QgsExpressionContextUtils::setProjectVariable( project, QStringLiteral( "test_project" ), "testval" );
|
||||
|
||||
QgsExpressionContext context;
|
||||
|
||||
QgsExpressionContextScope *projectScope = QgsExpressionContextUtils::projectScope( project );
|
||||
|
||||
QgsExpressionContextScope *globalScope = QgsExpressionContextUtils::globalScope();
|
||||
context << globalScope
|
||||
<< projectScope;
|
||||
|
||||
QCOMPARE( context.variable( "test_global" ).toString(), QString( "testval" ) );
|
||||
QCOMPARE( context.variable( "test_project" ).toString(), QString( "testval" ) );
|
||||
|
||||
auto scopes = context.takeScopes();
|
||||
|
||||
QCOMPARE( scopes.length(), 2 );
|
||||
Q_ASSERT( scopes.at( 0 )->hasVariable( "test_global" ) );
|
||||
Q_ASSERT( scopes.at( 1 )->hasVariable( "test_project" ) );
|
||||
|
||||
qDeleteAll( scopes );
|
||||
|
||||
Q_ASSERT( !context.variable( "test_global" ).isValid() );
|
||||
Q_ASSERT( !context.variable( "test_project" ).isValid() );
|
||||
}
|
||||
|
||||
void TestQgsExpressionContext::globalScope()
|
||||
{
|
||||
QgsExpressionContextUtils::setGlobalVariable( QStringLiteral( "test" ), "testval" );
|
||||
|
Loading…
x
Reference in New Issue
Block a user