summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/plugins/cpptools/cppmodelmanager.cpp20
-rw-r--r--src/plugins/cpptools/cppmodelmanager_test.cpp82
-rw-r--r--src/plugins/cpptools/cpptoolsplugin.h1
-rw-r--r--tests/cppmodelmanager/testdata_project1/foo.cpp7
-rw-r--r--tests/cppmodelmanager/testdata_project1/foo.h12
-rw-r--r--tests/cppmodelmanager/testdata_project1/main.cpp9
-rw-r--r--tests/cppmodelmanager/testdata_project2/bar.cpp7
-rw-r--r--tests/cppmodelmanager/testdata_project2/bar.h12
-rw-r--r--tests/cppmodelmanager/testdata_project2/main.cpp9
9 files changed, 153 insertions, 6 deletions
diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp
index b26bb706e6..b7abbe2d2d 100644
--- a/src/plugins/cpptools/cppmodelmanager.cpp
+++ b/src/plugins/cpptools/cppmodelmanager.cpp
@@ -556,23 +556,31 @@ void CppModelManager::updateProjectInfo(const ProjectInfo &pinfo)
return;
ProjectExplorer::Project *project = pinfo.project().data();
+ ProjectInfo oldProjectInfo = m_projects.value(project);
+ if (oldProjectInfo.isValid()) {
+ foreach (const ProjectPart::Ptr &projectPart, oldProjectInfo.projectParts()) {
+ foreach (const ProjectFile &cxxFile, projectPart->files) {
+ 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);
- foreach (const QString &fileName, m_snapshot.allIncludesForDocument(cxxFile.path))
- m_snapshot.remove(fileName);
- m_snapshot.remove(cxxFile.path);
}
}
}
-
- m_snapshot.remove(configurationFileName());
}
if (!qgetenv("QTCREATOR_DUMP_PROJECT_INFO").isEmpty())
diff --git a/src/plugins/cpptools/cppmodelmanager_test.cpp b/src/plugins/cpptools/cppmodelmanager_test.cpp
index 3805f157d2..d01c4ff5ab 100644
--- a/src/plugins/cpptools/cppmodelmanager_test.cpp
+++ b/src/plugins/cpptools/cppmodelmanager_test.cpp
@@ -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));
+}
diff --git a/src/plugins/cpptools/cpptoolsplugin.h b/src/plugins/cpptools/cpptoolsplugin.h
index 4c983bab6c..d10c690221 100644
--- a/src/plugins/cpptools/cpptoolsplugin.h
+++ b/src/plugins/cpptools/cpptoolsplugin.h
@@ -163,6 +163,7 @@ private slots:
void test_modelmanager_framework_headers();
void test_modelmanager_refresh_1();
void test_modelmanager_refresh_2();
+ void test_modelmanager_snapshot_after_two_projects();
private:
void test_completion();
diff --git a/tests/cppmodelmanager/testdata_project1/foo.cpp b/tests/cppmodelmanager/testdata_project1/foo.cpp
new file mode 100644
index 0000000000..cf92d5c5cc
--- /dev/null
+++ b/tests/cppmodelmanager/testdata_project1/foo.cpp
@@ -0,0 +1,7 @@
+// Copyright header
+
+#include "foo.h"
+
+Foo::Foo()
+{
+}
diff --git a/tests/cppmodelmanager/testdata_project1/foo.h b/tests/cppmodelmanager/testdata_project1/foo.h
new file mode 100644
index 0000000000..b427107633
--- /dev/null
+++ b/tests/cppmodelmanager/testdata_project1/foo.h
@@ -0,0 +1,12 @@
+// Copyright header
+
+#ifndef FOO_H
+#define FOO_H
+
+class Foo
+{
+public:
+ Foo();
+};
+
+#endif // FOO_H
diff --git a/tests/cppmodelmanager/testdata_project1/main.cpp b/tests/cppmodelmanager/testdata_project1/main.cpp
new file mode 100644
index 0000000000..eca708ea3f
--- /dev/null
+++ b/tests/cppmodelmanager/testdata_project1/main.cpp
@@ -0,0 +1,9 @@
+// Copyright header
+
+#include "foo.h"
+
+int main()
+{
+ Foo foo;
+ return 1;
+}
diff --git a/tests/cppmodelmanager/testdata_project2/bar.cpp b/tests/cppmodelmanager/testdata_project2/bar.cpp
new file mode 100644
index 0000000000..30882cdcd9
--- /dev/null
+++ b/tests/cppmodelmanager/testdata_project2/bar.cpp
@@ -0,0 +1,7 @@
+// Copyright header
+
+#include "bar.h"
+
+Bar::Bar()
+{
+}
diff --git a/tests/cppmodelmanager/testdata_project2/bar.h b/tests/cppmodelmanager/testdata_project2/bar.h
new file mode 100644
index 0000000000..abb6e59877
--- /dev/null
+++ b/tests/cppmodelmanager/testdata_project2/bar.h
@@ -0,0 +1,12 @@
+// Copyright header
+
+#ifndef BAR_H
+#define BAR_H
+
+class Bar
+{
+public:
+ Bar();
+};
+
+#endif // BAR_H
diff --git a/tests/cppmodelmanager/testdata_project2/main.cpp b/tests/cppmodelmanager/testdata_project2/main.cpp
new file mode 100644
index 0000000000..d6e00511eb
--- /dev/null
+++ b/tests/cppmodelmanager/testdata_project2/main.cpp
@@ -0,0 +1,9 @@
+// Copyright header
+
+#include "bar.h"
+
+int main()
+{
+ Bar bar;
+ return 1;
+}