diff options
author | Nikolai Kosjar <nikolai.kosjar@digia.com> | 2013-12-17 13:54:52 +0100 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@digia.com> | 2014-01-07 14:19:43 +0100 |
commit | 746da71527c2bd62e216e6727e6763ab7cda1c95 (patch) | |
tree | e07a53b19b653f31272411e32afca343491a318d | |
parent | 0bd59178679ea1f573b484e5f2baf178352c44ef (diff) | |
download | qt-creator-746da71527c2bd62e216e6727e6763ab7cda1c95.tar.gz |
CppEditor/CppTools: Avoid triggering garbage collector on editor close in tests
Closing an editor might trigger a timer which leads to the invocation of
the garbage collector. This is unfavourable for the plugin tests since a
test function closing an editor might influence a subsequent test
function (e.g. files get removed from the global snapshot although they
were added shortly before).
Change-Id: Ia80c11f99e2437fe145dc2d983b21962539b5181
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
-rw-r--r-- | src/plugins/cpptools/cpplocatorfilter_test.cpp | 2 | ||||
-rw-r--r-- | src/plugins/cpptools/cppmodelmanager.cpp | 9 | ||||
-rw-r--r-- | src/plugins/cpptools/cppmodelmanager.h | 2 | ||||
-rw-r--r-- | src/plugins/cpptools/cppmodelmanager_test.cpp | 3 | ||||
-rw-r--r-- | src/plugins/cpptools/cppmodelmanagerinterface.h | 1 | ||||
-rw-r--r-- | src/plugins/cpptools/cpptoolstestcase.cpp | 15 | ||||
-rw-r--r-- | src/plugins/cpptools/cpptoolstestcase.h | 2 |
7 files changed, 30 insertions, 4 deletions
diff --git a/src/plugins/cpptools/cpplocatorfilter_test.cpp b/src/plugins/cpptools/cpplocatorfilter_test.cpp index 9280fbcb72..fb30d4a1b7 100644 --- a/src/plugins/cpptools/cpplocatorfilter_test.cpp +++ b/src/plugins/cpptools/cpplocatorfilter_test.cpp @@ -126,7 +126,7 @@ private: void doAfterLocatorRun() { - EditorManager::closeEditor(m_editor, /*askAboutModifiedEditors=*/ false); + QVERIFY(closeEditorWithoutGarbageCollectorInvocation(m_editor)); QCoreApplication::processEvents(); QVERIFY(EditorManager::documentModel()->openedDocuments().isEmpty()); QVERIFY(garbageCollectGlobalSnapshot()); diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp index aad09a7f99..c7828334aa 100644 --- a/src/plugins/cpptools/cppmodelmanager.cpp +++ b/src/plugins/cpptools/cppmodelmanager.cpp @@ -846,7 +846,8 @@ void CppModelManager::onProjectAdded(ProjectExplorer::Project *) void CppModelManager::delayedGC() { - m_delayedGcTimer->start(500); + if (m_enableGC) + m_delayedGcTimer->start(500); } void CppModelManager::onAboutToRemoveProject(ProjectExplorer::Project *project) @@ -992,6 +993,12 @@ CppIndexingSupport *CppModelManager::indexingSupport() return m_indexingSupporter ? m_indexingSupporter : m_internalIndexingSupport; } +void CppModelManager::enableGarbageCollector(bool enable) +{ + m_delayedGcTimer->stop(); + m_enableGC = enable; +} + void CppModelManager::setExtraDiagnostics(const QString &fileName, const QString &kind, const QList<Document::DiagnosticMessage> &diagnostics) diff --git a/src/plugins/cpptools/cppmodelmanager.h b/src/plugins/cpptools/cppmodelmanager.h index 431c08aa38..4db0ffe63a 100644 --- a/src/plugins/cpptools/cppmodelmanager.h +++ b/src/plugins/cpptools/cppmodelmanager.h @@ -152,6 +152,8 @@ public: return m_definedMacros; } + void enableGarbageCollector(bool enable); + static QStringList timeStampModifiedFiles(const QList<Document::Ptr> documentsToCheck); signals: diff --git a/src/plugins/cpptools/cppmodelmanager_test.cpp b/src/plugins/cpptools/cppmodelmanager_test.cpp index fec382f7a4..cdf8ec6859 100644 --- a/src/plugins/cpptools/cppmodelmanager_test.cpp +++ b/src/plugins/cpptools/cppmodelmanager_test.cpp @@ -771,8 +771,9 @@ struct EditorCloser { EditorCloser(Core::IEditor *editor): editor(editor) {} ~EditorCloser() { + using namespace CppTools; if (editor) - Core::EditorManager::closeEditor(editor); + QVERIFY(Tests::TestCase::closeEditorWithoutGarbageCollectorInvocation(editor)); } }; diff --git a/src/plugins/cpptools/cppmodelmanagerinterface.h b/src/plugins/cpptools/cppmodelmanagerinterface.h index cb209f4340..d4c1a96693 100644 --- a/src/plugins/cpptools/cppmodelmanagerinterface.h +++ b/src/plugins/cpptools/cppmodelmanagerinterface.h @@ -269,6 +269,7 @@ public: virtual CppIndexingSupport *indexingSupport() = 0; virtual void setIncludePaths(const QStringList &includePaths) = 0; + virtual void enableGarbageCollector(bool enable) = 0; signals: /// Project data might be locked while this is emitted. diff --git a/src/plugins/cpptools/cpptoolstestcase.cpp b/src/plugins/cpptools/cpptoolstestcase.cpp index 80de9dfc1d..e75df702d8 100644 --- a/src/plugins/cpptools/cpptoolstestcase.cpp +++ b/src/plugins/cpptools/cpptoolstestcase.cpp @@ -36,6 +36,14 @@ #include <QtTest> +static bool closeEditorsWithoutGarbageCollectorInvocation(const QList<Core::IEditor *> &editors) +{ + CppTools::CppModelManagerInterface::instance()->enableGarbageCollector(false); + const bool closeEditorsSucceeded = Core::EditorManager::closeEditors(editors, false); + CppTools::CppModelManagerInterface::instance()->enableGarbageCollector(true); + return closeEditorsSucceeded; +} + static bool snapshotContains(const CPlusPlus::Snapshot &snapshot, const QStringList &filePaths) { foreach (const QString &filePath, filePaths) { @@ -80,7 +88,7 @@ TestCase::TestCase(bool runGarbageCollector) TestCase::~TestCase() { - QVERIFY(Core::EditorManager::closeEditors(m_editorsToClose, false)); + QVERIFY(closeEditorsWithoutGarbageCollectorInvocation(m_editorsToClose)); QCoreApplication::processEvents(); if (m_runGarbageCollector) @@ -130,6 +138,11 @@ void TestCase::closeEditorAtEndOfTestCase(Core::IEditor *editor) m_editorsToClose.append(editor); } +bool TestCase::closeEditorWithoutGarbageCollectorInvocation(Core::IEditor *editor) +{ + return closeEditorsWithoutGarbageCollectorInvocation(QList<Core::IEditor *>() << editor); +} + CPlusPlus::Document::Ptr TestCase::waitForFileInGlobalSnapshot(const QString &filePath) { return waitForFilesInGlobalSnapshot(QStringList(filePath)).first(); diff --git a/src/plugins/cpptools/cpptoolstestcase.h b/src/plugins/cpptools/cpptoolstestcase.h index cdca7c3db7..c0f161bef2 100644 --- a/src/plugins/cpptools/cpptoolstestcase.h +++ b/src/plugins/cpptools/cpptoolstestcase.h @@ -73,6 +73,8 @@ public: bool succeededSoFar() const; void closeEditorAtEndOfTestCase(Core::IEditor *editor); + static bool closeEditorWithoutGarbageCollectorInvocation(Core::IEditor *editor); + static bool parseFiles(const QString &filePath); static bool parseFiles(const QStringList &filePaths); |