tst_uasunittest.cc 1.88 KB
Newer Older
1 2 3 4
#include <QtCore/QString>
#include <QtTest/QtTest>
#include "UAS.h"
#include "MAVLinkProtocol.h"
5
#include "UASInterface.h"
6 7 8 9 10 11

class UASUnitTest : public QObject
{
    Q_OBJECT

public:
12 13 14
    #define  UASID  50
    MAVLinkProtocol* mav;
    UAS* uas;
15 16 17 18 19
    UASUnitTest();

private Q_SLOTS:
    void initTestCase();
    void cleanupTestCase();
20 21 22 23 24 25 26
    void getUASID_test();
    void getUASName_test();
    void getUpTime_test();
    void getCommunicationStatus_test();

private:

27 28 29 30 31 32 33 34
};

UASUnitTest::UASUnitTest()
{
}

void UASUnitTest::initTestCase()
{
35 36
  mav= new MAVLinkProtocol();
  uas=new UAS(mav,UASID);
37 38 39 40
}

void UASUnitTest::cleanupTestCase()
{
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
  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;
83 84
}

85
void UASUnitTest::getCommunicationStatus_test()
86
{
87 88
  // Verify that upon construction the Comm status is disconnected
  QCOMPARE(uas->getCommunicationStatus(), static_cast<int>(UASInterface::COMM_DISCONNECTED));
89 90 91 92 93
}

QTEST_APPLESS_MAIN(UASUnitTest);

#include "tst_uasunittest.moc"