Unverified Commit bc0afbca authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #6113 from DonLakeFlyer/ComplexUT

More work on better unit tests
parents 1fcee82b 4481da1d
...@@ -39,24 +39,15 @@ CorridorScanComplexItem::CorridorScanComplexItem(Vehicle* vehicle, QObject* pare ...@@ -39,24 +39,15 @@ CorridorScanComplexItem::CorridorScanComplexItem(Vehicle* vehicle, QObject* pare
connect(&_corridorWidthFact, &Fact::valueChanged, this, &CorridorScanComplexItem::_setDirty); connect(&_corridorWidthFact, &Fact::valueChanged, this, &CorridorScanComplexItem::_setDirty);
connect(&_corridorPolyline, &QGCMapPolyline::pathChanged, this, &CorridorScanComplexItem::_setDirty); connect(&_corridorPolyline, &QGCMapPolyline::pathChanged, this, &CorridorScanComplexItem::_setDirty);
connect(&_cameraCalc, &CameraCalc::distanceToSurfaceRelativeChanged, this, &CorridorScanComplexItem::coordinateHasRelativeAltitudeChanged); connect(&_cameraCalc, &CameraCalc::distanceToSurfaceRelativeChanged, this, &CorridorScanComplexItem::coordinateHasRelativeAltitudeChanged);
connect(&_cameraCalc, &CameraCalc::distanceToSurfaceRelativeChanged, this, &CorridorScanComplexItem::exitCoordinateHasRelativeAltitudeChanged); connect(&_cameraCalc, &CameraCalc::distanceToSurfaceRelativeChanged, this, &CorridorScanComplexItem::exitCoordinateHasRelativeAltitudeChanged);
connect(&_corridorPolyline, &QGCMapPolyline::dirtyChanged, this, &CorridorScanComplexItem::_polylineDirtyChanged); connect(&_corridorPolyline, &QGCMapPolyline::dirtyChanged, this, &CorridorScanComplexItem::_polylineDirtyChanged);
connect(&_corridorPolyline, &QGCMapPolyline::countChanged, this, &CorridorScanComplexItem::_polylineCountChanged); connect(&_corridorPolyline, &QGCMapPolyline::countChanged, this, &CorridorScanComplexItem::_polylineCountChanged);
connect(_cameraCalc.adjustedFootprintSide(), &Fact::valueChanged, this, &CorridorScanComplexItem::_rebuildTransects);
connect(&_corridorPolyline, &QGCMapPolyline::pathChanged, this, &CorridorScanComplexItem::_rebuildCorridor); connect(&_corridorPolyline, &QGCMapPolyline::pathChanged, this, &CorridorScanComplexItem::_rebuildCorridor);
connect(&_corridorWidthFact, &Fact::valueChanged, this, &CorridorScanComplexItem::_rebuildCorridor); connect(&_corridorWidthFact, &Fact::valueChanged, this, &CorridorScanComplexItem::_rebuildCorridor);
connect(&_corridorPolyline, &QGCMapPolyline::countChanged, this, &CorridorScanComplexItem::_signalLastSequenceNumberChanged);
connect(&_corridorWidthFact, &Fact::valueChanged, this, &CorridorScanComplexItem::_signalLastSequenceNumberChanged);
connect(_cameraCalc.adjustedFootprintSide(), &Fact::valueChanged, this, &CorridorScanComplexItem::_signalLastSequenceNumberChanged);
connect(this, &CorridorScanComplexItem::transectPointsChanged, this, &CorridorScanComplexItem::complexDistanceChanged);
connect(this, &CorridorScanComplexItem::transectPointsChanged, this, &CorridorScanComplexItem::greatestDistanceToChanged);
_rebuildCorridor(); _rebuildCorridor();
} }
......
...@@ -45,27 +45,53 @@ TransectStyleComplexItem::TransectStyleComplexItem(Vehicle* vehicle, QString set ...@@ -45,27 +45,53 @@ TransectStyleComplexItem::TransectStyleComplexItem(Vehicle* vehicle, QString set
, _hoverAndCaptureFact (_settingsGroup, _metaDataMap[hoverAndCaptureName]) , _hoverAndCaptureFact (_settingsGroup, _metaDataMap[hoverAndCaptureName])
, _refly90DegreesFact (_settingsGroup, _metaDataMap[refly90DegreesName]) , _refly90DegreesFact (_settingsGroup, _metaDataMap[refly90DegreesName])
{ {
connect(_cameraCalc.adjustedFootprintSide(), &Fact::valueChanged, this, &TransectStyleComplexItem::_rebuildTransects); connect(&_turnAroundDistanceFact, &Fact::valueChanged, this, &TransectStyleComplexItem::_rebuildTransects);
connect(_cameraCalc.adjustedFootprintSide(), &Fact::valueChanged, this, &TransectStyleComplexItem::_signalLastSequenceNumberChanged); connect(&_hoverAndCaptureFact, &Fact::valueChanged, this, &TransectStyleComplexItem::_rebuildTransects);
connect(&_refly90DegreesFact, &Fact::valueChanged, this, &TransectStyleComplexItem::_rebuildTransects);
connect(&_turnAroundDistanceFact, &Fact::valueChanged, this, &TransectStyleComplexItem::_rebuildTransects); connect(&_surveyAreaPolygon, &QGCMapPolygon::pathChanged, this, &TransectStyleComplexItem::_rebuildTransects);
connect(&_hoverAndCaptureFact, &Fact::valueChanged, this, &TransectStyleComplexItem::_rebuildTransects); connect(&_cameraTriggerInTurnAroundFact, &Fact::valueChanged, this, &TransectStyleComplexItem::_rebuildTransects);
connect(&_refly90DegreesFact, &Fact::valueChanged, this, &TransectStyleComplexItem::_rebuildTransects); connect(_cameraCalc.adjustedFootprintSide(), &Fact::valueChanged, this, &TransectStyleComplexItem::_rebuildTransects);
connect(&_surveyAreaPolygon, &QGCMapPolygon::pathChanged, this, &TransectStyleComplexItem::_rebuildTransects); connect(_cameraCalc.adjustedFootprintFrontal(), &Fact::valueChanged, this, &TransectStyleComplexItem::_rebuildTransects);
connect(&_turnAroundDistanceFact, &Fact::valueChanged, this, &TransectStyleComplexItem::_setDirty); connect(&_turnAroundDistanceFact, &Fact::valueChanged, this, &TransectStyleComplexItem::_signalLastSequenceNumberChanged);
connect(&_cameraTriggerInTurnAroundFact, &Fact::valueChanged, this, &TransectStyleComplexItem::_setDirty); connect(&_hoverAndCaptureFact, &Fact::valueChanged, this, &TransectStyleComplexItem::_signalLastSequenceNumberChanged);
connect(&_hoverAndCaptureFact, &Fact::valueChanged, this, &TransectStyleComplexItem::_setDirty); connect(&_refly90DegreesFact, &Fact::valueChanged, this, &TransectStyleComplexItem::_signalLastSequenceNumberChanged);
connect(&_refly90DegreesFact, &Fact::valueChanged, this, &TransectStyleComplexItem::_setDirty); connect(&_surveyAreaPolygon, &QGCMapPolygon::pathChanged, this, &TransectStyleComplexItem::_signalLastSequenceNumberChanged);
connect(&_surveyAreaPolygon, &QGCMapPolygon::pathChanged, this, &TransectStyleComplexItem::_setDirty); connect(&_cameraTriggerInTurnAroundFact, &Fact::valueChanged, this, &TransectStyleComplexItem::_signalLastSequenceNumberChanged);
connect(_cameraCalc.adjustedFootprintSide(), &Fact::valueChanged, this, &TransectStyleComplexItem::_signalLastSequenceNumberChanged);
connect(&_surveyAreaPolygon, &QGCMapPolygon::dirtyChanged, this, &TransectStyleComplexItem::_setIfDirty); connect(_cameraCalc.adjustedFootprintFrontal(), &Fact::valueChanged, this, &TransectStyleComplexItem::_signalLastSequenceNumberChanged);
connect(&_cameraCalc, &CameraCalc::dirtyChanged, this, &TransectStyleComplexItem::_setIfDirty);
connect(&_turnAroundDistanceFact, &Fact::valueChanged, this, &TransectStyleComplexItem::cameraShotsChanged);
connect(&_surveyAreaPolygon, &QGCMapPolygon::pathChanged, this, &TransectStyleComplexItem::coveredAreaChanged); connect(&_hoverAndCaptureFact, &Fact::valueChanged, this, &TransectStyleComplexItem::cameraShotsChanged);
connect(&_refly90DegreesFact, &Fact::valueChanged, this, &TransectStyleComplexItem::cameraShotsChanged);
connect(this, &TransectStyleComplexItem::transectPointsChanged, this, &TransectStyleComplexItem::complexDistanceChanged); connect(&_surveyAreaPolygon, &QGCMapPolygon::pathChanged, this, &TransectStyleComplexItem::cameraShotsChanged);
connect(this, &TransectStyleComplexItem::transectPointsChanged, this, &TransectStyleComplexItem::greatestDistanceToChanged); connect(&_cameraTriggerInTurnAroundFact, &Fact::valueChanged, this, &TransectStyleComplexItem::cameraShotsChanged);
connect(_cameraCalc.adjustedFootprintSide(), &Fact::valueChanged, this, &TransectStyleComplexItem::cameraShotsChanged);
connect(_cameraCalc.adjustedFootprintFrontal(), &Fact::valueChanged, this, &TransectStyleComplexItem::cameraShotsChanged);
connect(&_turnAroundDistanceFact, &Fact::valueChanged, this, &TransectStyleComplexItem::complexDistanceChanged);
connect(&_hoverAndCaptureFact, &Fact::valueChanged, this, &TransectStyleComplexItem::complexDistanceChanged);
connect(&_refly90DegreesFact, &Fact::valueChanged, this, &TransectStyleComplexItem::complexDistanceChanged);
connect(&_surveyAreaPolygon, &QGCMapPolygon::pathChanged, this, &TransectStyleComplexItem::complexDistanceChanged);
connect(&_turnAroundDistanceFact, &Fact::valueChanged, this, &TransectStyleComplexItem::greatestDistanceToChanged);
connect(&_hoverAndCaptureFact, &Fact::valueChanged, this, &TransectStyleComplexItem::greatestDistanceToChanged);
connect(&_refly90DegreesFact, &Fact::valueChanged, this, &TransectStyleComplexItem::greatestDistanceToChanged);
connect(&_surveyAreaPolygon, &QGCMapPolygon::pathChanged, this, &TransectStyleComplexItem::greatestDistanceToChanged);
connect(&_turnAroundDistanceFact, &Fact::valueChanged, this, &TransectStyleComplexItem::_setDirty);
connect(&_cameraTriggerInTurnAroundFact, &Fact::valueChanged, this, &TransectStyleComplexItem::_setDirty);
connect(&_hoverAndCaptureFact, &Fact::valueChanged, this, &TransectStyleComplexItem::_setDirty);
connect(&_refly90DegreesFact, &Fact::valueChanged, this, &TransectStyleComplexItem::_setDirty);
connect(&_surveyAreaPolygon, &QGCMapPolygon::pathChanged, this, &TransectStyleComplexItem::_setDirty);
connect(&_surveyAreaPolygon, &QGCMapPolygon::dirtyChanged, this, &TransectStyleComplexItem::_setIfDirty);
connect(&_cameraCalc, &CameraCalc::dirtyChanged, this, &TransectStyleComplexItem::_setIfDirty);
connect(&_surveyAreaPolygon, &QGCMapPolygon::pathChanged, this, &TransectStyleComplexItem::coveredAreaChanged);
connect(this, &TransectStyleComplexItem::transectPointsChanged, this, &TransectStyleComplexItem::complexDistanceChanged);
connect(this, &TransectStyleComplexItem::transectPointsChanged, this, &TransectStyleComplexItem::greatestDistanceToChanged);
} }
void TransectStyleComplexItem::_setScanDistance(double scanDistance) void TransectStyleComplexItem::_setScanDistance(double scanDistance)
......
...@@ -13,9 +13,10 @@ ...@@ -13,9 +13,10 @@
TransectStyleComplexItemTest::TransectStyleComplexItemTest(void) TransectStyleComplexItemTest::TransectStyleComplexItemTest(void)
: _offlineVehicle(NULL) : _offlineVehicle(NULL)
{ {
_linePoints << QGeoCoordinate(47.633550640000003, -122.08982199) _polygonVertices << QGeoCoordinate(47.633550640000003, -122.08982199)
<< QGeoCoordinate(47.634129020000003, -122.08887249) << QGeoCoordinate(47.634129020000003, -122.08887249)
<< QGeoCoordinate(47.633619320000001, -122.08811074); << QGeoCoordinate(47.633619320000001, -122.08811074)
<< QGeoCoordinate(47.633189139999999, -122.08900124);
} }
void TransectStyleComplexItemTest::init(void) void TransectStyleComplexItemTest::init(void)
...@@ -24,6 +25,8 @@ void TransectStyleComplexItemTest::init(void) ...@@ -24,6 +25,8 @@ void TransectStyleComplexItemTest::init(void)
_offlineVehicle = new Vehicle(MAV_AUTOPILOT_PX4, MAV_TYPE_QUADROTOR, qgcApp()->toolbox()->firmwarePluginManager(), this); _offlineVehicle = new Vehicle(MAV_AUTOPILOT_PX4, MAV_TYPE_QUADROTOR, qgcApp()->toolbox()->firmwarePluginManager(), this);
_transectStyleItem = new TransectStyleItem(_offlineVehicle, this); _transectStyleItem = new TransectStyleItem(_offlineVehicle, this);
_setSurveyAreaPolygon();
_transectStyleItem->setDirty(false);
_rgSignals[cameraShotsChangedIndex] = SIGNAL(cameraShotsChanged()); _rgSignals[cameraShotsChangedIndex] = SIGNAL(cameraShotsChanged());
_rgSignals[timeBetweenShotsChangedIndex] = SIGNAL(timeBetweenShotsChanged()); _rgSignals[timeBetweenShotsChangedIndex] = SIGNAL(timeBetweenShotsChanged());
...@@ -34,6 +37,7 @@ void TransectStyleComplexItemTest::init(void) ...@@ -34,6 +37,7 @@ void TransectStyleComplexItemTest::init(void)
_rgSignals[complexDistanceChangedIndex] = SIGNAL(complexDistanceChanged()); _rgSignals[complexDistanceChangedIndex] = SIGNAL(complexDistanceChanged());
_rgSignals[greatestDistanceToChangedIndex] = SIGNAL(greatestDistanceToChanged()); _rgSignals[greatestDistanceToChangedIndex] = SIGNAL(greatestDistanceToChanged());
_rgSignals[additionalTimeDelayChangedIndex] = SIGNAL(additionalTimeDelayChanged()); _rgSignals[additionalTimeDelayChangedIndex] = SIGNAL(additionalTimeDelayChanged());
_rgSignals[lastSequenceNumberChangedIndex] = SIGNAL(lastSequenceNumberChanged(int));
_multiSpy = new MultiSignalSpy(); _multiSpy = new MultiSignalSpy();
QCOMPARE(_multiSpy->init(_transectStyleItem, _rgSignals, _cSignals), true); QCOMPARE(_multiSpy->init(_transectStyleItem, _rgSignals, _cSignals), true);
...@@ -73,46 +77,106 @@ void TransectStyleComplexItemTest::_testDirty(void) ...@@ -73,46 +77,106 @@ void TransectStyleComplexItemTest::_testDirty(void)
foreach(Fact* fact, rgFacts) { foreach(Fact* fact, rgFacts) {
qDebug() << fact->name(); qDebug() << fact->name();
QVERIFY(!_transectStyleItem->dirty()); QVERIFY(!_transectStyleItem->dirty());
if (fact->typeIsBool()) { changeFactValue(fact);
fact->setRawValue(!fact->rawValue().toBool());
} else {
fact->setRawValue(fact->rawValue().toDouble() + 1);
}
QVERIFY(_multiSpy->checkSignalByMask(dirtyChangedMask)); QVERIFY(_multiSpy->checkSignalByMask(dirtyChangedMask));
_transectStyleItem->setDirty(false); _transectStyleItem->setDirty(false);
_multiSpy->clearAllSignals(); _multiSpy->clearAllSignals();
} }
rgFacts.clear(); rgFacts.clear();
_setPolyline(); _adjustSurveAreaPolygon();
QVERIFY(_transectStyleItem->dirty()); QVERIFY(_transectStyleItem->dirty());
_transectStyleItem->setDirty(false); _transectStyleItem->setDirty(false);
QVERIFY(!_transectStyleItem->surveyAreaPolygon()->dirty()); QVERIFY(!_transectStyleItem->surveyAreaPolygon()->dirty());
_multiSpy->clearAllSignals(); _multiSpy->clearAllSignals();
_transectStyleItem->cameraCalc()->distanceToSurface()->setRawValue(_transectStyleItem->cameraCalc()->distanceToSurface()->rawValue().toDouble() + 1); changeFactValue(_transectStyleItem->cameraCalc()->distanceToSurface());
QVERIFY(_transectStyleItem->dirty()); QVERIFY(_transectStyleItem->dirty());
_transectStyleItem->setDirty(false); _transectStyleItem->setDirty(false);
QVERIFY(!_transectStyleItem->cameraCalc()->dirty()); QVERIFY(!_transectStyleItem->cameraCalc()->dirty());
_multiSpy->clearAllSignals(); _multiSpy->clearAllSignals();
} }
void TransectStyleComplexItemTest::_setPolyline(void) void TransectStyleComplexItemTest::_setSurveyAreaPolygon(void)
{ {
for (int i=0; i<_linePoints.count(); i++) { foreach (const QGeoCoordinate vertex, _polygonVertices) {
QGeoCoordinate& vertex = _linePoints[i];
_transectStyleItem->surveyAreaPolygon()->appendVertex(vertex); _transectStyleItem->surveyAreaPolygon()->appendVertex(vertex);
} }
} }
void TransectStyleComplexItemTest::_testRebuildTransects(void)
{
// Changing the survey polygon should trigger:
// _rebuildTransects call
// coveredAreaChanged signal
// lastSequenceNumberChanged signal
// cameraShotsChanged signal
_adjustSurveAreaPolygon();
QVERIFY(_transectStyleItem->rebuildTransectsCalled);
QVERIFY(_multiSpy->checkSignalsByMask(coveredAreaChangedMask | lastSequenceNumberChangedMask | cameraShotsChangedMask));
_transectStyleItem->rebuildTransectsCalled = false;
_transectStyleItem->setDirty(false);
_multiSpy->clearAllSignals();
// Changes to these facts should trigger:
// _rebuildTransects call
// lastSequenceNumberChanged signal
// cameraShotsChanged signal
QList<Fact*> rgFacts;
rgFacts << _transectStyleItem->turnAroundDistance()
<< _transectStyleItem->cameraTriggerInTurnAround()
<< _transectStyleItem->hoverAndCapture()
<< _transectStyleItem->refly90Degrees()
<< _transectStyleItem->cameraCalc()->adjustedFootprintSide()
<< _transectStyleItem->cameraCalc()->adjustedFootprintFrontal();
foreach(Fact* fact, rgFacts) {
qDebug() << fact->name();
changeFactValue(fact);
QVERIFY(_transectStyleItem->rebuildTransectsCalled);
QVERIFY(_multiSpy->checkSignalsByMask(lastSequenceNumberChangedMask | cameraShotsChangedMask));
_transectStyleItem->setDirty(false);
_multiSpy->clearAllSignals();
_transectStyleItem->rebuildTransectsCalled = false;
}
rgFacts.clear();
}
void TransectStyleComplexItemTest::_testDistanceSignalling(void)
{
_adjustSurveAreaPolygon();
QVERIFY(_multiSpy->checkSignalsByMask(complexDistanceChangedMask | greatestDistanceToChangedMask));
_transectStyleItem->setDirty(false);
_multiSpy->clearAllSignals();
QList<Fact*> rgFacts;
rgFacts << _transectStyleItem->turnAroundDistance()
<< _transectStyleItem->hoverAndCapture()
<< _transectStyleItem->refly90Degrees();
foreach(Fact* fact, rgFacts) {
qDebug() << fact->name();
changeFactValue(fact);
QVERIFY(_multiSpy->checkSignalsByMask(complexDistanceChangedMask | greatestDistanceToChangedMask));
_transectStyleItem->setDirty(false);
_multiSpy->clearAllSignals();
}
rgFacts.clear();
}
void TransectStyleComplexItemTest::_adjustSurveAreaPolygon(void)
{
QGeoCoordinate vertex = _transectStyleItem->surveyAreaPolygon()->vertexCoordinate(0);
vertex.setLatitude(vertex.latitude() + 1);
_transectStyleItem->surveyAreaPolygon()->adjustVertex(0, vertex);
}
TransectStyleItem::TransectStyleItem(Vehicle* vehicle, QObject* parent) TransectStyleItem::TransectStyleItem(Vehicle* vehicle, QObject* parent)
: TransectStyleComplexItem (vehicle, QStringLiteral("UnitTestTransect"), parent) : TransectStyleComplexItem (vehicle, QStringLiteral("UnitTestTransect"), parent)
, _rebuildTransectsCalled (false) , rebuildTransectsCalled (false)
{ {
} }
void TransectStyleItem::_rebuildTransects(void) void TransectStyleItem::_rebuildTransects(void)
{ {
_rebuildTransectsCalled = true; rebuildTransectsCalled = true;
} }
...@@ -29,10 +29,13 @@ protected: ...@@ -29,10 +29,13 @@ protected:
void cleanup(void) final; void cleanup(void) final;
private slots: private slots:
void _testDirty(void); void _testDirty (void);
void _testRebuildTransects (void);
void _testDistanceSignalling (void);
private: private:
void _setPolyline(void); void _setSurveyAreaPolygon (void);
void _adjustSurveAreaPolygon(void);
enum { enum {
// These signals are from TransectStyleComplexItem // These signals are from TransectStyleComplexItem
...@@ -46,6 +49,8 @@ private: ...@@ -46,6 +49,8 @@ private:
complexDistanceChangedIndex, complexDistanceChangedIndex,
greatestDistanceToChangedIndex, greatestDistanceToChangedIndex,
additionalTimeDelayChangedIndex, additionalTimeDelayChangedIndex,
// These signals are from VisualMissionItem
lastSequenceNumberChangedIndex,
maxSignalIndex maxSignalIndex
}; };
...@@ -61,6 +66,8 @@ private: ...@@ -61,6 +66,8 @@ private:
complexDistanceChangedMask = 1 << complexDistanceChangedIndex, complexDistanceChangedMask = 1 << complexDistanceChangedIndex,
greatestDistanceToChangedMask = 1 << greatestDistanceToChangedIndex, greatestDistanceToChangedMask = 1 << greatestDistanceToChangedIndex,
additionalTimeDelayChangedMask = 1 << additionalTimeDelayChangedIndex, additionalTimeDelayChangedMask = 1 << additionalTimeDelayChangedIndex,
// These signals are from VisualMissionItem
lastSequenceNumberChangedMask = 1 << lastSequenceNumberChangedIndex,
}; };
static const size_t _cSignals = maxSignalIndex; static const size_t _cSignals = maxSignalIndex;
...@@ -68,7 +75,7 @@ private: ...@@ -68,7 +75,7 @@ private:
Vehicle* _offlineVehicle; Vehicle* _offlineVehicle;
MultiSignalSpy* _multiSpy; MultiSignalSpy* _multiSpy;
QList<QGeoCoordinate> _linePoints; QList<QGeoCoordinate> _polygonVertices;
TransectStyleItem* _transectStyleItem; TransectStyleItem* _transectStyleItem;
}; };
...@@ -90,10 +97,9 @@ public: ...@@ -90,10 +97,9 @@ public:
void appendMissionItems (QList<MissionItem*>& items, QObject* missionItemParent) final { Q_UNUSED(items); Q_UNUSED(missionItemParent); } void appendMissionItems (QList<MissionItem*>& items, QObject* missionItemParent) final { Q_UNUSED(items); Q_UNUSED(missionItemParent); }
void applyNewAltitude (double newAltitude) final { Q_UNUSED(newAltitude); } void applyNewAltitude (double newAltitude) final { Q_UNUSED(newAltitude); }
bool rebuildTransectsCalled;
private slots: private slots:
// Overrides from TransectStyleComplexItem // Overrides from TransectStyleComplexItem
void _rebuildTransects (void) final; void _rebuildTransects (void) final;
private:
bool _rebuildTransectsCalled;
}; };
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