From 027dce5ab39db365532cdff301a94df1a1ce3430 Mon Sep 17 00:00:00 2001 From: Lars Toenning Date: Fri, 22 Nov 2024 10:03:10 +0100 Subject: [PATCH] tests: Add aircraft situation unittests --- tests/misc/CMakeLists.txt | 6 ++ .../testaircraftsituation.cpp | 69 +++++++++++++-- tests/misc/aviation/testongroundinfo.cpp | 84 +++++++++++++++++++ 3 files changed, 151 insertions(+), 8 deletions(-) create mode 100644 tests/misc/aviation/testongroundinfo.cpp diff --git a/tests/misc/CMakeLists.txt b/tests/misc/CMakeLists.txt index 96ee8934c..f3b4adda8 100644 --- a/tests/misc/CMakeLists.txt +++ b/tests/misc/CMakeLists.txt @@ -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 ## ############## diff --git a/tests/misc/aviation/testaircraftsituation/testaircraftsituation.cpp b/tests/misc/aviation/testaircraftsituation/testaircraftsituation.cpp index 210bec9fc..b61924f53 100644 --- a/tests/misc/aviation/testaircraftsituation/testaircraftsituation.cpp +++ b/tests/misc/aviation/testaircraftsituation/testaircraftsituation.cpp @@ -5,19 +5,17 @@ //! \file //! \ingroup testmisc +#include +#include +#include + +#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 -#include -#include -#include - -#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()); diff --git a/tests/misc/aviation/testongroundinfo.cpp b/tests/misc/aviation/testongroundinfo.cpp new file mode 100644 index 000000000..ff31fcf48 --- /dev/null +++ b/tests/misc/aviation/testongroundinfo.cpp @@ -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 + +#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