Commit 36fafeec authored by Don Gagne's avatar Don Gagne

Mock implementations of UAS, UASManager and QGCUASParamManger

Used for unit testing
parent 190b1d8a
......@@ -511,7 +511,9 @@ HEADERS += src/MG.h \
src/ui/px4_configuration/QGCPX4MulticopterConfig.h \
src/ui/px4_configuration/QGCPX4SensorCalibration.h \
src/ui/designer/QGCXYPlot.h \
src/ui/menuactionhelper.h
src/ui/menuactionhelper.h \
src/uas/UASManagerInterface.h \
src/uas/QGCUASParamManagerInterface.h
# Google Earth is only supported on Mac OS and Windows with Visual Studio Compiler
macx|macx-g++|macx-g++42|win32-msvc2008|win32-msvc2010|win32-msvc2012::HEADERS += src/ui/map3D/QGCGoogleEarthView.h
......@@ -737,7 +739,7 @@ SOURCES += \
src/ui/px4_configuration/QGCPX4SensorCalibration.cc \
src/ui/designer/QGCXYPlot.cc \
src/ui/menuactionhelper.cpp
CONFIG(debug, debug|release) {
# Unit Test sources/headers go here
......@@ -746,10 +748,16 @@ CONFIG(debug, debug|release) {
HEADERS += \
src/qgcunittest/AutoTest.h \
src/qgcunittest/UASUnitTest.h
src/qgcunittest/UASUnitTest.h \
src/qgcunittest/MockUASManager.h \
src/qgcunittest/MockUAS.h \
src/qgcunittest/MockQGCUASParamManager.h
SOURCES += \
src/qgcunittest/UASUnitTest.cc
src/qgcunittest/UASUnitTest.cc \
src/qgcunittest/MockUASManager.cc \
src/qgcunittest/MockUAS.cc \
src/qgcunittest/MockQGCUASParamManager.cc
}
# Enable Google Earth only on Mac OS and Windows with Visual Studio compiler
......
#include "MockQGCUASParamManager.h"
#include <QTest>
#include <QDebug>
MockQGCUASParamManager::MockQGCUASParamManager(void)
{
}
bool MockQGCUASParamManager::getParameterValue(int component, const QString& parameter, QVariant& value) const
{
Q_UNUSED(component);
if (_mapParams.contains(parameter)) {
value = _mapParams[parameter];
}
return false;
}
void MockQGCUASParamManager::setParameter(int component, QString parameterName, QVariant value)
{
Q_UNUSED(component);
_mapParamsSet[parameterName] = value;
}
#ifndef MOCKQGCUASPARAMMANAGER_H
#define MOCKQGCUASPARAMMANAGER_H
#include "QGCUASParamManagerInterface.h"
/// @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
// currently none
public:
// Implemented QGCSUASParamManager overrides
virtual bool getParameterValue(int component, const QString& parameter, QVariant& value) const;
virtual int getDefaultComponentId(void) { return 0; }
virtual int countOnboardParams(void) { return _mapParams.count(); }
public slots:
// Implemented QGCSUASParamManager overrides
void setParameter(int component, QString parameterName, QVariant value);
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
ParamMap_t getMockSetParameters(void) { return _mapParamsSet; }
/// Clears the set of parameters set by setParameter calls
void clearMockSetParameters(void) { _mapParamsSet.clear(); }
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 sendPendingParameters(bool persistAfterSend = false, bool forceSend = false)
{ Q_ASSERT(false); Q_UNUSED(persistAfterSend); Q_UNUSED(forceSend); }
virtual void requestParameterList() { Q_ASSERT(false); }
virtual void requestParameterListIfEmpty() { Q_ASSERT(false); }
virtual void setPendingParam(int componentId, const QString& key, const QVariant& value, bool forceSend = false)
{ Q_ASSERT(false); Q_UNUSED(componentId); Q_UNUSED(key); Q_UNUSED(value); Q_UNUSED(forceSend); }
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:
ParamMap_t _mapParams;
ParamMap_t _mapParamsSet;
// Bogus variables used for return types of NYI methods
QList<int> _bogusQListInt;
};
#endif
\ No newline at end of file
#include "MockUAS.h"
QString MockUAS::_bogusStaticString;
MockUAS::MockUAS(void) :
_systemType(MAV_TYPE_QUADROTOR),
_systemId(1)
{
}
void MockUAS::setMockParametersAndSignal(MockQGCUASParamManager::ParamMap_t& map)
{
_paramManager.setMockParameters(map);
QMapIterator<QString, QVariant> i(map);
while (i.hasNext()) {
i.next();
emit parameterChanged(_systemId, 0, i.key(), i.value());
}
}
\ No newline at end of file
This diff is collapsed.
#include "MockUASManager.h"
MockUASManager::MockUASManager(void) :
_mockUAS(NULL)
{
}
UASInterface* MockUASManager::getActiveUAS(void)
{
return _mockUAS;
}
void MockUASManager::setMockActiveUAS(MockUAS* mockUAS)
{
// Signal components that the last UAS is no longer active.
if (_mockUAS != NULL) {
emit activeUASStatusChanged(_mockUAS, false);
emit activeUASStatusChanged(_mockUAS->getUASID(), false);
}
_mockUAS = mockUAS;
// And signal that a new UAS is.
emit activeUASSet(_mockUAS);
if (_mockUAS)
{
// We don't support swiching between different UAS
//_mockUAS->setSelected();
emit activeUASSet(_mockUAS->getUASID());
emit activeUASStatusChanged(_mockUAS, true);
emit activeUASStatusChanged(_mockUAS->getUASID(), true);
}
}
#ifndef MOCKUASMANAGER_H
#define MOCKUASMANAGER_H
#include "UASManagerInterface.h"
#include "MockUAS.h"
/// @file
/// @brief This is a mock implementation of a UASManager used for writing Unit Tests. In order
/// to use it you must call UASManager::setMockUASManager which will then cause all further
/// calls to UASManager::instance to return the mock UASManager instead of the normal one.
///
/// @author Don Gagne <don@thegagnes.com>
class MockUASManager : public UASManagerInterface
{
Q_OBJECT
signals:
// The following signals from UASManager interface are supported
void activeUASSet(UASInterface* UAS);
void activeUASSet(int systemId);
void activeUASStatusChanged(UASInterface* UAS, bool active);
void activeUASStatusChanged(int systemId, bool active);
public:
// Implemented UASManagerInterface overrides
virtual UASInterface* getActiveUAS(void);
public:
// MockUASManager methods
MockUASManager(void);
/// Sets the currently active mock UAS
/// @param mockUAS new mock uas, NULL for no active UAS
void setMockActiveUAS(MockUAS* mockUAS);
public:
// Unimplemented UASManagerInterface overrides
virtual UASWaypointManager *getActiveUASWaypointManager() { Q_ASSERT(false); return NULL; }
virtual UASInterface* silentGetActiveUAS() { Q_ASSERT(false); return NULL; }
virtual UASInterface* getUASForId(int id) { Q_ASSERT(false); Q_UNUSED(id); return NULL; }
virtual QList<UASInterface*> getUASList() { Q_ASSERT(false); return _bogusQListUASInterface; }
virtual double getHomeLatitude() const { Q_ASSERT(false); return std::numeric_limits<double>::quiet_NaN(); }
virtual double getHomeLongitude() const { Q_ASSERT(false); return std::numeric_limits<double>::quiet_NaN(); }
virtual double getHomeAltitude() const { Q_ASSERT(false); return std::numeric_limits<double>::quiet_NaN(); }
virtual int getHomeFrame() const { Q_ASSERT(false); return 0; }
virtual Eigen::Vector3d wgs84ToEcef(const double & latitude, const double & longitude, const double & altitude)
{ Q_ASSERT(false); Q_UNUSED(latitude); Q_UNUSED(longitude); Q_UNUSED(altitude); return _bogusEigenVector3d; }
virtual Eigen::Vector3d ecefToEnu(const Eigen::Vector3d & ecef)
{ Q_ASSERT(false); Q_UNUSED(ecef); return _bogusEigenVector3d; }
virtual void wgs84ToEnu(const double& lat, const double& lon, const double& alt, double* east, double* north, double* up)
{ Q_ASSERT(false); Q_UNUSED(lat); Q_UNUSED(lon); Q_UNUSED(alt); Q_UNUSED(east); Q_UNUSED(north); Q_UNUSED(up); }
virtual void enuToWgs84(const double& x, const double& y, const double& z, double* lat, double* lon, double* alt)
{ Q_ASSERT(false); Q_UNUSED(x); Q_UNUSED(y); Q_UNUSED(z); Q_UNUSED(lat); Q_UNUSED(lon); Q_UNUSED(alt); }
virtual void nedToWgs84(const double& x, const double& y, const double& z, double* lat, double* lon, double* alt)
{ Q_ASSERT(false); Q_UNUSED(x); Q_UNUSED(y); Q_UNUSED(z); Q_UNUSED(lat); Q_UNUSED(lon); Q_UNUSED(alt); }
virtual void getLocalNEDSafetyLimits(double* x1, double* y1, double* z1, double* x2, double* y2, double* z2)
{ Q_ASSERT(false); Q_UNUSED(x1); Q_UNUSED(y1); Q_UNUSED(z1); Q_UNUSED(x2); Q_UNUSED(y2); Q_UNUSED(z2); }
virtual bool isInLocalNEDSafetyLimits(double x, double y, double z)
{ Q_ASSERT(false); Q_UNUSED(x); Q_UNUSED(y); Q_UNUSED(z); return false; }
public slots:
// Unimplemented UASManagerInterface overrides
virtual void setActiveUAS(UASInterface* UAS) { Q_ASSERT(false); Q_UNUSED(UAS); }
virtual void addUAS(UASInterface* UAS) { Q_ASSERT(false); Q_UNUSED(UAS); }
virtual void removeUAS(UASInterface* uas) { Q_ASSERT(false); Q_UNUSED(uas);}
virtual bool launchActiveUAS() { Q_ASSERT(false); return false; }
virtual bool haltActiveUAS() { Q_ASSERT(false); return false; }
virtual bool continueActiveUAS() { Q_ASSERT(false); return false; }
virtual bool returnActiveUAS() { Q_ASSERT(false); return false; }
virtual bool stopActiveUAS() { Q_ASSERT(false); return false; }
virtual bool killActiveUAS() { Q_ASSERT(false); return false; }
virtual void configureActiveUAS() { Q_ASSERT(false); }
virtual bool shutdownActiveUAS() { Q_ASSERT(false); return false; }
virtual bool setHomePosition(double lat, double lon, double alt)
{ Q_ASSERT(false); Q_UNUSED(lat); Q_UNUSED(lon); Q_UNUSED(alt); return false; }
virtual bool setHomePositionAndNotify(double lat, double lon, double alt)
{ Q_ASSERT(false); Q_UNUSED(lat); Q_UNUSED(lon); Q_UNUSED(alt); return false; }
virtual void setLocalNEDSafetyBorders(double x1, double y1, double z1, double x2, double y2, double z2)
{ Q_ASSERT(false); Q_UNUSED(x1); Q_UNUSED(y1); Q_UNUSED(z1); Q_UNUSED(x2); Q_UNUSED(y2); Q_UNUSED(z2); }
virtual void uavChangedHomePosition(int uav, double lat, double lon, double alt)
{ Q_ASSERT(false); Q_UNUSED(uav); Q_UNUSED(lat); Q_UNUSED(lon); Q_UNUSED(alt); }
virtual void loadSettings() { Q_ASSERT(false); }
virtual void storeSettings() { Q_ASSERT(false); }
private:
MockUAS* _mockUAS;
// Bogus variables used for return types of NYI methods
QList<UASInterface*> _bogusQListUASInterface;
Eigen::Vector3d _bogusEigenVector3d;
public:
/* Need to align struct pointer to prevent a memory assertion:
* See http://eigen.tuxfamily.org/dox-devel/TopicUnalignedArrayAssert.html
* for details
*/
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};
#endif
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment