UASUnitTest.cc 6.87 KB
Newer Older
Alejandro's avatar
Alejandro committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
#include "UASUnitTest.h"

UASUnitTest::UASUnitTest()
{
}

void UASUnitTest::initTestCase()
{
  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);

    // Make sure that ID >= 0
    QCOMPARE(uas->getUASID(), -1);


}

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::getCommunicationStatus_test()
{
  // Verify that upon construction the Comm status is disconnected
  QCOMPARE(uas->getCommunicationStatus(), static_cast<int>(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 verificar=uas->getAutopilotType();
  // Verify that upon construction the autopilot is set to -1
  QCOMPARE(verificar, -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);

    //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);
}