Commit 7d8b78ed authored by Don Gagne's avatar Don Gagne

Add ComplexMIssionItem unit test

parent 3c60da97
......@@ -506,6 +506,7 @@ HEADERS += \
src/FactSystem/FactSystemTestBase.h \
src/FactSystem/FactSystemTestGeneric.h \
src/FactSystem/FactSystemTestPX4.h \
src/MissionManager/ComplexMissionItemTest.h \
src/MissionManager/MissionControllerTest.h \
src/MissionManager/MissionControllerManagerTest.h \
src/MissionManager/MissionItemTest.h \
......@@ -530,6 +531,7 @@ SOURCES += \
src/FactSystem/FactSystemTestBase.cc \
src/FactSystem/FactSystemTestGeneric.cc \
src/FactSystem/FactSystemTestPX4.cc \
src/MissionManager/ComplexMissionItemTest.cc \
src/MissionManager/MissionControllerTest.cc \
src/MissionManager/MissionControllerManagerTest.cc \
src/MissionManager/MissionItemTest.cc \
......
......@@ -59,7 +59,8 @@ ComplexMissionItem::ComplexMissionItem(Vehicle* vehicle, QObject* parent)
connect(&_gridSpacingFact, &Fact::valueChanged, this, &ComplexMissionItem::_generateGrid);
connect(&_gridAngleFact, &Fact::valueChanged, this, &ComplexMissionItem::_generateGrid);
connect(this, &ComplexMissionItem::cameraTriggerChanged, this, &ComplexMissionItem::_signalLastSequenceNumberChanged);
connect(this, &ComplexMissionItem::cameraTriggerChanged, this, &ComplexMissionItem::_cameraTriggerChanged);
}
void ComplexMissionItem::clearPolygon(void)
......@@ -77,8 +78,10 @@ void ComplexMissionItem::clearPolygon(void)
_polygonPath.clear();
_clearGrid();
setDirty(true);
emit specifiesCoordinateChanged();
emit lastSequenceNumberChanged(lastSequenceNumber());
}
void ComplexMissionItem::addPolygonCoordinate(const QGeoCoordinate coordinate)
......@@ -87,14 +90,13 @@ void ComplexMissionItem::addPolygonCoordinate(const QGeoCoordinate coordinate)
emit polygonPathChanged();
int pointCount = _polygonPath.count();
if (pointCount == 1) {
setCoordinate(coordinate);
} else if (pointCount == 3) {
emit specifiesCoordinateChanged();
if (pointCount >= 3) {
if (pointCount == 3) {
emit specifiesCoordinateChanged();
}
_generateGrid();
}
_setExitCoordinate(coordinate);
_generateGrid();
setDirty(true);
}
int ComplexMissionItem::lastSequenceNumber(void) const
......@@ -103,10 +105,10 @@ int ComplexMissionItem::lastSequenceNumber(void) const
if (_gridPoints.count()) {
lastSeq += _gridPoints.count() - 1;
}
if (_cameraTrigger) {
// Account for two trigger messages
lastSeq += 2;
if (_cameraTrigger) {
// Account for two trigger messages
lastSeq += 2;
}
}
return lastSeq;
......@@ -117,7 +119,6 @@ void ComplexMissionItem::setCoordinate(const QGeoCoordinate& coordinate)
if (_coordinate != coordinate) {
_coordinate = coordinate;
emit coordinateChanged(_coordinate);
_setExitCoordinate(coordinate);
}
}
......@@ -259,8 +260,6 @@ void ComplexMissionItem::_clearGrid(void)
}
emit gridPointsChanged();
_gridPoints.clear();
emit gridPointsChanged();
}
void ComplexMissionItem::_generateGrid(void)
......@@ -511,7 +510,11 @@ QmlObjectListModel* ComplexMissionItem::getMissionItems(void) const
return pMissionItems;
}
void ComplexMissionItem::_signalLastSequenceNumberChanged(void)
void ComplexMissionItem::_cameraTriggerChanged(void)
{
emit lastSequenceNumberChanged(lastSequenceNumber());
setDirty(true);
if (_gridPoints.count()) {
// If we have grid turn on/off camera trigger will add/remove two camera trigger mission items
emit lastSequenceNumberChanged(lastSequenceNumber());
}
}
......@@ -103,7 +103,7 @@ signals:
void gridAltitudeRelativeChanged (bool gridAltitudeRelative);
private slots:
void _signalLastSequenceNumberChanged(void);
void _cameraTriggerChanged(void);
private:
void _clear(void);
......
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL 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 3 of the License, or
(at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
#include "ComplexMissionItemTest.h"
ComplexMissionItemTest::ComplexMissionItemTest(void)
{
_polyPoints << QGeoCoordinate(47.633550640000003, -122.08982199) << QGeoCoordinate(47.634129020000003, -122.08887249) <<
QGeoCoordinate(47.633619320000001, -122.08811074) << QGeoCoordinate(47.633189139999999, -122.08900124);
}
void ComplexMissionItemTest::init(void)
{
_rgComplexMissionItemSignals[polygonPathChangedIndex] = SIGNAL(polygonPathChanged());
_rgComplexMissionItemSignals[lastSequenceNumberChangedIndex] = SIGNAL(lastSequenceNumberChanged(int));
_rgComplexMissionItemSignals[altitudeChangedIndex] = SIGNAL(altitudeChanged(double));
_rgComplexMissionItemSignals[gridAngleChangedIndex] = SIGNAL(gridAngleChanged(double));
_rgComplexMissionItemSignals[gridPointsChangedIndex] = SIGNAL(gridPointsChanged());
_rgComplexMissionItemSignals[cameraTriggerChangedIndex] = SIGNAL(cameraTriggerChanged(bool));
_rgComplexMissionItemSignals[altDifferenceChangedIndex] = SIGNAL(altDifferenceChanged(double));
_rgComplexMissionItemSignals[altPercentChangedIndex] = SIGNAL(altPercentChanged(double));
_rgComplexMissionItemSignals[azimuthChangedIndex] = SIGNAL(azimuthChanged(double));
_rgComplexMissionItemSignals[commandDescriptionChangedIndex] = SIGNAL(commandDescriptionChanged());
_rgComplexMissionItemSignals[commandNameChangedIndex] = SIGNAL(commandNameChanged());
_rgComplexMissionItemSignals[coordinateChangedIndex] = SIGNAL(coordinateChanged(const QGeoCoordinate&));
_rgComplexMissionItemSignals[exitCoordinateChangedIndex] = SIGNAL(exitCoordinateChanged(const QGeoCoordinate&));
_rgComplexMissionItemSignals[dirtyChangedIndex] = SIGNAL(dirtyChanged(bool));
_rgComplexMissionItemSignals[distanceChangedIndex] = SIGNAL(distanceChanged(double));
_rgComplexMissionItemSignals[isCurrentItemChangedIndex] = SIGNAL(isCurrentItemChanged(bool));
_rgComplexMissionItemSignals[sequenceNumberChangedIndex] = SIGNAL(sequenceNumberChanged(int));
_rgComplexMissionItemSignals[isSimpleItemChangedIndex] = SIGNAL(isSimpleItemChanged(bool));
_rgComplexMissionItemSignals[specifiesCoordinateChangedIndex] = SIGNAL(specifiesCoordinateChanged());
_rgComplexMissionItemSignals[isStandaloneCoordinateChangedIndex] = SIGNAL(isStandaloneCoordinateChanged());
_rgComplexMissionItemSignals[coordinateHasRelativeAltitudeChangedIndex] = SIGNAL(coordinateHasRelativeAltitudeChanged(bool));
_rgComplexMissionItemSignals[exitCoordinateHasRelativeAltitudeChangedIndex] = SIGNAL(exitCoordinateHasRelativeAltitudeChanged(bool));
_rgComplexMissionItemSignals[exitCoordinateSameAsEntryChangedIndex] = SIGNAL(exitCoordinateSameAsEntryChanged(bool));
_complexItem = new ComplexMissionItem(NULL /* Vehicle */, this);
// It's important to check that the right signals are emitted at the right time since that drives ui change.
// It's also important to check that things are not being over-signalled when they should not be, since that can lead
// to incorrect ui or perf impact of uneeded signals propogating ui change.
_multiSpy = new MultiSignalSpy();
Q_CHECK_PTR(_multiSpy);
QCOMPARE(_multiSpy->init(_complexItem, _rgComplexMissionItemSignals, _cComplexMissionItemSignals), true);
}
void ComplexMissionItemTest::cleanup(void)
{
delete _complexItem;
delete _multiSpy;
}
void ComplexMissionItemTest::_testDirty(void)
{
QVERIFY(!_complexItem->dirty());
_complexItem->setDirty(false);
QVERIFY(!_complexItem->dirty());
QVERIFY(_multiSpy->checkNoSignals());
_complexItem->setDirty(true);
QVERIFY(_complexItem->dirty());
QVERIFY(_multiSpy->checkOnlySignalByMask(dirtyChangedMask));
QVERIFY(_multiSpy->pullBoolFromSignalIndex(dirtyChangedIndex));
_multiSpy->clearAllSignals();
_complexItem->setDirty(false);
QVERIFY(!_complexItem->dirty());
QVERIFY(_multiSpy->checkOnlySignalByMask(dirtyChangedMask));
QVERIFY(!_multiSpy->pullBoolFromSignalIndex(dirtyChangedIndex));
}
void ComplexMissionItemTest::_testAddPolygonCoordinate(void)
{
QCOMPARE(_complexItem->polygonPath().count(), 0);
// First call to addPolygonCoordinate should trigger:
// polygonPathChanged
// dirtyChanged
_complexItem->addPolygonCoordinate(_polyPoints[0]);
QVERIFY(_multiSpy->checkOnlySignalByMask(polygonPathChangedMask | dirtyChangedMask));
// Validate object data
QVariantList polyList = _complexItem->polygonPath();
QCOMPARE(polyList.count(), 1);
QCOMPARE(polyList[0].value<QGeoCoordinate>(), _polyPoints[0]);
// Reset
_complexItem->setDirty(false);
_multiSpy->clearAllSignals();
// Second call to addPolygonCoordinate should only trigger:
// polygonPathChanged
// dirtyChanged
_complexItem->addPolygonCoordinate(_polyPoints[1]);
QVERIFY(_multiSpy->checkOnlySignalByMask(polygonPathChangedMask | dirtyChangedMask));
polyList = _complexItem->polygonPath();
QCOMPARE(polyList.count(), 2);
for (int i=0; i<polyList.count(); i++) {
QCOMPARE(polyList[i].value<QGeoCoordinate>(), _polyPoints[i]);
}
_complexItem->setDirty(false);
_multiSpy->clearAllSignals();
// Third call to addPolygonCoordinate should trigger:
// polygonPathChanged
// dirtyChanged
// Grid is generated for the first time on closing of polygon which triggers:
// coordinateChanged - grid generates new entry coordinate
// exitCoordinateChanged - grid generates new exit coordinate
// specifiesCoordinateChanged - once grid entry/exit shows up specifiesCoordinate gets set to true
// Grid generation triggers the following signals
// lastSequenceNumberChanged - number of internal mission items changes
// gridPointsChanged - grid points show up for the first time
_complexItem->addPolygonCoordinate(_polyPoints[2]);
QVERIFY(_multiSpy->checkOnlySignalByMask(polygonPathChangedMask | lastSequenceNumberChangedMask | gridPointsChangedMask | coordinateChangedMask |
exitCoordinateChangedMask | specifiesCoordinateChangedMask | dirtyChangedMask));
int seqNum = _multiSpy->pullIntFromSignalIndex(lastSequenceNumberChangedIndex);
QVERIFY(seqNum > 0);
polyList = _complexItem->polygonPath();
QCOMPARE(polyList.count(), 3);
for (int i=0; i<polyList.count(); i++) {
QCOMPARE(polyList[i].value<QGeoCoordinate>(), _polyPoints[i]);
}
_complexItem->setDirty(false);
_multiSpy->clearAllSignals();
// Forth call to addPolygonCoordinate should trigger:
// polygonPathChanged
// dirtyChanged
// Grid is generated again on polygon change which triggers:
// lastSequenceNumberChanged - number of internal mission items changes
// gridPointsChanged - grid points show up for the first time
// exitCoordinateChanged - grid generates new exit coordinate
// Note: Given the data set the entry coordinate stays the same
_complexItem->addPolygonCoordinate(_polyPoints[3]);
QVERIFY(_multiSpy->checkOnlySignalByMask(polygonPathChangedMask | lastSequenceNumberChangedMask | gridPointsChangedMask | exitCoordinateChangedMask |
dirtyChangedMask));
seqNum = _multiSpy->pullIntFromSignalIndex(lastSequenceNumberChangedIndex);
QVERIFY(seqNum > 0);
polyList = _complexItem->polygonPath();
QCOMPARE(polyList.count(), 4);
for (int i=0; i<polyList.count(); i++) {
QCOMPARE(polyList[i].value<QGeoCoordinate>(), _polyPoints[i]);
}
}
void ComplexMissionItemTest::_testClearPolygon(void)
{
for (int i=0; i<3; i++) {
_complexItem->addPolygonCoordinate(_polyPoints[i]);
}
_complexItem->setDirty(false);
_multiSpy->clearAllSignals();
// Call to clearPolygon should trigger:
// polygonPathChangedMask
// dirtyChanged
// lastSequenceNumberChangedMask
// gridPointsChangedMask
// dirtyChangedMask
// specifiesCoordinateChangedMask
_complexItem->clearPolygon();
QVERIFY(_multiSpy->checkOnlySignalByMask(polygonPathChangedMask | lastSequenceNumberChangedMask | gridPointsChangedMask | dirtyChangedMask |
specifiesCoordinateChangedMask));
QVERIFY(!_multiSpy->pullBoolFromSignalIndex(specifiesCoordinateChangedIndex));
QCOMPARE(_multiSpy->pullIntFromSignalIndex(lastSequenceNumberChangedIndex), 0);
QCOMPARE(_complexItem->polygonPath().count(), 0);
QCOMPARE(_complexItem->gridPoints().count(), 0);
_complexItem->setDirty(false);
_multiSpy->clearAllSignals();
}
void ComplexMissionItemTest::_testCameraTrigger(void)
{
QVERIFY(!_complexItem->property("cameraTrigger").toBool());
// Turning on/off camera triggering while there is no grid should trigger:
// cameraTriggerChanged
// dirtyChanged
// lastSequenceNumber should not change
int lastSeq = _complexItem->lastSequenceNumber();
_complexItem->setProperty("cameraTrigger", true);
QVERIFY(_multiSpy->checkOnlySignalByMask(dirtyChangedMask | cameraTriggerChangedMask));
QVERIFY(_multiSpy->pullBoolFromSignalIndex(cameraTriggerChangedIndex));
QCOMPARE(_complexItem->lastSequenceNumber(), lastSeq);
_complexItem->setDirty(false);
_multiSpy->clearAllSignals();
_complexItem->setProperty("cameraTrigger", false);
QVERIFY(_multiSpy->checkOnlySignalByMask(dirtyChangedMask | cameraTriggerChangedMask));
QVERIFY(!_multiSpy->pullBoolFromSignalIndex(cameraTriggerChangedIndex));
QCOMPARE(_complexItem->lastSequenceNumber(), lastSeq);
// Set up a grid
for (int i=0; i<3; i++) {
_complexItem->addPolygonCoordinate(_polyPoints[i]);
}
_complexItem->setDirty(false);
_multiSpy->clearAllSignals();
lastSeq = _complexItem->lastSequenceNumber();
QVERIFY(lastSeq > 0);
// Turning on camera triggering should add two more mission items, this should trigger:
// lastSequenceNumberChanged
// dirtyChanged
_complexItem->setProperty("cameraTrigger", true);
QVERIFY(_multiSpy->checkOnlySignalByMask(lastSequenceNumberChangedMask | dirtyChangedMask | cameraTriggerChangedMask));
QCOMPARE(_multiSpy->pullIntFromSignalIndex(lastSequenceNumberChangedIndex), lastSeq + 2);
_complexItem->setDirty(false);
_multiSpy->clearAllSignals();
// Turn off camera triggering and make sure things go back to previous count
_complexItem->setProperty("cameraTrigger", false);
QVERIFY(_multiSpy->checkOnlySignalByMask(lastSequenceNumberChangedMask | dirtyChangedMask | cameraTriggerChangedMask));
QCOMPARE(_multiSpy->pullIntFromSignalIndex(lastSequenceNumberChangedIndex), lastSeq);
}
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009 - 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL 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 3 of the License, or
(at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
#ifndef ComplexMissionItemTest_H
#define ComplexMissionItemTest_H
#include "UnitTest.h"
#include "TCPLink.h"
#include "MultiSignalSpy.h"
#include "ComplexMissionItem.h"
#include <QGeoCoordinate>
/// Unit test for SimpleMissionItem
class ComplexMissionItemTest : public UnitTest
{
Q_OBJECT
public:
ComplexMissionItemTest(void);
protected:
void init(void) final;
void cleanup(void) final;
private slots:
void _testDirty(void);
void _testAddPolygonCoordinate(void);
void _testClearPolygon(void);
void _testCameraTrigger(void);
private:
enum {
polygonPathChangedIndex = 0,
lastSequenceNumberChangedIndex,
altitudeChangedIndex,
gridAngleChangedIndex,
gridPointsChangedIndex,
cameraTriggerChangedIndex,
altDifferenceChangedIndex,
altPercentChangedIndex,
azimuthChangedIndex,
commandDescriptionChangedIndex,
commandNameChangedIndex,
coordinateChangedIndex,
exitCoordinateChangedIndex,
dirtyChangedIndex,
distanceChangedIndex,
isCurrentItemChangedIndex,
sequenceNumberChangedIndex,
isSimpleItemChangedIndex,
specifiesCoordinateChangedIndex,
isStandaloneCoordinateChangedIndex,
coordinateHasRelativeAltitudeChangedIndex,
exitCoordinateHasRelativeAltitudeChangedIndex,
exitCoordinateSameAsEntryChangedIndex,
maxSignalIndex
};
enum {
polygonPathChangedMask = 1 << polygonPathChangedIndex,
lastSequenceNumberChangedMask = 1 << lastSequenceNumberChangedIndex,
altitudeChangedMask = 1 << altitudeChangedIndex,
gridAngleChangedMask = 1 << gridAngleChangedIndex,
gridPointsChangedMask = 1 << gridPointsChangedIndex,
cameraTriggerChangedMask = 1 << cameraTriggerChangedIndex,
altDifferenceChangedMask = 1 << altDifferenceChangedIndex,
altPercentChangedMask = 1 << altPercentChangedIndex,
azimuthChangedMask = 1 << azimuthChangedIndex,
commandDescriptionChangedMask = 1 << commandDescriptionChangedIndex,
commandNameChangedMask = 1 << commandNameChangedIndex,
coordinateChangedMask = 1 << coordinateChangedIndex,
exitCoordinateChangedMask = 1 << exitCoordinateChangedIndex,
dirtyChangedMask = 1 << dirtyChangedIndex,
distanceChangedMask = 1 << distanceChangedIndex,
isCurrentItemChangedMask = 1 << isCurrentItemChangedIndex,
sequenceNumberChangedMask = 1 << sequenceNumberChangedIndex,
isSimpleItemChangedMask = 1 << isSimpleItemChangedIndex,
specifiesCoordinateChangedMask = 1 << specifiesCoordinateChangedIndex,
isStandaloneCoordinateChangedMask = 1 << isStandaloneCoordinateChangedIndex,
coordinateHasRelativeAltitudeChangedMask = 1 << coordinateHasRelativeAltitudeChangedIndex,
exitCoordinateHasRelativeAltitudeChangedMask = 1 << exitCoordinateHasRelativeAltitudeChangedIndex,
exitCoordinateSameAsEntryChangedMask = 1 << exitCoordinateSameAsEntryChangedIndex,
};
static const size_t _cComplexMissionItemSignals = maxSignalIndex;
const char* _rgComplexMissionItemSignals[_cComplexMissionItemSignals];
MultiSignalSpy* _multiSpy;
ComplexMissionItem* _complexItem;
QList<QGeoCoordinate> _polyPoints;
};
#endif
......@@ -75,7 +75,7 @@ public:
Q_PROPERTY(bool exitCoordinateHasRelativeAltitude READ exitCoordinateHasRelativeAltitude NOTIFY exitCoordinateHasRelativeAltitudeChanged)
/// @return true: exitCoordinate and coordinate are the same value
Q_PROPERTY(bool exitCoordinateSameAsEntry READ exitCoordinateSameAsEntry NOTIFY exitCoordinateSameAsEntry)
Q_PROPERTY(bool exitCoordinateSameAsEntry READ exitCoordinateSameAsEntry NOTIFY exitCoordinateSameAsEntryChanged)
// General properties associated with all types of visual mission items
......@@ -152,7 +152,7 @@ signals:
void coordinateHasRelativeAltitudeChanged (bool coordinateHasRelativeAltitude);
void exitCoordinateHasRelativeAltitudeChanged (bool exitCoordinateHasRelativeAltitude);
void exitCoordinateSameAsEntry (bool exitCoordinateSameAsEntry);
void exitCoordinateSameAsEntryChanged (bool exitCoordinateSameAsEntry);
protected:
Vehicle* _vehicle;
......
......@@ -33,6 +33,7 @@
#include "MessageBoxTest.h"
#include "MissionItemTest.h"
#include "SimpleMissionItemTest.h"
#include "ComplexMissionItemTest.h"
#include "MissionControllerTest.h"
#include "MissionManagerTest.h"
#include "RadioConfigTest.h"
......@@ -49,6 +50,7 @@ UT_REGISTER_TEST(MavlinkLogTest)
UT_REGISTER_TEST(MessageBoxTest)
UT_REGISTER_TEST(MissionItemTest)
UT_REGISTER_TEST(SimpleMissionItemTest)
UT_REGISTER_TEST(ComplexMissionItemTest)
UT_REGISTER_TEST(MissionControllerTest)
UT_REGISTER_TEST(MissionManagerTest)
UT_REGISTER_TEST(RadioConfigTest)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment