Skip to content

Commit

Permalink
Add test for regression #45153
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso authored and nyalldawson committed Sep 27, 2021
1 parent 157c489 commit bee364e
Showing 1 changed file with 31 additions and 0 deletions.
Expand Up @@ -31,6 +31,8 @@
#include "qgsmapmouseevent.h"
#include "testqgsmaptoolutils.h"

#include <QSignalSpy>


/**
* \ingroup UnitTests
Expand All @@ -47,6 +49,7 @@ class TestQgsMapToolAddFeaturePoint : public QObject
void cleanupTestCase();// will be called after the last testfunction was executed.

void testPoint();
void testMultiPoint(); //!< Test crash from regression GH #45153

private:
QgisApp *mQgisApp = nullptr;
Expand Down Expand Up @@ -139,5 +142,33 @@ void TestQgsMapToolAddFeaturePoint::testPoint()
mLayerPoint->undoStack()->undo();
}

void TestQgsMapToolAddFeaturePoint::testMultiPoint()
{

QgsAdvancedDigitizingDockWidget dw{mCanvas};

QgsVectorLayer layerMultiPoint { QStringLiteral( "MultiPoint?crs=EPSG:27700" ), QStringLiteral( "layer multi point" ), QStringLiteral( "memory" ) };
layerMultiPoint.startEditing();
mCanvas->setCurrentLayer( &layerMultiPoint );

QgsMapToolDigitizeFeature tool{mCanvas, &dw};
QgsFeature feature;

connect( &tool, &QgsMapToolDigitizeFeature::digitizingCompleted, this, [ & ]( const QgsFeature & f )
{
feature = f;
} );

QSignalSpy spy( &tool, SIGNAL( digitizingCompleted( const QgsFeature & ) ) );
QMouseEvent mouseEvt{QMouseEvent::Type::MouseButtonRelease, QPointF{128, 128}, Qt::MouseButton::LeftButton, Qt::NoButton, Qt::NoModifier};
QgsMapMouseEvent evt( mCanvas, &mouseEvt );

tool.cadCanvasReleaseEvent( &evt );

QCOMPARE( spy.count(), 1 );
QCOMPARE( feature.geometry().asWkt( 1 ).toUpper(), QString( "MULTIPOINT ((2 6))" ) );

}

QGSTEST_MAIN( TestQgsMapToolAddFeaturePoint )
#include "testqgsmaptooladdfeaturepoint.moc"

0 comments on commit bee364e

Please sign in to comment.