@@ -352,6 +352,7 @@ class TestQgsProcessing: public QObject
352
352
void tempUtils ();
353
353
void convertCompatible ();
354
354
void create ();
355
+ void combineFields ();
355
356
356
357
private:
357
358
@@ -5443,5 +5444,40 @@ void TestQgsProcessing::create()
5443
5444
QCOMPARE ( newInstance->provider (), &p );
5444
5445
}
5445
5446
5447
+ void TestQgsProcessing::combineFields ()
5448
+ {
5449
+ QgsFields a;
5450
+ QgsFields b;
5451
+ // combine empty fields
5452
+ QgsFields res = QgsProcessingUtils::combineFields ( a, b );
5453
+ QVERIFY ( res.isEmpty () );
5454
+
5455
+ // fields in a
5456
+ a.append ( QgsField ( " name" ) );
5457
+ res = QgsProcessingUtils::combineFields ( a, b );
5458
+ QCOMPARE ( res.count (), 1 );
5459
+ QCOMPARE ( res.at ( 0 ).name (), QStringLiteral ( " name" ) );
5460
+ b.append ( QgsField ( " name" ) );
5461
+ res = QgsProcessingUtils::combineFields ( a, b );
5462
+ QCOMPARE ( res.count (), 2 );
5463
+ QCOMPARE ( res.at ( 0 ).name (), QStringLiteral ( " name" ) );
5464
+ QCOMPARE ( res.at ( 1 ).name (), QStringLiteral ( " name_2" ) );
5465
+
5466
+ a.append ( QgsField ( " NEW" ) );
5467
+ res = QgsProcessingUtils::combineFields ( a, b );
5468
+ QCOMPARE ( res.count (), 3 );
5469
+ QCOMPARE ( res.at ( 0 ).name (), QStringLiteral ( " name" ) );
5470
+ QCOMPARE ( res.at ( 1 ).name (), QStringLiteral ( " NEW" ) );
5471
+ QCOMPARE ( res.at ( 2 ).name (), QStringLiteral ( " name_2" ) );
5472
+
5473
+ b.append ( QgsField ( " new" ) );
5474
+ res = QgsProcessingUtils::combineFields ( a, b );
5475
+ QCOMPARE ( res.count (), 4 );
5476
+ QCOMPARE ( res.at ( 0 ).name (), QStringLiteral ( " name" ) );
5477
+ QCOMPARE ( res.at ( 1 ).name (), QStringLiteral ( " NEW" ) );
5478
+ QCOMPARE ( res.at ( 2 ).name (), QStringLiteral ( " name_2" ) );
5479
+ QCOMPARE ( res.at ( 3 ).name (), QStringLiteral ( " new_2" ) );
5480
+ }
5481
+
5446
5482
QGSTEST_MAIN ( TestQgsProcessing )
5447
5483
#include " testqgsprocessing.moc"
0 commit comments