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"
This commit is contained in:
Klaus Basan
2016-06-15 22:26:55 +02:00
parent ef1b7b2c21
commit ce7362a9d9
4 changed files with 48 additions and 21 deletions

View File

@@ -89,6 +89,8 @@ namespace BlackCore
QCoreApplication::setApplicationName(this->m_applicationName); QCoreApplication::setApplicationName(this->m_applicationName);
QCoreApplication::setApplicationVersion(CVersion::version()); QCoreApplication::setApplicationVersion(CVersion::version());
this->setObjectName(this->m_applicationName); this->setObjectName(this->m_applicationName);
const QString executable = QFileInfo(QCoreApplication::applicationFilePath()).fileName();
if (executable.startsWith("test")) { this->m_unitTest = true; }
this->initParser(); this->initParser();
this->initLogging(); this->initLogging();
@@ -142,6 +144,7 @@ namespace BlackCore
CApplication::SwiftApplication CApplication::getSwiftApplication() const CApplication::SwiftApplication CApplication::getSwiftApplication() const
{ {
if (this->isUnitTest()) { return UnitTest; }
if (this->m_application != Unknown) { return this->m_application; } if (this->m_application != Unknown) { return this->m_application; }
// if not set, guess // if not set, guess
@@ -154,6 +157,11 @@ namespace BlackCore
return Unknown; return Unknown;
} }
bool CApplication::isUnitTest() const
{
return this->m_unitTest;
}
CGlobalSetup CApplication::getGlobalSetup() const CGlobalSetup CApplication::getGlobalSetup() const
{ {
if (this->m_shutdown) { return CGlobalSetup(); } if (this->m_shutdown) { return CGlobalSetup(); }
@@ -308,6 +316,7 @@ namespace BlackCore
bool CApplication::initIsRunningInDeveloperEnvironment() const bool CApplication::initIsRunningInDeveloperEnvironment() const
{ {
if (!CBuildConfig::canRunInDeveloperEnvironment()) { return false; } if (!CBuildConfig::canRunInDeveloperEnvironment()) { return false; }
if (this->m_unitTest) { return true; }
if (this->m_parser.isSet(this->m_cmdDevelopment)) if (this->m_parser.isSet(this->m_cmdDevelopment))
{ {
return this->isSetOrTrue(this->m_cmdDevelopment); return this->isSetOrTrue(this->m_cmdDevelopment);
@@ -543,16 +552,19 @@ namespace BlackCore
this->m_cmdHelp = this->m_parser.addHelpOption(); this->m_cmdHelp = this->m_parser.addHelpOption();
this->m_cmdVersion = this->m_parser.addVersionOption(); this->m_cmdVersion = this->m_parser.addVersionOption();
// dev. system
this->m_cmdDevelopment = QCommandLineOption({ "dev", "development" }, this->m_cmdDevelopment = QCommandLineOption({ "dev", "development" },
QCoreApplication::translate("application", "Dev.system feature?"), QCoreApplication::translate("application", "Dev.system feature?"),
"development"); "development");
this->addParserOption(this->m_cmdDevelopment); this->addParserOption(this->m_cmdDevelopment);
// can read a local bootsrap file
this->m_cmdSharedDir = QCommandLineOption({ "shared", "shareddir" }, this->m_cmdSharedDir = QCommandLineOption({ "shared", "shareddir" },
QCoreApplication::translate("application", "Local shared directory."), QCoreApplication::translate("application", "Local shared directory."),
"shared"); "shared");
this->addParserOption(this->m_cmdSharedDir); this->addParserOption(this->m_cmdSharedDir);
// reset caches upfront
this->m_cmdClearCache = QCommandLineOption({ "ccache", "clearcache" }, this->m_cmdClearCache = QCommandLineOption({ "ccache", "clearcache" },
QCoreApplication::translate("application", "Clear (reset) the caches."), QCoreApplication::translate("application", "Clear (reset) the caches."),
"clearcache"); "clearcache");

View File

@@ -86,7 +86,8 @@ namespace BlackCore
Laucher, Laucher,
PilotClientCore, PilotClientCore,
PilotClientGui, PilotClientGui,
MappingTool MappingTool,
UnitTest
}; };
//! Similar to \sa QCoreApplication::instance() returns the single instance //! Similar to \sa QCoreApplication::instance() returns the single instance
@@ -110,6 +111,9 @@ namespace BlackCore
//! swift application running //! swift application running
SwiftApplication getSwiftApplication() const; SwiftApplication getSwiftApplication() const;
//! Unit test?
bool isUnitTest() const;
//! Global setup //! Global setup
//! \threadsafe //! \threadsafe
BlackCore::Data::CGlobalSetup getGlobalSetup() const; BlackCore::Data::CGlobalSetup getGlobalSetup() const;
@@ -397,6 +401,7 @@ namespace BlackCore
bool m_useWebData = false; //!< use web data bool m_useWebData = false; //!< use web data
bool m_signalStartup = true; //!< signal startup automatically bool m_signalStartup = true; //!< signal startup automatically
bool m_devEnv = false; //!< dev. environment bool m_devEnv = false; //!< dev. environment
bool m_unitTest = false; //!< is UNIT test
}; };
} // namespace } // namespace

View File

@@ -36,7 +36,19 @@ using namespace BlackCore::Data;
namespace BlackCore namespace BlackCore
{ {
CSetupReader::CSetupReader(QObject *parent) : 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<QCommandLineOption> CSetupReader::getCmdLineOptions() const QList<QCommandLineOption> CSetupReader::getCmdLineOptions() const
@@ -132,9 +144,9 @@ namespace BlackCore
bool CSetupReader::parseCmdLineArguments() bool CSetupReader::parseCmdLineArguments()
{ {
this->m_bootstrapUrlFileValue = CGlobalSetup::buildBootstrapFileUrl( // bootstrap file URL where we can download the bootstrap file
sApp->getParserValue(this->m_cmdBootstrapUrl) const QString parserValueUrl = sApp->getParserValue(this->m_cmdBootstrapUrl);
); this->m_bootstrapUrlFileValue = CGlobalSetup::buildBootstrapFileUrl(parserValueUrl);
QUrl url(this->m_bootstrapUrlFileValue); QUrl url(this->m_bootstrapUrlFileValue);
const QString urlString(url.toString()); const QString urlString(url.toString());
this->m_bootstrapMode = stringToEnum(sApp->getParserValue(this->m_cmdBootstrapMode)); this->m_bootstrapMode = stringToEnum(sApp->getParserValue(this->m_cmdBootstrapMode));
@@ -230,6 +242,12 @@ namespace BlackCore
return Implicit; 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) bool CSetupReader::readLocalBootstrapFile(QString &fileName)
{ {
if (fileName.isEmpty()) { return false; } if (fileName.isEmpty()) { return false; }

View File

@@ -124,22 +124,11 @@ namespace BlackCore
BootstrapMode m_bootstrapMode = Explicit; //! How to bootstrap BootstrapMode m_bootstrapMode = Explicit; //! How to bootstrap
BlackMisc::Network::CFailoverUrlList m_bootstrapUrls; //!< location of setup files BlackMisc::Network::CFailoverUrlList m_bootstrapUrls; //!< location of setup files
BlackMisc::Network::CFailoverUrlList m_updateInfoUrls; //!< location of info files BlackMisc::Network::CFailoverUrlList m_updateInfoUrls; //!< location of info files
QCommandLineOption m_cmdBootstrapUrl; //!< bootstrap URL
QCommandLineOption m_cmdBootstrapMode; //!< bootstrap mode
BlackMisc::CData<BlackCore::Data::GlobalSetup> m_setup {this, &CSetupReader::ps_setupChanged}; //!< data cache setup BlackMisc::CData<BlackCore::Data::GlobalSetup> m_setup {this, &CSetupReader::ps_setupChanged}; //!< data cache setup
BlackMisc::CData<BlackCore::Data::UpdateInfo> m_updateInfo {this}; //!< data cache update info BlackMisc::CData<BlackCore::Data::UpdateInfo> 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 //! Read by local individual file and update cache from that
bool readLocalBootstrapFile(QString &fileName); bool readLocalBootstrapFile(QString &fileName);
@@ -156,6 +145,9 @@ namespace BlackCore
//! Convert string to mode //! Convert string to mode
static BootstrapMode stringToEnum(const QString &s); static BootstrapMode stringToEnum(const QString &s);
//! Bootsrap URL used for unit tests
static const QString &unitTestBootstrapUrl();
}; };
} // ns } // ns