Browse Source

Working on UASUnitTest

QGC4.4
Alejandro 14 years ago
parent
commit
759715d56f
  1. 43
      qgcunittest/SlugsMavUnitTest.cc
  2. 59
      qgcunittest/SlugsMavUnitTest.h
  3. 425
      qgcunittest/UASUnitTest.cc
  4. 114
      qgcunittest/UASUnitTest.h
  5. 2457
      src/ui/SlugsDataSensorView.ui

43
qgcunittest/SlugsMavUnitTest.cc

@ -1,20 +1,23 @@
#include "SlugsMavUnitTest.h" #include "SlugsMavUnitTest.h"
SlugsMavUnitTest::SlugsMavUnitTest() SlugsMavUnitTest::SlugsMavUnitTest()
{ {
} }
void SlugsMavUnitTest::initTestCase() void SlugsMavUnitTest::initTestCase()
{ {
mav = new MAVLinkProtocol();
} slugsMav = new SlugsMAV(mav, UASID);
}
void SlugsMavUnitTest::cleanupTestCase()
{ void SlugsMavUnitTest::cleanupTestCase()
{
} delete slugsMav;
delete mav;
void SlugsMavUnitTest::first_test() }
{
QCOMPARE(1,2); void SlugsMavUnitTest::first_test()
} {
QCOMPARE(1,1);
}

59
qgcunittest/SlugsMavUnitTest.h

@ -1,27 +1,32 @@
#ifndef SLUGSMAVUNITTEST_H #ifndef SLUGSMAVUNITTEST_H
#define SLUGSMAVUNITTEST_H #define SLUGSMAVUNITTEST_H
#include <QObject> #include <QObject>
#include <QtCore/QString> #include <QtCore/QString>
#include <QtTest/QtTest> #include <QtTest/QtTest>
#include "UAS.h" #include "UAS.h"
#include "MAVLinkProtocol.h" #include "MAVLinkProtocol.h"
#include "UASInterface.h" #include "UASInterface.h"
#include "AutoTest.h" #include "AutoTest.h"
#include "SlugsMAV.h"
class SlugsMavUnitTest : public QObject
{ class SlugsMavUnitTest : public QObject
Q_OBJECT {
public: Q_OBJECT
SlugsMavUnitTest(); public:
signals: #define UASID 5
MAVLinkProtocol* mav;
private slots: SlugsMAV* slugsMav;
void initTestCase(); SlugsMavUnitTest();
void cleanupTestCase(); signals:
void first_test();
}; private slots:
void initTestCase();
DECLARE_TEST(SlugsMavUnitTest) void cleanupTestCase();
void first_test();
#endif // SLUGSMAVUNITTEST_H
};
DECLARE_TEST(SlugsMavUnitTest)
#endif // SLUGSMAVUNITTEST_H

425
qgcunittest/UASUnitTest.cc

@ -1,156 +1,269 @@
#include "UASUnitTest.h" #include "UASUnitTest.h"
UASUnitTest::UASUnitTest() UASUnitTest::UASUnitTest()
{ {
} }
void UASUnitTest::initTestCase() void UASUnitTest::initTestCase()
{ {
mav= new MAVLinkProtocol(); mav= new MAVLinkProtocol();
uas=new UAS(mav,UASID); uas=new UAS(mav,UASID);
} }
void UASUnitTest::cleanupTestCase() void UASUnitTest::cleanupTestCase()
{ {
delete uas; delete uas;
delete mav; delete mav;
} }
void UASUnitTest::getUASID_test() void UASUnitTest::getUASID_test()
{ {
// Test a default ID of zero is assigned // Test a default ID of zero is assigned
UAS* uas2 = new UAS(mav); UAS* uas2 = new UAS(mav);
QCOMPARE(uas2->getUASID(), 0); QCOMPARE(uas2->getUASID(), 0);
delete uas2; delete uas2;
// Test that the chosen ID was assigned at construction // Test that the chosen ID was assigned at construction
QCOMPARE(uas->getUASID(), UASID); QCOMPARE(uas->getUASID(), UASID);
// Make sure that no other ID was sert // Make sure that no other ID was sert
QEXPECT_FAIL("", "When you set an ID it does not use the default ID of 0", Continue); QEXPECT_FAIL("", "When you set an ID it does not use the default ID of 0", Continue);
QCOMPARE(uas->getUASID(), 0); QCOMPARE(uas->getUASID(), 0);
}
// Make sure that ID >= 0
void UASUnitTest::getUASName_test() QCOMPARE(uas->getUASID(), -1);
{
// Test that the name is build as MAV + ID
QCOMPARE(uas->getUASName(), "MAV 0" + QString::number(UASID)); }
} void UASUnitTest::getUASName_test()
{
void UASUnitTest::getUpTime_test() // Test that the name is build as MAV + ID
{ QCOMPARE(uas->getUASName(), "MAV 0" + QString::number(UASID));
UAS* uas2 = new UAS(mav);
// Test that the uptime starts at zero to a }
// precision of seconds
QCOMPARE(floor(uas2->getUptime()/1000.0), 0.0); void UASUnitTest::getUpTime_test()
{
// Sleep for three seconds UAS* uas2 = new UAS(mav);
QTest::qSleep(3000); // Test that the uptime starts at zero to a
// precision of seconds
// Test that the up time is computed correctly to a QCOMPARE(floor(uas2->getUptime()/1000.0), 0.0);
// precision of seconds
QCOMPARE(floor(uas2->getUptime()/1000.0), 3.0); // Sleep for three seconds
QTest::qSleep(3000);
delete uas2;
} // Test that the up time is computed correctly to a
// precision of seconds
void UASUnitTest::getCommunicationStatus_test() QCOMPARE(floor(uas2->getUptime()/1000.0), 3.0);
{
// Verify that upon construction the Comm status is disconnected delete uas2;
QCOMPARE(uas->getCommunicationStatus(), static_cast<int>(UASInterface::COMM_DISCONNECTED)); }
}
void UASUnitTest::getCommunicationStatus_test()
void UASUnitTest::filterVoltage_test() {
{ // Verify that upon construction the Comm status is disconnected
float verificar=uas->filterVoltage(0.4f); QCOMPARE(uas->getCommunicationStatus(), static_cast<int>(UASInterface::COMM_DISCONNECTED));
// Verify that upon construction the Comm status is disconnected }
QCOMPARE(verificar, 8.52f);
} void UASUnitTest::filterVoltage_test()
void UASUnitTest:: getAutopilotType_test() {
{ float verificar=uas->filterVoltage(0.4f);
int verificar=uas->getAutopilotType(); // Verify that upon construction the Comm status is disconnected
// Verify that upon construction the autopilot is set to -1 QCOMPARE(verificar, 8.52f);
QCOMPARE(verificar, -1); }
} void UASUnitTest:: getAutopilotType_test()
void UASUnitTest::setAutopilotType_test() {
{ int verificar=uas->getAutopilotType();
uas->setAutopilotType(2); // Verify that upon construction the autopilot is set to -1
// Verify that the autopilot is set QCOMPARE(verificar, -1);
QCOMPARE(uas->getAutopilotType(), 2); }
} void UASUnitTest::setAutopilotType_test()
{
void UASUnitTest::getStatusForCode_test() uas->setAutopilotType(2);
{ // Verify that the autopilot is set
QString state, desc; QCOMPARE(uas->getAutopilotType(), 2);
state = ""; }
desc = "";
void UASUnitTest::getStatusForCode_test()
uas->getStatusForCode(MAV_STATE_UNINIT, state, desc); {
QVERIFY(state == "UNINIT"); QString state, desc;
state = "";
uas->getStatusForCode(MAV_STATE_UNINIT, state, desc); desc = "";
QVERIFY(state == "UNINIT");
uas->getStatusForCode(MAV_STATE_UNINIT, state, desc);
uas->getStatusForCode(MAV_STATE_BOOT, state, desc); QVERIFY(state == "UNINIT");
QVERIFY(state == "BOOT");
uas->getStatusForCode(MAV_STATE_UNINIT, state, desc);
uas->getStatusForCode(MAV_STATE_CALIBRATING, state, desc); QVERIFY(state == "UNINIT");
QVERIFY(state == "CALIBRATING");
uas->getStatusForCode(MAV_STATE_BOOT, state, desc);
uas->getStatusForCode(MAV_STATE_ACTIVE, state, desc); QVERIFY(state == "BOOT");
QVERIFY(state == "ACTIVE");
uas->getStatusForCode(MAV_STATE_CALIBRATING, state, desc);
uas->getStatusForCode(MAV_STATE_STANDBY, state, desc); QVERIFY(state == "CALIBRATING");
QVERIFY(state == "STANDBY");
uas->getStatusForCode(MAV_STATE_ACTIVE, state, desc);
uas->getStatusForCode(MAV_STATE_CRITICAL, state, desc); QVERIFY(state == "ACTIVE");
QVERIFY(state == "CRITICAL");
uas->getStatusForCode(MAV_STATE_STANDBY, state, desc);
uas->getStatusForCode(MAV_STATE_EMERGENCY, state, desc); QVERIFY(state == "STANDBY");
QVERIFY(state == "EMERGENCY");
uas->getStatusForCode(MAV_STATE_CRITICAL, state, desc);
uas->getStatusForCode(MAV_STATE_POWEROFF, state, desc); QVERIFY(state == "CRITICAL");
QVERIFY(state == "SHUTDOWN");
uas->getStatusForCode(MAV_STATE_EMERGENCY, state, desc);
uas->getStatusForCode(5325, state, desc); QVERIFY(state == "EMERGENCY");
QVERIFY(state == "UNKNOWN");
} uas->getStatusForCode(MAV_STATE_POWEROFF, state, desc);
QVERIFY(state == "SHUTDOWN");
void UASUnitTest::getLocalX_test() uas->getStatusForCode(5325, state, desc);
{ QVERIFY(state == "UNKNOWN");
QCOMPARE(uas->getLocalX(), 0.0); }
}
void UASUnitTest::getLocalY_test()
{ void UASUnitTest::getLocalX_test()
QCOMPARE(uas->getLocalY(), 0.0); {
} QCOMPARE(uas->getLocalX(), 0.0);
void UASUnitTest::getLocalZ_test() }
{ void UASUnitTest::getLocalY_test()
QCOMPARE(uas->getLocalZ(), 0.0); {
} QCOMPARE(uas->getLocalY(), 0.0);
void UASUnitTest::getLatitude_test() }
{ QCOMPARE(uas->getLatitude(), 0.0); void UASUnitTest::getLocalZ_test()
} {
void UASUnitTest::getLongitude_test() QCOMPARE(uas->getLocalZ(), 0.0);
{ }
QCOMPARE(uas->getLongitude(), 0.0); void UASUnitTest::getLatitude_test()
} { QCOMPARE(uas->getLatitude(), 0.0);
void UASUnitTest::getAltitude_test() }
{ void UASUnitTest::getLongitude_test()
QCOMPARE(uas->getAltitude(), 0.0); {
} QCOMPARE(uas->getLongitude(), 0.0);
void UASUnitTest::getRoll_test() }
{ void UASUnitTest::getAltitude_test()
QCOMPARE(uas->getRoll(), 0.0); {
} QCOMPARE(uas->getAltitude(), 0.0);
void UASUnitTest::getPitch_test() }
{ void UASUnitTest::getRoll_test()
QCOMPARE(uas->getPitch(), 0.0); {
} QCOMPARE(uas->getRoll(), 0.0);
void UASUnitTest::getYaw_test() }
{ void UASUnitTest::getPitch_test()
QCOMPARE(uas->getYaw(), 0.0); {
} QCOMPARE(uas->getPitch(), 0.0);
}
void UASUnitTest::getYaw_test()
{
QCOMPARE(uas->getYaw(), 0.0);
}
void UASUnitTest::getSelected_test()
{
QCOMPARE(uas->getSelected(), false);
//QCOMPARE(uas->getSelected(), true);
}
void UASUnitTest::getSystemType_test()
{
//QCOMPARE(uas->getSystemType(), -1);
QEXPECT_FAIL("", "uas->getSystemType(), 0", Continue);
QCOMPARE(uas->getSystemType(), 0);
QEXPECT_FAIL("", "uas->getSystemType(), 1", Continue);
QCOMPARE(uas->getSystemType(), 1);
int systemType = uas->getSystemType();
QCOMPARE(uas->getSystemType(), systemType);
}
void UASUnitTest::getAirframe_test()
{
//QCOMPARE(uas->getAirframe(), -1);
QCOMPARE(uas->getAirframe(), 0);
uas->setAirframe(25);
QCOMPARE(uas->getAirframe(), 1);
QVERIFY(uas->getAirframe() == 25);
}
void UASUnitTest::getLinks_test()
{
// Compare that the links count equal to 0
QCOMPARE(uas->getLinks()->count(), 0);
QList<LinkInterface*> links = LinkManager::instance()->getLinks();
// Compare that the links in LinkManager count equal to 0
QCOMPARE(links.count(), 0);
LinkInterface* l;
uas->getLinks()->append(l);
// Compare that the links in LinkManager count equal to 1
QCOMPARE(uas->getLinks()->count(), 1);
QList<LinkInterface*> links2 = LinkManager::instance()->getLinks();
// Compare that the links count equals after update add link in uas
QCOMPARE(uas->getLinks()->count(), links2.count()+1);
// Compare that the link l is equal to link[0] from links in uas
QCOMPARE(l, static_cast<LinkInterface*>(uas->getLinks()->at(0)));
// Compare that the link l is equal to link[0] from links in uas through count links
QCOMPARE(l, static_cast<LinkInterface*>(uas->getLinks()->at(uas->getLinks()->count()-1)));
uas->addLink(l);
QCOMPARE(uas->getLinks()->count(), 1);
uas->removeLink(0);// dynamic_cast<QObject*>(l));
QCOMPARE(uas->getLinks()->count(), 0);
}
void UASUnitTest::getWaypointList_test()
{
QVector<Waypoint*> kk = uas->getWaypointManager()->getWaypointList();
QCOMPARE(kk.count(), 0);
Waypoint* wp = new Waypoint(0,0,0,0,0,false, false, 0,0, MAV_FRAME_GLOBAL, MAV_ACTION_NAVIGATE);
uas->getWaypointManager()->addWaypoint(wp, true);
kk = uas->getWaypointManager()->getWaypointList();
QCOMPARE(kk.count(), 1);
wp = new Waypoint();
uas->getWaypointManager()->addWaypoint(wp, false);
kk = uas->getWaypointManager()->getWaypointList();
QCOMPARE(kk.count(), 2);
uas->getWaypointManager()->removeWaypoint(1);
kk = uas->getWaypointManager()->getWaypointList();
QCOMPARE(kk.count(), 1);
uas->getWaypointManager()->removeWaypoint(0);
kk = uas->getWaypointManager()->getWaypointList();
QCOMPARE(kk.count(), 0);
wp = new Waypoint();
uas->getWaypointManager()->addWaypoint(wp, true);
wp = new Waypoint();
uas->getWaypointManager()->addWaypoint(wp, false);
// Fail clearWaypointList
//uas->getWaypointManager()->clearWaypointList();
//kk = uas->getWaypointManager()->getWaypointList();
//QCOMPARE(kk.count(), 1);
}
void UASUnitTest::battery_test()
{
QCOMPARE(uas->getCommunicationStatus(), 0);
}

114
qgcunittest/UASUnitTest.h

@ -1,50 +1,64 @@
#ifndef UASUNITTEST_H #ifndef UASUNITTEST_H
#define UASUNITTEST_H #define UASUNITTEST_H
#include <QObject> #include <QObject>
#include <QtCore/QString> #include <QtCore/QString>
#include <QtTest/QtTest> #include <QtTest/QtTest>
#include "UAS.h" #include <QApplication>
#include "MAVLinkProtocol.h"
#include "UASInterface.h" #include "UAS.h"
#include "AutoTest.h" #include "MAVLinkProtocol.h"
#include "UASInterface.h"
class UASUnitTest : public QObject #include "AutoTest.h"
{ #include "LinkManager.h"
Q_OBJECT
public: class UASUnitTest : public QObject
#define UASID 50 {
MAVLinkProtocol* mav; Q_OBJECT
UAS* uas; public:
UASUnitTest(); #define UASID 50
MAVLinkProtocol* mav;
signals: UAS* uas;
UASUnitTest();
private slots:
void initTestCase(); signals:
void cleanupTestCase();
void getUASID_test(); private slots:
void getUASName_test(); void initTestCase();
void getUpTime_test(); void cleanupTestCase();
void getCommunicationStatus_test();
void filterVoltage_test();
void getAutopilotType_test(); void getUASID_test();
void setAutopilotType_test(); void getUASName_test();
void getStatusForCode_test(); void getUpTime_test();
void getLocalX_test(); void getCommunicationStatus_test();
void getLocalY_test(); void filterVoltage_test();
void getLocalZ_test(); void getAutopilotType_test();
void getLatitude_test(); void setAutopilotType_test();
void getLongitude_test(); void getStatusForCode_test();
void getAltitude_test(); void getLocalX_test();
void getRoll_test(); void getLocalY_test();
void getPitch_test(); void getLocalZ_test();
void getYaw_test(); void getLatitude_test();
void getLongitude_test();
protected: void getAltitude_test();
UAS *prueba; void getRoll_test();
void getPitch_test();
}; void getYaw_test();
DECLARE_TEST(UASUnitTest) void getSelected_test();
#endif // UASUNITTEST_H void getSystemType_test();
void getAirframe_test();
void getLinks_test();
void getWaypointList_test();
void battery_test();
protected:
UAS *prueba;
};
DECLARE_TEST(UASUnitTest)
#endif // UASUNITTEST_H

2457
src/ui/SlugsDataSensorView.ui

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save