forked from qt-creator/qt-creator
Introduce Utils::Singleton
Introduce Utils::Singleton class and Utils::SingletonWithOptionalDependencies class template that helps implementing singletons that depend on other singletons. It's guaranteed that whenever singleton B depends on singleton A, than A is always created before B is being created, and that the order of destruction is always opposite to the order of creation. Dependencies of singleton are listed as template arguments for SingletonWithOptionalDependencies class template. The first argument of SingletonWithOptionalDependencies class template is always a singleton class itself. Prepare a common interface for all singleton subclasses: SingletonSubClass *SingletonWithOptionalDependencies::instance(); Make instantiating singletons and its dependencies thread-safe. Create singletons on demand (only if some code needs them). It's not needed anymore to explicitly instantiate all required singletons in tests. Make it possible (and thread-safe) to instantiate ProcessReaper and LauncherInterface singletons in non-main threads. Make the following dependencies between existing singletons: SshConnectionManager depends on: -> LauncherInterface depends on: -> ProcessReaper Change-Id: Iefaacab561c2b3dcf07e7fafbb87339ea6a15278 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -30,7 +30,7 @@
|
||||
|
||||
#include <sqliteglobal.h>
|
||||
#include <utils/launcherinterface.h>
|
||||
#include <utils/processreaper.h>
|
||||
#include <utils/singleton.h>
|
||||
#include <utils/temporarydirectory.h>
|
||||
|
||||
#include <QGuiApplication>
|
||||
@@ -61,10 +61,8 @@ int main(int argc, char *argv[])
|
||||
Sqlite::Database::activateLogging();
|
||||
|
||||
QGuiApplication application(argc, argv);
|
||||
Utils::ProcessReaper processReaper;
|
||||
Utils::LauncherInterface::startLauncher(qApp->applicationDirPath() + '/'
|
||||
+ QLatin1String(TEST_RELATIVE_LIBEXEC_PATH));
|
||||
auto cleanup = qScopeGuard([] { Utils::LauncherInterface::stopLauncher(); });
|
||||
Utils::LauncherInterface::setPathToLauncher(qApp->applicationDirPath() + '/'
|
||||
+ QLatin1String(TEST_RELATIVE_LIBEXEC_PATH));
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
#ifdef WITH_BENCHMARKS
|
||||
benchmark::Initialize(&argc, argv);
|
||||
@@ -75,6 +73,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
int testsHaveErrors = RUN_ALL_TESTS();
|
||||
|
||||
Utils::Singleton::deleteAll();
|
||||
#ifdef WITH_BENCHMARKS
|
||||
if (testsHaveErrors == 0 && application.arguments().contains(QStringLiteral("--with-benchmarks")))
|
||||
benchmark::RunSpecifiedBenchmarks();
|
||||
|
||||
Reference in New Issue
Block a user