mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
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:
@@ -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");
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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<QCommandLineOption> 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; }
|
||||
|
||||
@@ -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<BlackCore::Data::GlobalSetup> m_setup {this, &CSetupReader::ps_setupChanged}; //!< data cache setup
|
||||
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
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user