SectionTest.cc 3.85 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/****************************************************************************
 *
 *   (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 "SectionTest.h"
11
#include "SurveyComplexItem.h"
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

SectionTest::SectionTest(void)
    : _simpleItem(NULL)
{
    
}

void SectionTest::init(void)
{
    VisualMissionItemTest::init();

    rgSectionSignals[availableChangedIndex] =           SIGNAL(availableChanged(bool));
    rgSectionSignals[settingsSpecifiedChangedIndex] =   SIGNAL(settingsSpecifiedChanged(bool));
    rgSectionSignals[dirtyChangedIndex] =               SIGNAL(dirtyChanged(bool));
    rgSectionSignals[itemCountChangedIndex] =           SIGNAL(itemCountChanged(int));

    MissionItem missionItem(1,              // sequence number
                            MAV_CMD_NAV_WAYPOINT,
                            MAV_FRAME_GLOBAL_RELATIVE_ALT,
                            10.1234567,     // param 1-7
                            20.1234567,
                            30.1234567,
                            40.1234567,
                            50.1234567,
                            60.1234567,
                            70.1234567,
                            true,           // autoContinue
                            false);         // isCurrentItem
40
    _simpleItem = new SimpleMissionItem(_offlineVehicle, false /* flyView */, missionItem, this);
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
}

void SectionTest::cleanup(void)
{
    delete _simpleItem;
    VisualMissionItemTest::cleanup();
}

void SectionTest::_createSpy(Section* section, MultiSignalSpy** sectionSpy)
{
    *sectionSpy = NULL;
    MultiSignalSpy* spy = new MultiSignalSpy();
    QCOMPARE(spy->init(section, rgSectionSignals, cSectionSignals), true);
    *sectionSpy = spy;
}

57
void SectionTest::_missionItemsEqual(MissionItem& actual, MissionItem& expected)
58
{
59 60 61
    QCOMPARE(actual.command(),      expected.command());
    QCOMPARE(actual.frame(),        expected.frame());
    QCOMPARE(actual.autoContinue(), expected.autoContinue());
62

63 64 65 66 67 68 69
    QVERIFY(UnitTest::doubleNaNCompare(actual.param1(), expected.param1()));
    QVERIFY(UnitTest::doubleNaNCompare(actual.param2(), expected.param2()));
    QVERIFY(UnitTest::doubleNaNCompare(actual.param3(), expected.param3()));
    QVERIFY(UnitTest::doubleNaNCompare(actual.param4(), expected.param4()));
    QVERIFY(UnitTest::doubleNaNCompare(actual.param5(), expected.param5()));
    QVERIFY(UnitTest::doubleNaNCompare(actual.param6(), expected.param6()));
    QVERIFY(UnitTest::doubleNaNCompare(actual.param7(), expected.param7()));
70 71 72 73 74 75 76 77 78 79
}

void SectionTest::_commonScanTest(Section* section)
{
    QCOMPARE(section->available(), true);

    QmlObjectListModel emptyVisualItems;

    QmlObjectListModel waypointVisualItems;
    MissionItem waypointItem(0, MAV_CMD_NAV_WAYPOINT, MAV_FRAME_GLOBAL_RELATIVE_ALT, 0, 0, 0, 0, 0, 0, 0, true, false);
80
    SimpleMissionItem simpleItem(_offlineVehicle, false /* flyView */, waypointItem, this);
81 82 83 84 85
    waypointVisualItems.append(&simpleItem);
    waypointVisualItems.append(&simpleItem);
    waypointVisualItems.append(&simpleItem);

    QmlObjectListModel complexVisualItems;
86
    SurveyComplexItem surveyItem(_offlineVehicle, false /* fly View */, QString() /* kmlFile */, this /* parent */);
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
    complexVisualItems.append(&surveyItem);

    // This tests the common cases which should not lead to scan succeess

    int scanIndex = 0;
    QCOMPARE(section->scanForSection(&emptyVisualItems, scanIndex), false);
    QCOMPARE(scanIndex, 0);

    scanIndex = 0;
    QCOMPARE(section->scanForSection(&waypointVisualItems, scanIndex), false);
    QCOMPARE(scanIndex, 0);

    scanIndex = 0;
    QCOMPARE(section->scanForSection(&complexVisualItems, scanIndex), false);
    QCOMPARE(scanIndex, 0);
}