From 73e270fe144997bde95b29166b617dc2418f6d35 Mon Sep 17 00:00:00 2001 From: Mariano Lizarraga Date: Wed, 12 Jan 2011 10:30:45 -0600 Subject: [PATCH] Some initial unit tests in place for UAS class --- qgcunittest/tst_uasunittest.cc | 63 +++++++++++++++++++++++++++++++--- qgroundcontrol.pri | 8 ++--- 2 files changed, 62 insertions(+), 9 deletions(-) diff --git a/qgcunittest/tst_uasunittest.cc b/qgcunittest/tst_uasunittest.cc index 82f4fe2c6b..5c4593cc54 100644 --- a/qgcunittest/tst_uasunittest.cc +++ b/qgcunittest/tst_uasunittest.cc @@ -2,18 +2,28 @@ #include #include "UAS.h" #include "MAVLinkProtocol.h" +#include "UASInterface.h" class UASUnitTest : public QObject { Q_OBJECT public: + #define UASID 50 + MAVLinkProtocol* mav; + UAS* uas; UASUnitTest(); private Q_SLOTS: void initTestCase(); void cleanupTestCase(); - void testCase1(); + void getUASID_test(); + void getUASName_test(); + void getUpTime_test(); + void getCommunicationStatus_test(); + +private: + }; UASUnitTest::UASUnitTest() @@ -22,17 +32,60 @@ UASUnitTest::UASUnitTest() void UASUnitTest::initTestCase() { - MAVLinkProtocol *mav= new MAVLinkProtocol(); - UAS *prueba=new UAS(mav,0); + mav= new MAVLinkProtocol(); + uas=new UAS(mav,UASID); } void UASUnitTest::cleanupTestCase() { + delete uas; + delete mav; + +} + +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 sert + QEXPECT_FAIL("", "When you set an ID it does not use the default ID of 0", Continue); + QCOMPARE(uas->getUASID(), 0); +} + +void UASUnitTest::getUASName_test() +{ + // Test that the name is build as MAV + ID + QCOMPARE(uas->getUASName(), "MAV 0" + 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::testCase1() +void UASUnitTest::getCommunicationStatus_test() { - QVERIFY2(true, "Failure"); + // Verify that upon construction the Comm status is disconnected + QCOMPARE(uas->getCommunicationStatus(), static_cast(UASInterface::COMM_DISCONNECTED)); } QTEST_APPLESS_MAIN(UASUnitTest); diff --git a/qgroundcontrol.pri b/qgroundcontrol.pri index f9725737bc..f65a94e30c 100644 --- a/qgroundcontrol.pri +++ b/qgroundcontrol.pri @@ -80,12 +80,12 @@ macx { ICON = $$BASEDIR/images/icons/macx.icns # Copy audio files if needed - QMAKE_POST_LINK += && cp -rf $$BASEDIR/audio $$TARGETDIR/qgroundcontrol.app/Contents/MacOs + QMAKE_POST_LINK += && cp -rf $$BASEDIR/audio $$TARGETDIR/qgroundcontrol.app/Contents/MacOS # Copy google earth starter file - QMAKE_POST_LINK += && cp -f $$BASEDIR/images/earth.html $$TARGETDIR/qgroundcontrol.app/Contents/MacOs + QMAKE_POST_LINK += && cp -f $$BASEDIR/images/earth.html $$TARGETDIR/qgroundcontrol.app/Contents/MacOS # Copy CSS stylesheets - QMAKE_POST_LINK += && cp -f $$BASEDIR/images/style-mission.css $$TARGETDIR/qgroundcontrol.app/Contents/MacOs/style-indoor.css - QMAKE_POST_LINK += && cp -f $$BASEDIR/images/style-outdoor.css $$TARGETDIR/qgroundcontrol.app/Contents/MacOs + QMAKE_POST_LINK += && cp -f $$BASEDIR/images/style-mission.css $$TARGETDIR/qgroundcontrol.app/Contents/MacOS/style-indoor.css + QMAKE_POST_LINK += && cp -f $$BASEDIR/images/style-outdoor.css $$TARGETDIR/qgroundcontrol.app/Contents/MacOS # Copy model files #QMAKE_POST_LINK += && cp -f $$BASEDIR/models/*.dae $$TARGETDIR/qgroundcontrol.app/Contents/MacOs -- GitLab