diff options
author | Daniel Teske <daniel.teske@theqtcompany.com> | 2015-10-01 14:54:31 +0200 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@theqtcompany.com> | 2015-10-06 13:17:55 +0000 |
commit | 307061032cf8c5389d91093cc5937d9cc351772a (patch) | |
tree | 683bd807d0d3795a7ec1e2ad5c110a17b154b23f /src/plugins/cpptools/cppmodelmanager_test.cpp | |
parent | 5eb8fe0306bc3cc5dd69d8159530826cf40eb934 (diff) |
Fix changing "#include" lines after file renaming
Didn't work if there was any folded text before the #include.
Change-Id: I8f16205f06bfaa8b8541401a9ebd5995c15b2227
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
Diffstat (limited to 'src/plugins/cpptools/cppmodelmanager_test.cpp')
-rw-r--r-- | src/plugins/cpptools/cppmodelmanager_test.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/plugins/cpptools/cppmodelmanager_test.cpp b/src/plugins/cpptools/cppmodelmanager_test.cpp index 10153298794..a3c1954a7b9 100644 --- a/src/plugins/cpptools/cppmodelmanager_test.cpp +++ b/src/plugins/cpptools/cppmodelmanager_test.cpp @@ -36,6 +36,7 @@ #include "editordocumenthandle.h" #include "modelmanagertesthelper.h" +#include <coreplugin/documentmanager.h> #include <coreplugin/editormanager/editormanager.h> #include <coreplugin/fileutils.h> #include <coreplugin/testdatadir.h> @@ -43,6 +44,7 @@ #include <projectexplorer/session.h> #include <cplusplus/LookupContext.h> +#include <utils/executeondestruction.h> #include <utils/hostosinfo.h> #include <QDebug> @@ -1107,6 +1109,69 @@ void CppToolsPlugin::test_modelmanager_renameIncludes() QCOMPARE(snapshot.allIncludesForDocument(sourceFile), QSet<QString>() << newHeader); } +void CppToolsPlugin::test_modelmanager_renameIncludesInEditor() +{ + struct ModelManagerGCHelper { + ~ModelManagerGCHelper() { CppModelManager::instance()->GC(); } + } GCHelper; + Q_UNUSED(GCHelper); // do not warn about being unused + + TemporaryDir tmpDir; + QVERIFY(tmpDir.isValid()); + + const QDir workingDir(tmpDir.path()); + const QStringList fileNames = QStringList() << _("foo.h") << _("foo.cpp") << _("main.cpp"); + const QString oldHeader(workingDir.filePath(_("foo.h"))); + const QString newHeader(workingDir.filePath(_("bar.h"))); + const QString mainFile(workingDir.filePath(_("main.cpp"))); + CppModelManager *modelManager = CppModelManager::instance(); + const MyTestDataDir testDir(_("testdata_project1")); + + ModelManagerTestHelper helper; + helper.resetRefreshedSourceFiles(); + + // Copy test files to a temporary directory + QSet<QString> sourceFiles; + foreach (const QString &fileName, fileNames) { + const QString &file = workingDir.filePath(fileName); + QVERIFY(QFile::copy(testDir.file(fileName), file)); + // Saving source file names for the model manager update, + // so we can update just the relevant files. + if (ProjectFile::classify(file) == ProjectFile::CXXSource) + sourceFiles.insert(file); + } + + // Update the c++ model manager and check for the old includes + modelManager->updateSourceFiles(sourceFiles).waitForFinished(); + QCoreApplication::processEvents(); + CPlusPlus::Snapshot snapshot = modelManager->snapshot(); + foreach (const QString &sourceFile, sourceFiles) + QCOMPARE(snapshot.allIncludesForDocument(sourceFile), QSet<QString>() << oldHeader); + + // Open a file in the editor + QCOMPARE(Core::DocumentModel::openedDocuments().size(), 0); + Core::IEditor *editor = Core::EditorManager::openEditor(mainFile); + QVERIFY(editor); + EditorCloser editorCloser(editor); + Utils::ExecuteOnDestruction saveAllFiles([](){ + Core::DocumentManager::saveAllModifiedDocumentsSilently(); + }); + QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1); + QVERIFY(modelManager->isCppEditor(editor)); + QVERIFY(modelManager->workingCopy().contains(mainFile)); + + // Renaming the header + QVERIFY(Core::FileUtils::renameFile(oldHeader, newHeader)); + + // Update the c++ model manager again and check for the new includes + TestCase::waitForProcessedEditorDocument(mainFile); + modelManager->updateSourceFiles(sourceFiles).waitForFinished(); + QCoreApplication::processEvents(); + snapshot = modelManager->snapshot(); + foreach (const QString &sourceFile, sourceFiles) + QCOMPARE(snapshot.allIncludesForDocument(sourceFile), QSet<QString>() << newHeader); +} + void CppToolsPlugin::test_modelmanager_documentsAndRevisions() { TestCase helper; |