swift
Loading...
Searching...
No Matches
testpropertyindex.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2017 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
7
8#include <QTest>
9
10#include "test.h"
11
13#include "misc/sequence.h"
16
17using namespace swift::misc;
18using namespace swift::misc::aviation;
19using namespace swift::misc::simulation;
20using namespace swift::misc::physical_quantities;
21
22namespace MiscTest
23{
26 {
28
29 private slots:
31 void propertyIndexCSimulatedAircraft();
32
34 void propertyIndexSort();
35 };
36
37 void CTestPropertyIndex::propertyIndexCSimulatedAircraft()
38 {
39 const CFrequency f(123.50, CFrequencyUnit::MHz());
40 const CPropertyIndex i({ CSimulatedAircraft::IndexCom1System, CComSystem::IndexActiveFrequency });
41 CSimulatedAircraft aircraft;
42 aircraft.setCallsign("DEIHL");
43 aircraft.setCom1ActiveFrequency(f);
44 CVariant vf = aircraft.propertyByIndex(i);
45 const auto pf = vf.value<CFrequency>();
46 QVERIFY2(pf == f, "Frequencies should have same value");
47 }
48
49 void CTestPropertyIndex::propertyIndexSort()
50 {
51 CCallsign cs1("DLH1000");
52 CCallsign cs2("DLH2000");
53 CCallsign cs3("DLH3000");
54 CSequence<CCallsign> callsigns;
55 callsigns.push_back(cs3);
56 callsigns.push_back(cs2);
57 callsigns.push_back(cs1);
58
59 const CPropertyIndex indexCs(CCallsign::IndexCallsignString);
60 const CPropertyIndexList indexListCs({ indexCs });
61
62 const int vrefCs = cs1.asString().compare(cs2.asString());
63 int v1 = cs1.comparePropertyByIndex(indexCs, cs2);
64 int v2 = cs2.comparePropertyByIndex(indexCs, cs1);
65 int v3 = cs1.comparePropertyByIndex(indexCs, cs1);
66 int v11 = indexCs.comparator()(cs1, cs2);
67 int v22 = indexCs.comparator()(cs2, cs1);
68 int v33 = indexCs.comparator()(cs1, cs1);
69 QVERIFY(v1 == v11 && v1 < 0 && vrefCs == v1);
70 QVERIFY(v2 == v22 && v2 > 0);
71 QVERIFY(v3 == v33 && v3 == 0);
72
73 QVERIFY(callsigns.front().equalsString("DLH3000"));
74
75 CStatusMessage s1(CStatusMessage::SeverityDebug, u"debug msg.");
76 s1.setMSecsSinceEpoch(4000);
77 CStatusMessage s2(CStatusMessage::SeverityInfo, u"info msg.");
78 s2.setMSecsSinceEpoch(3000);
79 CStatusMessage s3(CStatusMessage::SeverityWarning, u"warning msg.");
80 s3.setMSecsSinceEpoch(2000);
81 CStatusMessage s4(CStatusMessage::SeverityError, u"error msg.");
82 s4.setMSecsSinceEpoch(1000);
83
84 CStatusMessageList msgs;
85 msgs.push_back(s1);
86 msgs.push_back(s2);
87 msgs.push_back(s3);
88 msgs.push_back(s4);
89
90 const CPropertyIndex index(CStatusMessage::IndexUtcTimestamp);
91 const CPropertyIndexList indexList({ index });
92
93 int vrefTs = Compare::compare(s2.getUtcTimestamp(), s1.getUtcTimestamp());
94 int v4 = s2.comparePropertyByIndex(index, s1);
95 int v5 = s1.comparePropertyByIndex(index, s2);
96 int v6 = s3.comparePropertyByIndex(index, s3);
97
98 int v44 = index.comparator()(s2, s1);
99 int v55 = index.comparator()(s1, s2);
100 int v66 = index.comparator()(s3, s3);
101
102 QVERIFY(v4 == v44 && v1 < 0 && v4 == vrefTs);
103 QVERIFY(v5 == v55 && v2 > 0);
104 QVERIFY(v6 == v66 && v3 == 0);
105
106 QVERIFY(msgs.front().getMSecsSinceEpoch() == 4000);
107 QVERIFY(msgs.back().getMSecsSinceEpoch() == 1000);
108 }
109} // namespace MiscTest
110
113
114#include "testpropertyindex.moc"
115
static CFrequencyUnit MHz()
Megahertz.
Definition units.h:380
Testing property index access.
void push_back(const T &value)
Appends an element at the end of the sequence.
Definition sequence.h:308
reference front()
Access the first element.
Definition sequence.h:225
reference back()
Access the last element.
Definition sequence.h:249
static constexpr auto SeverityInfo
Status severities.
static constexpr auto SeverityError
Status severities.
static constexpr auto SeverityDebug
Status severities.
static constexpr auto SeverityWarning
Status severities.
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
Definition variant.h:69
T value() const
Return the value converted to the type T.
Definition variant.h:154
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
qint64 getMSecsSinceEpoch() const
Timestamp as ms value.
Comprehensive information of an aircraft.
void setCallsign(const aviation::CCallsign &callsign)
Set callsign.
Free functions in swift::misc.
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
QVERIFY(condition)
#define SWIFTTEST_APPLESS_MAIN(TestObject)
Implements a main() function that executes all tests in TestObject without instantiating a QApplicati...
Definition test.h:39