From 6e98941c074f8da55829a22f858b308be42dbf07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Bartoletti?= Date: Thu, 17 Apr 2025 16:29:58 +0200 Subject: [PATCH] Update testqgsprocessingcheckgeometry.cpp --- .../testqgsprocessingcheckgeometry.cpp | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/tests/src/analysis/testqgsprocessingcheckgeometry.cpp b/tests/src/analysis/testqgsprocessingcheckgeometry.cpp index 388e037aa9c..f8f550d9815 100644 --- a/tests/src/analysis/testqgsprocessingcheckgeometry.cpp +++ b/tests/src/analysis/testqgsprocessingcheckgeometry.cpp @@ -48,6 +48,9 @@ class TestQgsProcessingCheckGeometry : public QgsTest void selfIntersectionAlg_data(); void selfIntersectionAlg(); + void duplicateNodesAlg_data(); + void duplicateNodesAlg(); + void dangleAlg(); void followBoundariesAlg(); @@ -421,6 +424,46 @@ void TestQgsProcessingCheckGeometry::dangleAlg() QCOMPARE( errorsLayer->featureCount(), 6 ); } +void TestQgsProcessingCheckGeometry::duplicateNodesAlg_data() +{ + QTest::addColumn( "layerToTest" ); + QTest::addColumn( "expectedErrorCount" ); + QTest::newRow( "Line layer" ) << mLineLayer << 3; + QTest::newRow( "Polygon layer" ) << mPolygonLayer << 1; +} + +void TestQgsProcessingCheckGeometry::duplicateNodesAlg() +{ + QFETCH( QgsVectorLayer *, layerToTest ); + QFETCH( int, expectedErrorCount ); + + std::unique_ptr< QgsProcessingAlgorithm > alg( + QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:checkgeometryduplicatenodes" ) ) + ); + QVERIFY( alg != nullptr ); + + QVariantMap parameters; + parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( layerToTest ) ); + parameters.insert( QStringLiteral( "UNIQUE_ID" ), "id" ); + parameters.insert( QStringLiteral( "OUTPUT" ), QgsProcessing::TEMPORARY_OUTPUT ); + parameters.insert( QStringLiteral( "ERRORS" ), QgsProcessing::TEMPORARY_OUTPUT ); + + bool ok = false; + QgsProcessingFeedback feedback; + std::unique_ptr< QgsProcessingContext > context = std::make_unique< QgsProcessingContext >(); + + QVariantMap results; + results = alg->run( parameters, *context, &feedback, &ok ); + QVERIFY( ok ); + + std::unique_ptr outputLayer( qobject_cast< QgsVectorLayer * >( context->getMapLayer( results.value( QStringLiteral( "OUTPUT" ) ).toString() ) ) ); + std::unique_ptr errorsLayer( qobject_cast< QgsVectorLayer * >( context->getMapLayer( results.value( QStringLiteral( "ERRORS" ) ).toString() ) ) ); + QVERIFY( outputLayer->isValid() ); + QVERIFY( errorsLayer->isValid() ); + QCOMPARE( outputLayer->featureCount(), expectedErrorCount ); + QCOMPARE( errorsLayer->featureCount(), expectedErrorCount ); +} + void TestQgsProcessingCheckGeometry::followBoundariesAlg() { std::unique_ptr< QgsProcessingAlgorithm > alg( @@ -456,4 +499,4 @@ void TestQgsProcessingCheckGeometry::followBoundariesAlg() } QGSTEST_MAIN( TestQgsProcessingCheckGeometry ) -#include "testqgsprocessingcheckgeometry.moc" \ No newline at end of file +#include "testqgsprocessingcheckgeometry.moc"