SurveyComplexItemTest.cc 7 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
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9

10
#include "SurveyComplexItemTest.h"
Don Gagne's avatar
Don Gagne committed
11
#include "QGCApplication.h"
12

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

19
void SurveyComplexItemTest::init(void)
20
{
Don Gagne's avatar
Don Gagne committed
21 22
    UnitTest::init();

23 24 25 26 27 28
    _rgSurveySignals[surveyVisualTransectPointsChangedIndex] =    SIGNAL(visualTransectPointsChanged());
    _rgSurveySignals[surveyCameraShotsChangedIndex] =             SIGNAL(cameraShotsChanged());
    _rgSurveySignals[surveyCoveredAreaChangedIndex] =             SIGNAL(coveredAreaChanged());
    _rgSurveySignals[surveyTimeBetweenShotsChangedIndex] =        SIGNAL(timeBetweenShotsChanged());
    _rgSurveySignals[surveyRefly90DegreesChangedIndex] =          SIGNAL(refly90DegreesChanged(bool));
    _rgSurveySignals[surveyDirtyChangedIndex] =                   SIGNAL(dirtyChanged(bool));
Don Gagne's avatar
Don Gagne committed
29

30 31 32
    _masterController = new PlanMasterController(this);
    _controllerVehicle = _masterController->controllerVehicle();
    _surveyItem = new SurveyComplexItem(_masterController, false /* flyView */, QString() /* kmlFile */, this /* parent */);
33
    _surveyItem->turnAroundDistance()->setRawValue(0);  // Unit test written for no turnaround distance
DonLakeFlyer's avatar
DonLakeFlyer committed
34
    _surveyItem->setDirty(false);
35
    _mapPolygon = _surveyItem->surveyAreaPolygon();
36 37 38 39 40 41 42

    // 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
43
    QCOMPARE(_multiSpy->init(_surveyItem, _rgSurveySignals, _cSurveySignals), true);
44 45
}

46
void SurveyComplexItemTest::cleanup(void)
47
{
48
    delete _surveyItem;
49 50 51
    delete _multiSpy;
}

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

59 60
    _surveyItem->setDirty(true);
    QVERIFY(_surveyItem->dirty());
61 62
    QVERIFY(_multiSpy->checkOnlySignalByMask(surveyDirtyChangedMask));
    QVERIFY(_multiSpy->pullBoolFromSignalIndex(surveyDirtyChangedIndex));
63
    _multiSpy->clearAllSignals();
Don Gagne's avatar
Don Gagne committed
64

65 66
    _surveyItem->setDirty(false);
    QVERIFY(!_surveyItem->dirty());
67
    QVERIFY(_multiSpy->checkOnlySignalByMask(surveyDirtyChangedMask));
Don Gagne's avatar
Don Gagne committed
68 69 70 71
    _multiSpy->clearAllSignals();

    // These facts should set dirty when changed
    QList<Fact*> rgFacts;
72
    rgFacts << _surveyItem->gridAngle() << _surveyItem->flyAlternateTransects();
73
    for(Fact* fact: rgFacts) {
Don Gagne's avatar
Don Gagne committed
74 75 76 77 78 79 80
        qDebug() << fact->name();
        QVERIFY(!_surveyItem->dirty());
        if (fact->typeIsBool()) {
            fact->setRawValue(!fact->rawValue().toBool());
        } else {
            fact->setRawValue(fact->rawValue().toDouble() + 1);
        }
81 82
        QVERIFY(_multiSpy->checkSignalByMask(surveyDirtyChangedMask));
        QVERIFY(_multiSpy->pullBoolFromSignalIndex(surveyDirtyChangedIndex));
Don Gagne's avatar
Don Gagne committed
83 84 85 86
        _surveyItem->setDirty(false);
        _multiSpy->clearAllSignals();
    }
    rgFacts.clear();
87
}
88 89

// Clamp expected grid angle from 0<->180. We don't care about opposite angles like 90/270
90
double SurveyComplexItemTest::_clampGridAngle180(double gridAngle)
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
{
    if (gridAngle >= 0.0) {
        if (gridAngle == 360.0) {
            gridAngle = 0.0;
        } else if (gridAngle >= 180.0) {
            gridAngle -= 180.0;
        }
    } else {
        if (gridAngle < -180.0) {
            gridAngle += 360.0;
        } else {
            gridAngle += 180.0;
        }
    }
    return gridAngle;
}

108
void SurveyComplexItemTest::_setPolygon(void)
109 110 111
{
    for (int i=0; i<_polyPoints.count(); i++) {
        QGeoCoordinate& vertex = _polyPoints[i];
112
        _mapPolygon->appendVertex(vertex);
113
    }
114 115
}

116
void SurveyComplexItemTest::_testGridAngle(void)
117 118
{
    _setPolygon();
119 120 121 122

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

123
        QVariantList gridPoints = _surveyItem->visualTransectPoints();
124 125 126 127 128 129 130 131
        QGeoCoordinate firstTransectEntry = gridPoints[0].value<QGeoCoordinate>();
        QGeoCoordinate firstTransectExit = gridPoints[1].value<QGeoCoordinate>();
        double azimuth = firstTransectEntry.azimuthTo(firstTransectExit);
        //qDebug() << gridAngle << azimuth << _clampGridAngle180(gridAngle) << _clampGridAngle180(azimuth);
        QCOMPARE((int)_clampGridAngle180(gridAngle), (int)_clampGridAngle180(azimuth));
    }
}

132
void SurveyComplexItemTest::_testEntryLocation(void)
133
{
134
    _setPolygon();
135 136 137 138 139

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

        // Validate that each entry location is unique
DonLakeFlyer's avatar
DonLakeFlyer committed
140 141 142
        QList<QGeoCoordinate> rgSeenEntryCoords;
        for (int rotateCount=0; rotateCount<3; rotateCount++) {
            _surveyItem->rotateEntryPoint();
143 144 145
            QVERIFY(!rgSeenEntryCoords.contains(_surveyItem->coordinate()));
            rgSeenEntryCoords << _surveyItem->coordinate();
        }
DonLakeFlyer's avatar
DonLakeFlyer committed
146 147

        _surveyItem->rotateEntryPoint();    // Rotate back for first entry point
148 149 150
        rgSeenEntryCoords.clear();
    }
}
151 152


153
void SurveyComplexItemTest::_testItemCount(void)
154 155 156 157 158 159
{
    QList<MissionItem*> items;

    _setPolygon();

    _surveyItem->hoverAndCapture()->setRawValue(false);
160 161
    _surveyItem->cameraTriggerInTurnAround()->setRawValue(false);
    _surveyItem->refly90Degrees()->setRawValue(false);
162
    _surveyItem->appendMissionItems(items, this);
163
    QCOMPARE(items.count() - 1, _surveyItem->lastSequenceNumber());
164 165 166
    items.clear();

    _surveyItem->hoverAndCapture()->setRawValue(false);
167 168
    _surveyItem->cameraTriggerInTurnAround()->setRawValue(true);
    _surveyItem->refly90Degrees()->setRawValue(false);
169
    _surveyItem->appendMissionItems(items, this);
170
    QCOMPARE(items.count() - 1, _surveyItem->lastSequenceNumber());
171 172 173
    items.clear();

    _surveyItem->hoverAndCapture()->setRawValue(true);
174 175
    _surveyItem->cameraTriggerInTurnAround()->setRawValue(false);
    _surveyItem->refly90Degrees()->setRawValue(false);
176
    _surveyItem->appendMissionItems(items, this);
177
    QCOMPARE(items.count() - 1, _surveyItem->lastSequenceNumber());
178 179 180
    items.clear();

    _surveyItem->hoverAndCapture()->setRawValue(true);
181 182
    _surveyItem->cameraTriggerInTurnAround()->setRawValue(false);
    _surveyItem->refly90Degrees()->setRawValue(true);
183
    _surveyItem->appendMissionItems(items, this);
184
    QCOMPARE(items.count() - 1, _surveyItem->lastSequenceNumber());
185 186
    items.clear();
}