refs #879, use test data in samples/unit tests

This commit is contained in:
Klaus Basan
2017-02-13 00:24:00 +01:00
committed by Mathew Sutcliffe
parent 4b506f20ab
commit e73c8c4f36
8 changed files with 72 additions and 171 deletions

View File

@@ -11,6 +11,7 @@
//! \ingroup sampleblackmisc
#include "samplescontainer.h"
#include "blackmisc/test/testdata.h"
#include "blackmisc/aviation/atcstation.h"
#include "blackmisc/aviation/atcstationlist.h"
#include "blackmisc/aviation/callsign.h"
@@ -35,27 +36,16 @@ using namespace BlackMisc::Aviation;
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Geo;
using namespace BlackMisc::Network;
using namespace BlackMisc::Test;
namespace BlackSample
{
int CSamplesContainer::samples()
{
// ATC stations
QDateTime dtFrom = QDateTime::currentDateTimeUtc();
QDateTime dtUntil = dtFrom.addSecs(60 * 60); // 1 hour
QDateTime dtFrom2 = dtUntil;
QDateTime dtUntil2 = dtUntil.addSecs(60 * 60);
CFrequency freqEddmTwr(118.7, CFrequencyUnit::MHz());
CCallsign callsignEddmTwr("eddm_twr");
CCoordinateGeodetic geoPos =
CCoordinateGeodetic::fromWgs84("48° 21 13″ N", "11° 47 09″ E", { 1487, CLengthUnit::ft() });
CAtcStation station1(callsignEddmTwr, CUser("123456", "Joe Doe"),
freqEddmTwr,
geoPos, CLength(50, CLengthUnit::km()), false, dtFrom, dtUntil);
const CAtcStation station1(CTestData::getMunichTower());
CAtcStation station2(station1);
CAtcStation station3(CCallsign("eddm_app"), CUser("654321", "Jen Doe"),
CFrequency(120.7, CFrequencyUnit::MHz()),
geoPos, CLength(100, CLengthUnit::km()), false, dtFrom2, dtUntil2);
CAtcStation station3(CTestData::getMunichApproach());
// ATC List
CAtcStationList atcList;
@@ -85,7 +75,6 @@ namespace BlackSample
CFrequency changedFrequency(118.25, CFrequencyUnit::MHz());
CPropertyIndexVariantMap vm(CAtcStation::IndexFrequency, CVariant::from(changedFrequency));
// demonstration apply
CPropertyIndexList changedProperties;
changedProperties = station1Cpy.apply(vm, true);
@@ -95,11 +84,11 @@ namespace BlackSample
// applyIf
int changed;
changed = atcList.applyIf(&CAtcStation::getCallsign, callsignEddmTwr, vm);
changed = atcList.applyIf(&CAtcStation::getCallsign, CTestData::getMunichTower().getCallsign(), vm);
qDebug() << "applyIf, changed" << changed << vm << "expected 1";
changed = atcList.applyIf(&CAtcStation::getCallsign, callsignEddmTwr, vm);
changed = atcList.applyIf(&CAtcStation::getCallsign, CTestData::getMunichTower().getCallsign(), vm);
qDebug() << "applyIf, changed" << changed << vm << "expected 1";
changed = atcList.applyIf(&CAtcStation::getCallsign, callsignEddmTwr, vm, true);
changed = atcList.applyIf(&CAtcStation::getCallsign, CTestData::getMunichTower().getCallsign(), vm, true);
qDebug() << "applyIf, changed" << changed << vm << "expected 0";
return 0;

View File

@@ -29,6 +29,7 @@
#include "blackmisc/pq/speed.h"
#include "blackmisc/pq/units.h"
#include "blackmisc/simulation/simulatedaircraft.h"
#include "blackmisc/test/testdata.h"
#include "blackmisc/stringutils.h"
#include <stdio.h>
@@ -45,13 +46,10 @@ using namespace BlackMisc::Simulation;
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Geo;
using namespace BlackMisc::Network;
using namespace BlackMisc::Test;
namespace BlackSample
{
/*
* Samples
*/
int CSamplesJson::samples()
{
QTextStream cin(stdin);
@@ -61,14 +59,10 @@ namespace BlackSample
l.convertFromJson(json);
qDebug() << json << l;
qDebug() << "-------";
QDateTime dtFrom = QDateTime::currentDateTimeUtc();
QDateTime dtUntil = dtFrom.addSecs(60 * 60); // 1 hour
CCoordinateGeodetic geoPos = CCoordinateGeodetic::fromWgs84("48° 21 13″ N", "11° 47 09″ E", { 1487, CLengthUnit::ft() });
CAtcStation station(CCallsign("eddm_twr"), CUser("123456", "Joe Doe"),
CFrequency(118.7, CFrequencyUnit::MHz()), geoPos, CLength(50, CLengthUnit::km()), false, dtFrom, dtUntil);
CAtcStation station = CTestData::getMunichTower();
json = station.toJson();
QJsonDocument doc(json);
qDebug() << doc.toJson(QJsonDocument::Indented);
qDebug().noquote() << doc.toJson(QJsonDocument::Indented);
qDebug() << "-------";
station = CAtcStation();
@@ -77,14 +71,11 @@ namespace BlackSample
qDebug() << "------- Enter -----";
cin.readLine();
CAircraftSituation situation(geoPos, CHeading(10, CHeading::True, CAngleUnit::deg()),
CAngle(12, CAngleUnit::deg()), CAngle(5, CAngleUnit::deg()),
CSpeed(111, CSpeedUnit::km_h()));
CSimulatedAircraft aircraft(CCallsign("DAMBZ"), CUser("123456", "Joe Pilot"), situation);
CSimulatedAircraft aircraft(CCallsign("DAMBZ"), CUser("123456", "Joe Pilot"), CTestData::getAircraftSituationAboveMunichTower());
aircraft.setCom1System(CComSystem::getCom1System(122.8, 118.75));
aircraft.setCom2System(CComSystem::getCom2System(123.8, 124.00));
aircraft.setTransponder(CTransponder::getStandardTransponder(7000, CTransponder::ModeC));
aircraft.setIcaoCodes(CAircraftIcaoCode("B737", "L2J"), CAirlineIcaoCode("DLH"));
aircraft.setIcaoCodes(CTestData::getDBAircraftIcaoB737(), CAirlineIcaoCode("DLH"));
json = aircraft.toJson();
doc = QJsonDocument(json);
@@ -97,10 +88,7 @@ namespace BlackSample
qDebug() << "------- Enter -----";
cin.readLine();
CAtcStationList stations;
stations.push_back(station);
station.setCallsign(CCallsign("eddn_gnd"));
stations.push_back(station);
CAtcStationList stations = CTestData::getAtcStations();
json = stations.toJson();
doc.setObject(json);
qDebug() << doc.toJson(QJsonDocument::Indented);
@@ -124,5 +112,4 @@ namespace BlackSample
return 0;
}
} // namespace

View File

@@ -16,6 +16,7 @@
#include "blackmisc/test/testserviceinterface.h"
#include "blackmisc/dbusserver.h"
#include "blackmisc/network/server.h"
#include "blackmisc/test/testdata.h"
#include <stdio.h>
#include <stdlib.h>
@@ -96,7 +97,6 @@ namespace BlackSample
ITestServiceInterface testServiceInterface(CTestService::InterfaceName(), CTestService::ObjectPath(), connection);
QTextStream qtin(stdin);
QTextStream qtout(stdout);
QString line;
while (true)
{
@@ -138,17 +138,15 @@ namespace BlackSample
speed.switchUnit(CSpeedUnit::kts());
testServiceInterface.receiveSpeed(speed);
qtout << "Send speed via interface " << speed << endl;
QThread::msleep(2500);
speed.switchUnit(CSpeedUnit::km_h());
speed.addValueSameUnit(1.0);
// Network
const CServer trafficServer("fooserver", "a foo server", "localhost", 1234,
CUser("112233", "Some real name", "email@xyz.com", "secret"));
const CServer trafficServer = CTestData::getTrafficServer();
QVariant tsqv = QVariant::fromValue(trafficServer);
QDBusVariant tsv(tsqv);
testServiceInterface.receiveVariant(tsv, tsqv.userType());
qtout << "Send server via interface and variant " << trafficServer << tsqv.userType() << endl;
qtout << "Send server via interface and variant '" << trafficServer << QLatin1Literal("' ") << tsqv.userType() << endl;
// Aviation
const CComSystem comSystem = CComSystem("DBUS COM1", CPhysicalQuantitiesConstants::FrequencyInternationalAirDistress(), CPhysicalQuantitiesConstants::FrequencyUnicom());
@@ -179,59 +177,34 @@ namespace BlackSample
testServiceInterface.receiveLength(alt);
qtout << "Send altitude via interface " << alt << endl;
const CCallsign callsign("d-ambz");
const CCallsign callsign = CTestData::getRandomPilotCallsign();
testServiceInterface.receiveCallsign(callsign);
qtout << "Send callsign via interface " << callsign << endl;
CCoordinateGeodetic geoPos = CCoordinateGeodetic::fromWgs84("48° 21 13″ N", "11° 47 09″ E", { 1487, CLengthUnit::ft() }); // Munich
CAtcStation station(CCallsign("eddm_twr"), CUser("123456", "Joe Controller"),
CFrequency(118.7, CFrequencyUnit::MHz()),
geoPos, CLength(50, CLengthUnit::km()));
const CAtcStation station = CTestData::getMunichTower();
testServiceInterface.receiveAtcStation(station);
qtout << "Send ATC " << station << endl;
// Geo
// EDDF: 50° 2 0″ N, 8° 34 14″ E, 100m MSL
geoPos = CCoordinateGeodetic::fromWgs84("50° 2 1″ 23 N", "8° 34 14″ E", { 111, CLengthUnit::m() });
const CCoordinateGeodetic geoPos = CTestData::getCoordinateFrankfurtTower();
testServiceInterface.receiveGeoPosition(geoPos);
qtout << "Send geo position " << geoPos << endl;
CApplication::processEventsFor(1000);
qtout << "----------------- variant tests ----------------" << endl;
CVariantList cvList;
cvList.push_back(CVariant::fromValue(len));
cvList.push_back(CVariant::fromValue(alt));
CVariantList lengthsV;
lengthsV.push_back(CVariant::fromValue(len));
lengthsV.push_back(CVariant::fromValue(alt));
testServiceInterface.receiveLengthsQvl(cvList);
qtout << "Send lengths via interface as CVariantList" << endl;
testServiceInterface.receiveLengthsQl(lengthsV);
qtout << "Send lengths via interface as QList<CVariant>" << endl;
for (const CVariant &lv : cvList)
{
qtout << " " << "Send length in list: " << lv << endl;
}
CApplication::processEventsFor(2000);
const CVariantList cvList = CTestData::getCVariantList();
testServiceInterface.receiveVariantList(cvList);
qtout << "Send " << cvList.size() << " variants via interface as CVariantList" << endl;
// Value map
qtout << "----------------- index variant map ----------------" << endl;
CPropertyIndexVariantMap valueMap;
valueMap.addValue(1000, 111.222);
valueMap.addValue(2000, callsign);
valueMap.addValue(3000, alt);
valueMap.addValue(4000, track);
valueMap.addValue(5000, QDateTime::currentDateTime().addDays(1));
valueMap.addValue(6000, QString("foobar"));
const CPropertyIndexVariantMap valueMap = CTestData::getCPropertyIndexVariantMap();
testServiceInterface.receiveValueMap(valueMap);
qtout << "Send index variant map " << valueMap << endl;
CApplication::processEventsFor(2000);
qtout << "Send " << valueMap.size() << " index variant map entries" << endl;
CApplication::processEventsFor(1000);
qtout << "----------------- pings ----------------" << endl;
int errors = ITestServiceInterface::pingTests(testServiceInterface, false);
const int errors = ITestServiceInterface::pingTests(testServiceInterface, false);
qtout << "Ping errors " << errors << endl;
CApplication::processEventsFor(2000);
CApplication::processEventsFor(1000);
// Performance tools
qtout << "----------------- performance ----------------" << endl;
@@ -240,24 +213,24 @@ namespace BlackSample
timer.start();
for (int i = 0; i < 10; i++)
{
CSpeed speedDummy(i, CSpeedUnit::km_h());
speedDummy = testServiceInterface.getSpeed();
CSpeed speedDummy = testServiceInterface.getSpeed();
Q_UNUSED(speedDummy);
}
qint64 t10 = timer.elapsed(); // ms
timer.restart();
for (int i = 0; i < 100; i++)
{
CSpeed speedDummy(i, CSpeedUnit::km_h());
speedDummy = testServiceInterface.getSpeed();
CSpeed speedDummy = testServiceInterface.getSpeed();
Q_UNUSED(speedDummy);
}
qint64 t100 = timer.elapsed(); // ms
timer.restart();
for (int i = 0; i < 1000; i++)
{
CSpeed speedDummy(i, CSpeedUnit::km_h());
speedDummy = testServiceInterface.getSpeed();
CSpeed speedDummy = testServiceInterface.getSpeed();
Q_UNUSED(speedDummy);
}
qint64 t1000 = timer.elapsed(); // ms
timer.invalidate();
@@ -266,22 +239,22 @@ namespace BlackSample
timer.start();
for (int i = 0; i < 10; i++)
{
CAtcStation stationDummy(QString::number(i));
stationDummy = testServiceInterface.getAtcStation();
CAtcStation stationDummy = testServiceInterface.getAtcStation();
Q_UNUSED(stationDummy);
}
t10 = timer.elapsed(); // ms
timer.restart();
for (int i = 0; i < 100; i++)
{
CAtcStation stationDummy(QString::number(i));
stationDummy = testServiceInterface.getAtcStation();
CAtcStation stationDummy = testServiceInterface.getAtcStation();
Q_UNUSED(stationDummy);
}
t100 = timer.elapsed(); // ms
timer.restart();
for (int i = 0; i < 1000; i++)
{
CAtcStation stationDummy(QString::number(i));
stationDummy = testServiceInterface.getAtcStation();
CAtcStation stationDummy = testServiceInterface.getAtcStation();
Q_UNUSED(stationDummy);
}
t1000 = timer.elapsed(); // ms
qtout << "Reading station objects 10/100/1000 in ms: " << t10 << " " << t100 << " " << t1000 << endl;
@@ -326,7 +299,7 @@ namespace BlackSample
// next round?
qtout << "---------------------------------------" << endl;
qtout << "Key ....... x to exit" << endl;
line = qtin.readLine().toLower().trimmed();
QString line = qtin.readLine().toLower().trimmed();
if (line.startsWith('x'))
{
qtout << "Ending!" << endl;

View File

@@ -26,6 +26,7 @@
#include "blackmisc/pq/frequency.h"
#include "blackmisc/pq/length.h"
#include "blackmisc/pq/units.h"
#include "blackmisc/test/testdata.h"
#include "blackmisc/range.h"
#include "blackmisc/stringutils.h"
@@ -38,6 +39,7 @@ using namespace BlackMisc::Aviation;
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Geo;
using namespace BlackMisc::Network;
using namespace BlackMisc::Test;
namespace BlackSample
{
@@ -69,19 +71,11 @@ namespace BlackSample
CCallsign callsign2("DAmbz");
out << callsign1 << " " << callsign2 << " " << (callsign1 == callsign2) << endl;
QDateTime dtFrom = QDateTime::currentDateTimeUtc();
QDateTime dtUntil = dtFrom.addSecs(60 * 60); // 1 hour
QDateTime dtFrom2 = dtUntil;
QDateTime dtUntil2 = dtUntil.addSecs(60 * 60);
CCoordinateGeodetic geoPos =
CCoordinateGeodetic::fromWgs84("48° 21 13″ N", "11° 47 09″ E", { 1487, CLengthUnit::ft() });
CAtcStation station1(CCallsign("eddm_twr"), CUser("123456", "Joe Doe"),
CFrequency(118.7, CFrequencyUnit::MHz()),
geoPos, CLength(50, CLengthUnit::km()), false, dtFrom, dtUntil);
CAtcStation station1 = CTestData::getFrankfurtTower();
CAtcStation station2(station1);
CAtcStation station3(CCallsign("eddm_twr"), CUser("654321", "Jen Doe"),
CFrequency(118.7, CFrequencyUnit::MHz()),
geoPos, CLength(100, CLengthUnit::km()), false, dtFrom2, dtUntil2);
CAtcStation station3(station1);
station3.setController(CTestData::getRandomController());
out << station1 << " " << station2 << " " << (station1.getCallsign() == station2.getCallsign()) << endl;
// User parsing
@@ -89,13 +83,8 @@ namespace BlackSample
out << user.getRealName() << user.getHomeBase() << endl;
// ATC List
CAtcStationList atcList;
atcList.push_back(station1);
atcList.push_back(station2);
atcList.push_back(station3);
atcList.push_back(station1);
atcList.push_back(station2);
atcList.push_back(station3);
CAtcStationList atcList = CTestData::getAtcStations();
atcList.push_back(CTestData::getAtcStations());
atcList = atcList.findBy(&CAtcStation::getCallsign, "eddm_twr", &CAtcStation::getFrequency, CFrequency(118.7, CFrequencyUnit::MHz()));
atcList = atcList.sortedBy(&CAtcStation::getBookedFromUtc, &CAtcStation::getCallsign, &CAtcStation::getControllerRealName);
out << atcList << endl;