mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 15:45:46 +08:00
Split the giant test binaries into smaller unit tests
This is an intermediate step to have smaller unit tests. It is a trade off between having many many test executables compared to a few bigger ones. But this comes a lot closer to what QtTest is meant to be used.
This commit is contained in:
113
tests/blackmisc/aviation/testflightplan/testflightplan.cpp
Normal file
113
tests/blackmisc/aviation/testflightplan/testflightplan.cpp
Normal file
@@ -0,0 +1,113 @@
|
||||
/* Copyright (C) 2017
|
||||
* swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \cond PRIVATE_TESTS
|
||||
//! \file
|
||||
//! \ingroup testblackmisc
|
||||
|
||||
#include "blackmisc/aviation/flightplan.h"
|
||||
#include "blackmisc/aviation/selcal.h"
|
||||
#include "blackmisc/network/voicecapabilities.h"
|
||||
#include "test.h"
|
||||
#include <QTest>
|
||||
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Network;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
namespace BlackMiscTest
|
||||
{
|
||||
//! Flightplan unit tests
|
||||
class CTestFlightPlan : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
//! Flight plan remarks (parsing)
|
||||
void flightPlanRemarks();
|
||||
|
||||
//! Flight plan altitude
|
||||
void flightPlanAltitude();
|
||||
};
|
||||
|
||||
void CTestFlightPlan::flightPlanRemarks()
|
||||
{
|
||||
QString remarks;
|
||||
CFlightPlanRemarks fpRemarks(remarks);
|
||||
QVERIFY2(fpRemarks.isEmpty(), "Expect NULL flight plan remarks");
|
||||
|
||||
remarks = QStringLiteral("RT/KESTREL OPR/MYTRAVEL REG/G-DAJC SEL/FP-ES PER/C NAV/RNP10");
|
||||
fpRemarks = CFlightPlanRemarks(remarks);
|
||||
QVERIFY2(fpRemarks.getSelcalCode().getCode() == "FPES", "Wrong SELCAL code");
|
||||
QVERIFY2(fpRemarks.getFlightOperator() == "MYTRAVEL", "Wrong flight operator");
|
||||
QVERIFY2(fpRemarks.getRegistration().asString() == "GDAJC", "Wrong registration");
|
||||
|
||||
remarks = QStringLiteral("OPR/UAL CALLSIGN/UNITED");
|
||||
fpRemarks = CFlightPlanRemarks(remarks);
|
||||
QVERIFY2(fpRemarks.getAirlineIcao().getDesignator() == "UAL", "Wrong airline, expect UAL");
|
||||
QVERIFY2(fpRemarks.getFlightOperator().isEmpty(), "Expect to operator, should be in airline");
|
||||
QVERIFY2(fpRemarks.getRegistration().isEmpty(), "Expect no registration");
|
||||
QVERIFY2(fpRemarks.getRadioTelephony() == "UNITED", "Expect telephony");
|
||||
|
||||
remarks = QStringLiteral("/v/FPL-VIR9-IS-A346/DEP/S-EGLL/ARR/KJFK/REG/G-VGAS/TCAS RVR/200 OPR/VIRGIN AIRLINES");
|
||||
fpRemarks = CFlightPlanRemarks(remarks);
|
||||
QVERIFY2(fpRemarks.getRegistration().asString() == "GVGAS", "Wrong registration");
|
||||
QVERIFY2(fpRemarks.getFlightOperator() == "VIRGIN AIRLINES", "Wrong operator");
|
||||
QVERIFY2(fpRemarks.getVoiceCapabilities().getCapabilities() == CVoiceCapabilities::Voice, "Wrong airline, expect UAL");
|
||||
|
||||
remarks = QStringLiteral("/v/FPL-VIR9-IS-A346/ OPR/VIRGIN AIRLINES DEP/S-EGLL/ARR/KJFK/REG/G-VGAS/TCAS RVR/200");
|
||||
fpRemarks = CFlightPlanRemarks(remarks);
|
||||
QVERIFY2(fpRemarks.getRegistration().asString() == "GVGAS", "Wrong registration");
|
||||
QVERIFY2(fpRemarks.getFlightOperator() == "VIRGIN AIRLINES", "Wrong operator");
|
||||
QVERIFY2(fpRemarks.getVoiceCapabilities().getCapabilities() == CVoiceCapabilities::Voice, "Wrong airline, expect UAL");
|
||||
}
|
||||
|
||||
void CTestFlightPlan::flightPlanAltitude()
|
||||
{
|
||||
CAltitude a;
|
||||
a.parseFromFpAltitudeString("FL125");
|
||||
QVERIFY2(a == CAltitude(12500, CAltitude::FlightLevel, CLengthUnit::ft()), "Wrong altitude FL125");
|
||||
a.parseFromFpAltitudeString("A122");
|
||||
QVERIFY2(a == CAltitude(12200, CAltitude::MeanSeaLevel, CLengthUnit::ft()), "Wrong altitude A122");
|
||||
a.parseFromFpAltitudeString("123ft");
|
||||
QVERIFY2(a == CAltitude(123, CAltitude::MeanSeaLevel, CLengthUnit::ft()), "Wrong altitude 123ft");
|
||||
a.parseFromFpAltitudeString("1234m");
|
||||
QVERIFY2(a == CAltitude(1234, CAltitude::MeanSeaLevel, CLengthUnit::m()), "Wrong altitude 1234m");
|
||||
a.parseFromFpAltitudeString("S0666");
|
||||
QVERIFY2(a == CAltitude(6660, CAltitude::FlightLevel, CLengthUnit::m()), "Wrong altitude S0666");
|
||||
a.parseFromFpAltitudeString("M456");
|
||||
QVERIFY2(a == CAltitude(4560, CAltitude::MeanSeaLevel, CLengthUnit::m()), "Wrong altitude M456");
|
||||
|
||||
// some values which are supposed to be wrong
|
||||
CAltitude faulty(a);
|
||||
faulty.makeNegative();
|
||||
QVERIFY2(!faulty.isValidFpAltitude(), "Negative values not allowed");
|
||||
faulty.parseFromFpAltitudeString("FL111");
|
||||
QVERIFY2(!faulty.isValidFpAltitude(), "FL should end with 0/5");
|
||||
|
||||
// as string
|
||||
a = CAltitude(12500, CAltitude::FlightLevel, CLengthUnit::ft());
|
||||
QVERIFY2(a.asFpAltitudeString() == "FL125", "Expect FL125");
|
||||
QVERIFY2(a.asFpAltitudeSimpleVatsimString() == "FL125", "Expect FL125");
|
||||
a = CAltitude(15000, CAltitude::MeanSeaLevel, CLengthUnit::ft());
|
||||
QVERIFY2(a.asFpAltitudeString() == "A150", "Expect A150");
|
||||
QVERIFY2(a.asFpAltitudeSimpleVatsimString() == "15000", "Expect 15000");
|
||||
a = CAltitude(1500, CAltitude::FlightLevel, CLengthUnit::m());
|
||||
QVERIFY2(a.asFpAltitudeString() == "S0150", "Expect S0150");
|
||||
a = CAltitude(1600, CAltitude::MeanSeaLevel, CLengthUnit::m());
|
||||
QVERIFY2(a.asFpAltitudeString() == "M0160", "Expect M0160");
|
||||
}
|
||||
} // ns
|
||||
|
||||
//! main
|
||||
BLACKTEST_APPLESS_MAIN(BlackMiscTest::CTestFlightPlan);
|
||||
|
||||
#include "testflightplan.moc"
|
||||
|
||||
//! \endcond
|
||||
Reference in New Issue
Block a user