mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 21:15:33 +08:00
140 lines
5.7 KiB
C++
140 lines
5.7 KiB
C++
/* Copyright (C) 2013
|
||
* swift project Community / Contributors
|
||
*
|
||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||
* contained in the LICENSE file.
|
||
*/
|
||
|
||
#include "blackmisc/aviation/callsign.h"
|
||
#include "blackmisc/geo/coordinategeodetic.h"
|
||
#include "blackmisc/iterator.h"
|
||
#include "blackmisc/network/user.h"
|
||
#include "blackmisc/pq/frequency.h"
|
||
#include "blackmisc/pq/length.h"
|
||
#include "blackmisc/pq/physicalquantity.h"
|
||
#include "blackmisc/pq/units.h"
|
||
#include "blackmisc/propertyindexvariantmap.h"
|
||
#include "blackmisc/sequence.h"
|
||
#include "blackmisc/variant.h"
|
||
#include "testing.h"
|
||
|
||
#include <QDateTime>
|
||
#include <QList>
|
||
#include <QStringList>
|
||
#include <QtGlobal>
|
||
#include <tuple>
|
||
|
||
using namespace BlackMisc;
|
||
using namespace BlackMisc::Aviation;
|
||
using namespace BlackMisc::Geo;
|
||
using namespace BlackMisc::Network;
|
||
using namespace BlackMisc::PhysicalQuantities;
|
||
using namespace BlackMisc::Simulation::FsCommon;
|
||
|
||
namespace BlackMisc
|
||
{
|
||
namespace Test
|
||
{
|
||
CAtcStationList CTesting::createAtcStations(int number, bool byPropertyIndex)
|
||
{
|
||
CAtcStationList atcs;
|
||
for (int i = 0; i < number; i++)
|
||
{
|
||
atcs.push_back(createStation(i, byPropertyIndex));
|
||
}
|
||
return atcs;
|
||
}
|
||
|
||
CAtcStation CTesting::createStation(int index, bool byPropertyIndex)
|
||
{
|
||
// from WGS is slow, so static const (only 1 time init)
|
||
// https://dev.vatsim-germany.org/issues/322#note-2
|
||
static const CCoordinateGeodetic geoPos = CCoordinateGeodetic::fromWgs84("48° 21′ 13″ N", "11° 47′ 09″ E", CAltitude(index, CLengthUnit::ft()));
|
||
QString cs = QString("%1_TWR").arg(index);
|
||
QString usr = QString("Joe %1").arg(index);
|
||
QString id = QString("00000%1").arg(index).right(6);
|
||
double f = 118.0 + (index % 30) * 0.25;
|
||
|
||
const QDateTime dtFrom = QDateTime::currentDateTimeUtc();
|
||
const QDateTime dtUntil = dtFrom.addSecs(60 * 60); // 1 hour
|
||
const CUser user(id, usr);
|
||
|
||
CAtcStation station;
|
||
if (byPropertyIndex)
|
||
{
|
||
station.setPropertyByIndex(CAtcStation::IndexCallsign, CVariant::from(CCallsign(cs)));
|
||
station.setPropertyByIndex(CAtcStation::IndexController, CVariant::from(user));
|
||
station.setPropertyByIndex(CAtcStation::IndexFrequency, CVariant::from(CFrequency(f, CFrequencyUnit::MHz())));
|
||
station.setPropertyByIndex(CAtcStation::IndexRange, CVariant::from(CLength(50, CLengthUnit::km())));
|
||
station.setPropertyByIndex(CAtcStation::IndexPosition, CVariant::from(geoPos));
|
||
station.setPropertyByIndex(CAtcStation::IndexIsOnline, CVariant::from(false));
|
||
station.setPropertyByIndex(CAtcStation::IndexBookedFrom, CVariant::from(dtFrom));
|
||
station.setPropertyByIndex(CAtcStation::IndexBookedUntil, CVariant::from(dtUntil));
|
||
station.setPropertyByIndex(CAtcStation::IndexRelativeDistance, CVariant::from(CLength(index + 1, CLengthUnit::NM())));
|
||
}
|
||
else
|
||
{
|
||
station = CAtcStation(CCallsign(cs), user,
|
||
CFrequency(f, CFrequencyUnit::MHz()),
|
||
geoPos, CLength(50, CLengthUnit::km()), false, dtFrom, dtUntil);
|
||
station.setRelativeDistance(CLength(index + 1, CLengthUnit::NM()));
|
||
}
|
||
|
||
station.setVoiceRoomUrl("vvl://foo.bar.baz/room" + QString::number(index));
|
||
return station;
|
||
}
|
||
|
||
CAircraftCfgEntriesList CTesting::getAircraftCfgEntries(int number)
|
||
{
|
||
CAircraftCfgEntriesList list;
|
||
for (int i = 0; i < number; i++)
|
||
{
|
||
CAircraftCfgEntries e;
|
||
e.setAtcModel("atc model");
|
||
e.setAtcParkingCode(QString::number(i));
|
||
e.setIndex(i);
|
||
e.setFileName("this will be the file path and pretty long");
|
||
e.setTitle("I am the aircraft title foobar");
|
||
e.setAtcType("B737");
|
||
list.push_back(e);
|
||
}
|
||
return list;
|
||
}
|
||
|
||
CAirportList CTesting::getAirports(int number)
|
||
{
|
||
BlackMisc::Aviation::CAirportList list;
|
||
for (int i = 0; i < number; i++)
|
||
{
|
||
const char cc = 65 + (i % 26);
|
||
QString icao = QString("EXX%1").arg(QLatin1Char(cc));
|
||
BlackMisc::Aviation::CAirport a(icao);
|
||
a.setPosition(CCoordinateGeodetic(i, i, i));
|
||
list.push_back(a);
|
||
}
|
||
return list;
|
||
}
|
||
|
||
CClientList CTesting::getClients(int number)
|
||
{
|
||
BlackMisc::Network::CClientList list;
|
||
for (int i = 0; i < number; i++)
|
||
{
|
||
CCallsign cs(QString("DXX%1").arg(i));
|
||
QString rn = QString("Joe Doe%1").arg(i);
|
||
CUser user(QString::number(i), rn, cs);
|
||
user.setCallsign(cs);
|
||
CClient client(user);
|
||
client.setCapability(true, CClient::FsdWithInterimPositions);
|
||
client.setCapability(true, CClient::FsdWithIcaoCodes);
|
||
const QString myFooModel = QString("fooModel %1").arg(i);
|
||
client.setQueriedModelString(myFooModel);
|
||
list.push_back(client);
|
||
}
|
||
return list;
|
||
}
|
||
} // namespace
|
||
} // namespace
|