LandingComplexItemTest.h 5.17 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
/****************************************************************************
 *
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

#pragma once

#include "VisualMissionItemTest.h"
#include "LandingComplexItem.h"
#include "MultiSignalSpy.h"
#include "PlanMasterController.h"

class LandingComplexItemTest : public VisualMissionItemTest
{
    Q_OBJECT
    
public:
    LandingComplexItemTest(void);

    void cleanup(void) override;
    void init   (void) override;

private slots:
    void _testDirty                 (void);
    void _testItemCount             (void);
    void _testAppendSectionItems    (void);
    void _testScanForItems          (void);
    void _testSaveLoad              (void);

private:
    void _validateItem(LandingComplexItem* actualItem, LandingComplexItem* expectedItem);

    enum {
        finalApproachCoordinateChangedIndex = 0,
        loiterTangentCoordinateChangedIndex,
        landingCoordinateChangedIndex,
        landingCoordSetChangedIndex,
        loiterClockwiseChangedIndex,
        useLoiterToAltChangedIndex,
        altitudesAreRelativeChangedIndex,
        _updateFlightPathSegmentsSignalIndex,
        maxSignalIndex,
    };

    enum {
        finalApproachCoordinateChangedMask      = 1 << finalApproachCoordinateChangedIndex,
        loiterTangentCoordinateChangedMask      = 1 << loiterTangentCoordinateChangedIndex,
        landingCoordinateChangedMask            = 1 << landingCoordinateChangedIndex,
        landingCoordSetChangedMask              = 1 << landingCoordSetChangedIndex,
        loiterClockwiseChangedMask              = 1 << loiterClockwiseChangedIndex,
        useLoiterToAltChangedMask               = 1 << useLoiterToAltChangedIndex,
        altitudesAreRelativeChangedMask         = 1 << altitudesAreRelativeChangedIndex,
        _updateFlightPathSegmentsSignalMask     = 1 << _updateFlightPathSegmentsSignalIndex,
    };

    static const size_t cSignals = maxSignalIndex;
    const char*         rgSignals[cSignals];

    LandingComplexItem* _item                   = nullptr;
    MultiSignalSpy*     _multiSpy               = nullptr;
    MultiSignalSpy*     _viMultiSpy             = nullptr;
    SimpleMissionItem*  _validStopVideoItem     = nullptr;
    SimpleMissionItem*  _validStopDistanceItem  = nullptr;
    SimpleMissionItem*  _validStopTimeItem      = nullptr;
};

// Simple class used to test LandingComplexItem base class
class SimpleLandingComplexItem : public LandingComplexItem
{
    Q_OBJECT

public:
    SimpleLandingComplexItem(PlanMasterController* masterController, bool flyView, QObject* parent);

    // Overrides from ComplexMissionItem
    QString patternName (void) const final { return QString(); }
    bool    load        (const QJsonObject& /*complexObject*/, int /*sequenceNumber*/, QString& /*errorString*/) final { return false; };
    QString mapVisualQML(void) const final { return QStringLiteral("FWLandingPatternMapVisual.qml"); }

    // Overrides from VisualMissionItem
    void                save                        (QJsonArray&  /*missionItems*/) { };

    static const QString name;

    static const char* jsonComplexItemTypeValue;

    static const char* settingsGroup;

private:
    static LandingComplexItem*  _createItem     (PlanMasterController* masterController, bool flyView, QObject* parent) { return new SimpleLandingComplexItem(masterController, flyView, parent); }
    static bool                 _isValidLandItem(const MissionItem& missionItem);

    // Overrides from LandingComplexItem
    const Fact*     _finalApproachAltitude  (void) const final { return &_finalApproachAltitudeFact; }
    const Fact*     _loiterRadius           (void) const final { return &_loiterRadiusFact; }
    const Fact*     _loiterClockwise        (void) const final { return &_loiterClockwiseFact; }
    const Fact*     _landingAltitude        (void) const final { return &_landingAltitudeFact; }
    const Fact*     _landingDistance        (void) const final { return &_landingDistanceFact; }
    const Fact*     _landingHeading         (void) const final { return &_landingHeadingFact; }
    const Fact*     _useLoiterToAlt         (void) const final { return &_useLoiterToAltFact; }
    const Fact*     _stopTakingPhotos       (void) const final { return &_stopTakingPhotosFact; }
    const Fact*     _stopTakingVideo        (void) const final { return &_stopTakingVideoFact; }
    void            _calcGlideSlope         (void) final { };
    MissionItem*    _createLandItem         (int seqNum, bool altRel, double lat, double lon, double alt, QObject* parent) final;

    QMap<QString, FactMetaData*> _metaDataMap;

    Fact            _landingDistanceFact;
    Fact            _finalApproachAltitudeFact;
    Fact            _loiterRadiusFact;
    Fact            _loiterClockwiseFact;
    Fact            _landingHeadingFact;
    Fact            _landingAltitudeFact;
    Fact            _useLoiterToAltFact;
    Fact            _stopTakingPhotosFact;
    Fact            _stopTakingVideoFact;

    friend class LandingComplexItemTest;
};