From 6795158c7e6ee1e1409738add7b0a496da81e275 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 21 Sep 2014 18:36:55 +0200 Subject: [PATCH] refs #325, testing new applyIf method --- samples/blackmisc/sampleschangeobject.cpp | 6 ++--- samples/blackmisc/samplescontainer.cpp | 33 +++++++++++++++++++++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/samples/blackmisc/sampleschangeobject.cpp b/samples/blackmisc/sampleschangeobject.cpp index c014bfc57..98564f84e 100644 --- a/samples/blackmisc/sampleschangeobject.cpp +++ b/samples/blackmisc/sampleschangeobject.cpp @@ -14,7 +14,7 @@ #include "blackmisc/avionavsystem.h" #include "blackmisc/aviotransponder.h" #include "blackmisc/avatcstationlist.h" -#include "blackmisc/indexvariantmap.h" +#include "blackmisc/propertyindexallclasses.h" #include "blackmisc/predicates.h" #include "blackmisc/blackmiscfreefunctions.h" #include @@ -59,7 +59,7 @@ namespace BlackMiscTest qDebug() << atcList.toQString(); // put Jane in the tower - CIndexVariantMap newController; + CPropertyIndexVariantMap newController; newController.addValue(CAtcStation::IndexController, QVariant::fromValue(CUser("112233", "Jane Doe"))); atcList.applyIf( BlackMisc::Predicates::MemberEqual(&CAtcStation::getCallsign, CCallsign("eddm_twr")), @@ -68,7 +68,7 @@ namespace BlackMiscTest qDebug() << atcList.toQString(); // now Jane's time is over - CIndexVariantMap anotherController; + CPropertyIndexVariantMap anotherController; anotherController.addValue(CAtcStation::IndexController, QVariant::fromValue(CUser("445566", "Fuzzy"))); atcList.applyIf(newController, anotherController); diff --git a/samples/blackmisc/samplescontainer.cpp b/samples/blackmisc/samplescontainer.cpp index f76513de2..d98bdece6 100644 --- a/samples/blackmisc/samplescontainer.cpp +++ b/samples/blackmisc/samplescontainer.cpp @@ -10,9 +10,11 @@ #include "samplescontainer.h" #include "blackmisc/blackmiscfreefunctions.h" #include "blackmisc/avatcstationlist.h" +#include "blackmisc/propertyindexallclasses.h" #include #include +using namespace BlackMisc; using namespace BlackMisc::Aviation; using namespace BlackMisc::PhysicalQuantities; using namespace BlackMisc::Geo; @@ -31,10 +33,12 @@ namespace BlackMiscTest QDateTime dtUntil = dtFrom.addSecs(60 * 60.0); // 1 hour QDateTime dtFrom2 = dtUntil; QDateTime dtUntil2 = dtUntil.addSecs(60 * 60.0); + CFrequency freqEddmTwr(118.7, CFrequencyUnit::MHz()); + CCallsign callsignEddmTwr("eddm_twr"); CCoordinateGeodetic geoPos = CCoordinateGeodetic::fromWgs84("48° 21′ 13″ N", "11° 47′ 09″ E", CLength(1487, CLengthUnit::ft())); - CAtcStation station1(CCallsign("eddm_twr"), CUser("123456", "Joe Doe"), - CFrequency(118.7, CFrequencyUnit::MHz()), + CAtcStation station1(callsignEddmTwr, CUser("123456", "Joe Doe"), + freqEddmTwr, geoPos, CLength(50, CLengthUnit::km()), false, dtFrom, dtUntil); CAtcStation station2(station1); CAtcStation station3(CCallsign("eddm_app"), CUser("654321", "Jen Doe"), @@ -61,6 +65,31 @@ namespace BlackMiscTest qDebug() << atcListSort.toQString(); qDebug() << "-----------------------------------------------"; + + // Apply if tests + atcList.clear(); + atcList.push_back(station1); + CAtcStation station1Cpy(station1); + CFrequency changedFrequency(118.25, CFrequencyUnit::MHz()); + CPropertyIndexVariantMap vm(CAtcStation::IndexFrequency, changedFrequency.toQVariant()); + + + // demonstration apply + CPropertyIndexList changedProperties; + changedProperties = station1Cpy.apply(vm, true); + qDebug() << "apply, changed" << changedProperties << vm << "expected 1"; + changedProperties = station1Cpy.apply(vm, true); + qDebug() << "apply, changed" << changedProperties << vm << "expected 0"; + + // applyIf + int changed; + changed = atcList.applyIf(&CAtcStation::getCallsign, callsignEddmTwr, vm); + qDebug() << "applyIf, changed" << changed << vm << "expected 1"; + changed = atcList.applyIf(&CAtcStation::getCallsign, callsignEddmTwr, vm); + qDebug() << "applyIf, changed" << changed << vm << "expected 1"; + changed = atcList.applyIf(&CAtcStation::getCallsign, callsignEddmTwr, vm, true); + qDebug() << "applyIf, changed" << changed << vm << "expected 0"; + return 0; }