TransectStyleComplexItemTest.cc 11.4 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
 *
 * 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)
{
}

void TransectStyleComplexItemTest::init(void)
{
19
    TransectStyleComplexItemTestBase::init();
20

Remek Zajac's avatar
Remek Zajac committed
21
    _transectStyleItem = new TestTransectStyleItem(_masterController, this);
22
    _transectStyleItem->cameraTriggerInTurnAround()->setRawValue(false);
23
    _transectStyleItem->cameraCalc()->setCameraBrand(CameraCalc::canonicalCustomCameraName());
24 25
    _transectStyleItem->cameraCalc()->valueSetIsDistance()->setRawValue(true);
    _transectStyleItem->cameraCalc()->distanceToSurface()->setRawValue(100);
26
    _transectStyleItem->setDirty(false);
27 28 29

    _rgSignals[cameraShotsChangedIndex] =               SIGNAL(cameraShotsChanged());
    _rgSignals[timeBetweenShotsChangedIndex] =          SIGNAL(timeBetweenShotsChanged());
DonLakeFlyer's avatar
DonLakeFlyer committed
30
    _rgSignals[visualTransectPointsChangedIndex] =      SIGNAL(visualTransectPointsChanged());
31 32 33 34 35
    _rgSignals[coveredAreaChangedIndex] =               SIGNAL(coveredAreaChanged());
    _rgSignals[dirtyChangedIndex] =                     SIGNAL(dirtyChanged(bool));
    _rgSignals[complexDistanceChangedIndex] =           SIGNAL(complexDistanceChanged());
    _rgSignals[greatestDistanceToChangedIndex] =        SIGNAL(greatestDistanceToChanged());
    _rgSignals[additionalTimeDelayChangedIndex] =       SIGNAL(additionalTimeDelayChanged());
36
    _rgSignals[lastSequenceNumberChangedIndex] =        SIGNAL(lastSequenceNumberChanged(int));
37 38 39 40 41 42 43 44 45

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

void TransectStyleComplexItemTest::cleanup(void)
{
    delete _transectStyleItem;
    delete _multiSpy;
46
    TransectStyleComplexItemTestBase::cleanup();
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
}

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();
73
    for(Fact* fact: rgFacts) {
74 75
        qDebug() << fact->name();
        QVERIFY(!_transectStyleItem->dirty());
76
        changeFactValue(fact);
77 78 79 80 81 82
        QVERIFY(_multiSpy->checkSignalByMask(dirtyChangedMask));
        _transectStyleItem->setDirty(false);
        _multiSpy->clearAllSignals();
    }
    rgFacts.clear();

Remek Zajac's avatar
Remek Zajac committed
83
    _transectStyleItem->_adjustSurveAreaPolygon();
84 85 86 87 88
    QVERIFY(_transectStyleItem->dirty());
    _transectStyleItem->setDirty(false);
    QVERIFY(!_transectStyleItem->surveyAreaPolygon()->dirty());
    _multiSpy->clearAllSignals();

89
    changeFactValue(_transectStyleItem->cameraCalc()->distanceToSurface());
90 91 92 93 94 95
    QVERIFY(_transectStyleItem->dirty());
    _transectStyleItem->setDirty(false);
    QVERIFY(!_transectStyleItem->cameraCalc()->dirty());
    _multiSpy->clearAllSignals();
}

96 97 98
void TransectStyleComplexItemTest::_testRebuildTransects(void)
{
    // Changing the survey polygon should trigger:
99
    //  _rebuildTransects calls
100 101
    //  coveredAreaChanged signal
    //  lastSequenceNumberChanged signal
Remek Zajac's avatar
Remek Zajac committed
102
    _transectStyleItem->_adjustSurveAreaPolygon();
103
    QVERIFY(_transectStyleItem->rebuildTransectsPhase1Called);
104
    QVERIFY(_transectStyleItem->recalcCameraShotsCalled);
105 106
    // FIXME: Temproarily not possible
    //QVERIFY(_transectStyleItem->recalcComplexDistanceCalled);
107
    QVERIFY(_multiSpy->checkSignalsByMask(coveredAreaChangedMask | lastSequenceNumberChangedMask));
108
    _transectStyleItem->rebuildTransectsPhase1Called = false;
109 110
    _transectStyleItem->recalcCameraShotsCalled = false;
    _transectStyleItem->recalcComplexDistanceCalled = false;
111 112 113 114
    _transectStyleItem->setDirty(false);
    _multiSpy->clearAllSignals();

    // Changes to these facts should trigger:
115
    //  _rebuildTransects calls
116 117 118 119 120 121
    //  lastSequenceNumberChanged signal
    QList<Fact*> rgFacts;
    rgFacts << _transectStyleItem->turnAroundDistance()
            << _transectStyleItem->cameraTriggerInTurnAround()
            << _transectStyleItem->hoverAndCapture()
            << _transectStyleItem->refly90Degrees()
122 123
            << _transectStyleItem->cameraCalc()->frontalOverlap()
            << _transectStyleItem->cameraCalc()->sideOverlap();
124
    for(Fact* fact: rgFacts) {
125 126
        qDebug() << fact->name();
        changeFactValue(fact);
127
        QVERIFY(_transectStyleItem->rebuildTransectsPhase1Called);
128
        QVERIFY(_transectStyleItem->recalcCameraShotsCalled);
129 130
        // FIXME: Temproarily not possible
        //QVERIFY(_transectStyleItem->recalcComplexDistanceCalled);
131
        QVERIFY(_multiSpy->checkSignalsByMask(lastSequenceNumberChangedMask));
132 133
        _transectStyleItem->setDirty(false);
        _multiSpy->clearAllSignals();
134
        _transectStyleItem->rebuildTransectsPhase1Called = false;
135 136
        _transectStyleItem->recalcCameraShotsCalled = false;
        _transectStyleItem->recalcComplexDistanceCalled = false;
137 138
    }
    rgFacts.clear();
139 140 141

    _transectStyleItem->cameraCalc()->valueSetIsDistance()->setRawValue(false);
    _transectStyleItem->rebuildTransectsPhase1Called = false;
142 143
    _transectStyleItem->recalcCameraShotsCalled = false;
    _transectStyleItem->recalcComplexDistanceCalled = false;
144 145
    changeFactValue(_transectStyleItem->cameraCalc()->imageDensity());
    QVERIFY(_transectStyleItem->rebuildTransectsPhase1Called);
146
    QVERIFY(_transectStyleItem->recalcCameraShotsCalled);
147 148
    // FIXME: Temproarily not possible
    //QVERIFY(_transectStyleItem->recalcComplexDistanceCalled);
149 150 151 152 153
    QVERIFY(_multiSpy->checkSignalsByMask(lastSequenceNumberChangedMask));
    _multiSpy->clearAllSignals();

    _transectStyleItem->cameraCalc()->valueSetIsDistance()->setRawValue(true);
    _transectStyleItem->rebuildTransectsPhase1Called = false;
154 155
    _transectStyleItem->recalcCameraShotsCalled = false;
    _transectStyleItem->recalcComplexDistanceCalled = false;
156 157
    changeFactValue(_transectStyleItem->cameraCalc()->distanceToSurface());
    QVERIFY(_transectStyleItem->rebuildTransectsPhase1Called);
158
    QVERIFY(_transectStyleItem->recalcCameraShotsCalled);
159 160
    // FIXME: Temproarily not possible
    //QVERIFY(_transectStyleItem->recalcComplexDistanceCalled);
161 162
    QVERIFY(_multiSpy->checkSignalsByMask(lastSequenceNumberChangedMask));
    _multiSpy->clearAllSignals();
163 164 165 166
}

void TransectStyleComplexItemTest::_testDistanceSignalling(void)
{
Remek Zajac's avatar
Remek Zajac committed
167
    _transectStyleItem->_adjustSurveAreaPolygon();
168 169 170 171 172 173 174 175
    QVERIFY(_multiSpy->checkSignalsByMask(complexDistanceChangedMask | greatestDistanceToChangedMask));
    _transectStyleItem->setDirty(false);
    _multiSpy->clearAllSignals();

    QList<Fact*> rgFacts;
    rgFacts << _transectStyleItem->turnAroundDistance()
            << _transectStyleItem->hoverAndCapture()
            << _transectStyleItem->refly90Degrees();
176
    for(Fact* fact: rgFacts) {
177 178 179 180 181 182 183 184 185
        qDebug() << fact->name();
        changeFactValue(fact);
        QVERIFY(_multiSpy->checkSignalsByMask(complexDistanceChangedMask | greatestDistanceToChangedMask));
        _transectStyleItem->setDirty(false);
        _multiSpy->clearAllSignals();
    }
    rgFacts.clear();
}

Remek Zajac's avatar
Remek Zajac committed
186

187

DonLakeFlyer's avatar
DonLakeFlyer committed
188 189 190 191 192 193 194
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
195
    _transectStyleItem->cameraCalc()->setCameraBrand(CameraCalc::canonicalManualCameraName());
DonLakeFlyer's avatar
DonLakeFlyer committed
196
    _transectStyleItem->cameraCalc()->setDistanceToSurfaceRelative(false);
197
    _transectStyleItem->cameraCalc()->setCameraBrand(CameraCalc::canonicalCustomCameraName());
DonLakeFlyer's avatar
DonLakeFlyer committed
198 199 200 201 202 203 204 205 206 207 208 209 210 211
    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());
}

Remek Zajac's avatar
Remek Zajac committed
212 213 214
void TransectStyleComplexItemTest::_testFollowTerrain(void) {
    _multiSpy->clearAllSignals();
    _transectStyleItem->cameraCalc()->distanceToSurface()->setRawValue(50);
Remek Zajac's avatar
Remek Zajac committed
215
    _transectStyleItem->setFollowTerrain(true);
Remek Zajac's avatar
Remek Zajac committed
216
    _multiSpy->clearAllSignals();
Remek Zajac's avatar
Remek Zajac committed
217 218 219 220 221 222 223 224 225 226 227 228
    while(_transectStyleItem->readyForSaveState() != TransectStyleComplexItem::ReadyForSave) {
        QVERIFY(_multiSpy->waitForSignalByIndex(lastSequenceNumberChangedIndex, 50));
    }
    QList<double> expectedTerrainValues{497,509,512,512};
    QCOMPARE(_transectStyleItem->transects().size(), 1);
    for (const auto& transect : _transectStyleItem->transects()) {
        QCOMPARE(transect.size(), 4);
        for (const auto pt : transect) {
            QCOMPARE(pt.coord.altitude(), expectedTerrainValues.front());
            expectedTerrainValues.pop_front();
        }
    }
Remek Zajac's avatar
Remek Zajac committed
229 230
}

Remek Zajac's avatar
Remek Zajac committed
231
TestTransectStyleItem::TestTransectStyleItem(PlanMasterController* masterController, QObject* parent)
232
    : TransectStyleComplexItem      (masterController, false /* flyView */, QStringLiteral("UnitTestTransect"), parent)
233
    , rebuildTransectsPhase1Called  (false)
234 235
    , recalcComplexDistanceCalled   (false)
    , recalcCameraShotsCalled       (false)
236
{
Remek Zajac's avatar
Remek Zajac committed
237 238
    // We use a 100m by 100m square test polygon
    const double edgeDistance = 100;
Remek Zajac's avatar
Remek Zajac committed
239
    surveyAreaPolygon()->appendVertex(UnitTestTerrainQuery::linearSlopeRegion.center());
Remek Zajac's avatar
Remek Zajac committed
240 241 242 243 244 245 246
    surveyAreaPolygon()->appendVertex(surveyAreaPolygon()->vertexCoordinate(0).atDistanceAndAzimuth(edgeDistance, 90));
    surveyAreaPolygon()->appendVertex(surveyAreaPolygon()->vertexCoordinate(1).atDistanceAndAzimuth(edgeDistance, 180));
    surveyAreaPolygon()->appendVertex(surveyAreaPolygon()->vertexCoordinate(2).atDistanceAndAzimuth(edgeDistance, -90.0));
    _transects.append(QList<TransectStyleComplexItem::CoordInfo_t>{
        {surveyAreaPolygon()->vertexCoordinate(0), CoordTypeSurveyEntry},
        {surveyAreaPolygon()->vertexCoordinate(2), CoordTypeSurveyExit}}
    );
247 248
}

Remek Zajac's avatar
Remek Zajac committed
249
void TestTransectStyleItem::_rebuildTransectsPhase1(void)
250
{
251
    rebuildTransectsPhase1Called = true;
252
}
253

Remek Zajac's avatar
Remek Zajac committed
254
void TestTransectStyleItem::_recalcCameraShots(void)
255 256
{
    recalcCameraShotsCalled = true;
257
}
Remek Zajac's avatar
Remek Zajac committed
258 259 260 261 262 263 264 265

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