From eade49799b67a177a32bbecc97eb718e4889bb7c Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Fri, 9 Aug 2013 00:49:12 +0100 Subject: [PATCH 1/2] corrected error message --- src/blackcore/network_vatlib.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blackcore/network_vatlib.cpp b/src/blackcore/network_vatlib.cpp index 3c3e5de13..367a86156 100644 --- a/src/blackcore/network_vatlib.cpp +++ b/src/blackcore/network_vatlib.cpp @@ -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; From e194773c5bb56573cdc1c0de7fed4c3efa4f108c Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Fri, 9 Aug 2013 00:55:46 +0100 Subject: [PATCH 2/2] CAtcListManager class --- src/blackcore/atclistmgr.cpp | 39 +++++++++ src/blackcore/atclistmgr.h | 95 ++++++++++++++++++++++ src/blackmisc/atclist.h | 111 ++++++++++++++++++++++++++ tests/blackcore/blackcoretest.h | 10 ++- tests/blackcore/testblackcoremain.cpp | 5 ++ tests/blackcore/testnetmediators.cpp | 44 ++++++++++ tests/blackcore/testnetmediators.h | 61 ++++++++++++++ 7 files changed, 364 insertions(+), 1 deletion(-) create mode 100644 src/blackcore/atclistmgr.cpp create mode 100644 src/blackcore/atclistmgr.h create mode 100644 src/blackmisc/atclist.h create mode 100644 tests/blackcore/testnetmediators.cpp create mode 100644 tests/blackcore/testnetmediators.h diff --git a/src/blackcore/atclistmgr.cpp b/src/blackcore/atclistmgr.cpp new file mode 100644 index 000000000..5a0a67528 --- /dev/null +++ b/src/blackcore/atclistmgr.cpp @@ -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(); + + 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); +} \ No newline at end of file diff --git a/src/blackcore/atclistmgr.h b/src/blackcore/atclistmgr.h new file mode 100644 index 000000000..9079b9ba4 --- /dev/null +++ b/src/blackcore/atclistmgr.h @@ -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 + +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 \ No newline at end of file diff --git a/src/blackmisc/atclist.h b/src/blackmisc/atclist.h new file mode 100644 index 000000000..f6f14a145 --- /dev/null +++ b/src/blackmisc/atclist.h @@ -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 +#include +#include + +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 &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 m_map; + }; + +} //namespace BlackMisc + +Q_DECLARE_METATYPE(BlackMisc::CAtcList) + +#endif //BLACKMISC_ATCLIST_H \ No newline at end of file diff --git a/tests/blackcore/blackcoretest.h b/tests/blackcore/blackcoretest.h index 87965024d..825995de7 100644 --- a/tests/blackcore/blackcoretest.h +++ b/tests/blackcore/blackcoretest.h @@ -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 diff --git a/tests/blackcore/testblackcoremain.cpp b/tests/blackcore/testblackcoremain.cpp index 82468ac72..4e1251dea 100644 --- a/tests/blackcore/testblackcoremain.cpp +++ b/tests/blackcore/testblackcoremain.cpp @@ -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 diff --git a/tests/blackcore/testnetmediators.cpp b/tests/blackcore/testnetmediators.cpp new file mode 100644 index 000000000..6a2c765a2 --- /dev/null +++ b/tests/blackcore/testnetmediators.cpp @@ -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 + +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 \ No newline at end of file diff --git a/tests/blackcore/testnetmediators.h b/tests/blackcore/testnetmediators.h new file mode 100644 index 000000000..210eff6c7 --- /dev/null +++ b/tests/blackcore/testnetmediators.h @@ -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 + +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 \ No newline at end of file