forked from qt-creator/qt-creator
CppTools: Fix snapshot in case another project is opened
When a second project was opened the snapshot was reset. That resulted
in all kinds of problems since from then on the code model effectively
was not aware of the files of the first project.
The regression was introduced by commit a0d6df7b.
Change-Id: I1ccc9de68177205b49a4ba8ead2bc8abe4592b32
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@digia.com>
This commit is contained in:
@@ -96,6 +96,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 +314,49 @@ 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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user