Skip to content
Permalink
Browse files

Tests for fieldNamesToIndices() and indicesToFields()

  • Loading branch information
wonder-sk committed Apr 26, 2018
1 parent 091ed91 commit 5e7719c38f3fafd83aff42f3550ca8b0f9f73468
Showing with 41 additions and 0 deletions.
  1. +41 −0 tests/src/analysis/testqgsprocessing.cpp
@@ -482,6 +482,8 @@ class TestQgsProcessing: public QObject
void convertCompatible();
void create();
void combineFields();
void fieldNamesToIndices();
void indicesToFields();
void stringToPythonLiteral();
void defaultExtensionsForProvider();
void supportsNonFileBasedOutput();
@@ -6165,6 +6167,45 @@ void TestQgsProcessing::combineFields()
QCOMPARE( res.at( 3 ).name(), QStringLiteral( "new_2" ) );
}

void TestQgsProcessing::fieldNamesToIndices()
{
QgsFields fields;
fields.append( QgsField( "name" ) );
fields.append( QgsField( "address" ) );
fields.append( QgsField( "age" ) );

QList<int> indices1 = QgsProcessingUtils::fieldNamesToIndices( QStringList(), fields );
QCOMPARE( indices1, QList<int>() << 0 << 1 << 2 );

QList<int> indices2 = QgsProcessingUtils::fieldNamesToIndices( QStringList() << "address" << "age", fields );
QCOMPARE( indices2, QList<int>() << 1 << 2 );

QList<int> indices3 = QgsProcessingUtils::fieldNamesToIndices( QStringList() << "address" << "agegege", fields );
QCOMPARE( indices3, QList<int>() << 1 );
}

void TestQgsProcessing::indicesToFields()
{
QgsFields fields;
fields.append( QgsField( "name" ) );
fields.append( QgsField( "address" ) );
fields.append( QgsField( "age" ) );

QList<int> indices1 = QList<int>() << 0 << 1 << 2;
QgsFields fields1 = QgsProcessingUtils::indicesToFields( indices1, fields );
QCOMPARE( fields1, fields );

QList<int> indices2 = QList<int>() << 1;
QgsFields fields2expected;
fields2expected.append( QgsField( "address" ) );
QgsFields fields2 = QgsProcessingUtils::indicesToFields( indices2, fields );
QCOMPARE( fields2, fields2expected );

QList<int> indices3;
QgsFields fields3 = QgsProcessingUtils::indicesToFields( indices3, fields );
QCOMPARE( fields3, QgsFields() );
}

void TestQgsProcessing::stringToPythonLiteral()
{
QCOMPARE( QgsProcessingUtils::stringToPythonLiteral( QStringLiteral( "a" ) ), QStringLiteral( "'a'" ) );

0 comments on commit 5e7719c

Please sign in to comment.
You can’t perform that action at this time.