Commit 834c862c authored by Don Gagne's avatar Don Gagne

Merge pull request #2914 from DonLakeFlyer/ComplexUnitTest

ComplexMissionItem unit test
parents 1e58767a 7d8b78ed
...@@ -506,6 +506,7 @@ HEADERS += \ ...@@ -506,6 +506,7 @@ HEADERS += \
src/FactSystem/FactSystemTestBase.h \ src/FactSystem/FactSystemTestBase.h \
src/FactSystem/FactSystemTestGeneric.h \ src/FactSystem/FactSystemTestGeneric.h \
src/FactSystem/FactSystemTestPX4.h \ src/FactSystem/FactSystemTestPX4.h \
src/MissionManager/ComplexMissionItemTest.h \
src/MissionManager/MissionControllerTest.h \ src/MissionManager/MissionControllerTest.h \
src/MissionManager/MissionControllerManagerTest.h \ src/MissionManager/MissionControllerManagerTest.h \
src/MissionManager/MissionItemTest.h \ src/MissionManager/MissionItemTest.h \
...@@ -530,6 +531,7 @@ SOURCES += \ ...@@ -530,6 +531,7 @@ SOURCES += \
src/FactSystem/FactSystemTestBase.cc \ src/FactSystem/FactSystemTestBase.cc \
src/FactSystem/FactSystemTestGeneric.cc \ src/FactSystem/FactSystemTestGeneric.cc \
src/FactSystem/FactSystemTestPX4.cc \ src/FactSystem/FactSystemTestPX4.cc \
src/MissionManager/ComplexMissionItemTest.cc \
src/MissionManager/MissionControllerTest.cc \ src/MissionManager/MissionControllerTest.cc \
src/MissionManager/MissionControllerManagerTest.cc \ src/MissionManager/MissionControllerManagerTest.cc \
src/MissionManager/MissionItemTest.cc \ src/MissionManager/MissionItemTest.cc \
......
...@@ -59,7 +59,8 @@ ComplexMissionItem::ComplexMissionItem(Vehicle* vehicle, QObject* parent) ...@@ -59,7 +59,8 @@ ComplexMissionItem::ComplexMissionItem(Vehicle* vehicle, QObject* parent)
connect(&_gridSpacingFact, &Fact::valueChanged, this, &ComplexMissionItem::_generateGrid); connect(&_gridSpacingFact, &Fact::valueChanged, this, &ComplexMissionItem::_generateGrid);
connect(&_gridAngleFact, &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) void ComplexMissionItem::clearPolygon(void)
...@@ -77,8 +78,10 @@ void ComplexMissionItem::clearPolygon(void) ...@@ -77,8 +78,10 @@ void ComplexMissionItem::clearPolygon(void)
_polygonPath.clear(); _polygonPath.clear();
_clearGrid(); _clearGrid();
setDirty(true);
emit specifiesCoordinateChanged(); emit specifiesCoordinateChanged();
emit lastSequenceNumberChanged(lastSequenceNumber());
} }
void ComplexMissionItem::addPolygonCoordinate(const QGeoCoordinate coordinate) void ComplexMissionItem::addPolygonCoordinate(const QGeoCoordinate coordinate)
...@@ -87,14 +90,13 @@ void ComplexMissionItem::addPolygonCoordinate(const QGeoCoordinate coordinate) ...@@ -87,14 +90,13 @@ void ComplexMissionItem::addPolygonCoordinate(const QGeoCoordinate coordinate)
emit polygonPathChanged(); emit polygonPathChanged();
int pointCount = _polygonPath.count(); int pointCount = _polygonPath.count();
if (pointCount == 1) { if (pointCount >= 3) {
setCoordinate(coordinate); if (pointCount == 3) {
} else if (pointCount == 3) {
emit specifiesCoordinateChanged(); emit specifiesCoordinateChanged();
} }
_setExitCoordinate(coordinate);
_generateGrid(); _generateGrid();
}
setDirty(true);
} }
int ComplexMissionItem::lastSequenceNumber(void) const int ComplexMissionItem::lastSequenceNumber(void) const
...@@ -103,11 +105,11 @@ int ComplexMissionItem::lastSequenceNumber(void) const ...@@ -103,11 +105,11 @@ int ComplexMissionItem::lastSequenceNumber(void) const
if (_gridPoints.count()) { if (_gridPoints.count()) {
lastSeq += _gridPoints.count() - 1; lastSeq += _gridPoints.count() - 1;
}
if (_cameraTrigger) { if (_cameraTrigger) {
// Account for two trigger messages // Account for two trigger messages
lastSeq += 2; lastSeq += 2;
} }
}
return lastSeq; return lastSeq;
} }
...@@ -117,7 +119,6 @@ void ComplexMissionItem::setCoordinate(const QGeoCoordinate& coordinate) ...@@ -117,7 +119,6 @@ void ComplexMissionItem::setCoordinate(const QGeoCoordinate& coordinate)
if (_coordinate != coordinate) { if (_coordinate != coordinate) {
_coordinate = coordinate; _coordinate = coordinate;
emit coordinateChanged(_coordinate); emit coordinateChanged(_coordinate);
_setExitCoordinate(coordinate);
} }
} }
...@@ -259,8 +260,6 @@ void ComplexMissionItem::_clearGrid(void) ...@@ -259,8 +260,6 @@ void ComplexMissionItem::_clearGrid(void)
} }
emit gridPointsChanged(); emit gridPointsChanged();
_gridPoints.clear(); _gridPoints.clear();
emit gridPointsChanged();
} }
void ComplexMissionItem::_generateGrid(void) void ComplexMissionItem::_generateGrid(void)
...@@ -511,7 +510,11 @@ QmlObjectListModel* ComplexMissionItem::getMissionItems(void) const ...@@ -511,7 +510,11 @@ QmlObjectListModel* ComplexMissionItem::getMissionItems(void) const
return pMissionItems; return pMissionItems;
} }
void ComplexMissionItem::_signalLastSequenceNumberChanged(void) void ComplexMissionItem::_cameraTriggerChanged(void)
{ {
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()); emit lastSequenceNumberChanged(lastSequenceNumber());
}
} }
...@@ -103,7 +103,7 @@ signals: ...@@ -103,7 +103,7 @@ signals:
void gridAltitudeRelativeChanged (bool gridAltitudeRelative); void gridAltitudeRelativeChanged (bool gridAltitudeRelative);
private slots: private slots:
void _signalLastSequenceNumberChanged(void); void _cameraTriggerChanged(void);
private: private:
void _clear(void); 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: ...@@ -75,7 +75,7 @@ public:
Q_PROPERTY(bool exitCoordinateHasRelativeAltitude READ exitCoordinateHasRelativeAltitude NOTIFY exitCoordinateHasRelativeAltitudeChanged) Q_PROPERTY(bool exitCoordinateHasRelativeAltitude READ exitCoordinateHasRelativeAltitude NOTIFY exitCoordinateHasRelativeAltitudeChanged)
/// @return true: exitCoordinate and coordinate are the same value /// @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 // General properties associated with all types of visual mission items
...@@ -152,7 +152,7 @@ signals: ...@@ -152,7 +152,7 @@ signals:
void coordinateHasRelativeAltitudeChanged (bool coordinateHasRelativeAltitude); void coordinateHasRelativeAltitudeChanged (bool coordinateHasRelativeAltitude);
void exitCoordinateHasRelativeAltitudeChanged (bool exitCoordinateHasRelativeAltitude); void exitCoordinateHasRelativeAltitudeChanged (bool exitCoordinateHasRelativeAltitude);
void exitCoordinateSameAsEntry (bool exitCoordinateSameAsEntry); void exitCoordinateSameAsEntryChanged (bool exitCoordinateSameAsEntry);
protected: protected:
Vehicle* _vehicle; Vehicle* _vehicle;
......
...@@ -53,8 +53,7 @@ MultiSignalSpy::~MultiSignalSpy() ...@@ -53,8 +53,7 @@ MultiSignalSpy::~MultiSignalSpy()
/// Initializes the class. Must be called once before use. /// Initializes the class. Must be called once before use.
/// @return true if success, false for failure /// @return true if success, false for failure
bool MultiSignalSpy::init( bool MultiSignalSpy::init(QObject* signalEmitter, ///< [in] object which the signals are emitted from
QObject* signalEmitter, ///< [in] object which the signals are emitted from
const char** rgSignals, ///< [in] array of signals to spy on const char** rgSignals, ///< [in] array of signals to spy on
size_t cSignals) ///< [in] numbers of signals in rgSignals size_t cSignals) ///< [in] numbers of signals in rgSignals
{ {
...@@ -85,7 +84,7 @@ bool MultiSignalSpy::init( ...@@ -85,7 +84,7 @@ bool MultiSignalSpy::init(
return true; return true;
} }
bool MultiSignalSpy::_checkSignalByMaskWorker(quint16 mask, bool multipleSignalsAllowed) bool MultiSignalSpy::_checkSignalByMaskWorker(quint32 mask, bool multipleSignalsAllowed)
{ {
for (size_t i=0; i<_cSignals; i++) { for (size_t i=0; i<_cSignals; i++) {
if ((1 << i) & mask) { if ((1 << i) & mask) {
...@@ -94,7 +93,7 @@ bool MultiSignalSpy::_checkSignalByMaskWorker(quint16 mask, bool multipleSignals ...@@ -94,7 +93,7 @@ bool MultiSignalSpy::_checkSignalByMaskWorker(quint16 mask, bool multipleSignals
if ((multipleSignalsAllowed && spy->count() == 0) || (!multipleSignalsAllowed && spy->count() != 1)) { if ((multipleSignalsAllowed && spy->count() == 0) || (!multipleSignalsAllowed && spy->count() != 1)) {
qDebug() << "Failed index:" << i; qDebug() << "Failed index:" << i;
_printSignalState(); _printSignalState(mask);
return false; return false;
} }
} }
...@@ -103,7 +102,7 @@ bool MultiSignalSpy::_checkSignalByMaskWorker(quint16 mask, bool multipleSignals ...@@ -103,7 +102,7 @@ bool MultiSignalSpy::_checkSignalByMaskWorker(quint16 mask, bool multipleSignals
return true; return true;
} }
bool MultiSignalSpy::_checkOnlySignalByMaskWorker(quint16 mask, bool multipleSignalsAllowed) bool MultiSignalSpy::_checkOnlySignalByMaskWorker(quint32 mask, bool multipleSignalsAllowed)
{ {
for (size_t i=0; i<_cSignals; i++) { for (size_t i=0; i<_cSignals; i++) {
QSignalSpy* spy = _rgSpys[i]; QSignalSpy* spy = _rgSpys[i];
...@@ -111,12 +110,12 @@ bool MultiSignalSpy::_checkOnlySignalByMaskWorker(quint16 mask, bool multipleSig ...@@ -111,12 +110,12 @@ bool MultiSignalSpy::_checkOnlySignalByMaskWorker(quint16 mask, bool multipleSig
if ((1 << i) & mask) { if ((1 << i) & mask) {
if ((multipleSignalsAllowed && spy->count() == 0) || (!multipleSignalsAllowed && spy->count() != 1)) { if ((multipleSignalsAllowed && spy->count() == 0) || (!multipleSignalsAllowed && spy->count() != 1)) {
_printSignalState(); _printSignalState(mask);
return false; return false;
} }
} else { } else {
if (spy->count() != 0) { if (spy->count() != 0) {
_printSignalState(); _printSignalState(mask);
return false; return false;
} }
} }
...@@ -125,28 +124,28 @@ bool MultiSignalSpy::_checkOnlySignalByMaskWorker(quint16 mask, bool multipleSig ...@@ -125,28 +124,28 @@ bool MultiSignalSpy::_checkOnlySignalByMaskWorker(quint16 mask, bool multipleSig
return true; return true;
} }
bool MultiSignalSpy::checkSignalByMask(quint16 mask) bool MultiSignalSpy::checkSignalByMask(quint32 mask)
{ {
return _checkSignalByMaskWorker(mask, false /* multipleSignalsAllowed */); return _checkSignalByMaskWorker(mask, false /* multipleSignalsAllowed */);
} }
bool MultiSignalSpy::checkOnlySignalByMask(quint16 mask) bool MultiSignalSpy::checkOnlySignalByMask(quint32 mask)
{ {
return _checkOnlySignalByMaskWorker(mask, false /* multipleSignalsAllowed */); return _checkOnlySignalByMaskWorker(mask, false /* multipleSignalsAllowed */);
} }
bool MultiSignalSpy::checkSignalsByMask(quint16 mask) bool MultiSignalSpy::checkSignalsByMask(quint32 mask)
{ {
return _checkSignalByMaskWorker(mask, true /* multipleSignalsAllowed */); return _checkSignalByMaskWorker(mask, true /* multipleSignalsAllowed */);
} }
bool MultiSignalSpy::checkOnlySignalsByMask(quint16 mask) bool MultiSignalSpy::checkOnlySignalsByMask(quint32 mask)
{ {
return _checkOnlySignalByMaskWorker(mask, true /* multipleSignalsAllowed */); return _checkOnlySignalByMaskWorker(mask, true /* multipleSignalsAllowed */);
} }
/// @return true if signal count = 0 for specified signals /// @return true if signal count = 0 for specified signals
bool MultiSignalSpy::checkNoSignalByMask(quint16 mask) bool MultiSignalSpy::checkNoSignalByMask(quint32 mask)
{ {
for (size_t i=0; i<_cSignals; i++) { for (size_t i=0; i<_cSignals; i++) {
if ((1 << i) & mask) { if ((1 << i) & mask) {
...@@ -154,7 +153,7 @@ bool MultiSignalSpy::checkNoSignalByMask(quint16 mask) ...@@ -154,7 +153,7 @@ bool MultiSignalSpy::checkNoSignalByMask(quint16 mask)
Q_ASSERT(spy != NULL); Q_ASSERT(spy != NULL);
if (spy->count() != 0) { if (spy->count() != 0) {
_printSignalState(); _printSignalState(mask);
return false; return false;
} }
} }
...@@ -170,7 +169,7 @@ bool MultiSignalSpy::checkNoSignals(void) ...@@ -170,7 +169,7 @@ bool MultiSignalSpy::checkNoSignals(void)
} }
/// @return QSignalSpy for the specified signal /// @return QSignalSpy for the specified signal
QSignalSpy* MultiSignalSpy::getSpyByIndex(quint16 index) QSignalSpy* MultiSignalSpy::getSpyByIndex(quint32 index)
{ {
Q_ASSERT(index < _cSignals); Q_ASSERT(index < _cSignals);
Q_ASSERT(_rgSpys[index] != NULL); Q_ASSERT(_rgSpys[index] != NULL);
...@@ -179,7 +178,7 @@ QSignalSpy* MultiSignalSpy::getSpyByIndex(quint16 index) ...@@ -179,7 +178,7 @@ QSignalSpy* MultiSignalSpy::getSpyByIndex(quint16 index)
} }
/// Sets the signal count to 0 for the specified signal /// Sets the signal count to 0 for the specified signal
void MultiSignalSpy::clearSignalByIndex(quint16 index) void MultiSignalSpy::clearSignalByIndex(quint32 index)
{ {
Q_ASSERT(index < _cSignals); Q_ASSERT(index < _cSignals);
Q_ASSERT(_rgSpys[index] != NULL); Q_ASSERT(_rgSpys[index] != NULL);
...@@ -188,7 +187,7 @@ void MultiSignalSpy::clearSignalByIndex(quint16 index) ...@@ -188,7 +187,7 @@ void MultiSignalSpy::clearSignalByIndex(quint16 index)
} }
/// Sets the signal count to 0 for all specified signals /// Sets the signal count to 0 for all specified signals
void MultiSignalSpy::clearSignalsByMask(quint16 mask) void MultiSignalSpy::clearSignalsByMask(quint32 mask)
{ {
for (size_t i=0; i<_cSignals; i++) { for (size_t i=0; i<_cSignals; i++) {
if ((1 << i) & mask) { if ((1 << i) & mask) {
...@@ -203,7 +202,7 @@ void MultiSignalSpy::clearSignalsByMask(quint16 mask) ...@@ -203,7 +202,7 @@ void MultiSignalSpy::clearSignalsByMask(quint16 mask)
/// Sets the signal count to 0 for all signals /// Sets the signal count to 0 for all signals
void MultiSignalSpy::clearAllSignals(void) void MultiSignalSpy::clearAllSignals(void)
{ {
for (quint16 i=0;i<_cSignals; i++) { for (quint32 i=0;i<_cSignals; i++) {
clearSignalByIndex(i); clearSignalByIndex(i);
} }
} }
...@@ -217,7 +216,7 @@ void MultiSignalSpy::timerEvent(QTimerEvent * event) ...@@ -217,7 +216,7 @@ void MultiSignalSpy::timerEvent(QTimerEvent * event)
/// Waits the specified signal /// Waits the specified signal
/// @return false for timeout /// @return false for timeout
bool MultiSignalSpy::waitForSignalByIndex( bool MultiSignalSpy::waitForSignalByIndex(
quint16 index, ///< [in] index of signal to wait on quint32 index, ///< [in] index of signal to wait on
int msec) ///< [in] numbers of milleconds to wait before timeout, -1 wait forever int msec) ///< [in] numbers of milleconds to wait before timeout, -1 wait forever
{ {
// Check input parameters // Check input parameters
...@@ -250,17 +249,31 @@ bool MultiSignalSpy::waitForSignalByIndex( ...@@ -250,17 +249,31 @@ bool MultiSignalSpy::waitForSignalByIndex(
return spy->count() != 0; return spy->count() != 0;
} }
void MultiSignalSpy::_printSignalState(void) void MultiSignalSpy::_printSignalState(quint32 mask)
{ {
for (size_t i=0; i<_cSignals; i++) { for (size_t i=0; i<_cSignals; i++) {
bool expected = (1 << i) & mask;
QSignalSpy* spy = _rgSpys[i]; QSignalSpy* spy = _rgSpys[i];
Q_ASSERT(spy != NULL); Q_ASSERT(spy != NULL);
qDebug() << "Signal index:" << i << "count:" << spy->count(); qDebug() << "Signal index:" << i << "count:" << spy->count() << "expected:" << expected << _rgSignals[i];
} }
} }
bool MultiSignalSpy::pullBoolFromSignalIndex(quint16 index) bool MultiSignalSpy::pullBoolFromSignalIndex(quint32 index)
{ {
QSignalSpy* spy = getSpyByIndex(index); QSignalSpy* spy = getSpyByIndex(index);
return spy->value(0).value(0).toBool(); return spy->value(0).value(0).toBool();
} }
int MultiSignalSpy::pullIntFromSignalIndex(quint32 index)
{
QSignalSpy* spy = getSpyByIndex(index);
return spy->value(0).value(0).toInt();
}
QGeoCoordinate MultiSignalSpy::pullQGeoCoordinateFromSignalIndex(quint32 index)
{
QSignalSpy* spy = getSpyByIndex(index);
return spy->value(0).value(0).value<QGeoCoordinate>();
}
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <QObject> #include <QObject>
#include <QSignalSpy> #include <QSignalSpy>
#include <QGeoCoordinate>
/// @file /// @file
/// @brief This class allows you to keep track of signal counts on a set of signals associated with an object. /// @brief This class allows you to keep track of signal counts on a set of signals associated with an object.
...@@ -46,42 +47,44 @@ public: ...@@ -46,42 +47,44 @@ public:
/// @param mask bit mask specifying which signals to check. The lowest order bit represents /// @param mask bit mask specifying which signals to check. The lowest order bit represents
/// index 0 into the rgSignals array and so on up the bit mask. /// index 0 into the rgSignals array and so on up the bit mask.
/// @return true if signal count = 1 for the specified signals /// @return true if signal count = 1 for the specified signals
bool checkSignalByMask(quint16 mask); bool checkSignalByMask(quint32 mask);
/// @return true if signal count = 1 for specified signals and signal count of 0 /// @return true if signal count = 1 for specified signals and signal count of 0
/// for all other signals /// for all other signals
bool checkOnlySignalByMask(quint16 mask); bool checkOnlySignalByMask(quint32 mask);
/// @param mask bit mask specifying which signals to check. The lowest order bit represents /// @param mask bit mask specifying which signals to check. The lowest order bit represents
/// index 0 into the rgSignals array and so on up the bit mask. /// index 0 into the rgSignals array and so on up the bit mask.
/// @return true if signal count >= 1 for the specified signals /// @return true if signal count >= 1 for the specified signals
bool checkSignalsByMask(quint16 mask); bool checkSignalsByMask(quint32 mask);
/// @return true if signal count >= 1 for specified signals and signal count of 0 /// @return true if signal count >= 1 for specified signals and signal count of 0
/// for all other signals /// for all other signals
bool checkOnlySignalsByMask(quint16 mask); bool checkOnlySignalsByMask(quint32 mask);
bool checkNoSignalByMask(quint16 mask); bool checkNoSignalByMask(quint32 mask);
bool checkNoSignals(void); bool checkNoSignals(void);
void clearSignalByIndex(quint16 index); void clearSignalByIndex(quint32 index);
void clearSignalsByMask(quint16 mask); void clearSignalsByMask(quint32 mask);
void clearAllSignals(void); void clearAllSignals(void);
bool waitForSignalByIndex(quint16 index, int msec); bool waitForSignalByIndex(quint32 index, int msec);
QSignalSpy* getSpyByIndex(quint16 index); QSignalSpy* getSpyByIndex(quint32 index);
/// Returns the boolean value for a signal which has a single bool param // Returns the value type for the first parameter of the signal
bool pullBoolFromSignalIndex(quint16 index); bool pullBoolFromSignalIndex(quint32 index);
int pullIntFromSignalIndex(quint32 index);
QGeoCoordinate pullQGeoCoordinateFromSignalIndex(quint32 index);
private: private:
// QObject overrides // QObject overrides
void timerEvent(QTimerEvent * event); void timerEvent(QTimerEvent * event);
void _printSignalState(void); void _printSignalState(quint32 mask);
bool _checkSignalByMaskWorker(quint16 mask, bool multipleSignalsAllowed); bool _checkSignalByMaskWorker(quint32 mask, bool multipleSignalsAllowed);
bool _checkOnlySignalByMaskWorker(quint16 mask, bool multipleSignalsAllowed); bool _checkOnlySignalByMaskWorker(quint32 mask, bool multipleSignalsAllowed);
QObject* _signalEmitter; QObject* _signalEmitter;
const char** _rgSignals; const char** _rgSignals;
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "MessageBoxTest.h" #include "MessageBoxTest.h"
#include "MissionItemTest.h" #include "MissionItemTest.h"
#include "SimpleMissionItemTest.h" #include "SimpleMissionItemTest.h"
#include "ComplexMissionItemTest.h"
#include "MissionControllerTest.h" #include "MissionControllerTest.h"
#include "MissionManagerTest.h" #include "MissionManagerTest.h"
#include "RadioConfigTest.h" #include "RadioConfigTest.h"
...@@ -49,6 +50,7 @@ UT_REGISTER_TEST(MavlinkLogTest) ...@@ -49,6 +50,7 @@ UT_REGISTER_TEST(MavlinkLogTest)
UT_REGISTER_TEST(MessageBoxTest) UT_REGISTER_TEST(MessageBoxTest)
UT_REGISTER_TEST(MissionItemTest) UT_REGISTER_TEST(MissionItemTest)
UT_REGISTER_TEST(SimpleMissionItemTest) UT_REGISTER_TEST(SimpleMissionItemTest)
UT_REGISTER_TEST(ComplexMissionItemTest)
UT_REGISTER_TEST(MissionControllerTest) UT_REGISTER_TEST(MissionControllerTest)
UT_REGISTER_TEST(MissionManagerTest) UT_REGISTER_TEST(MissionManagerTest)
UT_REGISTER_TEST(RadioConfigTest) 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