Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a dedicated test for pointM avoid a crash in testsuite
- Loading branch information
1 parent
d5629fc
commit 6aa7095
Showing
3 changed files
with
150 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/*************************************************************************** | ||
testqgsmaptooladdfeaturepointm.cpp | ||
---------------------- | ||
Date : April 2021 | ||
Copyright : (C) 2021 by Loïc Bartoletti | ||
Email : loic dot bartoletti at oslandia dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgstest.h" | ||
|
||
#include "qgisapp.h" | ||
#include "qgsadvanceddigitizingdockwidget.h" | ||
#include "qgsgeometry.h" | ||
#include "qgsmapcanvas.h" | ||
#include "qgsmapcanvassnappingutils.h" | ||
#include "qgssnappingconfig.h" | ||
#include "qgssnappingutils.h" | ||
#include "qgsmaptooladdfeature.h" | ||
#include "qgsmapcanvastracer.h" | ||
#include "qgsproject.h" | ||
#include "qgssettings.h" | ||
#include "qgsvectorlayer.h" | ||
#include "qgsmapmouseevent.h" | ||
#include "testqgsmaptoolutils.h" | ||
|
||
|
||
/** | ||
* \ingroup UnitTests | ||
* This is a unit test for the vertex tool | ||
*/ | ||
class TestQgsMapToolAddFeaturePoint : public QObject | ||
{ | ||
Q_OBJECT | ||
public: | ||
TestQgsMapToolAddFeaturePoint(); | ||
|
||
private slots: | ||
void initTestCase();// will be called before the first testfunction is executed. | ||
void cleanupTestCase();// will be called after the last testfunction was executed. | ||
|
||
void testPointM(); | ||
|
||
private: | ||
QgisApp *mQgisApp = nullptr; | ||
QgsMapCanvas *mCanvas = nullptr; | ||
QgsMapToolAddFeature *mCaptureTool = nullptr; | ||
QgsVectorLayer *mLayerPointM = nullptr; | ||
}; | ||
|
||
TestQgsMapToolAddFeaturePoint::TestQgsMapToolAddFeaturePoint() = default; | ||
|
||
|
||
//runs before all tests | ||
void TestQgsMapToolAddFeaturePoint::initTestCase() | ||
{ | ||
qDebug() << "TestMapToolCapture::initTestCase()"; | ||
// init QGIS's paths - true means that all path will be inited from prefix | ||
QgsApplication::init(); | ||
QgsApplication::initQgis(); | ||
|
||
// Set up the QSettings environment | ||
QCoreApplication::setOrganizationName( QStringLiteral( "QGIS" ) ); | ||
QCoreApplication::setOrganizationDomain( QStringLiteral( "qgis.org" ) ); | ||
QCoreApplication::setApplicationName( QStringLiteral( "QGIS-TEST" ) ); | ||
|
||
mQgisApp = new QgisApp(); | ||
|
||
mCanvas = new QgsMapCanvas(); | ||
|
||
mCanvas->setDestinationCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:27700" ) ) ); | ||
|
||
mCanvas->setFrameStyle( QFrame::NoFrame ); | ||
mCanvas->resize( 512, 512 ); | ||
mCanvas->setExtent( QgsRectangle( 0, 0, 8, 8 ) ); | ||
mCanvas->show(); // to make the canvas resize | ||
mCanvas->hide(); | ||
|
||
// make testing M layer | ||
mLayerPointM = new QgsVectorLayer( QStringLiteral( "PointM?crs=EPSG:27700" ), QStringLiteral( "layer point M" ), QStringLiteral( "memory" ) ); | ||
QVERIFY( mLayerPointM->isValid() ); | ||
QgsProject::instance()->addMapLayers( QList<QgsMapLayer *>() << mLayerPointM ); | ||
|
||
mLayerPointM->startEditing(); | ||
QgsFeature pointFM; | ||
QString pointWktM = "PointM(7 7 4)"; | ||
pointFM.setGeometry( QgsGeometry::fromWkt( pointWktM ) ); | ||
|
||
mLayerPointM->addFeature( pointFM ); | ||
QCOMPARE( mLayerPointM->featureCount(), ( long )1 ); | ||
|
||
// create the tool | ||
mCaptureTool = new QgsMapToolAddFeature( mCanvas, /*mAdvancedDigitizingDockWidget, */ QgsMapToolCapture::CapturePoint ); | ||
mCanvas->setMapTool( mCaptureTool ); | ||
|
||
QCOMPARE( mCanvas->mapSettings().outputSize(), QSize( 512, 512 ) ); | ||
QCOMPARE( mCanvas->mapSettings().visibleExtent(), QgsRectangle( 0, 0, 8, 8 ) ); | ||
} | ||
|
||
//runs after all tests | ||
void TestQgsMapToolAddFeaturePoint::cleanupTestCase() | ||
{ | ||
delete mCaptureTool; | ||
delete mCanvas; | ||
QgsApplication::exitQgis(); | ||
} | ||
|
||
void TestQgsMapToolAddFeaturePoint::testPointM() | ||
{ | ||
TestQgsMapToolAdvancedDigitizingUtils utils( mCaptureTool ); | ||
mCanvas->setCurrentLayer( mLayerPointM ); | ||
// test with default M value = 333 | ||
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_m_value" ), 333 ); | ||
|
||
QSet<QgsFeatureId> oldFids = utils.existingFeatureIds(); | ||
|
||
utils.mouseClick( 4, 0, Qt::LeftButton, Qt::KeyboardModifiers(), true ); | ||
QgsFeatureId newFid = utils.newFeatureId( oldFids ); | ||
|
||
QCOMPARE( mLayerPointM->featureCount(), ( long )2 ); | ||
|
||
QString wkt = "PointM (4 0 333)"; | ||
QCOMPARE( mLayerPointM->getFeature( newFid ).geometry().asWkt(), wkt ); | ||
|
||
mLayerPointM->undoStack()->undo(); | ||
|
||
// test with default M value = 123 | ||
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_m_value" ), 123 ); | ||
|
||
oldFids = utils.existingFeatureIds(); | ||
utils.mouseClick( 6, 6, Qt::LeftButton, Qt::KeyboardModifiers(), true ); | ||
newFid = utils.newFeatureId( oldFids ); | ||
|
||
wkt = "PointM (6 6 123)"; | ||
QCOMPARE( mLayerPointM->getFeature( newFid ).geometry().asWkt(), wkt ); | ||
|
||
mLayerPointM->undoStack()->undo(); | ||
} | ||
|
||
QGSTEST_MAIN( TestQgsMapToolAddFeaturePoint ) | ||
#include "testqgsmaptooladdfeaturepointm.moc" |