Merge branch 'fsd' of git@dev.vatsim-germany.org:vatpilotclient/client.git into fsd

This commit is contained in:
gmt2001
2013-08-24 09:42:29 -04:00
8 changed files with 365 additions and 2 deletions

View File

@@ -0,0 +1,39 @@
/* Copyright (C) 2013 VATSIM Community / authors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "atclistmgr.h"
#include "network.h"
BlackCore::CAtcListManager::CAtcListManager(const BlackCoreTest::EnableTesting&)
{
}
BlackCore::CAtcListManager::CAtcListManager()
{
INetwork *net = BlackMisc::IContext::getInstance().singleton<INetwork>();
connect(net, &INetwork::atcPositionUpdate, this, &CAtcListManager::update, Qt::QueuedConnection);
connect(net, &INetwork::atcDisconnected, this, &CAtcListManager::remove, Qt::QueuedConnection);
connect(net, &INetwork::connectionStatusDisconnected, this, &CAtcListManager::clear, Qt::QueuedConnection);
}
void BlackCore::CAtcListManager::update(const QString& callsign, const BlackMisc::PhysicalQuantities::CFrequency& freq,
const BlackMisc::Geo::CCoordinateGeodetic& pos, const BlackMisc::PhysicalQuantities::CLength& range)
{
m_list.insert(BlackMisc::CAtcListEntry(callsign, freq, pos, range));
emit listChanged(m_list);
}
void BlackCore::CAtcListManager::remove(const QString& callsign)
{
m_list.remove(callsign);
emit listChanged(m_list);
}
void BlackCore::CAtcListManager::clear()
{
m_list.clear();
emit listChanged(m_list);
}

View File

@@ -0,0 +1,95 @@
/* Copyright (C) 2013 VATSIM Community / authors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*!
\file
*/
#ifndef BLACKCORE_ATCLISTMGR_H
#define BLACKCORE_ATCLISTMGR_H
#include "blackmisc/atclist.h"
#include <QObject>
namespace BlackCoreTest
{
class EnableTesting;
}
namespace BlackCore
{
/*!
* Abstract base class that manages and provides access to a list of available ATC stations.
*/
class IAtcListManager : public QObject
{
Q_OBJECT
Q_PROPERTY(BlackMisc::CAtcList list READ getList NOTIFY listChanged)
public:
BLACK_INTERFACE(BlackCore::IAtcListManager)
/*!
* Virtual destructor.
*/
virtual ~IAtcListManager() {}
/*!
* Immutable getter.
* \return
*/
virtual const BlackMisc::CAtcList &getList() const = 0;
signals:
/*!
* Emitted whenever there is a change in the ATC list.
* \param list The new list
*/
void listChanged(const BlackMisc::CAtcList &list);
};
/*!
* Concrete ATC list manager. Implementation of IAtcListManager.
*
* Has a dependency on INetwork. An INetwork must be available through the IContext singleton.
*/
class CAtcListManager : public IAtcListManager
{
Q_OBJECT
public:
/*!
* Constructor.
*/
CAtcListManager();
virtual const BlackMisc::CAtcList& getList() const { return m_list; }
public slots:
/*!
* CAtcListManager is responsible for connecting these slots.
* \{
*/
void update(const QString& callsign, const BlackMisc::PhysicalQuantities::CFrequency& freq,
const BlackMisc::Geo::CCoordinateGeodetic& pos, const BlackMisc::PhysicalQuantities::CLength& range);
void remove(const QString& callsign);
void clear();
/*! \} */
public:
/*!
* Constructor that does not connect INetwork signals to CAtcListManager slots.
* \warning Only used for testing purposes.
*/
explicit CAtcListManager(const BlackCoreTest::EnableTesting&);
private:
BlackMisc::CAtcList m_list;
};
}//namespace BlackCore
#endif //BLACKCORE_ATCLISTMGR_H

View File

@@ -514,7 +514,7 @@ namespace BlackCore
case Cvatlib_Network::error_CallsignTaken: qCritical() << "The requested callsign is already taken"; goto terminate;
case Cvatlib_Network::error_CallsignInvalid: qCritical() << "The requested callsign is not valid"; goto terminate;
case Cvatlib_Network::error_CIDPasswdInvalid: qCritical() << "Wrong user ID or password"; goto terminate;
case Cvatlib_Network::error_ProtoVersion: qCritical() << "This server uses an unsupported protocol version"; goto terminate;
case Cvatlib_Network::error_ProtoVersion: qCritical() << "This server does not support our protocol version"; goto terminate;
case Cvatlib_Network::error_LevelTooHigh: qCritical() << "You are not authorized to use the requested pilot rating"; goto terminate;
case Cvatlib_Network::error_ServerFull: qCritical() << "The server is full"; goto terminate;
case Cvatlib_Network::error_CIDSuspended: qCritical() << "Your user account is suspended"; goto terminate;

111
src/blackmisc/atclist.h Normal file
View File

@@ -0,0 +1,111 @@
/* Copyright (C) 2013 VATSIM Community / authors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*!
\file
*/
#ifndef BLACKMISC_ATCLIST_H
#define BLACKMISC_ATCLIST_H
#include "pqfrequency.h"
#include "pqlength.h"
#include "coordinategeodetic.h"
#include "context.h"
#include <QObject>
#include <QString>
#include <QMap>
namespace BlackMisc
{
/*!
* Value object encapsulating information about an ATC station.
*/
class CAtcListEntry
{
public:
/*!
* Default constructor.
*/
CAtcListEntry() {}
/*!
* Constructor.
*/
CAtcListEntry(const QString &callsign, const BlackMisc::PhysicalQuantities::CFrequency &freq,
const BlackMisc::Geo::CCoordinateGeodetic &pos, const BlackMisc::PhysicalQuantities::CLength &range)
: m_callsign(callsign), m_freq(freq), m_pos(pos), m_range(range)
{}
/*!
* Get callsign.
* \return
*/
const QString &getCallsign() const { return m_callsign; }
/*!
* Get frequency.
* \return
*/
const BlackMisc::PhysicalQuantities::CFrequency &getFrequency() const { return m_freq; }
/*!
* Get the position of the center of the controller's area of visibility.
* \return
*/
const BlackMisc::Geo::CCoordinateGeodetic &getPosition() const { return m_pos; }
/*!
* Get the radius of the controller's area of visibility.
* \return
*/
const BlackMisc::PhysicalQuantities::CLength &getAtcRange() const { return m_range; }
private:
QString m_callsign;
BlackMisc::PhysicalQuantities::CFrequency m_freq;
BlackMisc::Geo::CCoordinateGeodetic m_pos;
BlackMisc::PhysicalQuantities::CLength m_range;
};
/*!
* Value object encapsulating a list of ATC stations.
*/
class CAtcList
{
public:
/*!
* Immutable getter for the internal map.
* \return
*/
const QMap<QString, CAtcListEntry> &constMap() const { return m_map; }
/*!
* Insert an ATC station into the list.
* \param entry
*/
void insert(const CAtcListEntry &entry) { m_map.insert(entry.getCallsign(), entry); }
/*!
* Remove an ATC station from the list.
* \param callsign
*/
void remove(const QString &callsign) { m_map.remove(callsign); }
/*!
* Remove all ATC stations from the list.
*/
void clear() { m_map.clear(); }
private:
QMap<QString, CAtcListEntry> m_map;
};
} //namespace BlackMisc
Q_DECLARE_METATYPE(BlackMisc::CAtcList)
#endif //BLACKMISC_ATCLIST_H

View File

@@ -7,10 +7,18 @@
#define BLACKCORETEST_H
/*!
* @namespace BlackCoreTest
* \namespace BlackCoreTest
* Unit tests for BlackCore. Unit tests do have their own namespace, so
* the regular namespace BlackCore is completely free of unit tests.
* Add any new tests to TestMain::unitMain as shown there.
*/
namespace BlackCoreTest
{
/*!
* An "option type" used to alter the construction of objects under test.
*/
class EnableTesting {};
}
#endif // guard

View File

@@ -5,6 +5,7 @@
#include "testblackcoremain.h"
#include "testinterpolator.h"
#include "testnetmediators.h"
namespace BlackCoreTest
{
@@ -19,6 +20,10 @@ int CBlackCoreTestMain::unitMain(int argc, char *argv[])
CTestInterpolator interpolatorTests;
status |= QTest::qExec(&interpolatorTests, argc, argv);
}
{
CTestNetMediators mediatorTests;
status |= QTest::qExec(&mediatorTests, argc, argv);
}
return status;
}
} // namespace

View File

@@ -0,0 +1,44 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "testnetmediators.h"
#include <QObject>
namespace BlackCoreTest
{
using namespace BlackCore;
using namespace BlackMisc;
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Geo;
void CTestNetMediators::atcListManagerTest()
{
CAtcListManager mgr ( (EnableTesting()) ); //extra pair of parentheses to disambiguate most vexing parse
AtcListConsumer cons;
QObject::connect(&mgr, &IAtcListManager::listChanged, &cons, &AtcListConsumer::listChanged);
QVERIFY(cons.m_list.constMap().size() == 0);
mgr.update("EGLL_TWR", CFrequency(118.7, CFrequencyUnit::MHz()), CCoordinateGeodetic(51.4775, 0.46139, 0), CLength(50, CLengthUnit::m()));
QVERIFY(cons.m_list.constMap().size() == 1);
mgr.update("EGLL_GND", CFrequency(121.9, CFrequencyUnit::MHz()), CCoordinateGeodetic(51.4775, 0.46139, 0), CLength(20, CLengthUnit::m()));
QVERIFY(cons.m_list.constMap().size() == 2);
mgr.update("EGLL_TWR", CFrequency(118.5, CFrequencyUnit::MHz()), CCoordinateGeodetic(51.4775, 0.46139, 0), CLength(50, CLengthUnit::m()));
QVERIFY(cons.m_list.constMap().size() == 2);
mgr.remove("EGLL_TWR");
QVERIFY(cons.m_list.constMap().size() == 1);
mgr.clear();
QVERIFY(cons.m_list.constMap().size() == 0);
mgr.update("EGLL_TWR", CFrequency(118.5, CFrequencyUnit::MHz()), CCoordinateGeodetic(51.4775, 0.46139, 0), CLength(50, CLengthUnit::m()));
QVERIFY(cons.m_list.constMap().contains("EGLL_TWR"));
QVERIFY(cons.m_list.constMap()["EGLL_TWR"].getCallsign() == "EGLL_TWR");
QVERIFY(cons.m_list.constMap()["EGLL_TWR"].getFrequency() == CFrequency(118.5, CFrequencyUnit::MHz()));
QVERIFY(cons.m_list.constMap()["EGLL_TWR"].getPosition() == CCoordinateGeodetic(51.4775, 0.46139, 0));
QVERIFY(cons.m_list.constMap()["EGLL_TWR"].getAtcRange() == CLength(50, CLengthUnit::m()));
}
} //namespace BlackCoreTest

View File

@@ -0,0 +1,61 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef BLACKCORETEST_TESTNETMEDIATORS_H
#define BLACKCORETEST_TESTNETMEDIATORS_H
#include "blackcore/atclistmgr.h"
#include "blackcoretest.h"
#include <QtTest/QtTest>
namespace BlackCoreTest
{
/*!
* Network mediator classes tests
*/
class CTestNetMediators : public QObject
{
Q_OBJECT
public:
/*!
* Constructor.
* \param parent
*/
explicit CTestNetMediators(QObject *parent = 0) : QObject(parent) {}
private slots:
/*!
* Test CAtcListManager
*/
void atcListManagerTest();
};
/*!
* Helper class that connects to CAtcListManager signals
*/
class AtcListConsumer : public QObject
{
Q_OBJECT
public:
//! List is updated by the slot
BlackMisc::CAtcList m_list;
public slots:
/*!
* Slot updates the list
* \param list
*/
void listChanged(const BlackMisc::CAtcList &list)
{
m_list = list;
}
};
} //namespace BlackCoreTest
#endif //BLACKCORETEST_TESTNETMEDIATORS_H