11 #include <QDBusArgument>
35 using namespace swift::misc::aviation;
36 using namespace swift::misc::physical_quantities;
37 using namespace swift::misc::geo;
38 using namespace swift::misc::network;
71 QString toQString(
bool)
const {
return {}; }
72 friend QDBusArgument &
operator<<(QDBusArgument &arg,
const CTestMatcher &) {
return arg; }
73 friend const QDBusArgument &
operator>>(
const QDBusArgument &arg, CTestMatcher &) {
return arg; }
74 friend QDataStream &
operator<<(QDataStream &ds,
const CTestMatcher &) {
return ds; }
75 friend QDataStream &
operator>>(QDataStream &ds, CTestMatcher &) {
return ds; }
79 Q_DECLARE_METATYPE(MiscTest::CTestMatcher)
85 void CTestVariantAndMap::variant()
89 CCoordinateGeodetic::fromWgs84(
"48° 21′ 13″ N",
"11° 47′ 09″ E", { 1487, CLengthUnit::ft() });
91 CFrequency(118.7, CFrequencyUnit::MHz()), geoPos,
CLength(50, CLengthUnit::km()),
false);
94 CFrequency(120.7, CFrequencyUnit::MHz()), geoPos,
CLength(100, CLengthUnit::km()),
false);
99 QVERIFY2(l1 == l2,
"Null lengths should be equal");
101 CLength l3(0, CLengthUnit::m());
102 CLength l4(-1, CLengthUnit::m());
103 QVERIFY2(l1 != l3,
"Null length and non-null length should not be equal");
104 QVERIFY2(l1 != l4,
"Null length and non-null length should not be equal");
105 QVERIFY2((l1 < l4) != (l1 > l4),
"Null length and non-null length should be comparable");
106 QVERIFY2(
compare(l1, l4) != 0,
"Null length and non-null length should be sortable");
109 QVERIFY2(station1 == station1,
"Station should be equal");
111 QVERIFY(station1.getController() == station2.getController());
112 QVERIFY(station1.getRelativeDistance() == station2.getRelativeDistance());
114 QVERIFY2(station1 == station2,
"Station should be equal");
115 QVERIFY2(station1 != station3,
"Station should not be equal");
116 QVERIFY2(station1qv ==
CVariant::from(station1),
"Station should be equal (CVariant)");
117 QVERIFY2(
CVariant::from(station1) == station1qv,
"Station should be equal (CVariant)");
118 QVERIFY2(
CVariant::from(station2) == station1qv,
"Station should be equal (CVariant)");
119 QVERIFY2(
CVariant::from(station3) != station1qv,
"Station should be equal (CVariant)");
121 QVERIFY2(
compare(station1, station1) == 0,
"Station should be equal");
122 QVERIFY2(
compare(station1, station2) == 0,
"Station should be equal");
123 QVERIFY2(
compare(station1, station3) != 0,
"Station should not be equal");
126 void CTestVariantAndMap::variantList()
131 QVERIFY2(variant.
convert(qMetaTypeId<CVariantList>()),
"Variant containing list can convert to CVariantList");
133 QVERIFY2(ints.size() == variantInts.
size(),
"Variant list has same size as original list");
134 QVERIFY2(ints[0] == variantInts[0].to<int>(),
"Variant list has same element");
136 QVERIFY2(ints == variant.
to<
CSequence<int>>(),
"Variant list converted back compares equal");
141 QVERIFY2(variant.
convert(qMetaTypeId<CVariantList>()),
"Variant containing list can convert to CVariantList");
143 QVERIFY2(list.size() == variantList.
size(),
"Variant list has same size as original list");
144 QVERIFY2(list[0] == variantList[0].to<CAirlineIcaoCode>(),
"Variant list has same element");
149 void CTestVariantAndMap::matches()
151 CTestMatcher::registerMetadata();
152 const CTestMatcher matcher {};
154 QVERIFY2(variant.
matches(
CVariant()),
"Variant provides access to stored object's matches() method");
157 void CTestVariantAndMap::valueMap()
161 CCoordinateGeodetic::fromWgs84(
"48° 21′ 13″ N",
"11° 47′ 09″ E", { 1487, CLengthUnit::ft() });
163 CFrequency(118.7, CFrequencyUnit::MHz()), geoPos,
CLength(50, CLengthUnit::km()),
false);
177 QVERIFY2(vmWildcard.matches(station1),
"Station should be equal to wildcard");
178 QVERIFY2(!vmNoWildcard.matches(station1),
"Station should not be equal to empty list");
179 QVERIFY2(vm.
matches(station1),
"Controller should match");
180 QVERIFY2(vmWildcard == vmCopy,
"Maps should be equal");
181 QVERIFY2(
qHash(vmWildcard) ==
qHash(vmCopy),
"Hashs should be equal (simple)");
184 vm.
addValue(CAtcStation::IndexPosition, geoPos);
186 QVERIFY2(
qHash(vm) ==
qHash(vmCopy),
"Hashs should be equal (detailed)");
188 QVERIFY2(
qHash(vm) !=
qHash(vmCopy),
"Hashs should not be equal (detailed)");
195 #include "testvariantandmap.moc"
Variant and map related tests.
Specialized value object compliant map for variants, based on indexes.
bool matches(const T &value) const
True if this map matches the value.
void addValue(const CPropertyIndex &index, const CVariant &value)
Add a value.
bool isWildcard() const
Wildcard, only relevant when used in search.
Generic sequential container with value semantics.
size_type size() const
Returns number of elements in the sequence.
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
T to() const
Synonym for value().
static CVariant fromValue(T &&value)
Construct a variant from a value.
bool convert(int typeId)
Convert this variant to the type with the given metatype ID and return true if successful.
bool matches(const CVariant &event) const
If this is an event subscription, return true if it matches the given event.
static CVariant from(T &&value)
Synonym for fromValue().
bool canConvert(int typeId) const
True if this variant can be converted to the type with the given metatype ID.
Value object encapsulating a list of variants.
Value object for ICAO classification.
Value object encapsulating a list of ICAO codes.
Value object encapsulating information about an ATC station.
Value object encapsulating information of a callsign.
Value object encapsulating information of a user.
Physical unit length (length)
int compare(T a, T b)
Compare arithmetic values.
const QDBusArgument & operator>>(const QDBusArgument &arg, std::string &s)
Operator for std::string from QDBusArgument.
Free functions in swift::misc.
void registerMetadata()
Register all relevant metadata in Misc.
QDebug operator<<(QDebug d, const CRange< I > &range)
Streaming operators for CRange to qDebug.
SWIFTTEST_APPLESS_MAIN(MiscTest::CTestVariantAndMap)
main