Skip to content

Commit

Permalink
Also add test evaluating a function which references a layer from dif…
Browse files Browse the repository at this point in the history
…ferent threads
  • Loading branch information
nyalldawson committed Dec 15, 2022
1 parent 95f0325 commit c41b7f1
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/src/core/testqgsexpression.cpp
Expand Up @@ -4644,12 +4644,18 @@ class TestQgsExpression: public QObject
QCOMPARE( res, mPointsLayer );
QVERIFY( !exp.hasEvalError() );

exp = QgsExpression( QStringLiteral( "layer_property('%1', 'id')" ).arg( pointsLayerId ) );
QCOMPARE( exp.evaluate( &context ).toString(), pointsLayerId );

// with layer name
exp = QgsExpression();
res = QgsExpressionUtils::getMapLayer( pointsLayerName, &context, &exp );
QCOMPARE( res, mPointsLayer );
QVERIFY( !exp.hasEvalError() );

exp = QgsExpression( QStringLiteral( "layer_property('%1', 'id')" ).arg( pointsLayerName ) );
QCOMPARE( exp.evaluate( &context ).toString(), pointsLayerId );

// with string which is neither id or name
exp = QgsExpression();
res = QgsExpressionUtils::getMapLayer( QStringLiteral( "xxxA" ), &context, &exp );
Expand All @@ -4673,16 +4679,25 @@ class TestQgsExpression: public QObject
QCOMPARE( res, layer1 );
QVERIFY( !exp.hasEvalError() );

exp = QgsExpression( QStringLiteral( "layer_property('%1', 'id')" ).arg( layer1->id() ) );
QCOMPARE( exp.evaluate( &context ).toString(), layer1->id() );

exp = QgsExpression();
res = QgsExpressionUtils::getMapLayer( layer2->id(), &context, &exp );
QCOMPARE( res, layer2 );
QVERIFY( !exp.hasEvalError() );

exp = QgsExpression( QStringLiteral( "layer_property('%1', 'id')" ).arg( layer2->id() ) );
QCOMPARE( exp.evaluate( &context ).toString(), layer2->id() );

exp = QgsExpression();
res = QgsExpressionUtils::getMapLayer( pointsLayerId, &context, &exp );
QCOMPARE( res, mPointsLayer );
QVERIFY( !exp.hasEvalError() );

exp = QgsExpression( QStringLiteral( "layer_property('%1', 'id')" ).arg( pointsLayerId ) );
QCOMPARE( exp.evaluate( &context ).toString(), pointsLayerId );

// with a second store in a different scope
QgsExpressionContextScope *scope2 = new QgsExpressionContextScope();

Expand All @@ -4698,6 +4713,9 @@ class TestQgsExpression: public QObject
QCOMPARE( res, layer3 );
QVERIFY( !exp.hasEvalError() );

exp = QgsExpression( QStringLiteral( "layer_property('%1', 'id')" ).arg( layer3->id() ) );
QCOMPARE( exp.evaluate( &context ).toString(), layer3->id() );


// from layer store, by name

Expand All @@ -4706,21 +4724,33 @@ class TestQgsExpression: public QObject
QCOMPARE( res, layer1 );
QVERIFY( !exp.hasEvalError() );

exp = QgsExpression( QStringLiteral( "layer_property('%1', 'id')" ).arg( layer1->name() ) );
QCOMPARE( exp.evaluate( &context ).toString(), layer1->id() );

exp = QgsExpression();
res = QgsExpressionUtils::getMapLayer( layer2->name(), &context, &exp );
QCOMPARE( res, layer2 );
QVERIFY( !exp.hasEvalError() );

exp = QgsExpression( QStringLiteral( "layer_property('%1', 'id')" ).arg( layer2->name() ) );
QCOMPARE( exp.evaluate( &context ).toString(), layer2->id() );

exp = QgsExpression();
res = QgsExpressionUtils::getMapLayer( layer3->name(), &context, &exp );
QCOMPARE( res, layer3 );
QVERIFY( !exp.hasEvalError() );

exp = QgsExpression( QStringLiteral( "layer_property('%1', 'id')" ).arg( layer3->name() ) );
QCOMPARE( exp.evaluate( &context ).toString(), layer3->id() );

exp = QgsExpression();
res = QgsExpressionUtils::getMapLayer( pointsLayerName, &context, &exp );
QCOMPARE( res, mPointsLayer );
QVERIFY( !exp.hasEvalError() );

exp = QgsExpression( QStringLiteral( "layer_property('%1', 'id')" ).arg( pointsLayerName ) );
QCOMPARE( exp.evaluate( &context ).toString(), pointsLayerId );

#if 0
// TODO -- probably should flag an error here?
QVERIFY( !exp.hasEvalError() );
Expand Down

0 comments on commit c41b7f1

Please sign in to comment.