SurveyMissionItemTest.cc 11.6 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
#include "SurveyMissionItemTest.h"
Don Gagne's avatar
Don Gagne committed
11
#include "QGCApplication.h"
12

13
SurveyMissionItemTest::SurveyMissionItemTest(void)
Don Gagne's avatar
Don Gagne committed
14 15
    : _offlineVehicle(NULL)
{
16
    _polyPoints << QGeoCoordinate(47.633550640000003, -122.08982199) << QGeoCoordinate(47.634129020000003, -122.08887249) <<
Don Gagne's avatar
Don Gagne committed
17
                   QGeoCoordinate(47.633619320000001, -122.08811074) << QGeoCoordinate(47.633189139999999, -122.08900124);
18 19
}

20
void SurveyMissionItemTest::init(void)
21
{
Don Gagne's avatar
Don Gagne committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35
    UnitTest::init();

    _rgSurveySignals[gridPointsChangedIndex] =              SIGNAL(gridPointsChanged());
    _rgSurveySignals[cameraShotsChangedIndex] =             SIGNAL(cameraShotsChanged(int));
    _rgSurveySignals[coveredAreaChangedIndex] =             SIGNAL(coveredAreaChanged(double));
    _rgSurveySignals[cameraValueChangedIndex] =             SIGNAL(cameraValueChanged());
    _rgSurveySignals[gridTypeChangedIndex] =                SIGNAL(gridTypeChanged(QString));
    _rgSurveySignals[timeBetweenShotsChangedIndex] =        SIGNAL(timeBetweenShotsChanged());
    _rgSurveySignals[cameraOrientationFixedChangedIndex] =  SIGNAL(cameraOrientationFixedChanged(bool));
    _rgSurveySignals[refly90DegreesChangedIndex] =          SIGNAL(refly90DegreesChanged(bool));
    _rgSurveySignals[dirtyChangedIndex] =                   SIGNAL(dirtyChanged(bool));

    _offlineVehicle = new Vehicle(MAV_AUTOPILOT_PX4, MAV_TYPE_QUADROTOR, qgcApp()->toolbox()->firmwarePluginManager(), this);
    _surveyItem = new SurveyMissionItem(_offlineVehicle, this);
36
    _mapPolygon = _surveyItem->mapPolygon();
37 38 39 40 41 42 43

    // 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);
Don Gagne's avatar
Don Gagne committed
44
    QCOMPARE(_multiSpy->init(_surveyItem, _rgSurveySignals, _cSurveySignals), true);
45 46
}

47
void SurveyMissionItemTest::cleanup(void)
48
{
49
    delete _surveyItem;
Don Gagne's avatar
Don Gagne committed
50
    delete _offlineVehicle;
51 52 53
    delete _multiSpy;
}

54
void SurveyMissionItemTest::_testDirty(void)
55
{
56 57 58
    QVERIFY(!_surveyItem->dirty());
    _surveyItem->setDirty(false);
    QVERIFY(!_surveyItem->dirty());
59
    QVERIFY(_multiSpy->checkNoSignals());
Don Gagne's avatar
Don Gagne committed
60

61 62
    _surveyItem->setDirty(true);
    QVERIFY(_surveyItem->dirty());
63 64 65
    QVERIFY(_multiSpy->checkOnlySignalByMask(dirtyChangedMask));
    QVERIFY(_multiSpy->pullBoolFromSignalIndex(dirtyChangedIndex));
    _multiSpy->clearAllSignals();
Don Gagne's avatar
Don Gagne committed
66

67 68
    _surveyItem->setDirty(false);
    QVERIFY(!_surveyItem->dirty());
69 70
    QVERIFY(_multiSpy->checkOnlySignalByMask(dirtyChangedMask));
    QVERIFY(!_multiSpy->pullBoolFromSignalIndex(dirtyChangedIndex));
Don Gagne's avatar
Don Gagne committed
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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
    _multiSpy->clearAllSignals();

    // These facts should set dirty when changed
    QList<Fact*> rgFacts;
    rgFacts << _surveyItem->gridAltitude() << _surveyItem->gridAngle() << _surveyItem->gridSpacing() << _surveyItem->turnaroundDist() << _surveyItem->cameraTriggerDistance() <<
               _surveyItem->gridAltitudeRelative() << _surveyItem->cameraTriggerInTurnaround() << _surveyItem->hoverAndCapture();
    foreach(Fact* fact, rgFacts) {
        qDebug() << fact->name();
        QVERIFY(!_surveyItem->dirty());
        if (fact->typeIsBool()) {
            fact->setRawValue(!fact->rawValue().toBool());
        } else {
            fact->setRawValue(fact->rawValue().toDouble() + 1);
        }
        QVERIFY(_multiSpy->checkSignalByMask(dirtyChangedMask));
        QVERIFY(_multiSpy->pullBoolFromSignalIndex(dirtyChangedIndex));
        _surveyItem->setDirty(false);
        _multiSpy->clearAllSignals();
    }
    rgFacts.clear();

    // These facts should not change dirty bit
    rgFacts << _surveyItem->groundResolution() << _surveyItem->frontalOverlap() << _surveyItem->sideOverlap() << _surveyItem->cameraSensorWidth() << _surveyItem->cameraSensorHeight() <<
               _surveyItem->cameraResolutionWidth() << _surveyItem->cameraResolutionHeight() << _surveyItem->cameraFocalLength() << _surveyItem->cameraOrientationLandscape() <<
                _surveyItem->fixedValueIsAltitude() << _surveyItem->camera() << _surveyItem->manualGrid();
    foreach(Fact* fact, rgFacts) {
        qDebug() << fact->name();
        QVERIFY(!_surveyItem->dirty());
        if (fact->typeIsBool()) {
            fact->setRawValue(!fact->rawValue().toBool());
        } else {
            fact->setRawValue(fact->rawValue().toDouble() + 1);
        }
        QVERIFY(_multiSpy->checkNoSignalByMask(dirtyChangedMask));
        QVERIFY(!_surveyItem->dirty());
        _multiSpy->clearAllSignals();
    }
    rgFacts.clear();
}

void SurveyMissionItemTest::_testCameraValueChanged(void)
{
    // These facts should trigger cameraValueChanged when changed
    QList<Fact*> rgFacts;
    rgFacts << _surveyItem->groundResolution() << _surveyItem->frontalOverlap() << _surveyItem->sideOverlap() << _surveyItem->cameraSensorWidth() << _surveyItem->cameraSensorHeight() <<
               _surveyItem->cameraResolutionWidth() << _surveyItem->cameraResolutionHeight() << _surveyItem->cameraFocalLength() << _surveyItem->cameraOrientationLandscape();
    foreach(Fact* fact, rgFacts) {
        qDebug() << fact->name();
        if (fact->typeIsBool()) {
            fact->setRawValue(!fact->rawValue().toBool());
        } else {
            fact->setRawValue(fact->rawValue().toDouble() + 1);
        }
        QVERIFY(_multiSpy->checkSignalByMask(cameraValueChangedMask));
        _multiSpy->clearAllSignals();
    }
    rgFacts.clear();

    // These facts should not trigger cameraValueChanged
    rgFacts << _surveyItem->gridAltitude() << _surveyItem->gridAngle() << _surveyItem->gridSpacing() << _surveyItem->turnaroundDist() << _surveyItem->cameraTriggerDistance() <<
               _surveyItem->gridAltitudeRelative() << _surveyItem->cameraTriggerInTurnaround() << _surveyItem->hoverAndCapture() <<
               _surveyItem->fixedValueIsAltitude() << _surveyItem->camera() << _surveyItem->manualGrid();
    foreach(Fact* fact, rgFacts) {
        qDebug() << fact->name();
        if (fact->typeIsBool()) {
            fact->setRawValue(!fact->rawValue().toBool());
        } else {
            fact->setRawValue(fact->rawValue().toDouble() + 1);
        }
        QVERIFY(_multiSpy->checkNoSignalByMask(cameraValueChangedMask));
        _multiSpy->clearAllSignals();
    }
    rgFacts.clear();
144 145
}

Don Gagne's avatar
Don Gagne committed
146
#if 0
147
void SurveyMissionItemTest::_testAddPolygonCoordinate(void)
148
{
149
    QCOMPARE(_mapPolygon->count(), 0);
150 151 152 153 154

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

155
    _mapPolygon->appendVertex(_polyPoints[0]);
156 157 158
    QVERIFY(_multiSpy->checkOnlySignalByMask(polygonPathChangedMask | dirtyChangedMask));

    // Validate object data
159
    QVariantList polyList = _mapPolygon->path();
160 161 162 163
    QCOMPARE(polyList.count(), 1);
    QCOMPARE(polyList[0].value<QGeoCoordinate>(), _polyPoints[0]);

    // Reset
164
    _surveyItem->setDirty(false);
165 166 167 168 169 170
    _multiSpy->clearAllSignals();

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

171
    _mapPolygon->appendVertex(_polyPoints[1]);
172 173
    QVERIFY(_multiSpy->checkOnlySignalByMask(polygonPathChangedMask | dirtyChangedMask));

174
    polyList = _mapPolygon->path();
175 176 177 178 179
    QCOMPARE(polyList.count(), 2);
    for (int i=0; i<polyList.count(); i++) {
        QCOMPARE(polyList[i].value<QGeoCoordinate>(), _polyPoints[i]);
    }

180
    _surveyItem->setDirty(false);
181 182 183 184 185 186 187 188 189 190 191 192 193
    _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

194
    _mapPolygon->appendVertex(_polyPoints[2]);
195
    QVERIFY(_multiSpy->checkOnlySignalByMask(polygonPathChangedMask | lastSequenceNumberChangedMask | gridPointsChangedMask | coordinateChangedMask |
Don Gagne's avatar
Don Gagne committed
196
                                             exitCoordinateChangedMask | specifiesCoordinateChangedMask | dirtyChangedMask));
197 198 199
    int seqNum = _multiSpy->pullIntFromSignalIndex(lastSequenceNumberChangedIndex);
    QVERIFY(seqNum > 0);

200
    polyList = _mapPolygon->path();
201 202 203 204
    QCOMPARE(polyList.count(), 3);
    for (int i=0; i<polyList.count(); i++) {
        QCOMPARE(polyList[i].value<QGeoCoordinate>(), _polyPoints[i]);
    }
205 206

    // Test that number of waypoints is doubled when using turnaround waypoints
207 208 209 210
    _surveyItem->setTurnaroundDist(60.0);
    QVariantList gridPoints = _surveyItem->gridPoints();
    _surveyItem->setTurnaroundDist(0.0);
    QVariantList gridPointsNoT = _surveyItem->gridPoints();
211 212
    QCOMPARE(gridPoints.count(), 2 * gridPointsNoT.count());

213 214
}

215
void SurveyMissionItemTest::_testClearPolygon(void)
216 217
{
    for (int i=0; i<3; i++) {
218
        _mapPolygon->appendVertex(_polyPoints[i]);
219
    }
220
    _surveyItem->setDirty(false);
221 222 223 224 225 226 227 228 229 230
    _multiSpy->clearAllSignals();

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

231
    _mapPolygon->clear();
232 233 234 235 236
    QVERIFY(_multiSpy->checkOnlySignalByMask(polygonPathChangedMask | lastSequenceNumberChangedMask | gridPointsChangedMask | dirtyChangedMask |
                                             specifiesCoordinateChangedMask));
    QVERIFY(!_multiSpy->pullBoolFromSignalIndex(specifiesCoordinateChangedIndex));
    QCOMPARE(_multiSpy->pullIntFromSignalIndex(lastSequenceNumberChangedIndex), 0);

237 238
    QCOMPARE(_mapPolygon->path().count(), 0);
    QCOMPARE(_surveyItem->gridPoints().count(), 0);
239

240
    _surveyItem->setDirty(false);
241 242 243
    _multiSpy->clearAllSignals();
}

244
void SurveyMissionItemTest::_testCameraTrigger(void)
245
{
246
    QCOMPARE(_surveyItem->property("cameraTrigger").toBool(), true);
247 248 249 250

    // Set up a grid

    for (int i=0; i<3; i++) {
251
        _mapPolygon->appendVertex(_polyPoints[i]);
252 253
    }

254
    _surveyItem->setDirty(false);
255 256
    _multiSpy->clearAllSignals();

257
    int lastSeq = _surveyItem->lastSequenceNumber();
258 259
    QVERIFY(lastSeq > 0);

260
    // Turning off camera triggering should remove two camera trigger mission items, this should trigger:
261 262 263
    //      lastSequenceNumberChanged
    //      dirtyChanged

264
    _surveyItem->setProperty("cameraTrigger", false);
265
    QVERIFY(_multiSpy->checkOnlySignalByMask(lastSequenceNumberChangedMask | dirtyChangedMask | cameraTriggerChangedMask));
266
    QCOMPARE(_multiSpy->pullIntFromSignalIndex(lastSequenceNumberChangedIndex), lastSeq - 2);
267

268
    _surveyItem->setDirty(false);
269 270
    _multiSpy->clearAllSignals();

271
    // Turn on camera triggering and make sure things go back to previous count
272

273
    _surveyItem->setProperty("cameraTrigger", true);
274 275 276
    QVERIFY(_multiSpy->checkOnlySignalByMask(lastSequenceNumberChangedMask | dirtyChangedMask | cameraTriggerChangedMask));
    QCOMPARE(_multiSpy->pullIntFromSignalIndex(lastSequenceNumberChangedIndex), lastSeq);
}
Don Gagne's avatar
Don Gagne committed
277
#endif