mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
tests: Add aircraft situation unittests
This commit is contained in:
@@ -36,6 +36,12 @@ add_swift_test(
|
||||
LINK_LIBRARIES misc tests_test Qt::Core
|
||||
)
|
||||
|
||||
add_swift_test(
|
||||
NAME misc_aviation_ongroundinfo
|
||||
SOURCES aviation/testongroundinfo.cpp
|
||||
LINK_LIBRARIES misc tests_test Qt::Core
|
||||
)
|
||||
|
||||
##############
|
||||
## Geo ##
|
||||
##############
|
||||
|
||||
@@ -5,19 +5,17 @@
|
||||
//! \file
|
||||
//! \ingroup testmisc
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QTest>
|
||||
|
||||
#include "test.h"
|
||||
|
||||
#include "config/buildconfig.h"
|
||||
#include "misc/aviation/aircraftsituationchange.h"
|
||||
#include "misc/aviation/aircraftsituationlist.h"
|
||||
#include "misc/cputime.h"
|
||||
#include "misc/network/fsdsetup.h"
|
||||
// #include "misc/math/mathutils.h"
|
||||
// #include "misc/stringutils.h"
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QTest>
|
||||
#include <QTimer>
|
||||
|
||||
#include "test.h"
|
||||
|
||||
using namespace swift::config;
|
||||
using namespace swift::misc;
|
||||
@@ -35,6 +33,9 @@ namespace MiscTest
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
// Default constructor
|
||||
void defaultConstructor();
|
||||
|
||||
//! All GND flags
|
||||
void allGndFlagsAndTakeOff() const;
|
||||
|
||||
@@ -59,6 +60,14 @@ namespace MiscTest
|
||||
//! Using sort hint
|
||||
void sortHint();
|
||||
|
||||
void isGfLanding();
|
||||
|
||||
void isGfStarting();
|
||||
|
||||
void isGfEqualAirborne();
|
||||
|
||||
void isGfEqualOnGround();
|
||||
|
||||
private:
|
||||
//! Test situations (ascending)
|
||||
static swift::misc::aviation::CAircraftSituationList testSituations();
|
||||
@@ -75,6 +84,17 @@ namespace MiscTest
|
||||
static const swift::misc::physical_quantities::CLength &cg();
|
||||
};
|
||||
|
||||
void CTestAircraftSituation::defaultConstructor()
|
||||
{
|
||||
CAircraftSituation sit;
|
||||
|
||||
QVERIFY2(sit.isNull(), "Situation should be null");
|
||||
QVERIFY2(!sit.isOnGround(), "Should not be on ground");
|
||||
QVERIFY2(!sit.isOnGroundFromNetwork(), "Should not be on ground from network");
|
||||
QVERIFY2(!sit.isOnGroundFromParts(), "Should not be on ground from network");
|
||||
QVERIFY2(!sit.isOnGroundInfoAvailable(), "Should not be on ground from network");
|
||||
}
|
||||
|
||||
void CTestAircraftSituation::allGndFlagsAndTakeOff() const
|
||||
{
|
||||
CAircraftSituationList situations = testSituations();
|
||||
@@ -363,6 +383,39 @@ namespace MiscTest
|
||||
return newSituations;
|
||||
}
|
||||
|
||||
void CTestAircraftSituation::isGfLanding()
|
||||
{
|
||||
|
||||
QVERIFY2(CAircraftSituation::isGfLanding(1.0, 0.0), "Should be landing");
|
||||
QVERIFY2(!CAircraftSituation::isGfLanding(0.0, 1.0), "Should be landing");
|
||||
QVERIFY2(!CAircraftSituation::isGfLanding(1.0, 0.9), "Should be landing");
|
||||
QVERIFY2(!CAircraftSituation::isGfLanding(0.5, 0.5), "Should be landing");
|
||||
}
|
||||
|
||||
void CTestAircraftSituation::isGfStarting()
|
||||
{
|
||||
QVERIFY2(CAircraftSituation::isGfStarting(0.0, 1.0), "Should be starting");
|
||||
QVERIFY2(!CAircraftSituation::isGfStarting(1.0, 0.0), "Should be starting");
|
||||
QVERIFY2(!CAircraftSituation::isGfStarting(0.9, 1.0), "Should be starting");
|
||||
QVERIFY2(!CAircraftSituation::isGfStarting(0.5, 0.5), "Should be starting");
|
||||
}
|
||||
|
||||
void CTestAircraftSituation::isGfEqualAirborne()
|
||||
{
|
||||
QVERIFY2(CAircraftSituation::isGfEqualAirborne(0.0, 0.0), "Should be airborne");
|
||||
QVERIFY2(!CAircraftSituation::isGfEqualAirborne(1.0, 1.0), "Should be airborne");
|
||||
QVERIFY2(!CAircraftSituation::isGfEqualAirborne(0.0, 0.1), "Should be airborne");
|
||||
QVERIFY2(!CAircraftSituation::isGfEqualAirborne(0.5, 0.5), "Should be airborne");
|
||||
}
|
||||
|
||||
void CTestAircraftSituation::isGfEqualOnGround()
|
||||
{
|
||||
QVERIFY2(CAircraftSituation::isGfEqualOnGround(1.0, 1.0), "Should be ground");
|
||||
QVERIFY2(!CAircraftSituation::isGfEqualOnGround(0.0, 0.0), "Should be ground");
|
||||
QVERIFY2(!CAircraftSituation::isGfEqualOnGround(1.0, 0.9), "Should be ground");
|
||||
QVERIFY2(!CAircraftSituation::isGfEqualOnGround(0.5, 0.5), "Should be on ground");
|
||||
}
|
||||
|
||||
const CLength &CTestAircraftSituation::cg()
|
||||
{
|
||||
static const CLength cg(2.0, CLengthUnit::m());
|
||||
|
||||
84
tests/misc/aviation/testongroundinfo.cpp
Normal file
84
tests/misc/aviation/testongroundinfo.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
// SPDX-FileCopyrightText: Copyright (C) swift Project Community / Contributors
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
|
||||
|
||||
//! \cond PRIVATE_TESTS
|
||||
//! \file
|
||||
//! \ingroup testmisc
|
||||
#include <QTest>
|
||||
|
||||
#include "test.h"
|
||||
|
||||
#include "misc/aviation/ongroundinfo.h"
|
||||
|
||||
using namespace swift::misc::aviation;
|
||||
|
||||
namespace MiscTest
|
||||
{
|
||||
//! Aviation classes basic tests
|
||||
class CMiscOnGroundInfo : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void createDefault();
|
||||
void createFromGndFactorNotOnGround();
|
||||
void createFromGndFactorOnGround();
|
||||
void getGroundFactorUnknown();
|
||||
void getGroundFactorOnGround();
|
||||
void getGroundFactorNotOnGround();
|
||||
};
|
||||
|
||||
void CMiscOnGroundInfo::createDefault()
|
||||
{
|
||||
COnGroundInfo info;
|
||||
QVERIFY2(info.getGroundFactor() == -1, "Wrong ground factor");
|
||||
QVERIFY2(info.getGroundDetails() == COnGroundInfo::NotSetGroundDetails, "Wrong ground details");
|
||||
QVERIFY2(info.getOnGround() == COnGroundInfo::OnGroundSituationUnknown, "Wrong on ground situation");
|
||||
}
|
||||
|
||||
void CMiscOnGroundInfo::createFromGndFactorNotOnGround()
|
||||
{
|
||||
COnGroundInfo info(0.5);
|
||||
QCOMPARE(info.getGroundFactor(), 0.5);
|
||||
QVERIFY2(info.getGroundDetails() == COnGroundInfo::OnGroundByInterpolation, "Wrong ground details");
|
||||
QVERIFY2(info.getOnGround() == COnGroundInfo::NotOnGround, "Wrong on ground situation");
|
||||
}
|
||||
|
||||
void CMiscOnGroundInfo::createFromGndFactorOnGround()
|
||||
{
|
||||
COnGroundInfo info(0.96);
|
||||
QCOMPARE(info.getGroundFactor(), 0.96);
|
||||
QVERIFY2(info.getGroundDetails() == COnGroundInfo::OnGroundByInterpolation, "Wrong ground details");
|
||||
QVERIFY2(info.getOnGround() == COnGroundInfo::OnGround, "Wrong on ground situation");
|
||||
}
|
||||
|
||||
void CMiscOnGroundInfo::getGroundFactorUnknown()
|
||||
{
|
||||
COnGroundInfo info(COnGroundInfo::OnGroundSituationUnknown, COnGroundInfo::NotSetGroundDetails);
|
||||
QVERIFY2(info.getGroundFactor() == -1, "Wrong ground factor");
|
||||
QVERIFY2(info.getGroundDetails() == COnGroundInfo::NotSetGroundDetails, "Wrong ground details");
|
||||
QVERIFY2(info.getOnGround() == COnGroundInfo::OnGroundSituationUnknown, "Wrong on ground situation");
|
||||
}
|
||||
|
||||
void CMiscOnGroundInfo::getGroundFactorOnGround()
|
||||
{
|
||||
COnGroundInfo info(COnGroundInfo::OnGround, COnGroundInfo::InFromNetwork);
|
||||
QVERIFY2(info.getGroundFactor() == 1, "Wrong ground factor");
|
||||
QVERIFY2(info.getGroundDetails() == COnGroundInfo::InFromNetwork, "Wrong ground details");
|
||||
QVERIFY2(info.getOnGround() == COnGroundInfo::OnGround, "Wrong on ground situation");
|
||||
}
|
||||
|
||||
void CMiscOnGroundInfo::getGroundFactorNotOnGround()
|
||||
{
|
||||
COnGroundInfo info(COnGroundInfo::NotOnGround, COnGroundInfo::InFromNetwork);
|
||||
QVERIFY2(info.getGroundFactor() == 0, "Wrong ground factor");
|
||||
QVERIFY2(info.getGroundDetails() == COnGroundInfo::InFromNetwork, "Wrong ground details");
|
||||
QVERIFY2(info.getOnGround() == COnGroundInfo::NotOnGround, "Wrong on ground situation");
|
||||
}
|
||||
|
||||
} // namespace MiscTest
|
||||
|
||||
SWIFTTEST_APPLESS_MAIN(MiscTest::CMiscOnGroundInfo);
|
||||
|
||||
#include "testongroundinfo.moc"
|
||||
|
||||
//! \endcond
|
||||
Reference in New Issue
Block a user