CorridorScanComplexItemTest.cc 7.77 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

#include "CorridorScanComplexItemTest.h"
#include "QGCApplication.h"

CorridorScanComplexItemTest::CorridorScanComplexItemTest(void)
{
    _linePoints << QGeoCoordinate(47.633550640000003, -122.08982199)
                << QGeoCoordinate(47.634129020000003, -122.08887249)
                << QGeoCoordinate(47.633619320000001, -122.08811074);
}

void CorridorScanComplexItemTest::init(void)
{
    UnitTest::init();

24 25 26
    _masterController = new PlanMasterController(this);
    _controllerVehicle = _masterController->controllerVehicle();
    _corridorItem = new CorridorScanComplexItem(_masterController, false /* flyView */, QString() /* kmlFile */, this /* parent */);
27 28 29 30 31 32

    // vehicleSpeed need for terrain calcs
    MissionController::MissionFlightStatus_t missionFlightStatus;
    missionFlightStatus.vehicleSpeed = 5;
    _corridorItem->setMissionFlightStatus(missionFlightStatus);

33
    _setPolyline();
34 35 36 37 38
    _corridorItem->setDirty(false);

    _rgCorridorPolygonSignals[corridorPolygonPathChangedIndex] = SIGNAL(pathChanged());

    _multiSpyCorridorPolygon = new MultiSignalSpy();
39
    QCOMPARE(_multiSpyCorridorPolygon->init(_corridorItem->surveyAreaPolygon(), _rgCorridorPolygonSignals, _cCorridorPolygonSignals), true);
40 41 42 43 44 45 46 47 48
}

void CorridorScanComplexItemTest::cleanup(void)
{
    delete _corridorItem;
}

void CorridorScanComplexItemTest::_testDirty(void)
{
49 50 51
    Fact* fact = _corridorItem->corridorWidth();
    fact->setRawValue(fact->rawValue().toDouble() + 1);
    QVERIFY(_corridorItem->dirty());
52 53
    _corridorItem->setDirty(false);

54
    changeFactValue(_corridorItem->cameraCalc()->distanceToSurface());
55 56 57
    QVERIFY(_corridorItem->dirty());
    _corridorItem->setDirty(false);

58 59 60 61 62
    QGeoCoordinate coord = _corridorItem->corridorPolyline()->vertexCoordinate(0);
    coord.setLatitude(coord.latitude() + 1);
    _corridorItem->corridorPolyline()->adjustVertex(1, coord);
    QVERIFY(_corridorItem->dirty());
    _corridorItem->setDirty(false);
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
}

void CorridorScanComplexItemTest::_testCameraTrigger(void)
{
#if 0
    QCOMPARE(_corridorItem->property("cameraTrigger").toBool(), true);

    // Set up a grid

    for (int i=0; i<3; i++) {
        _mapPolyline->appendVertex(_linePoints[i]);
    }

    _corridorItem->setDirty(false);
    _multiSpy->clearAllSignals();

    int lastSeq = _corridorItem->lastSequenceNumber();
    QVERIFY(lastSeq > 0);

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

    _corridorItem->setProperty("cameraTrigger", false);
    QVERIFY(_multiSpy->checkOnlySignalByMask(lastSequenceNumberChangedMask | dirtyChangedMask | cameraTriggerChangedMask));
    QCOMPARE(_multiSpy->pullIntFromSignalIndex(lastSequenceNumberChangedIndex), lastSeq - 2);

    _corridorItem->setDirty(false);
    _multiSpy->clearAllSignals();

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

    _corridorItem->setProperty("cameraTrigger", true);
    QVERIFY(_multiSpy->checkOnlySignalByMask(lastSequenceNumberChangedMask | dirtyChangedMask | cameraTriggerChangedMask));
    QCOMPARE(_multiSpy->pullIntFromSignalIndex(lastSequenceNumberChangedIndex), lastSeq);
#endif
}

void CorridorScanComplexItemTest::_setPolyline(void)
{
    for (int i=0; i<_linePoints.count(); i++) {
        QGeoCoordinate& vertex = _linePoints[i];
105
        _corridorItem->corridorPolyline()->appendVertex(vertex);
106 107 108 109 110 111 112 113 114 115 116 117 118
    }
}

#if 0
void CorridorScanComplexItemTest::_testEntryLocation(void)
{
    _setPolygon();

    for (double gridAngle=-360.0; gridAngle<=360.0; gridAngle++) {
        _corridorItem->gridAngle()->setRawValue(gridAngle);

        QList<QGeoCoordinate> rgSeenEntryCoords;
        QList<int> rgEntryLocation;
119 120 121 122
        rgEntryLocation << SurveyComplexItem::EntryLocationTopLeft
                        << SurveyComplexItem::EntryLocationTopRight
                        << SurveyComplexItem::EntryLocationBottomLeft
                        << SurveyComplexItem::EntryLocationBottomRight;
123 124 125 126 127 128 129 130 131 132 133 134 135 136

        // Validate that each entry location is unique
        for (int i=0; i<rgEntryLocation.count(); i++) {
            int entryLocation = rgEntryLocation[i];

            _corridorItem->gridEntryLocation()->setRawValue(entryLocation);
            QVERIFY(!rgSeenEntryCoords.contains(_corridorItem->coordinate()));
            rgSeenEntryCoords << _corridorItem->coordinate();
        }
        rgSeenEntryCoords.clear();
    }
}
#endif

137 138 139 140
void CorridorScanComplexItemTest::_waitForReadyForSave(void)
{
    int loops = 0;
    while (loops++ < 8) {
DonLakeFlyer's avatar
DonLakeFlyer committed
141
        if (_corridorItem->readyForSaveState() == CorridorScanComplexItem::ReadyForSave) {
142 143 144 145 146 147 148
            return;
        }
        QTest::qWait(500);
    }
    QVERIFY(false);
}

149 150 151 152
void CorridorScanComplexItemTest::_testItemCount(void)
{
    QList<MissionItem*> items;

153 154 155 156 157
    _corridorItem->turnAroundDistance()->setRawValue(0);
    _corridorItem->cameraTriggerInTurnAround()->setRawValue(true);
    _corridorItem->appendMissionItems(items, this);
    QCOMPARE(items.count() - 1, _corridorItem->lastSequenceNumber());
    items.clear();
158

159
    _corridorItem->turnAroundDistance()->setRawValue(0);
160 161
    _corridorItem->cameraTriggerInTurnAround()->setRawValue(false);
    _corridorItem->appendMissionItems(items, this);
DonLakeFlyer's avatar
DonLakeFlyer committed
162
    QCOMPARE(items.count() - 1, _corridorItem->lastSequenceNumber());
163 164
    items.clear();

165
    _corridorItem->turnAroundDistance()->setRawValue(20);
166 167 168 169 170 171 172 173 174 175 176
    _corridorItem->cameraTriggerInTurnAround()->setRawValue(true);
    _corridorItem->appendMissionItems(items, this);
    QCOMPARE(items.count() - 1, _corridorItem->lastSequenceNumber());
    items.clear();

    _corridorItem->turnAroundDistance()->setRawValue(20);
    _corridorItem->cameraTriggerInTurnAround()->setRawValue(false);
    _corridorItem->appendMissionItems(items, this);
    QCOMPARE(items.count() - 1, _corridorItem->lastSequenceNumber());
    items.clear();

DonLakeFlyer's avatar
DonLakeFlyer committed
177 178
#if 0
    // Terrain queries seem to take random amount of time so these don't work 100%
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
    _corridorItem->setFollowTerrain(true);

    _corridorItem->turnAroundDistance()->setRawValue(0);
    _corridorItem->cameraTriggerInTurnAround()->setRawValue(true);
    _waitForReadyForSave();
    _corridorItem->appendMissionItems(items, this);
    QCOMPARE(items.count() - 1, _corridorItem->lastSequenceNumber());
    items.clear();

    _corridorItem->turnAroundDistance()->setRawValue(0);
    _corridorItem->cameraTriggerInTurnAround()->setRawValue(false);
    _waitForReadyForSave();
    _corridorItem->appendMissionItems(items, this);
    QCOMPARE(items.count() - 1, _corridorItem->lastSequenceNumber());
    items.clear();

195
    _corridorItem->turnAroundDistance()->setRawValue(20);
196
    _corridorItem->cameraTriggerInTurnAround()->setRawValue(true);
197 198 199 200 201 202 203 204
    _waitForReadyForSave();
    _corridorItem->appendMissionItems(items, this);
    QCOMPARE(items.count() - 1, _corridorItem->lastSequenceNumber());
    items.clear();

    _corridorItem->turnAroundDistance()->setRawValue(20);
    _corridorItem->cameraTriggerInTurnAround()->setRawValue(false);
    _waitForReadyForSave();
205
    _corridorItem->appendMissionItems(items, this);
DonLakeFlyer's avatar
DonLakeFlyer committed
206
    QCOMPARE(items.count() - 1, _corridorItem->lastSequenceNumber());
207
    items.clear();
DonLakeFlyer's avatar
DonLakeFlyer committed
208
#endif
209 210 211 212
}

void CorridorScanComplexItemTest::_testPathChanges(void)
{
213
     QGeoCoordinate vertex = _corridorItem->corridorPolyline()->vertexCoordinate(1);
214
     vertex.setLatitude(vertex.latitude() + 0.01);
215
     _corridorItem->corridorPolyline()->adjustVertex(1, vertex);
216 217 218

     QVERIFY(_multiSpyCorridorPolygon->checkSignalsByMask(corridorPolygonPathChangedMask));
}