summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cpptoolstestcase.cpp
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@theqtcompany.com>2015-04-13 17:41:17 +0200
committerNikolai Kosjar <nikolai.kosjar@theqtcompany.com>2015-04-14 07:58:23 +0000
commit05e0b074c1dbfef8aac7e719e3ab23c7916288ac (patch)
tree8e1a0260b907c7ac9a9d14ab81e169fd6e1af11f /src/plugins/cpptools/cpptoolstestcase.cpp
parent315585056b961d5b84132df190eca6f09c912189 (diff)
downloadqt-creator-05e0b074c1dbfef8aac7e719e3ab23c7916288ac.tar.gz
CppTools: Tests: Clean up ProjectOpenerAndCloser and introduce timeout
Change-Id: Id46305a7e9fba1d8383622a4d21f22ee8cbc470c Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
Diffstat (limited to 'src/plugins/cpptools/cpptoolstestcase.cpp')
-rw-r--r--src/plugins/cpptools/cpptoolstestcase.cpp38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/plugins/cpptools/cpptoolstestcase.cpp b/src/plugins/cpptools/cpptoolstestcase.cpp
index 4d0627faa1..5aebd87428 100644
--- a/src/plugins/cpptools/cpptoolstestcase.cpp
+++ b/src/plugins/cpptools/cpptoolstestcase.cpp
@@ -41,6 +41,7 @@
#include <texteditor/codeassist/iassistproposalmodel.h>
#include <cplusplus/CppDocument.h>
+#include <utils/executeondestruction.h>
#include <utils/fileutils.h>
#include <QtTest>
@@ -228,27 +229,30 @@ bool TestCase::writeFile(const QString &filePath, const QByteArray &contents)
return true;
}
-ProjectOpenerAndCloser::ProjectOpenerAndCloser(bool waitForFinishedGcOnDestruction)
- : m_waitForFinishedGcOnDestruction(waitForFinishedGcOnDestruction)
- , m_gcFinished(false)
+ProjectOpenerAndCloser::ProjectOpenerAndCloser()
{
QVERIFY(!SessionManager::hasProjects());
- if (m_waitForFinishedGcOnDestruction) {
- CppModelManager *mm = CppModelManager::instance();
- connect(mm, &CppModelManager::gcFinished, this, &ProjectOpenerAndCloser::onGcFinished);
- }
}
ProjectOpenerAndCloser::~ProjectOpenerAndCloser()
{
+ if (m_openProjects.isEmpty())
+ return;
+
+ bool hasGcFinished = false;
+ QMetaObject::Connection connection;
+ Utils::ExecuteOnDestruction disconnect([&]() { QObject::disconnect(connection); });
+ connection = QObject::connect(CppModelManager::instance(), &CppModelManager::gcFinished, [&]() {
+ hasGcFinished = true;
+ });
+
foreach (Project *project, m_openProjects)
ProjectExplorerPlugin::unloadProject(project);
- if (m_waitForFinishedGcOnDestruction) {
- m_gcFinished = false;
- while (!m_gcFinished)
- QCoreApplication::processEvents();
- }
+ QTime t;
+ t.start();
+ while (!hasGcFinished && t.elapsed() <= 30000)
+ QCoreApplication::processEvents();
}
ProjectInfo ProjectOpenerAndCloser::open(const QString &projectFile, bool configureAsExampleProject)
@@ -259,22 +263,18 @@ ProjectInfo ProjectOpenerAndCloser::open(const QString &projectFile, bool config
qWarning() << error;
if (!project)
return ProjectInfo();
- m_openProjects.append(project);
if (configureAsExampleProject)
project->configureAsExampleProject(QStringList());
- if (TestCase::waitUntilCppModelManagerIsAwareOf(project))
+ if (TestCase::waitUntilCppModelManagerIsAwareOf(project)) {
+ m_openProjects.append(project);
return CppModelManager::instance()->projectInfo(project);
+ }
return ProjectInfo();
}
-void ProjectOpenerAndCloser::onGcFinished()
-{
- m_gcFinished = true;
-}
-
TemporaryDir::TemporaryDir()
: m_temporaryDir(QFileInfo(QDir::tempPath()).canonicalFilePath()
+ QLatin1String("/qtcreator-tests-XXXXXX"))