From 299a27e3356ad1fff9b42955aa304cdf3d6dad73 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Mon, 5 Jun 2017 20:55:01 -0700 Subject: [PATCH] Unit tests for survey grid angle and entry location --- src/MissionManager/SurveyMissionItemTest.cc | 71 +++++++++++++++++++++ src/MissionManager/SurveyMissionItemTest.h | 4 ++ 2 files changed, 75 insertions(+) diff --git a/src/MissionManager/SurveyMissionItemTest.cc b/src/MissionManager/SurveyMissionItemTest.cc index f8715946b..5fa0e4e33 100644 --- a/src/MissionManager/SurveyMissionItemTest.cc +++ b/src/MissionManager/SurveyMissionItemTest.cc @@ -178,3 +178,74 @@ void SurveyMissionItemTest::_testCameraTrigger(void) QCOMPARE(_multiSpy->pullIntFromSignalIndex(lastSequenceNumberChangedIndex), lastSeq); #endif } + +// Clamp expected grid angle from 0<->180. We don't care about opposite angles like 90/270 +double SurveyMissionItemTest::_clampGridAngle180(double gridAngle) +{ + if (gridAngle >= 0.0) { + if (gridAngle == 360.0) { + gridAngle = 0.0; + } else if (gridAngle >= 180.0) { + gridAngle -= 180.0; + } + } else { + if (gridAngle < -180.0) { + gridAngle += 360.0; + } else { + gridAngle += 180.0; + } + } + return gridAngle; +} + +void SurveyMissionItemTest::_testGridAngle(void) +{ + QGCMapPolygon* mapPolygon = _surveyItem->mapPolygon(); + + for (int i=0; i<_polyPoints.count(); i++) { + QGeoCoordinate& vertex = _polyPoints[i]; + mapPolygon->appendVertex(vertex); + } + + for (double gridAngle=-360.0; gridAngle<=360.0; gridAngle++) { + _surveyItem->gridAngle()->setRawValue(gridAngle); + + QVariantList gridPoints = _surveyItem->gridPoints(); + QGeoCoordinate firstTransectEntry = gridPoints[0].value(); + QGeoCoordinate firstTransectExit = gridPoints[1].value(); + double azimuth = firstTransectEntry.azimuthTo(firstTransectExit); + //qDebug() << gridAngle << azimuth << _clampGridAngle180(gridAngle) << _clampGridAngle180(azimuth); + QCOMPARE((int)_clampGridAngle180(gridAngle), (int)_clampGridAngle180(azimuth)); + } +} + +void SurveyMissionItemTest::_testEntryLocation(void) +{ + QGCMapPolygon* mapPolygon = _surveyItem->mapPolygon(); + + for (int i=0; i<_polyPoints.count(); i++) { + QGeoCoordinate& vertex = _polyPoints[i]; + mapPolygon->appendVertex(vertex); + } + + for (double gridAngle=-360.0; gridAngle<=360.0; gridAngle++) { + _surveyItem->gridAngle()->setRawValue(gridAngle); + + QList rgSeenEntryCoords; + QList rgEntryLocation; + rgEntryLocation << SurveyMissionItem::EntryLocationTopLeft + << SurveyMissionItem::EntryLocationTopRight + << SurveyMissionItem::EntryLocationBottomLeft + << SurveyMissionItem::EntryLocationBottomRight; + + // Validate that each entry location is unique + for (int i=0; igridEntryLocation()->setRawValue(entryLocation); + QVERIFY(!rgSeenEntryCoords.contains(_surveyItem->coordinate())); + rgSeenEntryCoords << _surveyItem->coordinate(); + } + rgSeenEntryCoords.clear(); + } +} diff --git a/src/MissionManager/SurveyMissionItemTest.h b/src/MissionManager/SurveyMissionItemTest.h index 78c9bef76..db5969207 100644 --- a/src/MissionManager/SurveyMissionItemTest.h +++ b/src/MissionManager/SurveyMissionItemTest.h @@ -34,8 +34,12 @@ private slots: void _testDirty(void); void _testCameraValueChanged(void); void _testCameraTrigger(void); + void _testGridAngle(void); + void _testEntryLocation(void); private: + double _clampGridAngle180(double gridAngle); + enum { gridPointsChangedIndex = 0, cameraShotsChangedIndex, -- 2.22.0