TransectStyleComplexItemTest.cc 9.94 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/

#include "TransectStyleComplexItemTest.h"
#include "QGCApplication.h"

TransectStyleComplexItemTest::TransectStyleComplexItemTest(void)
    : _offlineVehicle(NULL)
{
16 17 18 19
    _polygonVertices << QGeoCoordinate(47.633550640000003, -122.08982199)
                     << QGeoCoordinate(47.634129020000003, -122.08887249)
                     << QGeoCoordinate(47.633619320000001, -122.08811074)
                     << QGeoCoordinate(47.633189139999999, -122.08900124);
20 21 22 23 24 25 26 27
}

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

    _offlineVehicle = new Vehicle(MAV_AUTOPILOT_PX4, MAV_TYPE_QUADROTOR, qgcApp()->toolbox()->firmwarePluginManager(), this);
    _transectStyleItem = new TransectStyleItem(_offlineVehicle, this);
28 29 30 31
    _transectStyleItem->cameraTriggerInTurnAround()->setRawValue(false);
    _transectStyleItem->cameraCalc()->cameraName()->setRawValue(_transectStyleItem->cameraCalc()->customCameraName());
    _transectStyleItem->cameraCalc()->valueSetIsDistance()->setRawValue(true);
    _transectStyleItem->cameraCalc()->distanceToSurface()->setRawValue(100);
32 33
    _setSurveyAreaPolygon();
    _transectStyleItem->setDirty(false);
34 35 36 37

    _rgSignals[cameraShotsChangedIndex] =               SIGNAL(cameraShotsChanged());
    _rgSignals[timeBetweenShotsChangedIndex] =          SIGNAL(timeBetweenShotsChanged());
    _rgSignals[cameraMinTriggerIntervalChangedIndex] =  SIGNAL(cameraMinTriggerIntervalChanged(double));
DonLakeFlyer's avatar
DonLakeFlyer committed
38
    _rgSignals[visualTransectPointsChangedIndex] =      SIGNAL(visualTransectPointsChanged());
39 40 41 42 43
    _rgSignals[coveredAreaChangedIndex] =               SIGNAL(coveredAreaChanged());
    _rgSignals[dirtyChangedIndex] =                     SIGNAL(dirtyChanged(bool));
    _rgSignals[complexDistanceChangedIndex] =           SIGNAL(complexDistanceChanged());
    _rgSignals[greatestDistanceToChangedIndex] =        SIGNAL(greatestDistanceToChanged());
    _rgSignals[additionalTimeDelayChangedIndex] =       SIGNAL(additionalTimeDelayChanged());
44
    _rgSignals[lastSequenceNumberChangedIndex] =        SIGNAL(lastSequenceNumberChanged(int));
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83

    _multiSpy = new MultiSignalSpy();
    QCOMPARE(_multiSpy->init(_transectStyleItem, _rgSignals, _cSignals), true);
}

void TransectStyleComplexItemTest::cleanup(void)
{
    delete _transectStyleItem;
    delete _offlineVehicle;
    delete _multiSpy;
}

void TransectStyleComplexItemTest::_testDirty(void)
{
    QVERIFY(!_transectStyleItem->dirty());
    _transectStyleItem->setDirty(false);
    QVERIFY(!_transectStyleItem->dirty());
    QVERIFY(_multiSpy->checkNoSignals());

    _transectStyleItem->setDirty(true);
    QVERIFY(_transectStyleItem->dirty());
    QVERIFY(_multiSpy->checkOnlySignalByMask(dirtyChangedMask));
    QVERIFY(_multiSpy->pullBoolFromSignalIndex(dirtyChangedIndex));
    _multiSpy->clearAllSignals();

    _transectStyleItem->setDirty(false);
    QVERIFY(!_transectStyleItem->dirty());
    QVERIFY(_multiSpy->checkOnlySignalByMask(dirtyChangedMask));
    _multiSpy->clearAllSignals();

    // These facts should set dirty when changed
    QList<Fact*> rgFacts;
    rgFacts << _transectStyleItem->turnAroundDistance()
            << _transectStyleItem->cameraTriggerInTurnAround()
            << _transectStyleItem->hoverAndCapture()
            << _transectStyleItem->refly90Degrees();
    foreach(Fact* fact, rgFacts) {
        qDebug() << fact->name();
        QVERIFY(!_transectStyleItem->dirty());
84
        changeFactValue(fact);
85 86 87 88 89 90
        QVERIFY(_multiSpy->checkSignalByMask(dirtyChangedMask));
        _transectStyleItem->setDirty(false);
        _multiSpy->clearAllSignals();
    }
    rgFacts.clear();

91
    _adjustSurveAreaPolygon();
92 93 94 95 96
    QVERIFY(_transectStyleItem->dirty());
    _transectStyleItem->setDirty(false);
    QVERIFY(!_transectStyleItem->surveyAreaPolygon()->dirty());
    _multiSpy->clearAllSignals();

97
    changeFactValue(_transectStyleItem->cameraCalc()->distanceToSurface());
98 99 100 101 102 103
    QVERIFY(_transectStyleItem->dirty());
    _transectStyleItem->setDirty(false);
    QVERIFY(!_transectStyleItem->cameraCalc()->dirty());
    _multiSpy->clearAllSignals();
}

104
void TransectStyleComplexItemTest::_setSurveyAreaPolygon(void)
105
{
106
    foreach (const QGeoCoordinate vertex, _polygonVertices) {
107 108 109 110
        _transectStyleItem->surveyAreaPolygon()->appendVertex(vertex);
    }
}

111 112 113
void TransectStyleComplexItemTest::_testRebuildTransects(void)
{
    // Changing the survey polygon should trigger:
114
    //  _rebuildTransects calls
115 116 117
    //  coveredAreaChanged signal
    //  lastSequenceNumberChanged signal
    _adjustSurveAreaPolygon();
118 119
    QVERIFY(_transectStyleItem->rebuildTransectsPhase1Called);
    QVERIFY(_transectStyleItem->rebuildTransectsPhase2Called);
120
    QVERIFY(_multiSpy->checkSignalsByMask(coveredAreaChangedMask | lastSequenceNumberChangedMask));
121 122
    _transectStyleItem->rebuildTransectsPhase1Called = false;
    _transectStyleItem->rebuildTransectsPhase2Called = false;
123 124 125 126
    _transectStyleItem->setDirty(false);
    _multiSpy->clearAllSignals();

    // Changes to these facts should trigger:
127
    //  _rebuildTransects calls
128 129 130 131 132 133
    //  lastSequenceNumberChanged signal
    QList<Fact*> rgFacts;
    rgFacts << _transectStyleItem->turnAroundDistance()
            << _transectStyleItem->cameraTriggerInTurnAround()
            << _transectStyleItem->hoverAndCapture()
            << _transectStyleItem->refly90Degrees()
134 135
            << _transectStyleItem->cameraCalc()->frontalOverlap()
            << _transectStyleItem->cameraCalc()->sideOverlap();
136 137 138
    foreach(Fact* fact, rgFacts) {
        qDebug() << fact->name();
        changeFactValue(fact);
139 140
        QVERIFY(_transectStyleItem->rebuildTransectsPhase1Called);
        QVERIFY(_transectStyleItem->rebuildTransectsPhase2Called);
141
        QVERIFY(_multiSpy->checkSignalsByMask(lastSequenceNumberChangedMask));
142 143
        _transectStyleItem->setDirty(false);
        _multiSpy->clearAllSignals();
144 145
        _transectStyleItem->rebuildTransectsPhase1Called = false;
        _transectStyleItem->rebuildTransectsPhase2Called = false;
146 147
    }
    rgFacts.clear();
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165

    _transectStyleItem->cameraCalc()->valueSetIsDistance()->setRawValue(false);
    _transectStyleItem->rebuildTransectsPhase1Called = false;
    _transectStyleItem->rebuildTransectsPhase2Called = false;
    changeFactValue(_transectStyleItem->cameraCalc()->imageDensity());
    QVERIFY(_transectStyleItem->rebuildTransectsPhase1Called);
    QVERIFY(_transectStyleItem->rebuildTransectsPhase2Called);
    QVERIFY(_multiSpy->checkSignalsByMask(lastSequenceNumberChangedMask));
    _multiSpy->clearAllSignals();

    _transectStyleItem->cameraCalc()->valueSetIsDistance()->setRawValue(true);
    _transectStyleItem->rebuildTransectsPhase1Called = false;
    _transectStyleItem->rebuildTransectsPhase2Called = false;
    changeFactValue(_transectStyleItem->cameraCalc()->distanceToSurface());
    QVERIFY(_transectStyleItem->rebuildTransectsPhase1Called);
    QVERIFY(_transectStyleItem->rebuildTransectsPhase2Called);
    QVERIFY(_multiSpy->checkSignalsByMask(lastSequenceNumberChangedMask));
    _multiSpy->clearAllSignals();
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
}

void TransectStyleComplexItemTest::_testDistanceSignalling(void)
{
    _adjustSurveAreaPolygon();
    QVERIFY(_multiSpy->checkSignalsByMask(complexDistanceChangedMask | greatestDistanceToChangedMask));
    _transectStyleItem->setDirty(false);
    _multiSpy->clearAllSignals();

    QList<Fact*> rgFacts;
    rgFacts << _transectStyleItem->turnAroundDistance()
            << _transectStyleItem->hoverAndCapture()
            << _transectStyleItem->refly90Degrees();
    foreach(Fact* fact, rgFacts) {
        qDebug() << fact->name();
        changeFactValue(fact);
        QVERIFY(_multiSpy->checkSignalsByMask(complexDistanceChangedMask | greatestDistanceToChangedMask));
        _transectStyleItem->setDirty(false);
        _multiSpy->clearAllSignals();
    }
    rgFacts.clear();
}

void TransectStyleComplexItemTest::_adjustSurveAreaPolygon(void)
{
    QGeoCoordinate vertex = _transectStyleItem->surveyAreaPolygon()->vertexCoordinate(0);
    vertex.setLatitude(vertex.latitude() + 1);
    _transectStyleItem->surveyAreaPolygon()->adjustVertex(0, vertex);
}

DonLakeFlyer's avatar
DonLakeFlyer committed
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
void TransectStyleComplexItemTest::_testAltMode(void)
{
    // Default should be relative
    QVERIFY(_transectStyleItem->cameraCalc()->distanceToSurfaceRelative());

    // Manual camera allows non-relative altitudes, validate that changing back to known
    // camera switches back to relative
    _transectStyleItem->cameraCalc()->cameraName()->setRawValue(_transectStyleItem->cameraCalc()->manualCameraName());
    _transectStyleItem->cameraCalc()->setDistanceToSurfaceRelative(false);
    _transectStyleItem->cameraCalc()->cameraName()->setRawValue(_transectStyleItem->cameraCalc()->customCameraName());
    QVERIFY(_transectStyleItem->cameraCalc()->distanceToSurfaceRelative());

    // When you turn off terrain following mode make sure that the altitude mode changed back to relative altitudes
    _transectStyleItem->cameraCalc()->setDistanceToSurfaceRelative(false);
    _transectStyleItem->setFollowTerrain(true);

    QVERIFY(!_transectStyleItem->cameraCalc()->distanceToSurfaceRelative());
    QVERIFY(_transectStyleItem->followTerrain());

    _transectStyleItem->setFollowTerrain(false);
    QVERIFY(_transectStyleItem->cameraCalc()->distanceToSurfaceRelative());
    QVERIFY(!_transectStyleItem->followTerrain());
}

220
TransectStyleItem::TransectStyleItem(Vehicle* vehicle, QObject* parent)
221 222 223
    : TransectStyleComplexItem      (vehicle, false /* flyView */, QStringLiteral("UnitTestTransect"), parent)
    , rebuildTransectsPhase1Called  (false)
    , rebuildTransectsPhase2Called  (false)
224 225 226 227
{

}

228
void TransectStyleItem::_rebuildTransectsPhase1(void)
229
{
230
    rebuildTransectsPhase1Called = true;
231
}
232 233 234

void TransectStyleItem::_rebuildTransectsPhase2(void)
{
235
    rebuildTransectsPhase2Called = true;
236
}