SurveyMissionItemTest.cc 9.57 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 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.
 *
 ****************************************************************************/
9 10


11
#include "SurveyMissionItemTest.h"
12

13
SurveyMissionItemTest::SurveyMissionItemTest(void)
14 15 16 17 18
{    
    _polyPoints << QGeoCoordinate(47.633550640000003, -122.08982199) << QGeoCoordinate(47.634129020000003, -122.08887249) <<
                  QGeoCoordinate(47.633619320000001, -122.08811074) << QGeoCoordinate(47.633189139999999, -122.08900124);
}

19
void SurveyMissionItemTest::init(void)
20 21 22 23 24 25 26 27 28 29 30 31 32
{
    _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());
33
    _rgComplexMissionItemSignals[abbreviationChangedIndex] =            SIGNAL(abbreviationChanged());
34 35 36 37 38 39 40 41 42 43 44 45 46 47
    _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));

48 49
    _surveyItem = new SurveyMissionItem(NULL /* Vehicle */, this);
    _mapPolygon = _surveyItem->mapPolygon();
50 51 52 53 54 55 56

    // 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);
57
    QCOMPARE(_multiSpy->init(_surveyItem, _rgComplexMissionItemSignals, _cComplexMissionItemSignals), true);
58 59
}

60
void SurveyMissionItemTest::cleanup(void)
61
{
62
    delete _surveyItem;
63 64 65
    delete _multiSpy;
}

66
void SurveyMissionItemTest::_testDirty(void)
67
{
68 69 70
    QVERIFY(!_surveyItem->dirty());
    _surveyItem->setDirty(false);
    QVERIFY(!_surveyItem->dirty());
71
    QVERIFY(_multiSpy->checkNoSignals());
72 73
    _surveyItem->setDirty(true);
    QVERIFY(_surveyItem->dirty());
74 75 76
    QVERIFY(_multiSpy->checkOnlySignalByMask(dirtyChangedMask));
    QVERIFY(_multiSpy->pullBoolFromSignalIndex(dirtyChangedIndex));
    _multiSpy->clearAllSignals();
77 78
    _surveyItem->setDirty(false);
    QVERIFY(!_surveyItem->dirty());
79 80 81 82
    QVERIFY(_multiSpy->checkOnlySignalByMask(dirtyChangedMask));
    QVERIFY(!_multiSpy->pullBoolFromSignalIndex(dirtyChangedIndex));
}

83
void SurveyMissionItemTest::_testAddPolygonCoordinate(void)
84
{
85
    QCOMPARE(_mapPolygon->count(), 0);
86 87 88 89 90

    // First call to addPolygonCoordinate should trigger:
    //      polygonPathChanged
    //      dirtyChanged

91
    _mapPolygon->appendVertex(_polyPoints[0]);
92 93 94
    QVERIFY(_multiSpy->checkOnlySignalByMask(polygonPathChangedMask | dirtyChangedMask));

    // Validate object data
95
    QVariantList polyList = _mapPolygon->path();
96 97 98 99
    QCOMPARE(polyList.count(), 1);
    QCOMPARE(polyList[0].value<QGeoCoordinate>(), _polyPoints[0]);

    // Reset
100
    _surveyItem->setDirty(false);
101 102 103 104 105 106
    _multiSpy->clearAllSignals();

    // Second call to addPolygonCoordinate should only trigger:
    //      polygonPathChanged
    //      dirtyChanged

107
    _mapPolygon->appendVertex(_polyPoints[1]);
108 109
    QVERIFY(_multiSpy->checkOnlySignalByMask(polygonPathChangedMask | dirtyChangedMask));

110
    polyList = _mapPolygon->path();
111 112 113 114 115
    QCOMPARE(polyList.count(), 2);
    for (int i=0; i<polyList.count(); i++) {
        QCOMPARE(polyList[i].value<QGeoCoordinate>(), _polyPoints[i]);
    }

116
    _surveyItem->setDirty(false);
117 118 119 120 121 122 123 124 125 126 127 128 129
    _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

130
    _mapPolygon->appendVertex(_polyPoints[2]);
131 132 133 134 135
    QVERIFY(_multiSpy->checkOnlySignalByMask(polygonPathChangedMask | lastSequenceNumberChangedMask | gridPointsChangedMask | coordinateChangedMask |
                                            exitCoordinateChangedMask | specifiesCoordinateChangedMask | dirtyChangedMask));
    int seqNum = _multiSpy->pullIntFromSignalIndex(lastSequenceNumberChangedIndex);
    QVERIFY(seqNum > 0);

136
    polyList = _mapPolygon->path();
137 138 139 140
    QCOMPARE(polyList.count(), 3);
    for (int i=0; i<polyList.count(); i++) {
        QCOMPARE(polyList[i].value<QGeoCoordinate>(), _polyPoints[i]);
    }
141 142

    // Test that number of waypoints is doubled when using turnaround waypoints
143 144 145 146
    _surveyItem->setTurnaroundDist(60.0);
    QVariantList gridPoints = _surveyItem->gridPoints();
    _surveyItem->setTurnaroundDist(0.0);
    QVariantList gridPointsNoT = _surveyItem->gridPoints();
147 148
    QCOMPARE(gridPoints.count(), 2 * gridPointsNoT.count());

149 150
}

151
void SurveyMissionItemTest::_testClearPolygon(void)
152 153
{
    for (int i=0; i<3; i++) {
154
        _mapPolygon->appendVertex(_polyPoints[i]);
155
    }
156
    _surveyItem->setDirty(false);
157 158 159 160 161 162 163 164 165 166
    _multiSpy->clearAllSignals();

    // Call to clearPolygon should trigger:
    //      polygonPathChangedMask
    //      dirtyChanged
    //      lastSequenceNumberChangedMask
    //      gridPointsChangedMask
    //      dirtyChangedMask
    //      specifiesCoordinateChangedMask

167
    _mapPolygon->clear();
168 169 170 171 172
    QVERIFY(_multiSpy->checkOnlySignalByMask(polygonPathChangedMask | lastSequenceNumberChangedMask | gridPointsChangedMask | dirtyChangedMask |
                                             specifiesCoordinateChangedMask));
    QVERIFY(!_multiSpy->pullBoolFromSignalIndex(specifiesCoordinateChangedIndex));
    QCOMPARE(_multiSpy->pullIntFromSignalIndex(lastSequenceNumberChangedIndex), 0);

173 174
    QCOMPARE(_mapPolygon->path().count(), 0);
    QCOMPARE(_surveyItem->gridPoints().count(), 0);
175

176
    _surveyItem->setDirty(false);
177 178 179
    _multiSpy->clearAllSignals();
}

180
void SurveyMissionItemTest::_testCameraTrigger(void)
181
{
182
    QCOMPARE(_surveyItem->property("cameraTrigger").toBool(), true);
183 184 185 186

    // Set up a grid

    for (int i=0; i<3; i++) {
187
        _mapPolygon->appendVertex(_polyPoints[i]);
188 189
    }

190
    _surveyItem->setDirty(false);
191 192
    _multiSpy->clearAllSignals();

193
    int lastSeq = _surveyItem->lastSequenceNumber();
194 195
    QVERIFY(lastSeq > 0);

196
    // Turning off camera triggering should remove two camera trigger mission items, this should trigger:
197 198 199
    //      lastSequenceNumberChanged
    //      dirtyChanged

200
    _surveyItem->setProperty("cameraTrigger", false);
201
    QVERIFY(_multiSpy->checkOnlySignalByMask(lastSequenceNumberChangedMask | dirtyChangedMask | cameraTriggerChangedMask));
202
    QCOMPARE(_multiSpy->pullIntFromSignalIndex(lastSequenceNumberChangedIndex), lastSeq - 2);
203

204
    _surveyItem->setDirty(false);
205 206
    _multiSpy->clearAllSignals();

207
    // Turn on camera triggering and make sure things go back to previous count
208

209
    _surveyItem->setProperty("cameraTrigger", true);
210 211 212
    QVERIFY(_multiSpy->checkOnlySignalByMask(lastSequenceNumberChangedMask | dirtyChangedMask | cameraTriggerChangedMask));
    QCOMPARE(_multiSpy->pullIntFromSignalIndex(lastSequenceNumberChangedIndex), lastSeq);
}