forked from qt-creator/qt-creator
Merge remote-tracking branch 'origin/2.8' into HEAD
Conflicts: qtcreator.pri qtcreator.qbs Change-Id: I5d2018d3437b99bcdffa92bf1a212f42923c4fad
This commit is contained in:
@@ -556,23 +556,31 @@ void CppModelManager::updateProjectInfo(const ProjectInfo &pinfo)
|
||||
return;
|
||||
|
||||
ProjectExplorer::Project *project = pinfo.project().data();
|
||||
m_projects.insert(project, pinfo);
|
||||
m_dirty = true;
|
||||
|
||||
m_srcToProjectPart.clear();
|
||||
|
||||
foreach (const ProjectInfo &projectInfo, m_projects) {
|
||||
foreach (const ProjectPart::Ptr &projectPart, projectInfo.projectParts()) {
|
||||
ProjectInfo oldProjectInfo = m_projects.value(project);
|
||||
if (oldProjectInfo.isValid()) {
|
||||
foreach (const ProjectPart::Ptr &projectPart, oldProjectInfo.projectParts()) {
|
||||
foreach (const ProjectFile &cxxFile, projectPart->files) {
|
||||
m_srcToProjectPart[cxxFile.path].append(projectPart);
|
||||
foreach (const QString &fileName, m_snapshot.allIncludesForDocument(cxxFile.path))
|
||||
foreach (const QString &fileName,
|
||||
m_snapshot.allIncludesForDocument(cxxFile.path)) {
|
||||
m_snapshot.remove(fileName);
|
||||
}
|
||||
m_snapshot.remove(cxxFile.path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_snapshot.remove(configurationFileName());
|
||||
|
||||
m_projects.insert(project, pinfo);
|
||||
m_dirty = true;
|
||||
|
||||
m_srcToProjectPart.clear();
|
||||
foreach (const ProjectInfo &projectInfo, m_projects) {
|
||||
foreach (const ProjectPart::Ptr &projectPart, projectInfo.projectParts()) {
|
||||
foreach (const ProjectFile &cxxFile, projectPart->files) {
|
||||
m_srcToProjectPart[cxxFile.path].append(projectPart);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!qgetenv("QTCREATOR_DUMP_PROJECT_INFO").isEmpty())
|
||||
@@ -607,9 +615,14 @@ void CppModelManager::deleteEditorSupport(TextEditor::BaseTextEditor *textEditor
|
||||
if (!isCppEditor(textEditor))
|
||||
return;
|
||||
|
||||
QMutexLocker locker(&m_editorSupportMutex);
|
||||
CppEditorSupport *editorSupport = m_editorSupport.value(textEditor, 0);
|
||||
m_editorSupport.remove(textEditor);
|
||||
CppEditorSupport *editorSupport;
|
||||
|
||||
{ // only lock the operations on m_editorSupport
|
||||
QMutexLocker locker(&m_editorSupportMutex);
|
||||
editorSupport = m_editorSupport.value(textEditor, 0);
|
||||
m_editorSupport.remove(textEditor);
|
||||
}
|
||||
|
||||
delete editorSupport;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,9 @@
|
||||
#include "cpppreprocessor.h"
|
||||
#include "modelmanagertesthelper.h"
|
||||
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/session.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
#include <QtTest>
|
||||
@@ -96,6 +99,42 @@ private:
|
||||
const QString m_testDataDirectory;
|
||||
};
|
||||
|
||||
|
||||
// TODO: When possible, use this helper class in all tests
|
||||
class ProjectCreator
|
||||
{
|
||||
public:
|
||||
ProjectCreator(ModelManagerTestHelper *modelManagerTestHelper)
|
||||
: modelManagerTestHelper(modelManagerTestHelper)
|
||||
{}
|
||||
|
||||
/// 'files' is expected to be a list of file names that reside in 'dir'.
|
||||
void create(const QString &name, const QString &dir, const QStringList files)
|
||||
{
|
||||
const TestDataDirectory projectDir(dir);
|
||||
foreach (const QString &file, files)
|
||||
projectFiles << projectDir.file(file);
|
||||
|
||||
Project *project = modelManagerTestHelper->createProject(name);
|
||||
projectInfo = CppModelManager::instance()->projectInfo(project);
|
||||
QCOMPARE(projectInfo.project().data(), project);
|
||||
|
||||
ProjectPart::Ptr part(new ProjectPart);
|
||||
projectInfo.appendProjectPart(part);
|
||||
part->cxxVersion = ProjectPart::CXX98;
|
||||
part->qtVersion = ProjectPart::Qt5;
|
||||
foreach (const QString &file, projectFiles) {
|
||||
ProjectFile projectFile(file, ProjectFile::classify(file));
|
||||
part->files.append(projectFile);
|
||||
}
|
||||
}
|
||||
|
||||
ModelManagerTestHelper *modelManagerTestHelper;
|
||||
ProjectInfo projectInfo;
|
||||
QStringList projectFiles;
|
||||
};
|
||||
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
void CppToolsPlugin::test_modelmanager_paths()
|
||||
@@ -278,3 +317,99 @@ void CppToolsPlugin::test_modelmanager_refresh_2()
|
||||
QVERIFY(document->diagnosticMessages().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
void CppToolsPlugin::test_modelmanager_snapshot_after_two_projects()
|
||||
{
|
||||
QStringList refreshedFiles;
|
||||
ModelManagerTestHelper helper;
|
||||
ProjectCreator project1(&helper);
|
||||
ProjectCreator project2(&helper);
|
||||
CppModelManager *mm = CppModelManager::instance();
|
||||
|
||||
// Project 1
|
||||
project1.create(QLatin1String("snapshot_after_two_projects.1"),
|
||||
QLatin1String("testdata_project1"),
|
||||
QStringList() << QLatin1String("foo.h")
|
||||
<< QLatin1String("foo.cpp")
|
||||
<< QLatin1String("main.cpp"));
|
||||
|
||||
mm->updateProjectInfo(project1.projectInfo);
|
||||
mm->updateSourceFiles(project1.projectFiles);
|
||||
refreshedFiles = helper.waitForRefreshedSourceFiles();
|
||||
QCOMPARE(refreshedFiles.toSet(), project1.projectFiles.toSet());
|
||||
const int snapshotSizeAfterProject1 = mm->snapshot().size();
|
||||
|
||||
foreach (const QString &file, project1.projectFiles)
|
||||
QVERIFY(mm->snapshot().contains(file));
|
||||
|
||||
// Project 2
|
||||
project2.create(QLatin1String("snapshot_after_two_projects.2"),
|
||||
QLatin1String("testdata_project2"),
|
||||
QStringList() << QLatin1String("bar.h")
|
||||
<< QLatin1String("bar.cpp")
|
||||
<< QLatin1String("main.cpp"));
|
||||
|
||||
mm->updateProjectInfo(project2.projectInfo);
|
||||
mm->updateSourceFiles(project2.projectFiles);
|
||||
refreshedFiles = helper.waitForRefreshedSourceFiles();
|
||||
QCOMPARE(refreshedFiles.toSet(), project2.projectFiles.toSet());
|
||||
|
||||
const int snapshotSizeAfterProject2 = mm->snapshot().size();
|
||||
QVERIFY(snapshotSizeAfterProject2 > snapshotSizeAfterProject1);
|
||||
QVERIFY(snapshotSizeAfterProject2 >= snapshotSizeAfterProject1 + project2.projectFiles.size());
|
||||
|
||||
foreach (const QString &file, project1.projectFiles)
|
||||
QVERIFY(mm->snapshot().contains(file));
|
||||
foreach (const QString &file, project2.projectFiles)
|
||||
QVERIFY(mm->snapshot().contains(file));
|
||||
}
|
||||
|
||||
void CppToolsPlugin::test_modelmanager_extraeditorsupport_uiFiles()
|
||||
{
|
||||
TestDataDirectory testDataDirectory(QLatin1String("testdata_guiproject1"));
|
||||
const QString projectFile = testDataDirectory.file(QLatin1String("testdata_guiproject1.pro"));
|
||||
|
||||
// Open project with *.ui file
|
||||
ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance();
|
||||
QString errorOpeningProject;
|
||||
Project *project = pe->openProject(projectFile, &errorOpeningProject);
|
||||
QVERIFY(errorOpeningProject.isEmpty());
|
||||
project->configureAsExampleProject(QStringList());
|
||||
|
||||
// Check working copy.
|
||||
// An AbstractEditorSupport object should have been added for the ui_* file.
|
||||
CppModelManagerInterface *mm = CppModelManagerInterface::instance();
|
||||
CppModelManagerInterface::WorkingCopy workingCopy = mm->workingCopy();
|
||||
|
||||
QCOMPARE(workingCopy.size(), 2); // mm->configurationFileName() and "ui_*.h"
|
||||
|
||||
QStringList fileNamesInWorkinCopy;
|
||||
QHashIterator<QString, QPair<QString, unsigned> > it = workingCopy.iterator();
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
fileNamesInWorkinCopy << QFileInfo(it.key()).fileName();
|
||||
}
|
||||
fileNamesInWorkinCopy.sort();
|
||||
const QString expectedUiHeaderFileName = QLatin1String("ui_mainwindow.h");
|
||||
QCOMPARE(fileNamesInWorkinCopy.at(0), mm->configurationFileName());
|
||||
QCOMPARE(fileNamesInWorkinCopy.at(1), expectedUiHeaderFileName);
|
||||
|
||||
// Check CppPreprocessor / includes.
|
||||
// The CppPreprocessor is expected to find the ui_* file in the working copy.
|
||||
const QString fileIncludingTheUiFile = testDataDirectory.file(QLatin1String("mainwindow.cpp"));
|
||||
while (!mm->snapshot().document(fileIncludingTheUiFile))
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
const CPlusPlus::Snapshot snapshot = mm->snapshot();
|
||||
const Document::Ptr document = snapshot.document(fileIncludingTheUiFile);
|
||||
QVERIFY(document);
|
||||
const QStringList includedFiles = document->includedFiles();
|
||||
QCOMPARE(includedFiles.size(), 2);
|
||||
QCOMPARE(QFileInfo(includedFiles.at(0)).fileName(), QLatin1String("mainwindow.h"));
|
||||
QCOMPARE(QFileInfo(includedFiles.at(1)).fileName(), QLatin1String("ui_mainwindow.h"));
|
||||
|
||||
// Close Project
|
||||
ProjectExplorer::SessionManager *sm = pe->session();
|
||||
sm->removeProject(project);
|
||||
ModelManagerTestHelper::verifyClean();
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ QString CppPreprocessor::resolveFile_helper(const QString &fileName, IncludeType
|
||||
|
||||
foreach (const QString &includePath, m_includePaths) {
|
||||
QString path = includePath + fileName;
|
||||
if (checkFile(path))
|
||||
if (m_workingCopy.contains(path) || checkFile(path))
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
@@ -171,6 +171,8 @@ private slots:
|
||||
void test_modelmanager_framework_headers();
|
||||
void test_modelmanager_refresh_1();
|
||||
void test_modelmanager_refresh_2();
|
||||
void test_modelmanager_snapshot_after_two_projects();
|
||||
void test_modelmanager_extraeditorsupport_uiFiles();
|
||||
|
||||
private:
|
||||
void test_completion();
|
||||
|
||||
@@ -79,7 +79,7 @@ public:
|
||||
~ModelManagerTestHelper();
|
||||
|
||||
void cleanup();
|
||||
void verifyClean();
|
||||
static void verifyClean();
|
||||
|
||||
Project *createProject(const QString &name);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user