MockQGCUASParamManager.h 4.67 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*=====================================================================
 
 QGroundControl Open Source Ground Control Station
 
 (c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 
 This file is part of the QGROUNDCONTROL project
 
 QGROUNDCONTROL is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 QGROUNDCONTROL is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
 
 ======================================================================*/

24 25 26
#ifndef MOCKQGCUASPARAMMANAGER_H
#define MOCKQGCUASPARAMMANAGER_H

Don Gagne's avatar
Don Gagne committed
27 28
#include <QLoggingCategory>

29 30
#include "QGCUASParamManagerInterface.h"

Don Gagne's avatar
Don Gagne committed
31 32
Q_DECLARE_LOGGING_CATEGORY(MockQGCUASParamManagerLog)

33 34 35 36 37 38 39 40 41 42 43 44
/// @file
///     @brief This is a mock implementation of QGCUASParamManager for writing Unit Tests.
///
///     @author Don Gagne <don@thegagnes.com>


class MockQGCUASParamManager : public QGCUASParamManagerInterface
{
    Q_OBJECT
    
signals:
    // The following QGCSUASParamManagerInterface signals are supported
Don Gagne's avatar
Don Gagne committed
45
    void parameterListUpToDate();   // You can connect to this signal, but it will never be emitted
Don Gagne's avatar
Don Gagne committed
46
    void parameterUpdated(int compId, QString paramName, QVariant value);
47 48 49 50
    
public:
    // Implemented QGCSUASParamManager overrides
    virtual bool getParameterValue(int component, const QString& parameter, QVariant& value) const;
Don Gagne's avatar
Don Gagne committed
51
    virtual int getDefaultComponentId(void) { return _defaultComponentId; }
52 53
    virtual int countOnboardParams(void) { return _mapParams.count(); }
    
54
public slots:
55 56
    // Implemented QGCSUASParamManager overrides
    void setParameter(int component, QString parameterName, QVariant value);
Don Gagne's avatar
Don Gagne committed
57 58 59 60
    virtual void setPendingParam(int componentId,  const QString& key,  const QVariant& value, bool forceSend = false)
        { Q_UNUSED(forceSend); setParameter(componentId, key, value); }
    virtual void sendPendingParameters(bool persistAfterSend = false, bool forceSend = false)
        { Q_UNUSED(persistAfterSend); Q_UNUSED(forceSend); }
Don Gagne's avatar
Don Gagne committed
61
    virtual bool parametersReady(void) { return true; }
62 63 64 65 66 67 68 69 70 71 72 73
    
public:
    // MockQGCUASParamManager methods
    MockQGCUASParamManager(void);
    
    /// QMap of parameters, QString key is paremeter name, QVariant value is parameter value
    typedef QMap<QString, QVariant> ParamMap_t;
    
    /// Sets current set of parameters to support calls like getParameterValue
    void setMockParameters(ParamMap_t& map) { _mapParams = map; }
    
    /// Returns the parameters which were set by calls to setParameter calls
Don Gagne's avatar
Don Gagne committed
74
    ParamMap_t getMockSetParameters(void) { return _mapParams; }
75
    /// Clears the set of parameters set by setParameter calls
Don Gagne's avatar
Don Gagne committed
76
    void clearMockSetParameters(void) { _mapParams.clear(); }
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    
public:
    // Unimplemented QGCUASParamManagerInterface overrides
    virtual QList<int> getComponentForParam(const QString& parameter) const { Q_ASSERT(false); Q_UNUSED(parameter); return _bogusQListInt; }
    virtual void setParamDescriptions(const QMap<QString,QString>& paramDescs) { Q_ASSERT(false); Q_UNUSED(paramDescs); }
    virtual int countPendingParams() { Q_ASSERT(false); return 0; }
    virtual UASParameterDataModel* dataModel() { Q_ASSERT(false); return NULL; }
    
public slots:
    // Unimplemented QGCUASParamManagerInterface overrides
    virtual void requestParameterList() { Q_ASSERT(false); }
    virtual void requestParameterListIfEmpty() { Q_ASSERT(false); }
    virtual void clearAllPendingParams() { Q_ASSERT(false); }
    virtual void requestParameterUpdate(int component, const QString& parameter)
        { Q_ASSERT(false); Q_UNUSED(component); Q_UNUSED(parameter); }
    virtual void writeOnboardParamsToStream(QTextStream &stream, const QString& uasName)
        { Q_ASSERT(false); Q_UNUSED(stream); Q_UNUSED(uasName); }
    virtual void readPendingParamsFromStream(QTextStream &stream) { Q_ASSERT(false); Q_UNUSED(stream); }
    virtual void requestRcCalibrationParamsUpdate() { Q_ASSERT(false); }
    virtual void copyVolatileParamsToPersistent() { Q_ASSERT(false); }
    virtual void copyPersistentParamsToVolatile() { Q_ASSERT(false); }
    
private:
100 101
    void _loadParams(void);
    
102
    ParamMap_t          _mapParams;
Don Gagne's avatar
Don Gagne committed
103 104
    
    static const int    _defaultComponentId = 50;
105 106 107 108 109 110

    // Bogus variables used for return types of NYI methods
    QList<int>          _bogusQListInt;
};

#endif