Skip to content

Commit

Permalink
[processing] Don't try to run test which requires postgres if
Browse files Browse the repository at this point in the history
ENABLE_PGTEST is false
  • Loading branch information
nyalldawson committed Aug 2, 2021
1 parent 9ca5eb9 commit d2bcacb
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions tests/src/analysis/testqgsprocessing.cpp
Expand Up @@ -609,6 +609,9 @@ class TestQgsProcessing: public QObject
void generateTemporaryDestination();
void parseDestinationString();
void createFeatureSink();
#ifdef ENABLE_PGTEST
void createFeatureSinkPostgres();
#endif
void source();
void parameters();
void algorithmParameters();
Expand Down Expand Up @@ -2093,22 +2096,40 @@ void TestQgsProcessing::createFeatureSink()
QCOMPARE( layer->featureCount(), 2L );
QVERIFY( layer->getFeatures().nextFeature( f ) );
QCOMPARE( f.attribute( "my_field" ).toString(), QStringLiteral( "val2" ) );
}

#ifdef ENABLE_PGTEST
void TestQgsProcessing::createFeatureSinkPostgres()
{
QgsProcessingContext context;

QgsFields fields;
fields.append( QgsField( QStringLiteral( "my_field" ), QVariant::String, QString(), 100 ) );

// save to database
destination = "postgres://dbname='qgis_test' service='qgis_test' table=\"public\".\"test_feature_sink\" (geom)";
sink.reset( QgsProcessingUtils::createFeatureSink( destination, context, fields, QgsWkbTypes::Polygon, QgsCoordinateReferenceSystem::fromEpsgId( 3111 ) ) );
QString destination = "postgres://dbname='qgis_test' service='qgis_test' table=\"public\".\"test_feature_sink\" (geom)";
std::unique_ptr< QgsFeatureSink > sink;
try
{
sink.reset( QgsProcessingUtils::createFeatureSink( destination, context, fields, QgsWkbTypes::Polygon, QgsCoordinateReferenceSystem::fromEpsgId( 3111 ) ) );
}
catch ( QgsProcessingException &e )
{
QFAIL( "could not create layer -- perhaps postgres test db is not accessible?" );
}
QVERIFY( sink.get() );
f = QgsFeature( fields );
QgsFeature f = QgsFeature( fields );
f.setGeometry( QgsGeometry::fromWkt( QStringLiteral( "Polygon((0 0, 0 1, 1 1, 1 0, 0 0 ))" ) ) );
f.setAttributes( QgsAttributes() << "val" );
QVERIFY( sink->addFeature( f ) );
sink.reset( nullptr );
layer = qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::mapLayerFromString( destination, context, true ) );
QgsVectorLayer *layer = qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::mapLayerFromString( destination, context, true ) );
QVERIFY( layer && layer->isValid() );
QCOMPARE( layer->wkbType(), QgsWkbTypes::Polygon );
QVERIFY( layer->getFeatures().nextFeature( f ) );
QCOMPARE( f.attribute( "my_field" ).toString(), QStringLiteral( "val" ) );
}
#endif

void TestQgsProcessing::source()
{
Expand Down

0 comments on commit d2bcacb

Please sign in to comment.