From 5ed1b5bcc8b21ae76470da4676607606d9b75394 Mon Sep 17 00:00:00 2001 From: Jessica Date: Fri, 20 Jul 2012 15:50:23 -0700 Subject: [PATCH 1/4] System type is set to generic in constructor of UAS. --- qgcunittest/UASUnitTest.cc | 11 ++++++----- src/uas/UAS.cc | 35 ++++++++++++++++++++--------------- src/uas/UAS.h | 3 +-- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/qgcunittest/UASUnitTest.cc b/qgcunittest/UASUnitTest.cc index cf2c49a..ce36f77 100644 --- a/qgcunittest/UASUnitTest.cc +++ b/qgcunittest/UASUnitTest.cc @@ -1,5 +1,6 @@ #include "UASUnitTest.h" #include +#include UASUnitTest::UASUnitTest() { } @@ -167,8 +168,9 @@ void UASUnitTest::getSelected_test() } void UASUnitTest::getSystemType_test() -{ //best guess: it is not initialized in the constructor, - //what should it be initialized to? +{ //check that system type is set to MAV_TYPE_GENERIC when initialized + QCOMPARE(uas->getSystemType(), 0); + uas->setSystemType(13); QCOMPARE(uas->getSystemType(), 13); } @@ -251,13 +253,12 @@ void UASUnitTest::getWaypoint_test() void UASUnitTest::signalWayPoint_test() { - QSignalSpy spy(uas->getWaypointManager(), SIGNAL(waypointListChanged(UASID))); - + QSignalSpy spy(uas->getWaypointManager(), SIGNAL(waypointEditableListChanged(UASID))); Waypoint* wp = new Waypoint(0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,false, false, MAV_FRAME_GLOBAL, MAV_CMD_MISSION_START, "blah"); uas->getWaypointManager()->addWaypointEditable(wp, true); printf("spy.count = %d\n", spy.count()); - //QCOMPARE(spy.count(), 1); // 1 listChanged for add wayPoint + QCOMPARE(spy.count(), 1); // 1 listChanged for add wayPoint uas->getWaypointManager()->removeWaypoint(0); QCOMPARE(spy.count(), 2); // 2 listChanged for remove wayPoint QSignalSpy spyDestroyed(uas->getWaypointManager(), SIGNAL(destroyed())); diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index f555ef8..30f3f3e 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -111,7 +111,8 @@ UAS::UAS(MAVLinkProtocol* protocol, int id) : UASInterface(), connect(statusTimeout, SIGNAL(timeout()), this, SLOT(updateState())); connect(this, SIGNAL(systemSpecsChanged(int)), this, SLOT(writeSettings())); statusTimeout->start(500); - readSettings(); + readSettings(); + type = MAV_TYPE_GENERIC; // Initial signals emit disarmed(); emit armingChanged(false); @@ -2081,21 +2082,25 @@ void UAS::requestParameter(int component, const QString& parameter) void UAS::setSystemType(int systemType) { - type = systemType; - // If the airframe is still generic, change it to a close default type - if (airframe == 0) + if((systemType >= MAV_TYPE_GENERIC) && (systemType < MAV_TYPE_ENUM_END)) { - switch (systemType) - { - case MAV_TYPE_FIXED_WING: - airframe = QGC_AIRFRAME_EASYSTAR; - break; - case MAV_TYPE_QUADROTOR: - airframe = QGC_AIRFRAME_MIKROKOPTER; - break; - } - } - emit systemSpecsChanged(uasId); + type = systemType; + + // If the airframe is still generic, change it to a close default type + if (airframe == 0) + { + switch (systemType) + { + case MAV_TYPE_FIXED_WING: + airframe = QGC_AIRFRAME_EASYSTAR; + break; + case MAV_TYPE_QUADROTOR: + airframe = QGC_AIRFRAME_MIKROKOPTER; + break; + } + } + emit systemSpecsChanged(uasId); + } } void UAS::setUASName(const QString& name) diff --git a/src/uas/UAS.h b/src/uas/UAS.h index bab9d55..3f2e591 100644 --- a/src/uas/UAS.h +++ b/src/uas/UAS.h @@ -490,7 +490,7 @@ public slots: /** @brief Set the specific airframe type */ void setAirframe(int airframe) { - if((airframe >= 0) && (airframe < 12)) + if((airframe >= QGC_AIRFRAME_GENERIC) && (airframe < QGC_AIRFRAME_END_OF_ENUM)) { this->airframe = airframe; emit systemSpecsChanged(uasId); @@ -643,7 +643,6 @@ public slots: void stopDataRecording(); void deleteSettings(); signals: - /** @brief The main/battery voltage has changed/was updated */ //void voltageChanged(int uasId, double voltage); // Defined in UASInterface already /** @brief An actuator value has changed */ From 16f4c928ad8d3b41d40e1f7aa88a9f4dea5856d7 Mon Sep 17 00:00:00 2001 From: Jessica Date: Sat, 21 Jul 2012 11:00:19 -0700 Subject: [PATCH 2/4] Signal waypoint test passes. --- qgcunittest/UASUnitTest.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/qgcunittest/UASUnitTest.cc b/qgcunittest/UASUnitTest.cc index ce36f77..5df3bf7 100644 --- a/qgcunittest/UASUnitTest.cc +++ b/qgcunittest/UASUnitTest.cc @@ -16,8 +16,10 @@ void UASUnitTest::cleanup() { delete mav; mav = NULL; + if(uas != NULL){ delete uas; uas = NULL; + } } void UASUnitTest::getUASID_test() @@ -253,32 +255,35 @@ void UASUnitTest::getWaypoint_test() void UASUnitTest::signalWayPoint_test() { - QSignalSpy spy(uas->getWaypointManager(), SIGNAL(waypointEditableListChanged(UASID))); - Waypoint* wp = new Waypoint(0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,false, false, MAV_FRAME_GLOBAL, MAV_CMD_MISSION_START, "blah"); + QSignalSpy spy(uas->getWaypointManager(), SIGNAL(waypointEditableListChanged())); + + Waypoint* wp = new Waypoint(0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,false, false, MAV_FRAME_GLOBAL, MAV_CMD_MISSION_START, "blah"); uas->getWaypointManager()->addWaypointEditable(wp, true); - printf("spy.count = %d\n", spy.count()); QCOMPARE(spy.count(), 1); // 1 listChanged for add wayPoint uas->getWaypointManager()->removeWaypoint(0); + QCOMPARE(spy.count(), 2); // 2 listChanged for remove wayPoint QSignalSpy spyDestroyed(uas->getWaypointManager(), SIGNAL(destroyed())); QVERIFY(spyDestroyed.isValid()); QCOMPARE( spyDestroyed.count(), 0 ); delete uas;// delete(destroyed) uas for validating + uas = NULL; QCOMPARE(spyDestroyed.count(), 1);// count destroyed uas should are 1 - uas = new UAS(mav,UASID); - QSignalSpy spy2(uas->getWaypointManager(), SIGNAL(waypointListChanged())); + QSignalSpy spy2(uas->getWaypointManager(), SIGNAL(waypointEditableListChanged())); QCOMPARE(spy2.count(), 0); + Waypoint* wp2 = new Waypoint(0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,false, false, MAV_FRAME_GLOBAL, MAV_CMD_MISSION_START, "blah"); - uas->getWaypointManager()->addWaypointEditable(wp, true); + uas->getWaypointManager()->addWaypointEditable(wp2, true); QCOMPARE(spy2.count(), 1); uas->getWaypointManager()->clearWaypointList(); QVector wpList = uas->getWaypointManager()->getWaypointEditableList(); QCOMPARE(wpList.count(), 1); + delete wp2; } void UASUnitTest::signalUASLink_test() From 8d3f5c4ce5cb56c0752b6252183aced7952ec41c Mon Sep 17 00:00:00 2001 From: Jessica Date: Sat, 21 Jul 2012 11:11:41 -0700 Subject: [PATCH 3/4] Signal waypoint test passes. --- qgcunittest/UASUnitTest.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/qgcunittest/UASUnitTest.cc b/qgcunittest/UASUnitTest.cc index 5df3bf7..5280e80 100644 --- a/qgcunittest/UASUnitTest.cc +++ b/qgcunittest/UASUnitTest.cc @@ -257,13 +257,14 @@ void UASUnitTest::signalWayPoint_test() { QSignalSpy spy(uas->getWaypointManager(), SIGNAL(waypointEditableListChanged())); - Waypoint* wp = new Waypoint(0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,false, false, MAV_FRAME_GLOBAL, MAV_CMD_MISSION_START, "blah"); + Waypoint* wp = new Waypoint(0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,false, false, MAV_FRAME_GLOBAL, MAV_CMD_MISSION_START, "blah"); uas->getWaypointManager()->addWaypointEditable(wp, true); + QCOMPARE(spy.count(), 1); // 1 listChanged for add wayPoint uas->getWaypointManager()->removeWaypoint(0); - QCOMPARE(spy.count(), 2); // 2 listChanged for remove wayPoint + QSignalSpy spyDestroyed(uas->getWaypointManager(), SIGNAL(destroyed())); QVERIFY(spyDestroyed.isValid()); QCOMPARE( spyDestroyed.count(), 0 ); From ec6d473bc245b94e3401e146ef3b680e6169e6be Mon Sep 17 00:00:00 2001 From: Jessica Date: Fri, 27 Jul 2012 17:55:07 -0700 Subject: [PATCH 4/4] Put qgcunittest into src. Left the .pro file in the root directory. --- qgcunittest.pro | 2 +- qgcunittest/AutoTest.h | 85 ---------- qgcunittest/UASUnitTest.cc | 371 ----------------------------------------- qgcunittest/UASUnitTest.h | 61 ------- qgcunittest/testSuite.cc | 28 ---- src/qgcunittest/AutoTest.h | 85 ++++++++++ src/qgcunittest/UASUnitTest.cc | 371 +++++++++++++++++++++++++++++++++++++++++ src/qgcunittest/UASUnitTest.h | 61 +++++++ src/qgcunittest/testSuite.cc | 28 ++++ 9 files changed, 546 insertions(+), 546 deletions(-) delete mode 100755 qgcunittest/AutoTest.h delete mode 100644 qgcunittest/UASUnitTest.cc delete mode 100644 qgcunittest/UASUnitTest.h delete mode 100755 qgcunittest/testSuite.cc create mode 100755 src/qgcunittest/AutoTest.h create mode 100644 src/qgcunittest/UASUnitTest.cc create mode 100644 src/qgcunittest/UASUnitTest.h create mode 100755 src/qgcunittest/testSuite.cc diff --git a/qgcunittest.pro b/qgcunittest.pro index 5aea295..f51452d 100644 --- a/qgcunittest.pro +++ b/qgcunittest.pro @@ -34,7 +34,7 @@ QT += network \ TEMPLATE = app TARGET = qgcunittest BASEDIR = $${IN_PWD} -TESTDIR = $$BASEDIR/qgcunittest +TESTDIR = $$BASEDIR/src/qgcunittest linux-g++|linux-g++-64{ debug { TARGETDIR = $${OUT_PWD}/debug diff --git a/qgcunittest/AutoTest.h b/qgcunittest/AutoTest.h deleted file mode 100755 index 892d814..0000000 --- a/qgcunittest/AutoTest.h +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @author Rob Caldecott -* @note This was obtained from http://qtcreator.blogspot.com/2010/04/sample-multiple-unit-test-project.html -* -*/ - -#ifndef AUTOTEST_H -#define AUTOTEST_H - -#include -#include -#include -#include - -namespace AutoTest -{ - typedef QList TestList; - - inline TestList& testList() - { - static TestList list; - return list; - } - - inline bool findObject(QObject* object) - { - TestList& list = testList(); - if (list.contains(object)) - { - return true; - } - foreach (QObject* test, list) - { - if (test->objectName() == object->objectName()) - { - return true; - } - } - return false; - } - - inline void addTest(QObject* object) - { - TestList& list = testList(); - if (!findObject(object)) - { - list.append(object); - } - } - - inline int run(int argc, char *argv[]) - { - int ret = 0; - QCoreApplication t(argc, argv); - foreach (QObject* test, testList()) - { - ret += QTest::qExec(test, argc, argv); - } - - return ret; - } -} - -template -class Test -{ -public: - QSharedPointer child; - - Test(const QString& name) : child(new T) - { - child->setObjectName(name); - AutoTest::addTest(child.data()); - } -}; - -#define DECLARE_TEST(className) static Test t(#className); - -#define TEST_MAIN \ - int main(int argc, char *argv[]) \ - { \ - return AutoTest::run(argc, argv); \ - } - -#endif // AUTOTEST_H diff --git a/qgcunittest/UASUnitTest.cc b/qgcunittest/UASUnitTest.cc deleted file mode 100644 index 5280e80..0000000 --- a/qgcunittest/UASUnitTest.cc +++ /dev/null @@ -1,371 +0,0 @@ -#include "UASUnitTest.h" -#include -#include -UASUnitTest::UASUnitTest() -{ -} -//This function is called after every test -void UASUnitTest::init() -{ - mav = new MAVLinkProtocol(); - uas = new UAS(mav, UASID); - uas->deleteSettings(); -} -//this function is called after every test -void UASUnitTest::cleanup() -{ - delete mav; - mav = NULL; - if(uas != NULL){ - delete uas; - uas = NULL; - } -} - -void UASUnitTest::getUASID_test() -{ - // Test a default ID of zero is assigned - UAS* uas2 = new UAS(mav); - QCOMPARE(uas2->getUASID(), 0); - delete uas2; - - // Test that the chosen ID was assigned at construction - QCOMPARE(uas->getUASID(), UASID); - - // Make sure that no other ID was set - QEXPECT_FAIL("", "When you set an ID it does not use the default ID of 0", Continue); - QCOMPARE(uas->getUASID(), 0); - - // Make sure that ID >= 0 - QCOMPARE(uas->getUASID(), 100); - -} - -void UASUnitTest::getUASName_test() -{ - // Test that the name is build as MAV + ID - QCOMPARE(uas->getUASName(), "MAV " + QString::number(UASID)); - -} - -void UASUnitTest::getUpTime_test() -{ - 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); - - // Sleep for three seconds - QTest::qSleep(3000); - - // Test that the up time is computed correctly to a - // precision of seconds - QCOMPARE(floor(uas2->getUptime()/1000.0), 3.0); - - delete uas2; -} - -void UASUnitTest::getCommunicationStatus_test() -{ - // Verify that upon construction the Comm status is disconnected - QCOMPARE(uas->getCommunicationStatus(), static_cast(UASInterface::COMM_DISCONNECTED)); -} - -void UASUnitTest::filterVoltage_test() -{ - float verificar=uas->filterVoltage(0.4f); - // Verify that upon construction the Comm status is disconnected - QCOMPARE(verificar, 8.52f); -} -void UASUnitTest:: getAutopilotType_test() -{ - int type = uas->getAutopilotType(); - // Verify that upon construction the autopilot is set to -1 - QCOMPARE(type, -1); -} -void UASUnitTest::setAutopilotType_test() -{ - uas->setAutopilotType(2); - // Verify that the autopilot is set - QCOMPARE(uas->getAutopilotType(), 2); -} - -void UASUnitTest::getStatusForCode_test() -{ - QString state, desc; - state = ""; - desc = ""; - - uas->getStatusForCode(MAV_STATE_UNINIT, state, desc); - QVERIFY(state == "UNINIT"); - - uas->getStatusForCode(MAV_STATE_UNINIT, state, desc); - QVERIFY(state == "UNINIT"); - - uas->getStatusForCode(MAV_STATE_BOOT, state, desc); - QVERIFY(state == "BOOT"); - - uas->getStatusForCode(MAV_STATE_CALIBRATING, state, desc); - QVERIFY(state == "CALIBRATING"); - - uas->getStatusForCode(MAV_STATE_ACTIVE, state, desc); - QVERIFY(state == "ACTIVE"); - - uas->getStatusForCode(MAV_STATE_STANDBY, state, desc); - QVERIFY(state == "STANDBY"); - - uas->getStatusForCode(MAV_STATE_CRITICAL, state, desc); - QVERIFY(state == "CRITICAL"); - - uas->getStatusForCode(MAV_STATE_EMERGENCY, state, desc); - QVERIFY(state == "EMERGENCY"); - - uas->getStatusForCode(MAV_STATE_POWEROFF, state, desc); - QVERIFY(state == "SHUTDOWN"); - - uas->getStatusForCode(5325, state, desc); - QVERIFY(state == "UNKNOWN"); - -} - -void UASUnitTest::getLocalX_test() -{ - QCOMPARE(uas->getLocalX(), 0.0); -} -void UASUnitTest::getLocalY_test() -{ - QCOMPARE(uas->getLocalY(), 0.0); -} -void UASUnitTest::getLocalZ_test() -{ - QCOMPARE(uas->getLocalZ(), 0.0); -} -void UASUnitTest::getLatitude_test() -{ QCOMPARE(uas->getLatitude(), 0.0); -} -void UASUnitTest::getLongitude_test() -{ - QCOMPARE(uas->getLongitude(), 0.0); -} -void UASUnitTest::getAltitude_test() -{ - QCOMPARE(uas->getAltitude(), 0.0); -} -void UASUnitTest::getRoll_test() -{ - QCOMPARE(uas->getRoll(), 0.0); -} -void UASUnitTest::getPitch_test() -{ - QCOMPARE(uas->getPitch(), 0.0); -} -void UASUnitTest::getYaw_test() -{ - QCOMPARE(uas->getYaw(), 0.0); -} - -void UASUnitTest::getSelected_test() -{ - QCOMPARE(uas->getSelected(), false); -} - -void UASUnitTest::getSystemType_test() -{ //check that system type is set to MAV_TYPE_GENERIC when initialized - QCOMPARE(uas->getSystemType(), 0); - uas->setSystemType(13); - QCOMPARE(uas->getSystemType(), 13); -} - -void UASUnitTest::getAirframe_test() -{ - //when uas is constructed, airframe is set to QGC_AIRFRAME_GENERIC which is 0 - QCOMPARE(uas->getAirframe(), 0); -} - -void UASUnitTest::setAirframe_test() -{ - //check at construction, that airframe=0 (GENERIC) - QVERIFY(uas->getAirframe() == 0); - - //check that set airframe works - uas->setAirframe(11); - QVERIFY(uas->getAirframe() == 11); - - //check that setAirframe will not assign a number to airframe, that is - //not defined in the enum - uas->setAirframe(12); - QVERIFY(uas->getAirframe() == 11); -} -void UASUnitTest::getWaypointList_test() -{ - QVector kk = uas->getWaypointManager()->getWaypointEditableList(); - QCOMPARE(kk.count(), 0); - - Waypoint* wp = new Waypoint(0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,false, false, MAV_FRAME_GLOBAL, MAV_CMD_MISSION_START, "blah"); - uas->getWaypointManager()->addWaypointEditable(wp, true); - - kk = uas->getWaypointManager()->getWaypointEditableList(); - QCOMPARE(kk.count(), 1); - - wp = new Waypoint(); - uas->getWaypointManager()->addWaypointEditable(wp, false); - - kk = uas->getWaypointManager()->getWaypointEditableList(); - QCOMPARE(kk.count(), 2); - - uas->getWaypointManager()->removeWaypoint(1); - kk = uas->getWaypointManager()->getWaypointEditableList(); - QCOMPARE(kk.count(), 1); - - uas->getWaypointManager()->removeWaypoint(0); - kk = uas->getWaypointManager()->getWaypointEditableList(); - QCOMPARE(kk.count(), 0); - - qDebug()<<"disconnect SIGNAL waypointListChanged"; - -} - -void UASUnitTest::getWaypoint_test() -{ - Waypoint* wp = new Waypoint(0,5.6,2.0,3.0,0.0,0.0,0.0,0.0,false, false, MAV_FRAME_GLOBAL, MAV_CMD_MISSION_START, "blah"); - - uas->getWaypointManager()->addWaypointEditable(wp, true); - - QVector wpList = uas->getWaypointManager()->getWaypointEditableList(); - - QCOMPARE(wpList.count(), 1); - QCOMPARE(static_cast(0), static_cast(wpList.at(0))->getId()); - - Waypoint* wp3 = new Waypoint(1, 5.6, 2.0, 3.0); - uas->getWaypointManager()->addWaypointEditable(wp3, true); - wpList = uas->getWaypointManager()->getWaypointEditableList(); - Waypoint* wp2 = static_cast(wpList.at(0)); - - QCOMPARE(wpList.count(), 2); - QCOMPARE(wp3->getX(), wp2->getX()); - QCOMPARE(wp3->getY(), wp2->getY()); - QCOMPARE(wp3->getZ(), wp2->getZ()); - QCOMPARE(wpList.at(1)->getId(), static_cast(1)); - QCOMPARE(wp3->getFrame(), MAV_FRAME_GLOBAL); - QCOMPARE(wp3->getFrame(), wp2->getFrame()); - - delete wp3; - delete wp; -} - -void UASUnitTest::signalWayPoint_test() -{ - QSignalSpy spy(uas->getWaypointManager(), SIGNAL(waypointEditableListChanged())); - - Waypoint* wp = new Waypoint(0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,false, false, MAV_FRAME_GLOBAL, MAV_CMD_MISSION_START, "blah"); - uas->getWaypointManager()->addWaypointEditable(wp, true); - - - QCOMPARE(spy.count(), 1); // 1 listChanged for add wayPoint - uas->getWaypointManager()->removeWaypoint(0); - QCOMPARE(spy.count(), 2); // 2 listChanged for remove wayPoint - - QSignalSpy spyDestroyed(uas->getWaypointManager(), SIGNAL(destroyed())); - QVERIFY(spyDestroyed.isValid()); - QCOMPARE( spyDestroyed.count(), 0 ); - - delete uas;// delete(destroyed) uas for validating - uas = NULL; - QCOMPARE(spyDestroyed.count(), 1);// count destroyed uas should are 1 - uas = new UAS(mav,UASID); - QSignalSpy spy2(uas->getWaypointManager(), SIGNAL(waypointEditableListChanged())); - QCOMPARE(spy2.count(), 0); - Waypoint* wp2 = new Waypoint(0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,false, false, MAV_FRAME_GLOBAL, MAV_CMD_MISSION_START, "blah"); - - uas->getWaypointManager()->addWaypointEditable(wp2, true); - QCOMPARE(spy2.count(), 1); - - uas->getWaypointManager()->clearWaypointList(); - QVector wpList = uas->getWaypointManager()->getWaypointEditableList(); - QCOMPARE(wpList.count(), 1); - - delete wp2; -} - -void UASUnitTest::signalUASLink_test() -{ - QSignalSpy spy(uas, SIGNAL(modeChanged(int,QString,QString))); - uas->setMode(2); - QCOMPARE(spy.count(), 0);// not solve for UAS not receiving message from UAS - - QSignalSpy spyS(LinkManager::instance(), SIGNAL(newLink(LinkInterface*))); - SerialLink* link = new SerialLink(); - LinkManager::instance()->add(link); - LinkManager::instance()->addProtocol(link, mav); - QCOMPARE(spyS.count(), 1); - - LinkManager::instance()->add(link); - LinkManager::instance()->addProtocol(link, mav); - QCOMPARE(spyS.count(), 1);// not add SerialLink, exist in list - - SerialLink* link2 = new SerialLink(); - LinkManager::instance()->add(link2); - LinkManager::instance()->addProtocol(link2, mav); - QCOMPARE(spyS.count(), 2);// add SerialLink, not exist in list - - QList links = LinkManager::instance()->getLinks(); - foreach(LinkInterface* link, links) - { - qDebug()<< link->getName(); - qDebug()<< QString::number(link->getId()); - qDebug()<< QString::number(link->getNominalDataRate()); - QVERIFY(link != NULL); - uas->addLink(link); - } - - SerialLink* ff = static_cast(uas->getLinks()->at(0)); - - QCOMPARE(ff->isConnected(), false); - - QCOMPARE(ff->isRunning(), false); - - QCOMPARE(ff->isFinished(), false); - - QCOMPARE(links.count(), uas->getLinks()->count()); - QCOMPARE(uas->getLinks()->count(), 2); - - LinkInterface* ff99 = static_cast(links.at(1)); - LinkManager::instance()->removeLink(ff99); - - QCOMPARE(LinkManager::instance()->getLinks().count(), 1); - QCOMPARE(uas->getLinks()->count(), 2); - - - QCOMPARE(static_cast(LinkManager::instance()->getLinks().at(0))->getId(), - static_cast(uas->getLinks()->at(0))->getId()); - - link = new SerialLink(); - LinkManager::instance()->add(link); - LinkManager::instance()->addProtocol(link, mav); - QCOMPARE(spyS.count(), 3); - -} - -void UASUnitTest::signalIdUASLink_test() -{ - SerialLink* myLink = new SerialLink(); - myLink->setPortName("COM 17"); - LinkManager::instance()->add(myLink); - LinkManager::instance()->addProtocol(myLink, mav); - - myLink = new SerialLink(); - myLink->setPortName("COM 18"); - LinkManager::instance()->add(myLink); - LinkManager::instance()->addProtocol(myLink, mav); - - QCOMPARE(LinkManager::instance()->getLinks().count(), 4); - - QList links = LinkManager::instance()->getLinks(); - - LinkInterface* a = static_cast(links.at(2)); - LinkInterface* b = static_cast(links.at(3)); - - QCOMPARE(a->getName(), QString("serial port COM 17")); - QCOMPARE(b->getName(), QString("serial port COM 18")); - -} diff --git a/qgcunittest/UASUnitTest.h b/qgcunittest/UASUnitTest.h deleted file mode 100644 index 192257e..0000000 --- a/qgcunittest/UASUnitTest.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef UASUNITTEST_H -#define UASUNITTEST_H - -#include -#include -#include -#include - -#include "UAS.h" -#include "MAVLinkProtocol.h" -#include "SerialLink.h" -#include "UASInterface.h" -#include "AutoTest.h" -#include "LinkManager.h" -#include "UASWaypointManager.h" -#include "SerialLink.h" -#include "LinkInterface.h" - -class UASUnitTest : public QObject -{ - Q_OBJECT -public: - #define UASID 100 - MAVLinkProtocol* mav; - UAS* uas; - UASUnitTest(); - -private slots: - void init(); - void cleanup(); - - void getUASID_test(); - void getUASName_test(); - void getUpTime_test(); - void getCommunicationStatus_test(); - void filterVoltage_test(); - void getAutopilotType_test(); - void setAutopilotType_test(); - void getStatusForCode_test(); - void getLocalX_test(); - void getLocalY_test(); - void getLocalZ_test(); - void getLatitude_test(); - void getLongitude_test(); - void getAltitude_test(); - void getRoll_test(); - void getPitch_test(); - void getYaw_test(); - void getSelected_test(); - void getSystemType_test(); - void getAirframe_test(); - void setAirframe_test(); - void getWaypointList_test(); - void signalWayPoint_test(); - void getWaypoint_test(); - void signalUASLink_test(); - void signalIdUASLink_test(); -}; - -DECLARE_TEST(UASUnitTest) -#endif // UASUNITTEST_H diff --git a/qgcunittest/testSuite.cc b/qgcunittest/testSuite.cc deleted file mode 100755 index 0489b22..0000000 --- a/qgcunittest/testSuite.cc +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @author Rob Caldecott -* @note This was obtained from http://qtcreator.blogspot.com/2010/04/sample-multiple-unit-test-project.html -* -*/ - -#include "AutoTest.h" -#include - -#if 1 -// This is all you need to run all the tests -TEST_MAIN -#else -// Or supply your own main function -int main(int argc, char *argv[]) -{ - int failures = AutoTest::run(argc, argv); - if (failures == 0) - { - qDebug() << "ALL TESTS PASSED"; - } - else - { - qDebug() << failures << " TESTS FAILED!"; - } - return failures; -} -#endif diff --git a/src/qgcunittest/AutoTest.h b/src/qgcunittest/AutoTest.h new file mode 100755 index 0000000..892d814 --- /dev/null +++ b/src/qgcunittest/AutoTest.h @@ -0,0 +1,85 @@ +/** +* @author Rob Caldecott +* @note This was obtained from http://qtcreator.blogspot.com/2010/04/sample-multiple-unit-test-project.html +* +*/ + +#ifndef AUTOTEST_H +#define AUTOTEST_H + +#include +#include +#include +#include + +namespace AutoTest +{ + typedef QList TestList; + + inline TestList& testList() + { + static TestList list; + return list; + } + + inline bool findObject(QObject* object) + { + TestList& list = testList(); + if (list.contains(object)) + { + return true; + } + foreach (QObject* test, list) + { + if (test->objectName() == object->objectName()) + { + return true; + } + } + return false; + } + + inline void addTest(QObject* object) + { + TestList& list = testList(); + if (!findObject(object)) + { + list.append(object); + } + } + + inline int run(int argc, char *argv[]) + { + int ret = 0; + QCoreApplication t(argc, argv); + foreach (QObject* test, testList()) + { + ret += QTest::qExec(test, argc, argv); + } + + return ret; + } +} + +template +class Test +{ +public: + QSharedPointer child; + + Test(const QString& name) : child(new T) + { + child->setObjectName(name); + AutoTest::addTest(child.data()); + } +}; + +#define DECLARE_TEST(className) static Test t(#className); + +#define TEST_MAIN \ + int main(int argc, char *argv[]) \ + { \ + return AutoTest::run(argc, argv); \ + } + +#endif // AUTOTEST_H diff --git a/src/qgcunittest/UASUnitTest.cc b/src/qgcunittest/UASUnitTest.cc new file mode 100644 index 0000000..5280e80 --- /dev/null +++ b/src/qgcunittest/UASUnitTest.cc @@ -0,0 +1,371 @@ +#include "UASUnitTest.h" +#include +#include +UASUnitTest::UASUnitTest() +{ +} +//This function is called after every test +void UASUnitTest::init() +{ + mav = new MAVLinkProtocol(); + uas = new UAS(mav, UASID); + uas->deleteSettings(); +} +//this function is called after every test +void UASUnitTest::cleanup() +{ + delete mav; + mav = NULL; + if(uas != NULL){ + delete uas; + uas = NULL; + } +} + +void UASUnitTest::getUASID_test() +{ + // Test a default ID of zero is assigned + UAS* uas2 = new UAS(mav); + QCOMPARE(uas2->getUASID(), 0); + delete uas2; + + // Test that the chosen ID was assigned at construction + QCOMPARE(uas->getUASID(), UASID); + + // Make sure that no other ID was set + QEXPECT_FAIL("", "When you set an ID it does not use the default ID of 0", Continue); + QCOMPARE(uas->getUASID(), 0); + + // Make sure that ID >= 0 + QCOMPARE(uas->getUASID(), 100); + +} + +void UASUnitTest::getUASName_test() +{ + // Test that the name is build as MAV + ID + QCOMPARE(uas->getUASName(), "MAV " + QString::number(UASID)); + +} + +void UASUnitTest::getUpTime_test() +{ + 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); + + // Sleep for three seconds + QTest::qSleep(3000); + + // Test that the up time is computed correctly to a + // precision of seconds + QCOMPARE(floor(uas2->getUptime()/1000.0), 3.0); + + delete uas2; +} + +void UASUnitTest::getCommunicationStatus_test() +{ + // Verify that upon construction the Comm status is disconnected + QCOMPARE(uas->getCommunicationStatus(), static_cast(UASInterface::COMM_DISCONNECTED)); +} + +void UASUnitTest::filterVoltage_test() +{ + float verificar=uas->filterVoltage(0.4f); + // Verify that upon construction the Comm status is disconnected + QCOMPARE(verificar, 8.52f); +} +void UASUnitTest:: getAutopilotType_test() +{ + int type = uas->getAutopilotType(); + // Verify that upon construction the autopilot is set to -1 + QCOMPARE(type, -1); +} +void UASUnitTest::setAutopilotType_test() +{ + uas->setAutopilotType(2); + // Verify that the autopilot is set + QCOMPARE(uas->getAutopilotType(), 2); +} + +void UASUnitTest::getStatusForCode_test() +{ + QString state, desc; + state = ""; + desc = ""; + + uas->getStatusForCode(MAV_STATE_UNINIT, state, desc); + QVERIFY(state == "UNINIT"); + + uas->getStatusForCode(MAV_STATE_UNINIT, state, desc); + QVERIFY(state == "UNINIT"); + + uas->getStatusForCode(MAV_STATE_BOOT, state, desc); + QVERIFY(state == "BOOT"); + + uas->getStatusForCode(MAV_STATE_CALIBRATING, state, desc); + QVERIFY(state == "CALIBRATING"); + + uas->getStatusForCode(MAV_STATE_ACTIVE, state, desc); + QVERIFY(state == "ACTIVE"); + + uas->getStatusForCode(MAV_STATE_STANDBY, state, desc); + QVERIFY(state == "STANDBY"); + + uas->getStatusForCode(MAV_STATE_CRITICAL, state, desc); + QVERIFY(state == "CRITICAL"); + + uas->getStatusForCode(MAV_STATE_EMERGENCY, state, desc); + QVERIFY(state == "EMERGENCY"); + + uas->getStatusForCode(MAV_STATE_POWEROFF, state, desc); + QVERIFY(state == "SHUTDOWN"); + + uas->getStatusForCode(5325, state, desc); + QVERIFY(state == "UNKNOWN"); + +} + +void UASUnitTest::getLocalX_test() +{ + QCOMPARE(uas->getLocalX(), 0.0); +} +void UASUnitTest::getLocalY_test() +{ + QCOMPARE(uas->getLocalY(), 0.0); +} +void UASUnitTest::getLocalZ_test() +{ + QCOMPARE(uas->getLocalZ(), 0.0); +} +void UASUnitTest::getLatitude_test() +{ QCOMPARE(uas->getLatitude(), 0.0); +} +void UASUnitTest::getLongitude_test() +{ + QCOMPARE(uas->getLongitude(), 0.0); +} +void UASUnitTest::getAltitude_test() +{ + QCOMPARE(uas->getAltitude(), 0.0); +} +void UASUnitTest::getRoll_test() +{ + QCOMPARE(uas->getRoll(), 0.0); +} +void UASUnitTest::getPitch_test() +{ + QCOMPARE(uas->getPitch(), 0.0); +} +void UASUnitTest::getYaw_test() +{ + QCOMPARE(uas->getYaw(), 0.0); +} + +void UASUnitTest::getSelected_test() +{ + QCOMPARE(uas->getSelected(), false); +} + +void UASUnitTest::getSystemType_test() +{ //check that system type is set to MAV_TYPE_GENERIC when initialized + QCOMPARE(uas->getSystemType(), 0); + uas->setSystemType(13); + QCOMPARE(uas->getSystemType(), 13); +} + +void UASUnitTest::getAirframe_test() +{ + //when uas is constructed, airframe is set to QGC_AIRFRAME_GENERIC which is 0 + QCOMPARE(uas->getAirframe(), 0); +} + +void UASUnitTest::setAirframe_test() +{ + //check at construction, that airframe=0 (GENERIC) + QVERIFY(uas->getAirframe() == 0); + + //check that set airframe works + uas->setAirframe(11); + QVERIFY(uas->getAirframe() == 11); + + //check that setAirframe will not assign a number to airframe, that is + //not defined in the enum + uas->setAirframe(12); + QVERIFY(uas->getAirframe() == 11); +} +void UASUnitTest::getWaypointList_test() +{ + QVector kk = uas->getWaypointManager()->getWaypointEditableList(); + QCOMPARE(kk.count(), 0); + + Waypoint* wp = new Waypoint(0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,false, false, MAV_FRAME_GLOBAL, MAV_CMD_MISSION_START, "blah"); + uas->getWaypointManager()->addWaypointEditable(wp, true); + + kk = uas->getWaypointManager()->getWaypointEditableList(); + QCOMPARE(kk.count(), 1); + + wp = new Waypoint(); + uas->getWaypointManager()->addWaypointEditable(wp, false); + + kk = uas->getWaypointManager()->getWaypointEditableList(); + QCOMPARE(kk.count(), 2); + + uas->getWaypointManager()->removeWaypoint(1); + kk = uas->getWaypointManager()->getWaypointEditableList(); + QCOMPARE(kk.count(), 1); + + uas->getWaypointManager()->removeWaypoint(0); + kk = uas->getWaypointManager()->getWaypointEditableList(); + QCOMPARE(kk.count(), 0); + + qDebug()<<"disconnect SIGNAL waypointListChanged"; + +} + +void UASUnitTest::getWaypoint_test() +{ + Waypoint* wp = new Waypoint(0,5.6,2.0,3.0,0.0,0.0,0.0,0.0,false, false, MAV_FRAME_GLOBAL, MAV_CMD_MISSION_START, "blah"); + + uas->getWaypointManager()->addWaypointEditable(wp, true); + + QVector wpList = uas->getWaypointManager()->getWaypointEditableList(); + + QCOMPARE(wpList.count(), 1); + QCOMPARE(static_cast(0), static_cast(wpList.at(0))->getId()); + + Waypoint* wp3 = new Waypoint(1, 5.6, 2.0, 3.0); + uas->getWaypointManager()->addWaypointEditable(wp3, true); + wpList = uas->getWaypointManager()->getWaypointEditableList(); + Waypoint* wp2 = static_cast(wpList.at(0)); + + QCOMPARE(wpList.count(), 2); + QCOMPARE(wp3->getX(), wp2->getX()); + QCOMPARE(wp3->getY(), wp2->getY()); + QCOMPARE(wp3->getZ(), wp2->getZ()); + QCOMPARE(wpList.at(1)->getId(), static_cast(1)); + QCOMPARE(wp3->getFrame(), MAV_FRAME_GLOBAL); + QCOMPARE(wp3->getFrame(), wp2->getFrame()); + + delete wp3; + delete wp; +} + +void UASUnitTest::signalWayPoint_test() +{ + QSignalSpy spy(uas->getWaypointManager(), SIGNAL(waypointEditableListChanged())); + + Waypoint* wp = new Waypoint(0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,false, false, MAV_FRAME_GLOBAL, MAV_CMD_MISSION_START, "blah"); + uas->getWaypointManager()->addWaypointEditable(wp, true); + + + QCOMPARE(spy.count(), 1); // 1 listChanged for add wayPoint + uas->getWaypointManager()->removeWaypoint(0); + QCOMPARE(spy.count(), 2); // 2 listChanged for remove wayPoint + + QSignalSpy spyDestroyed(uas->getWaypointManager(), SIGNAL(destroyed())); + QVERIFY(spyDestroyed.isValid()); + QCOMPARE( spyDestroyed.count(), 0 ); + + delete uas;// delete(destroyed) uas for validating + uas = NULL; + QCOMPARE(spyDestroyed.count(), 1);// count destroyed uas should are 1 + uas = new UAS(mav,UASID); + QSignalSpy spy2(uas->getWaypointManager(), SIGNAL(waypointEditableListChanged())); + QCOMPARE(spy2.count(), 0); + Waypoint* wp2 = new Waypoint(0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,false, false, MAV_FRAME_GLOBAL, MAV_CMD_MISSION_START, "blah"); + + uas->getWaypointManager()->addWaypointEditable(wp2, true); + QCOMPARE(spy2.count(), 1); + + uas->getWaypointManager()->clearWaypointList(); + QVector wpList = uas->getWaypointManager()->getWaypointEditableList(); + QCOMPARE(wpList.count(), 1); + + delete wp2; +} + +void UASUnitTest::signalUASLink_test() +{ + QSignalSpy spy(uas, SIGNAL(modeChanged(int,QString,QString))); + uas->setMode(2); + QCOMPARE(spy.count(), 0);// not solve for UAS not receiving message from UAS + + QSignalSpy spyS(LinkManager::instance(), SIGNAL(newLink(LinkInterface*))); + SerialLink* link = new SerialLink(); + LinkManager::instance()->add(link); + LinkManager::instance()->addProtocol(link, mav); + QCOMPARE(spyS.count(), 1); + + LinkManager::instance()->add(link); + LinkManager::instance()->addProtocol(link, mav); + QCOMPARE(spyS.count(), 1);// not add SerialLink, exist in list + + SerialLink* link2 = new SerialLink(); + LinkManager::instance()->add(link2); + LinkManager::instance()->addProtocol(link2, mav); + QCOMPARE(spyS.count(), 2);// add SerialLink, not exist in list + + QList links = LinkManager::instance()->getLinks(); + foreach(LinkInterface* link, links) + { + qDebug()<< link->getName(); + qDebug()<< QString::number(link->getId()); + qDebug()<< QString::number(link->getNominalDataRate()); + QVERIFY(link != NULL); + uas->addLink(link); + } + + SerialLink* ff = static_cast(uas->getLinks()->at(0)); + + QCOMPARE(ff->isConnected(), false); + + QCOMPARE(ff->isRunning(), false); + + QCOMPARE(ff->isFinished(), false); + + QCOMPARE(links.count(), uas->getLinks()->count()); + QCOMPARE(uas->getLinks()->count(), 2); + + LinkInterface* ff99 = static_cast(links.at(1)); + LinkManager::instance()->removeLink(ff99); + + QCOMPARE(LinkManager::instance()->getLinks().count(), 1); + QCOMPARE(uas->getLinks()->count(), 2); + + + QCOMPARE(static_cast(LinkManager::instance()->getLinks().at(0))->getId(), + static_cast(uas->getLinks()->at(0))->getId()); + + link = new SerialLink(); + LinkManager::instance()->add(link); + LinkManager::instance()->addProtocol(link, mav); + QCOMPARE(spyS.count(), 3); + +} + +void UASUnitTest::signalIdUASLink_test() +{ + SerialLink* myLink = new SerialLink(); + myLink->setPortName("COM 17"); + LinkManager::instance()->add(myLink); + LinkManager::instance()->addProtocol(myLink, mav); + + myLink = new SerialLink(); + myLink->setPortName("COM 18"); + LinkManager::instance()->add(myLink); + LinkManager::instance()->addProtocol(myLink, mav); + + QCOMPARE(LinkManager::instance()->getLinks().count(), 4); + + QList links = LinkManager::instance()->getLinks(); + + LinkInterface* a = static_cast(links.at(2)); + LinkInterface* b = static_cast(links.at(3)); + + QCOMPARE(a->getName(), QString("serial port COM 17")); + QCOMPARE(b->getName(), QString("serial port COM 18")); + +} diff --git a/src/qgcunittest/UASUnitTest.h b/src/qgcunittest/UASUnitTest.h new file mode 100644 index 0000000..192257e --- /dev/null +++ b/src/qgcunittest/UASUnitTest.h @@ -0,0 +1,61 @@ +#ifndef UASUNITTEST_H +#define UASUNITTEST_H + +#include +#include +#include +#include + +#include "UAS.h" +#include "MAVLinkProtocol.h" +#include "SerialLink.h" +#include "UASInterface.h" +#include "AutoTest.h" +#include "LinkManager.h" +#include "UASWaypointManager.h" +#include "SerialLink.h" +#include "LinkInterface.h" + +class UASUnitTest : public QObject +{ + Q_OBJECT +public: + #define UASID 100 + MAVLinkProtocol* mav; + UAS* uas; + UASUnitTest(); + +private slots: + void init(); + void cleanup(); + + void getUASID_test(); + void getUASName_test(); + void getUpTime_test(); + void getCommunicationStatus_test(); + void filterVoltage_test(); + void getAutopilotType_test(); + void setAutopilotType_test(); + void getStatusForCode_test(); + void getLocalX_test(); + void getLocalY_test(); + void getLocalZ_test(); + void getLatitude_test(); + void getLongitude_test(); + void getAltitude_test(); + void getRoll_test(); + void getPitch_test(); + void getYaw_test(); + void getSelected_test(); + void getSystemType_test(); + void getAirframe_test(); + void setAirframe_test(); + void getWaypointList_test(); + void signalWayPoint_test(); + void getWaypoint_test(); + void signalUASLink_test(); + void signalIdUASLink_test(); +}; + +DECLARE_TEST(UASUnitTest) +#endif // UASUNITTEST_H diff --git a/src/qgcunittest/testSuite.cc b/src/qgcunittest/testSuite.cc new file mode 100755 index 0000000..0489b22 --- /dev/null +++ b/src/qgcunittest/testSuite.cc @@ -0,0 +1,28 @@ +/** +* @author Rob Caldecott +* @note This was obtained from http://qtcreator.blogspot.com/2010/04/sample-multiple-unit-test-project.html +* +*/ + +#include "AutoTest.h" +#include + +#if 1 +// This is all you need to run all the tests +TEST_MAIN +#else +// Or supply your own main function +int main(int argc, char *argv[]) +{ + int failures = AutoTest::run(argc, argv); + if (failures == 0) + { + qDebug() << "ALL TESTS PASSED"; + } + else + { + qDebug() << failures << " TESTS FAILED!"; + } + return failures; +} +#endif