FactSystemTestBase.cc 3.25 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

Don Gagne's avatar
Don Gagne committed
10 11 12 13

/// @file
///     @author Don Gagne <don@thegagnes.com>

14
#include "FactSystemTestBase.h"
Don Gagne's avatar
Don Gagne committed
15
#include "LinkManager.h"
16
#ifdef QT_DEBUG
Don Gagne's avatar
Don Gagne committed
17
#include "MockLink.h"
18
#endif
19
#include "MultiVehicleManager.h"
Don Gagne's avatar
Don Gagne committed
20
#include "QGCApplication.h"
21
#include "ParameterManager.h"
Don Gagne's avatar
Don Gagne committed
22 23 24 25

#include <QQuickItem>

/// FactSystem Unit Test
26
FactSystemTestBase::FactSystemTestBase(void)
Don Gagne's avatar
Don Gagne committed
27
{
28

Don Gagne's avatar
Don Gagne committed
29 30
}

31
void FactSystemTestBase::_init(MAV_AUTOPILOT autopilot)
Don Gagne's avatar
Don Gagne committed
32 33
{
    UnitTest::init();
34

35
    _connectMockLink(autopilot);
36

37
    _plugin = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()->autopilotPlugin();
Don Gagne's avatar
Don Gagne committed
38 39 40
    Q_ASSERT(_plugin);
}

41
void FactSystemTestBase::_cleanup(void)
Don Gagne's avatar
Don Gagne committed
42 43 44 45 46
{
    UnitTest::cleanup();
}

/// Basic test of parameter values in Fact System
47
void FactSystemTestBase::_parameter_default_component_id_test(void)
Don Gagne's avatar
Don Gagne committed
48
{
49 50
    QVERIFY(_vehicle->parameterManager()->parameterExists(FactSystem::defaultComponentId, "RC_MAP_THROTTLE"));
    Fact* fact = _vehicle->parameterManager()->getParameter(FactSystem::defaultComponentId, "RC_MAP_THROTTLE");
51
    QVERIFY(fact != NULL);
Don Gagne's avatar
Don Gagne committed
52
    QVariant factValue = fact->rawValue();
53
    QCOMPARE(factValue.isValid(), true);
54

55
    QCOMPARE(factValue.toInt(), 3);
56 57 58 59
}

void FactSystemTestBase::_parameter_specific_component_id_test(void)
{
60 61
    QVERIFY(_vehicle->parameterManager()->parameterExists(MAV_COMP_ID_AUTOPILOT1, "RC_MAP_THROTTLE"));
    Fact* fact = _vehicle->parameterManager()->getParameter(MAV_COMP_ID_AUTOPILOT1, "RC_MAP_THROTTLE");
Don Gagne's avatar
Don Gagne committed
62
    QVERIFY(fact != NULL);
Don Gagne's avatar
Don Gagne committed
63
    QVariant factValue = fact->rawValue();
Don Gagne's avatar
Don Gagne committed
64
    QCOMPARE(factValue.isValid(), true);
65
    QCOMPARE(factValue.toInt(), 3);
Don Gagne's avatar
Don Gagne committed
66 67 68
}

/// Test that QML can reference a Fact
69
void FactSystemTestBase::_qml_test(void)
Don Gagne's avatar
Don Gagne committed
70
{
71 72
    //-- TODO
#if 0
Don Gagne's avatar
Don Gagne committed
73
    QGCQuickWidget* widget = new QGCQuickWidget;
74

75
    widget->setAutoPilot(_plugin);
76

Don Gagne's avatar
Don Gagne committed
77
    widget->setSource(QUrl::fromUserInput("qrc:unittest/FactSystemTest.qml"));
78

Don Gagne's avatar
Don Gagne committed
79 80 81 82 83
    QQuickItem* rootObject = widget->rootObject();
    QObject* control = rootObject->findChild<QObject*>("testControl");
    QVERIFY(control != NULL);
    QVariant qmlValue = control->property("text").toInt();

84
    QCOMPARE(qmlValue.toInt(), 3);
85

Don Gagne's avatar
Don Gagne committed
86
    delete widget;
87
#endif
Don Gagne's avatar
Don Gagne committed
88 89 90
}

/// Test QML getting an updated Fact value
91
void FactSystemTestBase::_qmlUpdate_test(void)
Don Gagne's avatar
Don Gagne committed
92
{
93 94
    //-- TODO
#if 0
Don Gagne's avatar
Don Gagne committed
95
    QGCQuickWidget* widget = new QGCQuickWidget;
96

97
    widget->setAutoPilot(_plugin);
98

Don Gagne's avatar
Don Gagne committed
99
    widget->setSource(QUrl::fromUserInput("qrc:unittest/FactSystemTest.qml"));
100

101
    // Change the value
102

Don Gagne's avatar
Don Gagne committed
103
    QVariant paramValue = 12;
104
    qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()->parameterManager()->getParameter(FactSystem::defaultComponentId, "RC_MAP_THROTTLE")->setRawValue(paramValue);
Don Gagne's avatar
Don Gagne committed
105 106

    QTest::qWait(500); // Let the signals flow through
107

Don Gagne's avatar
Don Gagne committed
108
    // Make sure the qml has the right value
109

Don Gagne's avatar
Don Gagne committed
110 111 112 113
    QQuickItem* rootObject = widget->rootObject();
    QObject* control = rootObject->findChild<QObject*>("testControl");
    QVERIFY(control != NULL);
    QCOMPARE(control->property("text").toInt(), 12);
114

Don Gagne's avatar
Don Gagne committed
115
    delete widget;
116
#endif
Don Gagne's avatar
Don Gagne committed
117 118
}