Skip to content

Commit 5e7719c

Browse files
committed
Tests for fieldNamesToIndices() and indicesToFields()
1 parent 091ed91 commit 5e7719c

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/src/analysis/testqgsprocessing.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,8 @@ class TestQgsProcessing: public QObject
482482
void convertCompatible();
483483
void create();
484484
void combineFields();
485+
void fieldNamesToIndices();
486+
void indicesToFields();
485487
void stringToPythonLiteral();
486488
void defaultExtensionsForProvider();
487489
void supportsNonFileBasedOutput();
@@ -6165,6 +6167,45 @@ void TestQgsProcessing::combineFields()
61656167
QCOMPARE( res.at( 3 ).name(), QStringLiteral( "new_2" ) );
61666168
}
61676169

6170+
void TestQgsProcessing::fieldNamesToIndices()
6171+
{
6172+
QgsFields fields;
6173+
fields.append( QgsField( "name" ) );
6174+
fields.append( QgsField( "address" ) );
6175+
fields.append( QgsField( "age" ) );
6176+
6177+
QList<int> indices1 = QgsProcessingUtils::fieldNamesToIndices( QStringList(), fields );
6178+
QCOMPARE( indices1, QList<int>() << 0 << 1 << 2 );
6179+
6180+
QList<int> indices2 = QgsProcessingUtils::fieldNamesToIndices( QStringList() << "address" << "age", fields );
6181+
QCOMPARE( indices2, QList<int>() << 1 << 2 );
6182+
6183+
QList<int> indices3 = QgsProcessingUtils::fieldNamesToIndices( QStringList() << "address" << "agegege", fields );
6184+
QCOMPARE( indices3, QList<int>() << 1 );
6185+
}
6186+
6187+
void TestQgsProcessing::indicesToFields()
6188+
{
6189+
QgsFields fields;
6190+
fields.append( QgsField( "name" ) );
6191+
fields.append( QgsField( "address" ) );
6192+
fields.append( QgsField( "age" ) );
6193+
6194+
QList<int> indices1 = QList<int>() << 0 << 1 << 2;
6195+
QgsFields fields1 = QgsProcessingUtils::indicesToFields( indices1, fields );
6196+
QCOMPARE( fields1, fields );
6197+
6198+
QList<int> indices2 = QList<int>() << 1;
6199+
QgsFields fields2expected;
6200+
fields2expected.append( QgsField( "address" ) );
6201+
QgsFields fields2 = QgsProcessingUtils::indicesToFields( indices2, fields );
6202+
QCOMPARE( fields2, fields2expected );
6203+
6204+
QList<int> indices3;
6205+
QgsFields fields3 = QgsProcessingUtils::indicesToFields( indices3, fields );
6206+
QCOMPARE( fields3, QgsFields() );
6207+
}
6208+
61686209
void TestQgsProcessing::stringToPythonLiteral()
61696210
{
61706211
QCOMPARE( QgsProcessingUtils::stringToPythonLiteral( QStringLiteral( "a" ) ), QStringLiteral( "'a'" ) );

0 commit comments

Comments
 (0)