From 14f411da4a771501600c68c2b9cd9fea679b8cca Mon Sep 17 00:00:00 2001 From: Aleksey Kontsevich Date: Tue, 9 Jun 2020 00:25:49 +0300 Subject: [PATCH] Select vertex functionality test --- src/MissionManager/QGCMapPolygonTest.cc | 35 ++++++++++++++++++++++++ src/MissionManager/QGCMapPolygonTest.h | 5 ++-- src/MissionManager/QGCMapPolylineTest.cc | 35 ++++++++++++++++++++++++ src/MissionManager/QGCMapPolylineTest.h | 5 ++-- 4 files changed, 76 insertions(+), 4 deletions(-) diff --git a/src/MissionManager/QGCMapPolygonTest.cc b/src/MissionManager/QGCMapPolygonTest.cc index 91bc90a0d..a493ccccc 100644 --- a/src/MissionManager/QGCMapPolygonTest.cc +++ b/src/MissionManager/QGCMapPolygonTest.cc @@ -219,3 +219,38 @@ void QGCMapPolygonTest::_testKMLLoad(void) QVERIFY(!_mapPolygon->loadKMLOrSHPFile(QStringLiteral(":/unittest/PolygonBadCoordinatesNode.kml"))); checkExpectedMessageBox(); } + +void QGCMapPolygonTest::_testSelectVertex(void) +{ + // Create polygon + foreach (auto vertex, _polyPoints) { + _mapPolygon->appendVertex(vertex); + } + + QVERIFY(_mapPolygon->selectedVertex() == -1); + QVERIFY(_mapPolygon->count() == _polyPoints.count()); + + // Test deselect + _mapPolygon->selectVertex(-1); + QVERIFY(_mapPolygon->selectedVertex() == -1); + // Test out of bounds + _mapPolygon->selectVertex(_polyPoints.count()); + QVERIFY(_mapPolygon->selectedVertex() == -1); + // Simple select test + _mapPolygon->selectVertex(_polyPoints.count() - 1); + QVERIFY(_mapPolygon->selectedVertex() == _polyPoints.count() - 1); + // Keep selected test + _mapPolygon->selectVertex(0); + _mapPolygon->removeVertex(_polyPoints.count() - 1); + QVERIFY(_mapPolygon->selectedVertex() == 0); + // Deselect if selected vertex removed + _mapPolygon->appendVertex(_polyPoints[_polyPoints.count() - 1]); + _mapPolygon->selectVertex(_polyPoints.count() - 1); + _mapPolygon->removeVertex(_polyPoints.count() - 1); + QVERIFY(_mapPolygon->selectedVertex() == -1); + // Shift selected index down if removed index < selected index + _mapPolygon->appendVertex(_polyPoints[_polyPoints.count() - 1]); + _mapPolygon->selectVertex(_polyPoints.count() - 1); + _mapPolygon->removeVertex(0); + QVERIFY(_mapPolygon->selectedVertex() == _mapPolygon->count() - 1); +} diff --git a/src/MissionManager/QGCMapPolygonTest.h b/src/MissionManager/QGCMapPolygonTest.h index a5a09886b..835482b9b 100644 --- a/src/MissionManager/QGCMapPolygonTest.h +++ b/src/MissionManager/QGCMapPolygonTest.h @@ -17,18 +17,19 @@ class QGCMapPolygonTest : public UnitTest { Q_OBJECT - + public: QGCMapPolygonTest(void); protected: void init(void) final; void cleanup(void) final; - + private slots: void _testDirty(void); void _testVertexManipulation(void); void _testKMLLoad(void); + void _testSelectVertex(void); private: enum { diff --git a/src/MissionManager/QGCMapPolylineTest.cc b/src/MissionManager/QGCMapPolylineTest.cc index 02bd2bdaf..92afce337 100644 --- a/src/MissionManager/QGCMapPolylineTest.cc +++ b/src/MissionManager/QGCMapPolylineTest.cc @@ -200,3 +200,38 @@ void QGCMapPolylineTest::_testKMLLoad(void) checkExpectedMessageBox(); } #endif + +void QGCMapPolylineTest::_testSelectVertex(void) +{ + // Create polyline + foreach (auto vertex, _linePoints) { + _mapPolyline->appendVertex(vertex); + } + + QVERIFY(_mapPolyline->selectedVertex() == -1); + QVERIFY(_mapPolyline->count() == _linePoints.count()); + + // Test deselect + _mapPolyline->selectVertex(-1); + QVERIFY(_mapPolyline->selectedVertex() == -1); + // Test out of bounds + _mapPolyline->selectVertex(_linePoints.count()); + QVERIFY(_mapPolyline->selectedVertex() == -1); + // Simple select test + _mapPolyline->selectVertex(_linePoints.count() - 1); + QVERIFY(_mapPolyline->selectedVertex() == _linePoints.count() - 1); + // Keep selected test + _mapPolyline->selectVertex(0); + _mapPolyline->removeVertex(_linePoints.count() - 1); + QVERIFY(_mapPolyline->selectedVertex() == 0); + // Deselect if selected vertex removed + _mapPolyline->appendVertex(_linePoints[_linePoints.count() - 1]); + _mapPolyline->selectVertex(_linePoints.count() - 1); + _mapPolyline->removeVertex(_linePoints.count() - 1); + QVERIFY(_mapPolyline->selectedVertex() == -1); + // Shift selected index down if removed index < selected index + _mapPolyline->appendVertex(_linePoints[_linePoints.count() - 1]); + _mapPolyline->selectVertex(_linePoints.count() - 1); + _mapPolyline->removeVertex(0); + QVERIFY(_mapPolyline->selectedVertex() == _mapPolyline->count() - 1); +} diff --git a/src/MissionManager/QGCMapPolylineTest.h b/src/MissionManager/QGCMapPolylineTest.h index a2c8caa54..873c6d4cb 100644 --- a/src/MissionManager/QGCMapPolylineTest.h +++ b/src/MissionManager/QGCMapPolylineTest.h @@ -17,18 +17,19 @@ class QGCMapPolylineTest : public UnitTest { Q_OBJECT - + public: QGCMapPolylineTest(void); protected: void init(void) final; void cleanup(void) final; - + private slots: void _testDirty(void); void _testVertexManipulation(void); // void _testKMLLoad(void); + void _testSelectVertex(void); private: enum { -- 2.22.0