From c84e3a27d61f2b4e407751760d0e3dacfc4640c8 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Tue, 16 Jul 2013 16:20:46 +0200 Subject: CppTools: Garbage collect if the last CppEditor is closed Task-number: QTCREATORBUG-9828 Change-Id: Ie0ef9757cedb772702e49542b58d5b589506aa9e Reviewed-by: Erik Verbruggen --- src/plugins/cpptools/cppmodelmanager_test.cpp | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/plugins/cpptools/cppmodelmanager_test.cpp') diff --git a/src/plugins/cpptools/cppmodelmanager_test.cpp b/src/plugins/cpptools/cppmodelmanager_test.cpp index 305b16b2c2..7bd128d209 100644 --- a/src/plugins/cpptools/cppmodelmanager_test.cpp +++ b/src/plugins/cpptools/cppmodelmanager_test.cpp @@ -32,6 +32,7 @@ #include "cpppreprocessor.h" #include "modelmanagertesthelper.h" +#include #include #include @@ -413,3 +414,33 @@ void CppToolsPlugin::test_modelmanager_extraeditorsupport_uiFiles() sm->removeProject(project); ModelManagerTestHelper::verifyClean(); } + +/// QTCREATORBUG-9828: Locator shows symbols of closed files +/// Check: The garbage collector should be run if the last CppEditor is closed. +void CppToolsPlugin::test_modelmanager_gc_if_last_cppeditor_closed() +{ + TestDataDirectory testDataDirectory(QLatin1String("testdata_guiproject1")); + const QString file = testDataDirectory.file(QLatin1String("main.cpp")); + + Core::EditorManager *em = Core::EditorManager::instance(); + CppModelManager *mm = CppModelManager::instance(); + + // Open a file in the editor + QCOMPARE(Core::EditorManager::documentModel()->openedDocuments().size(), 0); + Core::IEditor *editor = em->openEditor(file); + QVERIFY(editor); + QCOMPARE(Core::EditorManager::documentModel()->openedDocuments().size(), 1); + QVERIFY(mm->isCppEditor(editor)); + QVERIFY(mm->workingCopy().contains(file)); + + // Check: File is in the snapshot + QVERIFY(mm->snapshot().contains(file)); + + // Close file/editor + const QList editorsToClose = QList() << editor; + em->closeEditors(editorsToClose, /*askAboutModifiedEditors=*/ false); + + // Check: File is removed from the snapshpt + QVERIFY(!mm->workingCopy().contains(file)); + QVERIFY(!mm->snapshot().contains(file)); +} -- cgit v1.2.1