From ce7362a9d9f5b1613fe2c3024089e756ef9f3502 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 15 Jun 2016 22:26:55 +0200 Subject: [PATCH] refs #675 default URL for bootstrap file * CApplication now has member function isUnitTest * bootstrap URL has hardcoded default URL when running as unit test * unit tests are automatically marked as "running in dev. environment" --- src/blackcore/application.cpp | 18 +++++++++++++++--- src/blackcore/application.h | 7 ++++++- src/blackcore/setupreader.cpp | 26 ++++++++++++++++++++++---- src/blackcore/setupreader.h | 18 +++++------------- 4 files changed, 48 insertions(+), 21 deletions(-) diff --git a/src/blackcore/application.cpp b/src/blackcore/application.cpp index 9337feedd..0c640a7ea 100644 --- a/src/blackcore/application.cpp +++ b/src/blackcore/application.cpp @@ -89,6 +89,8 @@ namespace BlackCore QCoreApplication::setApplicationName(this->m_applicationName); QCoreApplication::setApplicationVersion(CVersion::version()); this->setObjectName(this->m_applicationName); + const QString executable = QFileInfo(QCoreApplication::applicationFilePath()).fileName(); + if (executable.startsWith("test")) { this->m_unitTest = true; } this->initParser(); this->initLogging(); @@ -142,6 +144,7 @@ namespace BlackCore CApplication::SwiftApplication CApplication::getSwiftApplication() const { + if (this->isUnitTest()) { return UnitTest; } if (this->m_application != Unknown) { return this->m_application; } // if not set, guess @@ -154,6 +157,11 @@ namespace BlackCore return Unknown; } + bool CApplication::isUnitTest() const + { + return this->m_unitTest; + } + CGlobalSetup CApplication::getGlobalSetup() const { if (this->m_shutdown) { return CGlobalSetup(); } @@ -308,6 +316,7 @@ namespace BlackCore bool CApplication::initIsRunningInDeveloperEnvironment() const { if (!CBuildConfig::canRunInDeveloperEnvironment()) { return false; } + if (this->m_unitTest) { return true; } if (this->m_parser.isSet(this->m_cmdDevelopment)) { return this->isSetOrTrue(this->m_cmdDevelopment); @@ -529,9 +538,9 @@ namespace BlackCore // File logger static const QString logPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + - "/org.swift-project/" + - CDirectoryUtils::normalizedApplicationDirectory() + - "/logs"; + "/org.swift-project/" + + CDirectoryUtils::normalizedApplicationDirectory() + + "/logs"; this->m_fileLogger.reset(new CFileLogger(executable(), logPath)); this->m_fileLogger->changeLogPattern(CLogPattern().withSeverityAtOrAbove(CStatusMessage::SeverityDebug)); } @@ -543,16 +552,19 @@ namespace BlackCore this->m_cmdHelp = this->m_parser.addHelpOption(); this->m_cmdVersion = this->m_parser.addVersionOption(); + // dev. system this->m_cmdDevelopment = QCommandLineOption({ "dev", "development" }, QCoreApplication::translate("application", "Dev.system feature?"), "development"); this->addParserOption(this->m_cmdDevelopment); + // can read a local bootsrap file this->m_cmdSharedDir = QCommandLineOption({ "shared", "shareddir" }, QCoreApplication::translate("application", "Local shared directory."), "shared"); this->addParserOption(this->m_cmdSharedDir); + // reset caches upfront this->m_cmdClearCache = QCommandLineOption({ "ccache", "clearcache" }, QCoreApplication::translate("application", "Clear (reset) the caches."), "clearcache"); diff --git a/src/blackcore/application.h b/src/blackcore/application.h index 66eabcf92..27e9d17b0 100644 --- a/src/blackcore/application.h +++ b/src/blackcore/application.h @@ -86,7 +86,8 @@ namespace BlackCore Laucher, PilotClientCore, PilotClientGui, - MappingTool + MappingTool, + UnitTest }; //! Similar to \sa QCoreApplication::instance() returns the single instance @@ -110,6 +111,9 @@ namespace BlackCore //! swift application running SwiftApplication getSwiftApplication() const; + //! Unit test? + bool isUnitTest() const; + //! Global setup //! \threadsafe BlackCore::Data::CGlobalSetup getGlobalSetup() const; @@ -397,6 +401,7 @@ namespace BlackCore bool m_useWebData = false; //!< use web data bool m_signalStartup = true; //!< signal startup automatically bool m_devEnv = false; //!< dev. environment + bool m_unitTest = false; //!< is UNIT test }; } // namespace diff --git a/src/blackcore/setupreader.cpp b/src/blackcore/setupreader.cpp index 28a44a6ca..62f366e83 100644 --- a/src/blackcore/setupreader.cpp +++ b/src/blackcore/setupreader.cpp @@ -36,7 +36,19 @@ using namespace BlackCore::Data; namespace BlackCore { CSetupReader::CSetupReader(QObject *parent) : - QObject(parent) + QObject(parent), + m_cmdBootstrapUrl + { + { "url", "bootstrapurl" }, + QCoreApplication::translate("application", "bootstrap URL, e.g. datastore.swift-project.org"), + "bootstrapurl", (sApp->isUnitTest()) ? unitTestBootstrapUrl() : "" + }, + m_cmdBootstrapMode + { + { "bmode", "bootstrapmode" }, + QCoreApplication::translate("application", "bootstrap mode: explicit, implicit, cache(-only)"), + "bootstrapmode", "explicit" + } { } QList CSetupReader::getCmdLineOptions() const @@ -132,9 +144,9 @@ namespace BlackCore bool CSetupReader::parseCmdLineArguments() { - this->m_bootstrapUrlFileValue = CGlobalSetup::buildBootstrapFileUrl( - sApp->getParserValue(this->m_cmdBootstrapUrl) - ); + // bootstrap file URL where we can download the bootstrap file + const QString parserValueUrl = sApp->getParserValue(this->m_cmdBootstrapUrl); + this->m_bootstrapUrlFileValue = CGlobalSetup::buildBootstrapFileUrl(parserValueUrl); QUrl url(this->m_bootstrapUrlFileValue); const QString urlString(url.toString()); this->m_bootstrapMode = stringToEnum(sApp->getParserValue(this->m_cmdBootstrapMode)); @@ -230,6 +242,12 @@ namespace BlackCore return Implicit; } + const QString &CSetupReader::unitTestBootstrapUrl() + { + static const QString url("https://vatsim-germany.org:50443/mapping/public/shared"); + return url; + } + bool CSetupReader::readLocalBootstrapFile(QString &fileName) { if (fileName.isEmpty()) { return false; } diff --git a/src/blackcore/setupreader.h b/src/blackcore/setupreader.h index fb27aca9f..575a21f67 100644 --- a/src/blackcore/setupreader.h +++ b/src/blackcore/setupreader.h @@ -124,22 +124,11 @@ namespace BlackCore BootstrapMode m_bootstrapMode = Explicit; //! How to bootstrap BlackMisc::Network::CFailoverUrlList m_bootstrapUrls; //!< location of setup files BlackMisc::Network::CFailoverUrlList m_updateInfoUrls; //!< location of info files + QCommandLineOption m_cmdBootstrapUrl; //!< bootstrap URL + QCommandLineOption m_cmdBootstrapMode; //!< bootstrap mode BlackMisc::CData m_setup {this, &CSetupReader::ps_setupChanged}; //!< data cache setup BlackMisc::CData m_updateInfo {this}; //!< data cache update info - QCommandLineOption m_cmdBootstrapUrl - { - { "url", "bootstrapurl" }, - QCoreApplication::translate("application", "bootstrap URL, e.g. datastore.swift-project.org"), - "bootstrapurl" - }; //!< bootstrap URL - QCommandLineOption m_cmdBootstrapMode - { - { "bmode", "bootstrapmode" }, - QCoreApplication::translate("application", "bootstrap mode: explicit, implicit, cache(-only)"), - "bootstrapmode", "explicit" - }; //!< bootstrap mode - //! Read by local individual file and update cache from that bool readLocalBootstrapFile(QString &fileName); @@ -156,6 +145,9 @@ namespace BlackCore //! Convert string to mode static BootstrapMode stringToEnum(const QString &s); + + //! Bootsrap URL used for unit tests + static const QString &unitTestBootstrapUrl(); }; } // ns