From 746da71527c2bd62e216e6727e6763ab7cda1c95 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Tue, 17 Dec 2013 13:54:52 +0100 Subject: 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 --- src/plugins/cpptools/cpptoolstestcase.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/plugins/cpptools/cpptoolstestcase.cpp') 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 +static bool closeEditorsWithoutGarbageCollectorInvocation(const QList &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() << editor); +} + CPlusPlus::Document::Ptr TestCase::waitForFileInGlobalSnapshot(const QString &filePath) { return waitForFilesInGlobalSnapshot(QStringList(filePath)).first(); -- cgit v1.2.1