swift
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 
12 #include "misc/comparefunctions.h"
13 #include "misc/sequence.h"
15 #include "misc/statusmessagelist.h"
16 
17 using namespace swift::misc;
18 using namespace swift::misc::aviation;
19 using namespace swift::misc::simulation;
20 using namespace swift::misc::physical_quantities;
21 
22 namespace MiscTest
23 {
25  class CTestPropertyIndex : public QObject
26  {
27  Q_OBJECT
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 CFrequency 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 
76  s1.setMSecsSinceEpoch(4000);
78  s2.setMSecsSinceEpoch(3000);
80  s3.setMSecsSinceEpoch(2000);
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 
Testing property index access.
Value object encapsulating a list of property indexes.
Generic sequential container with value semantics.
Definition: sequence.h:86
void push_back(const T &value)
Appends an element at the end of the sequence.
Definition: sequence.h:305
reference front()
Access the first element.
Definition: sequence.h:225
reference back()
Access the last element.
Definition: sequence.h:249
Streamable status message, e.g.
constexpr static auto SeverityDebug
Status severities.
constexpr static auto SeverityError
Status severities.
constexpr static auto SeverityInfo
Status severities.
constexpr static auto SeverityWarning
Status severities.
Status messages, e.g. from Core -> GUI.
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
Definition: variant.h:66
T value() const
Return the value converted to the type T.
Definition: variant.h:169
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
qint64 getMSecsSinceEpoch() const
Timestamp as ms value.
Value object encapsulating information of a callsign.
Definition: callsign.h:30
Comprehensive information of an aircraft.
void setCallsign(const aviation::CCallsign &callsign)
Set callsign.
Free functions in swift::misc.
SWIFTTEST_APPLESS_MAIN(MiscTest::CTestPropertyIndex)
main