From a750c02520bc09a1542b5e84b4a974193318a352 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 11 May 2018 03:03:52 +0200 Subject: [PATCH] Added unit tests for status message and property index sorting --- tests/blackmisc/testblackmiscmain.cpp | 13 +++-- tests/blackmisc/testmisc.cpp | 47 ++++++++++++++++++ tests/blackmisc/testmisc.h | 38 +++++++++++++++ tests/blackmisc/testpropertyindex.cpp | 69 +++++++++++++++++++++++++++ tests/blackmisc/testpropertyindex.h | 3 ++ 5 files changed, 166 insertions(+), 4 deletions(-) create mode 100644 tests/blackmisc/testmisc.cpp create mode 100644 tests/blackmisc/testmisc.h diff --git a/tests/blackmisc/testblackmiscmain.cpp b/tests/blackmisc/testblackmiscmain.cpp index 1fae88029..23b30e5ab 100644 --- a/tests/blackmisc/testblackmiscmain.cpp +++ b/tests/blackmisc/testblackmiscmain.cpp @@ -11,15 +11,15 @@ //! \file //! \ingroup testblackmisc -#include "testaviation.h" -#include "testcompress.h" -#include "testblackmiscmain.h" +#include "testaircraftparts.h" #include "testaircraftsituation.h" +#include "testaviation.h" +#include "testblackmiscmain.h" +#include "testcompress.h" #include "testcontainers.h" #include "testdbus.h" #include "testflightplan.h" #include "testgeo.h" -#include "testaircraftparts.h" #include "testicon.h" #include "testidentifier.h" #include "testinput.h" @@ -27,6 +27,7 @@ #include "testinterpolatorparts.h" #include "testlibrarypath.h" #include "testmath.h" +#include "testmisc.h" #include "testphysicalquantities.h" #include "testprocess.h" #include "testpropertyindex.h" @@ -54,6 +55,10 @@ namespace BlackMiscTest CTestCompress compressTest; status |= test.exec(&compressTest, "blackmisc_compress"); } + { + CTestMisc miscTest; + status |= test.exec(&miscTest, "blackmisc_misc"); + } { CTestPhysicalQuantities pqBaseTests; status |= test.exec(&pqBaseTests, "blackmisc_physicalQuantities"); diff --git a/tests/blackmisc/testmisc.cpp b/tests/blackmisc/testmisc.cpp new file mode 100644 index 000000000..5d23c9ab5 --- /dev/null +++ b/tests/blackmisc/testmisc.cpp @@ -0,0 +1,47 @@ +/* Copyright (C) 2018 + * 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 "testmisc.h" +#include "blackmisc/statusmessage.h" +#include + +using namespace BlackMisc; + +namespace BlackMiscTest +{ + CTestMisc::CTestMisc(QObject *parent): QObject(parent) + { + // void + } + + void CTestMisc::statusMessage() + { + CStatusMessage s1(CStatusMessage::SeverityDebug, "debug msg."); + s1.setMSecsSinceEpoch(4000); + CStatusMessage s2(CStatusMessage::SeverityInfo, "info msg."); + s2.setMSecsSinceEpoch(3000); + // CStatusMessage s3(CStatusMessage::SeverityWarning, "warning msg."); + // s3.setMSecsSinceEpoch(2000); + // CStatusMessage s4(CStatusMessage::SeverityError, "error msg."); + // s4.setMSecsSinceEpoch(1000); + + CStatusMessage cCopy(s1); + QVERIFY(cCopy.getMSecsSinceEpoch() == s1.getMSecsSinceEpoch()); + + CStatusMessage cAssign; + cAssign = s2; + QVERIFY(cAssign.getMSecsSinceEpoch() == s2.getMSecsSinceEpoch()); + } +} // namespace + +//! \endcond diff --git a/tests/blackmisc/testmisc.h b/tests/blackmisc/testmisc.h new file mode 100644 index 000000000..67b03ee1f --- /dev/null +++ b/tests/blackmisc/testmisc.h @@ -0,0 +1,38 @@ +/* Copyright (C) 2018 + * 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. + */ + +#ifndef BLACKMISCTEST_TESTMISC_H +#define BLACKMISCTEST_TESTMISC_H + +//! \cond PRIVATE_TESTS +//! \file +//! \ingroup testblackmisc + +#include + +namespace BlackMiscTest +{ + //! Testing property index access + class CTestMisc : public QObject + { + Q_OBJECT + + public: + //! Standard test case constructor + explicit CTestMisc(QObject *parent = nullptr); + + private slots: + //! Status message + void statusMessage(); + }; +} // namespace + +//! \endcond + +#endif // guard diff --git a/tests/blackmisc/testpropertyindex.cpp b/tests/blackmisc/testpropertyindex.cpp index 981a84c61..ae07f3b32 100644 --- a/tests/blackmisc/testpropertyindex.cpp +++ b/tests/blackmisc/testpropertyindex.cpp @@ -13,6 +13,9 @@ #include "testpropertyindex.h" #include "blackmisc/simulation/simulatedaircraft.h" +#include "blackmisc/statusmessagelist.h" +#include "blackmisc/sequence.h" +#include "blackmisc/comparefunctions.h" #include using namespace BlackMisc; @@ -38,6 +41,72 @@ namespace BlackMiscTest const CFrequency pf = vf.value(); QVERIFY2(pf == f, "Frequencies should have same value"); } + + void CTestPropertyIndex::propertyIndexSort() + { + CCallsign cs1("DLH1000"); + CCallsign cs2("DLH2000"); + CCallsign cs3("DLH3000"); + CSequence callsigns; + callsigns.push_back(cs3); + callsigns.push_back(cs2); + callsigns.push_back(cs1); + + const CPropertyIndex indexCs(CCallsign::IndexCallsignString); + const CPropertyIndexList indexListCs({ indexCs }); + + const int vrefCs = cs1.asString().compare(cs2.asString()); + int v1 = cs1.comparePropertyByIndex(indexCs, cs2); + int v2 = cs2.comparePropertyByIndex(indexCs, cs1); + int v3 = cs1.comparePropertyByIndex(indexCs, cs1); + int v11 = indexCs.comparator()(cs1, cs2); + int v22 = indexCs.comparator()(cs2, cs1); + int v33 = indexCs.comparator()(cs1, cs1); + QVERIFY(v1 == v11 && v1 < 0 && vrefCs == v1); + QVERIFY(v2 == v22 && v2 > 0); + QVERIFY(v3 == v33 && v3 == 0); + + QVERIFY(callsigns.front().equalsString("DLH3000")); + callsigns.sortByProperty(indexListCs); + QVERIFY(callsigns.front().equalsString("DLH1000")); + + CStatusMessage s1(CStatusMessage::SeverityDebug, "debug msg."); + s1.setMSecsSinceEpoch(4000); + CStatusMessage s2(CStatusMessage::SeverityInfo, "info msg."); + s2.setMSecsSinceEpoch(3000); + CStatusMessage s3(CStatusMessage::SeverityWarning, "warning msg."); + s3.setMSecsSinceEpoch(2000); + CStatusMessage s4(CStatusMessage::SeverityError, "error msg."); + s4.setMSecsSinceEpoch(1000); + + CStatusMessageList msgs; + msgs.push_back(s1); + msgs.push_back(s2); + msgs.push_back(s3); + msgs.push_back(s4); + + const CPropertyIndex index(CStatusMessage::IndexUtcTimestamp); + const CPropertyIndexList indexList({ index }); + + int vrefTs = Compare::compare(s2.getUtcTimestamp(), s1.getUtcTimestamp()); + int v4 = s2.comparePropertyByIndex(index, s1); + int v5 = s1.comparePropertyByIndex(index, s2); + int v6 = s3.comparePropertyByIndex(index, s3); + + int v44 = index.comparator()(s2, s1); + int v55 = index.comparator()(s1, s2); + int v66 = index.comparator()(s3, s3); + + QVERIFY(v4 == v44 && v1 < 0 && v4 == vrefTs); + QVERIFY(v5 == v55 && v2 > 0); + QVERIFY(v6 == v66 && v3 == 0); + + QVERIFY(msgs.front().getMSecsSinceEpoch() == 4000); + QVERIFY(msgs.back().getMSecsSinceEpoch() == 1000); + msgs.sortByProperty(indexList); + QVERIFY(msgs.front().getMSecsSinceEpoch() == 1000); + QVERIFY(msgs.back().getMSecsSinceEpoch() == 4000); + } } // namespace //! \endcond diff --git a/tests/blackmisc/testpropertyindex.h b/tests/blackmisc/testpropertyindex.h index d052a0d83..9d48485e8 100644 --- a/tests/blackmisc/testpropertyindex.h +++ b/tests/blackmisc/testpropertyindex.h @@ -30,6 +30,9 @@ namespace BlackMiscTest private slots: //! Simulated aircraft index checks void propertyIndexCSimulatedAircraft(); + + //! Sorting based on property index + void propertyIndexSort(); }; } // namespace