diff --git a/lib/kdevplatform/CMakeLists.txt b/lib/kdevplatform/CMakeLists.txt index d5d5ed3f4..68f1a2733 100644 --- a/lib/kdevplatform/CMakeLists.txt +++ b/lib/kdevplatform/CMakeLists.txt @@ -1,13 +1,12 @@ add_library(KDevTests STATIC tests/testcore.cpp tests/autotestshell.cpp) target_include_directories(KDevTests PUBLIC tests) target_link_libraries(KDevTests PUBLIC KDev::Shell #KDev::Language #KDev::Project #KDev::Debugger PRIVATE - Qt5::Test ) add_library(KDev::Tests ALIAS KDevTests) diff --git a/lib/kdevplatform/tests/testcore.cpp b/lib/kdevplatform/tests/testcore.cpp index f04d9ce83..8bd411362 100644 --- a/lib/kdevplatform/tests/testcore.cpp +++ b/lib/kdevplatform/tests/testcore.cpp @@ -1,147 +1,151 @@ /*************************************************************************** * Copyright 2008 Andreas Pakulat * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "testcore.h" #include #include #include #include #include #include #include #include #include #include #include "../shell/core_p.h" #include -#include +#include + +namespace QTest { + void qWait(int i) { QThread::msleep(i); } +} #include namespace KDevelop { TestCore::TestCore() : Core(new CorePrivate(this)) { Core::m_self = this; } TestCore* TestCore::initialize(Core::Setup mode, const QString& session) { qRegisterMetaType>("QList"); if (!Core::m_self) { new TestCore; } auto* core = qobject_cast(Core::m_self); Q_ASSERT(core); core->initializeNonStatic(mode, session); if (mode == Default) { // we don't want the window to be visible, hide it // the unit tests should work anyways core->uiController()->activeMainWindow()->hide(); } // resume the background parser when a unit test replaces the project controller QObject::connect(core->d->projectController.data(), &ProjectController::destroyed, core, [core]() { core->d->languageController->backgroundParser()->resume(); }); return core; } void TestCore::initializeNonStatic(Core::Setup mode, const QString& _session) { QString session = _session; if (_session.isEmpty()) { // use a distinct session name for unit test sessions // they are temporary (see below) but still - we want to make sure session = QLatin1String("test-") + qApp->applicationName(); } d->initialize(mode, session); if (_session.isEmpty()) { activeSession()->setTemporary(true); } } void TestCore::shutdown() { if (self()) { // trigger eventloop to handle Queued connections // before entering cleanup // this can fix random crashes under certain conditions QTest::qWait(1); self()->shutdown(); // wait until Core is deleted via event loop QTest::qWait(1); } } void TestCore::setShuttingDown(bool shuttingDown) { d->m_shuttingDown = shuttingDown; } void TestCore::setSessionController(SessionController* ctrl) { d->sessionController = ctrl; } void TestCore::setPluginController(PluginController* ctrl) { d->pluginController = ctrl; } void TestCore::setRunController(RunController* ctrl) { d->runController = ctrl; } void TestCore::setDocumentController(DocumentController* ctrl) { d->documentController = ctrl; } void TestCore::setPartController(PartController* ctrl) { d->partController = ctrl; } void TestCore::setProjectController(ProjectController* ctrl) { d->projectController = ctrl; } void TestCore::setLanguageController(LanguageController* ctrl) { d->languageController = ctrl; } void TestCore::setUiController(UiController* ctrl) { d->uiController = ctrl; } }