Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
domi4484 committed Nov 29, 2021
1 parent e1cfb4e commit 013613e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/src/core/testqgsvectorlayer.cpp
Expand Up @@ -79,6 +79,7 @@ class TestQgsVectorLayer : public QObject
void testAddTopologicalPoints();
void testCopyPasteFieldConfiguration();
void testCopyPasteFieldConfiguration_data();
void testFieldExpression();
};

void TestQgsVectorLayer::initTestCase()
Expand Down Expand Up @@ -470,5 +471,16 @@ void TestQgsVectorLayer::testCopyPasteFieldConfiguration()
QCOMPARE( layer3.fieldConfigurationFlags( 0 ), categories.testFlag( QgsMapLayer::Fields ) ? QgsField::ConfigurationFlag::NotSearchable : QgsField::ConfigurationFlags() );
}

void TestQgsVectorLayer::testFieldExpression()
{
QgsVectorLayer layer1( QStringLiteral( "Point?field=name:string" ), QStringLiteral( "layer1" ), QStringLiteral( "memory" ) );
QVERIFY( layer1.isValid() );

layer1.addExpressionField( QStringLiteral( "'abc'" ), QgsField( QStringLiteral( "virtual_field" ), QVariant::String ) );

QCOMPARE( layer1.expressionField( layer1.fields().lookupField( QStringLiteral( "virtual_field" ) ) ), QStringLiteral( "'abc'" ) );
QCOMPARE( layer1.expressionField( layer1.fields().lookupField( QStringLiteral( "name" ) ) ), QString() );
}

QGSTEST_MAIN( TestQgsVectorLayer )
#include "testqgsvectorlayer.moc"

0 comments on commit 013613e

Please sign in to comment.