FWLandingPatternTest.cc 3.3 KB
Newer Older
1 2
/****************************************************************************
 *
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
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

#include "FWLandingPatternTest.h"
#include "QGCApplication.h"
#include "MissionCommandTree.h"
#include "MissionCommandUIInfo.h"
#include "CameraSectionTest.h"

FWLandingPatternTest::FWLandingPatternTest(void)
{
    
}

void FWLandingPatternTest::init(void)
{
23
    VisualMissionItemTest::init();
24

25 26
    _fwItem = new FixedWingLandingComplexItem(_masterController, false /* flyView */, this);
    _createSpy(_fwItem, &_viSpy);
27 28 29 30 31 32

    // Start in a clean state
    QVERIFY(!_fwItem->dirty());
    _fwItem->setLandingCoordinate(QGeoCoordinate(47, -122));
    _fwItem->setDirty(false);
    QVERIFY(!_fwItem->dirty());
33
    _viSpy->clearAllSignals();
34

35 36 37
    _validStopVideoItem =       CameraSectionTest::createValidStopTimeItem(_masterController, this);
    _validStopDistanceItem =    CameraSectionTest::createValidStopTimeItem(_masterController, this);
    _validStopTimeItem =        CameraSectionTest::createValidStopTimeItem(_masterController, this);
38 39 40 41 42
}

void FWLandingPatternTest::cleanup(void)
{
    delete _fwItem;
43
    delete _viSpy;
44 45 46
    delete _validStopVideoItem;
    delete _validStopDistanceItem;
    delete _validStopTimeItem;
47
    VisualMissionItemTest::cleanup();
48 49 50 51 52 53 54 55 56 57 58 59 60
}


void FWLandingPatternTest::_testDefaults(void)
{
    QCOMPARE(_fwItem->stopTakingPhotos()->rawValue().toBool(), true);
    QCOMPARE(_fwItem->stopTakingVideo()->rawValue().toBool(), true);
}

void FWLandingPatternTest::_testDirty(void)
{
    _fwItem->setDirty(true);
    QVERIFY(_fwItem->dirty());
61 62
    QVERIFY(_viSpy->checkOnlySignalByMask(dirtyChangedMask));
    QVERIFY(_viSpy->pullBoolFromSignalIndex(dirtyChangedIndex));
63
    _fwItem->setDirty(false);
64
    _viSpy->clearAllSignals();
65 66 67

    // These facts should set dirty when changed
    QList<Fact*> rgFacts;
68
    rgFacts << _fwItem->glideSlope()
69
            << _fwItem->valueSetIsDistance();
70 71 72
    for(Fact* fact: rgFacts) {
        qDebug() << fact->name();
        QVERIFY(!_fwItem->dirty());
73 74 75
        changeFactValue(fact);
        QVERIFY(_viSpy->checkSignalByMask(dirtyChangedMask));
        QVERIFY(_viSpy->pullBoolFromSignalIndex(dirtyChangedIndex));
76
        _fwItem->setDirty(false);
77
        _viSpy->clearAllSignals();
78 79 80 81 82 83
    }
    rgFacts.clear();
}

void FWLandingPatternTest::_testSaveLoad(void)
{
84
    QJsonArray items;
85

86 87 88
    _fwItem->save(items);

    QString errorString;
89
    FixedWingLandingComplexItem* newItem = new FixedWingLandingComplexItem(_masterController, false /* flyView */, this /* parent */);
90 91 92 93 94 95 96 97 98 99 100 101 102 103
    bool success =newItem->load(items[0].toObject(), 10, errorString);
    if (!success) {
        qDebug() << errorString;
    }
    QVERIFY(success);
    QVERIFY(errorString.isEmpty());
    _validateItem(newItem);
    newItem->deleteLater();
}

void FWLandingPatternTest::_validateItem(FixedWingLandingComplexItem* newItem)
{
    QVERIFY(newItem);

104 105
    QCOMPARE(newItem->glideSlope()->rawValue().toInt(),             _fwItem->glideSlope()->rawValue().toInt());
    QCOMPARE(newItem->valueSetIsDistance()->rawValue().toBool(),    _fwItem->valueSetIsDistance()->rawValue().toBool());
106
}