diff --git a/qgcunittest.pro b/qgcunittest.pro index 5aea295778c8b3c05880e4b1d303781afe8d9ceb..f51452df91f7aadf2a7eec15f66e4a2e1385208d 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/src/comm/QGCFlightGearLink.cc b/src/comm/QGCFlightGearLink.cc index 5301dc9c596275992f2230ca100a119952eaea5d..13fcfd32442b34e79f08b4b06ac3d06face964ec 100644 --- a/src/comm/QGCFlightGearLink.cc +++ b/src/comm/QGCFlightGearLink.cc @@ -53,8 +53,11 @@ QGCFlightGearLink::QGCFlightGearLink(UASInterface* mav, QString remoteHost, QHos } QGCFlightGearLink::~QGCFlightGearLink() -{ - disconnectSimulation(); +{ //do not disconnect unless it is connected. + //disconnectSimulation will delete the memory that was allocated for proces, terraSync and socket + if(connectState){ + disconnectSimulation(); + } } /** @@ -136,6 +139,7 @@ void QGCFlightGearLink::setRemoteHost(const QString& host) currentHost = info.addresses().first(); } } + } void QGCFlightGearLink::updateControls(uint64_t time, float rollAilerons, float pitchElevator, float yawRudder, float throttle, uint8_t systemMode, uint8_t navMode) diff --git a/src/comm/QGCMAVLink.h b/src/comm/QGCMAVLink.h index b9808ddaf5dadbb6a0592a02c7cf1e0575bbbae5..bd58a506fafefa8a5b7fa359a5b9fdbcdaa47d0a 100644 --- a/src/comm/QGCMAVLink.h +++ b/src/comm/QGCMAVLink.h @@ -30,7 +30,7 @@ This file is part of the QGROUNDCONTROL project #ifndef QGCMAVLINK_H #define QGCMAVLINK_H -#include +#include <../../mavlink/include/mavlink/v1.0/common/mavlink.h> //#ifdef MAVLINK_CONF //#define MY_MACRO(x) diff --git a/qgcunittest/AutoTest.h b/src/qgcunittest/AutoTest.h similarity index 100% rename from qgcunittest/AutoTest.h rename to src/qgcunittest/AutoTest.h diff --git a/qgcunittest/UASUnitTest.cc b/src/qgcunittest/UASUnitTest.cc similarity index 78% rename from qgcunittest/UASUnitTest.cc rename to src/qgcunittest/UASUnitTest.cc index cf2c49a1d7e808f2d0bec08471c2c11d4e988d62..c3d893e1b5cd3218658caa1a56fe2b2b76ff773f 100644 --- a/qgcunittest/UASUnitTest.cc +++ b/src/qgcunittest/UASUnitTest.cc @@ -1,5 +1,6 @@ #include "UASUnitTest.h" #include +#include UASUnitTest::UASUnitTest() { } @@ -13,10 +14,11 @@ void UASUnitTest::init() //this function is called after every test void UASUnitTest::cleanup() { - delete mav; - mav = NULL; - delete uas; - uas = NULL; + delete uas; + uas = NULL; + + delete mav; + mav = NULL; } void UASUnitTest::getUASID_test() @@ -122,7 +124,6 @@ void UASUnitTest::getStatusForCode_test() uas->getStatusForCode(5325, state, desc); QVERIFY(state == "UNKNOWN"); - } void UASUnitTest::getLocalX_test() @@ -138,7 +139,8 @@ void UASUnitTest::getLocalZ_test() QCOMPARE(uas->getLocalZ(), 0.0); } void UASUnitTest::getLatitude_test() -{ QCOMPARE(uas->getLatitude(), 0.0); +{ + QCOMPARE(uas->getLatitude(), 0.0); } void UASUnitTest::getLongitude_test() { @@ -167,8 +169,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); } @@ -192,6 +195,7 @@ void UASUnitTest::setAirframe_test() uas->setAirframe(12); QVERIFY(uas->getAirframe() == 11); } + void UASUnitTest::getWaypointList_test() { QVector kk = uas->getWaypointManager()->getWaypointEditableList(); @@ -251,43 +255,48 @@ void UASUnitTest::getWaypoint_test() void UASUnitTest::signalWayPoint_test() { - QSignalSpy spy(uas->getWaypointManager(), SIGNAL(waypointListChanged(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,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())); 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 uas; + uas = NULL; + 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); @@ -324,41 +333,74 @@ void UASUnitTest::signalUASLink_test() LinkInterface* ff99 = static_cast(links.at(1)); LinkManager::instance()->removeLink(ff99); + delete link2; 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); + SerialLink* link3 = new SerialLink(); + LinkManager::instance()->add(link3); + LinkManager::instance()->addProtocol(link3, mav); QCOMPARE(spyS.count(), 3); + QCOMPARE(LinkManager::instance()->getLinks().count(), 2); + LinkManager::instance()->removeLink(link3); + delete link3; + QCOMPARE(LinkManager::instance()->getLinks().count(), 1); + LinkManager::instance()->removeLink(link); + delete link; + + QCOMPARE(LinkManager::instance()->getLinks().count(), 0); } void UASUnitTest::signalIdUASLink_test() { + + QCOMPARE(LinkManager::instance()->getLinks().count(), 0); 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); + SerialLink* myLink2 = new SerialLink(); + myLink2->setPortName("COM 18"); + LinkManager::instance()->add(myLink2); + LinkManager::instance()->addProtocol(myLink2, mav); + + SerialLink* myLink3 = new SerialLink(); + myLink3->setPortName("COM 19"); + LinkManager::instance()->add(myLink3); + LinkManager::instance()->addProtocol(myLink3, mav); + + SerialLink* myLink4 = new SerialLink(); + myLink4->setPortName("COM 20"); + LinkManager::instance()->add(myLink4); + LinkManager::instance()->addProtocol(myLink4, 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)); - + LinkInterface* a = static_cast(links.at(0)); + LinkInterface* b = static_cast(links.at(1)); + LinkInterface* c = static_cast(links.at(2)); + LinkInterface* d = static_cast(links.at(3)); QCOMPARE(a->getName(), QString("serial port COM 17")); QCOMPARE(b->getName(), QString("serial port COM 18")); - + QCOMPARE(c->getName(), QString("serial port COM 19")); + QCOMPARE(d->getName(), QString("serial port COM 20")); + + LinkManager::instance()->removeLink(myLink4); + delete myLink4; + LinkManager::instance()->removeLink(myLink3); + delete myLink3; + LinkManager::instance()->removeLink(myLink2); + delete myLink2; + LinkManager::instance()->removeLink(myLink); + delete myLink; + + QCOMPARE(LinkManager::instance()->getLinks().count(), 0); } diff --git a/qgcunittest/UASUnitTest.h b/src/qgcunittest/UASUnitTest.h similarity index 100% rename from qgcunittest/UASUnitTest.h rename to src/qgcunittest/UASUnitTest.h diff --git a/qgcunittest/testSuite.cc b/src/qgcunittest/testSuite.cc similarity index 100% rename from qgcunittest/testSuite.cc rename to src/qgcunittest/testSuite.cc diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index f555ef806fde01fb08bd5da7fa7ef53d1946341e..4ec02a1e6ffe5e6f071ad6e3c04eee7f9fcbd66a 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -106,22 +106,24 @@ UAS::UAS(MAVLinkProtocol* protocol, int id) : UASInterface(), } color = UASInterface::getNextColor(); - setBatterySpecs(QString("9V,9.5V,12.6V")); 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); + emit armingChanged(false); } UAS::~UAS() { writeSettings(); delete links; - links=NULL; + delete statusTimeout; + delete simulation; + delete paramManager; } void UAS::writeSettings() { @@ -2081,21 +2083,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 bab9d55478b6cf7b6cfe097a3d0187da730a05e0..3f2e591c6bf8d607335cc8edb351112d789dea88 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 */ diff --git a/test b/test new file mode 100644 index 0000000000000000000000000000000000000000..345e6aef713208c8d50cdea23b85e6ad831f0449 --- /dev/null +++ b/test @@ -0,0 +1 @@ +Test