mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Added unit tests for status message and property index sorting
This commit is contained in:
@@ -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");
|
||||
|
||||
47
tests/blackmisc/testmisc.cpp
Normal file
47
tests/blackmisc/testmisc.cpp
Normal file
@@ -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 <QTest>
|
||||
|
||||
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
|
||||
38
tests/blackmisc/testmisc.h
Normal file
38
tests/blackmisc/testmisc.h
Normal file
@@ -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 <QObject>
|
||||
|
||||
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
|
||||
@@ -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 <QTest>
|
||||
|
||||
using namespace BlackMisc;
|
||||
@@ -38,6 +41,72 @@ namespace BlackMiscTest
|
||||
const CFrequency pf = vf.value<CFrequency>();
|
||||
QVERIFY2(pf == f, "Frequencies should have same value");
|
||||
}
|
||||
|
||||
void CTestPropertyIndex::propertyIndexSort()
|
||||
{
|
||||
CCallsign cs1("DLH1000");
|
||||
CCallsign cs2("DLH2000");
|
||||
CCallsign cs3("DLH3000");
|
||||
CSequence<CCallsign> 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
|
||||
|
||||
@@ -30,6 +30,9 @@ namespace BlackMiscTest
|
||||
private slots:
|
||||
//! Simulated aircraft index checks
|
||||
void propertyIndexCSimulatedAircraft();
|
||||
|
||||
//! Sorting based on property index
|
||||
void propertyIndexSort();
|
||||
};
|
||||
} // namespace
|
||||
|
||||
|
||||
Reference in New Issue
Block a user