SurveyComplexItemTest.cc 7.06 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 "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
    : _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 SurveyComplexItemTest::init(void)
21
{
Don Gagne's avatar
Don Gagne committed
22 23
    UnitTest::init();

24 25 26 27 28 29
    _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
30 31

    _offlineVehicle = new Vehicle(MAV_AUTOPILOT_PX4, MAV_TYPE_QUADROTOR, qgcApp()->toolbox()->firmwarePluginManager(), this);
32
    _surveyItem = new SurveyComplexItem(_offlineVehicle, 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;
Don Gagne's avatar
Don Gagne committed
49
    delete _offlineVehicle;
50 51 52
    delete _multiSpy;
}

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

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

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

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

// Clamp expected grid angle from 0<->180. We don't care about opposite angles like 90/270
91
double SurveyComplexItemTest::_clampGridAngle180(double gridAngle)
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
{
    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;
}

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

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

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

124
        QVariantList gridPoints = _surveyItem->visualTransectPoints();
125 126 127 128 129 130 131 132
        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));
    }
}

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

    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
141 142 143
        QList<QGeoCoordinate> rgSeenEntryCoords;
        for (int rotateCount=0; rotateCount<3; rotateCount++) {
            _surveyItem->rotateEntryPoint();
144 145 146
            QVERIFY(!rgSeenEntryCoords.contains(_surveyItem->coordinate()));
            rgSeenEntryCoords << _surveyItem->coordinate();
        }
DonLakeFlyer's avatar
DonLakeFlyer committed
147 148

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


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

    _setPolygon();

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

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

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

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