|
|
|
|
@@ -121,13 +121,13 @@ public:
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
projectInfo.appendProjectPart(part);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ModelManagerTestHelper *modelManagerTestHelper;
|
|
|
|
|
@@ -135,27 +135,68 @@ public:
|
|
|
|
|
QStringList projectFiles;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// Open and configure given project as example project and remove
|
|
|
|
|
/// generated *.user file on destruction.
|
|
|
|
|
///
|
|
|
|
|
/// Requirement: No *.user file exists for the project.
|
|
|
|
|
class ExampleProjectConfigurator
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ExampleProjectConfigurator(const QString &projectFile,
|
|
|
|
|
ProjectExplorer::ProjectExplorerPlugin *projectExplorer)
|
|
|
|
|
{
|
|
|
|
|
const QString projectUserFile = projectFile + QLatin1String(".user");
|
|
|
|
|
QVERIFY(!QFileInfo(projectUserFile).exists());
|
|
|
|
|
|
|
|
|
|
// Open project
|
|
|
|
|
QString errorOpeningProject;
|
|
|
|
|
m_project = projectExplorer->openProject(projectFile, &errorOpeningProject);
|
|
|
|
|
QVERIFY(m_project);
|
|
|
|
|
QVERIFY(errorOpeningProject.isEmpty());
|
|
|
|
|
|
|
|
|
|
// Configure project
|
|
|
|
|
m_project->configureAsExampleProject(QStringList());
|
|
|
|
|
|
|
|
|
|
m_fileToRemove = projectUserFile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~ExampleProjectConfigurator()
|
|
|
|
|
{
|
|
|
|
|
QVERIFY(!m_fileToRemove.isEmpty());
|
|
|
|
|
QVERIFY(QFile::remove(m_fileToRemove));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::Project *project() const
|
|
|
|
|
{
|
|
|
|
|
return m_project;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
ProjectExplorer::Project *m_project;
|
|
|
|
|
QString m_fileToRemove;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
|
|
void CppToolsPlugin::test_modelmanager_paths()
|
|
|
|
|
/// Check: The preprocessor cleans include and framework paths.
|
|
|
|
|
void CppToolsPlugin::test_modelmanager_paths_are_clean()
|
|
|
|
|
{
|
|
|
|
|
ModelManagerTestHelper helper;
|
|
|
|
|
CppModelManager *mm = CppModelManager::instance();
|
|
|
|
|
|
|
|
|
|
const TestDataDirectory testDataDir(QLatin1String("testdata"));
|
|
|
|
|
|
|
|
|
|
Project *project = helper.createProject(QLatin1String("test_modelmanager_paths"));
|
|
|
|
|
Project *project = helper.createProject(QLatin1String("test_modelmanager_paths_are_clean"));
|
|
|
|
|
ProjectInfo pi = mm->projectInfo(project);
|
|
|
|
|
QCOMPARE(pi.project().data(), project);
|
|
|
|
|
|
|
|
|
|
ProjectPart::Ptr part(new ProjectPart);
|
|
|
|
|
pi.appendProjectPart(part);
|
|
|
|
|
part->cxxVersion = ProjectPart::CXX98;
|
|
|
|
|
part->qtVersion = ProjectPart::Qt5;
|
|
|
|
|
part->defines = QByteArray("#define OH_BEHAVE -1\n");
|
|
|
|
|
part->includePaths = QStringList() << testDataDir.includeDir(false);
|
|
|
|
|
part->frameworkPaths = QStringList() << testDataDir.frameworksDir(false);
|
|
|
|
|
pi.appendProjectPart(part);
|
|
|
|
|
|
|
|
|
|
mm->updateProjectInfo(pi);
|
|
|
|
|
|
|
|
|
|
@@ -168,6 +209,7 @@ void CppToolsPlugin::test_modelmanager_paths()
|
|
|
|
|
QVERIFY(frameworkPaths.contains(testDataDir.frameworksDir()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Check: Frameworks headers are resolved.
|
|
|
|
|
void CppToolsPlugin::test_modelmanager_framework_headers()
|
|
|
|
|
{
|
|
|
|
|
ModelManagerTestHelper helper;
|
|
|
|
|
@@ -180,7 +222,6 @@ void CppToolsPlugin::test_modelmanager_framework_headers()
|
|
|
|
|
QCOMPARE(pi.project().data(), project);
|
|
|
|
|
|
|
|
|
|
ProjectPart::Ptr part(new ProjectPart);
|
|
|
|
|
pi.appendProjectPart(part);
|
|
|
|
|
part->cxxVersion = ProjectPart::CXX98;
|
|
|
|
|
part->qtVersion = ProjectPart::Qt5;
|
|
|
|
|
part->defines = QByteArray("#define OH_BEHAVE -1\n");
|
|
|
|
|
@@ -189,6 +230,7 @@ void CppToolsPlugin::test_modelmanager_framework_headers()
|
|
|
|
|
const QString &source = testDataDir.fileFromSourcesDir(
|
|
|
|
|
QLatin1String("test_modelmanager_framework_headers.cpp"));
|
|
|
|
|
part->files << ProjectFile(source, ProjectFile::CXXSource);
|
|
|
|
|
pi.appendProjectPart(part);
|
|
|
|
|
|
|
|
|
|
mm->updateProjectInfo(pi);
|
|
|
|
|
mm->updateSourceFiles(QStringList(source)).waitForFinished();
|
|
|
|
|
@@ -212,7 +254,9 @@ void CppToolsPlugin::test_modelmanager_framework_headers()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// QTCREATORBUG-9056
|
|
|
|
|
void CppToolsPlugin::test_modelmanager_refresh_1()
|
|
|
|
|
/// Check: If the project configuration changes, all project files and their
|
|
|
|
|
/// includes have to be reparsed.
|
|
|
|
|
void CppToolsPlugin::test_modelmanager_refresh_also_includes_of_project_files()
|
|
|
|
|
{
|
|
|
|
|
ModelManagerTestHelper helper;
|
|
|
|
|
CppModelManager *mm = CppModelManager::instance();
|
|
|
|
|
@@ -224,20 +268,20 @@ void CppToolsPlugin::test_modelmanager_refresh_1()
|
|
|
|
|
const QString testHeader(testDataDir.fileFromSourcesDir(
|
|
|
|
|
QLatin1String("test_modelmanager_refresh.h")));
|
|
|
|
|
|
|
|
|
|
Project *project = helper.createProject(QLatin1String("test_modelmanager_refresh_1"));
|
|
|
|
|
Project *project = helper.createProject(
|
|
|
|
|
QLatin1String("test_modelmanager_refresh_also_includes_of_project_files"));
|
|
|
|
|
ProjectInfo pi = mm->projectInfo(project);
|
|
|
|
|
QCOMPARE(pi.project().data(), project);
|
|
|
|
|
|
|
|
|
|
ProjectPart::Ptr part(new ProjectPart);
|
|
|
|
|
pi.appendProjectPart(part);
|
|
|
|
|
part->cxxVersion = ProjectPart::CXX98;
|
|
|
|
|
part->qtVersion = ProjectPart::Qt5;
|
|
|
|
|
part->defines = QByteArray("#define OH_BEHAVE -1\n");
|
|
|
|
|
part->includePaths = QStringList() << testDataDir.includeDir(false);
|
|
|
|
|
part->files.append(ProjectFile(testCpp, ProjectFile::CXXSource));
|
|
|
|
|
pi.appendProjectPart(part);
|
|
|
|
|
|
|
|
|
|
mm->updateProjectInfo(pi);
|
|
|
|
|
mm->updateSourceFiles(QStringList() << testCpp);
|
|
|
|
|
|
|
|
|
|
QStringList refreshedFiles = helper.waitForRefreshedSourceFiles();
|
|
|
|
|
|
|
|
|
|
@@ -247,13 +291,16 @@ void CppToolsPlugin::test_modelmanager_refresh_1()
|
|
|
|
|
QVERIFY(snapshot.contains(testHeader));
|
|
|
|
|
QVERIFY(snapshot.contains(testCpp));
|
|
|
|
|
|
|
|
|
|
part->defines = QByteArray();
|
|
|
|
|
mm->updateProjectInfo(pi);
|
|
|
|
|
snapshot = mm->snapshot();
|
|
|
|
|
QVERIFY(!snapshot.contains(testHeader));
|
|
|
|
|
QVERIFY(!snapshot.contains(testCpp));
|
|
|
|
|
Document::Ptr headerDocumentBefore = snapshot.document(testHeader);
|
|
|
|
|
const QList<CPlusPlus::Macro> macrosInHeaderBefore = headerDocumentBefore->definedMacros();
|
|
|
|
|
QCOMPARE(macrosInHeaderBefore.size(), 1);
|
|
|
|
|
QVERIFY(macrosInHeaderBefore.first().name() == "test_modelmanager_refresh_h");
|
|
|
|
|
|
|
|
|
|
mm->updateSourceFiles(QStringList() << testCpp);
|
|
|
|
|
// Introduce a define that will enable another define once the document is reparsed.
|
|
|
|
|
part->defines = QByteArray("#define TEST_DEFINE 1\n");
|
|
|
|
|
pi.clearProjectParts();
|
|
|
|
|
pi.appendProjectPart(part);
|
|
|
|
|
mm->updateProjectInfo(pi);
|
|
|
|
|
refreshedFiles = helper.waitForRefreshedSourceFiles();
|
|
|
|
|
|
|
|
|
|
QCOMPARE(refreshedFiles.size(), 1);
|
|
|
|
|
@@ -261,10 +308,18 @@ void CppToolsPlugin::test_modelmanager_refresh_1()
|
|
|
|
|
snapshot = mm->snapshot();
|
|
|
|
|
QVERIFY(snapshot.contains(testHeader));
|
|
|
|
|
QVERIFY(snapshot.contains(testCpp));
|
|
|
|
|
|
|
|
|
|
Document::Ptr headerDocumentAfter = snapshot.document(testHeader);
|
|
|
|
|
const QList<CPlusPlus::Macro> macrosInHeaderAfter = headerDocumentAfter->definedMacros();
|
|
|
|
|
QCOMPARE(macrosInHeaderAfter.size(), 2);
|
|
|
|
|
QVERIFY(macrosInHeaderAfter.at(0).name() == "test_modelmanager_refresh_h");
|
|
|
|
|
QVERIFY(macrosInHeaderAfter.at(1).name() == "TEST_DEFINE_DEFINED");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// QTCREATORBUG-9205
|
|
|
|
|
void CppToolsPlugin::test_modelmanager_refresh_2()
|
|
|
|
|
/// Check: When reparsing the same files again, no errors occur
|
|
|
|
|
/// (The CppPreprocessor's already seen files are properly cleared!).
|
|
|
|
|
void CppToolsPlugin::test_modelmanager_refresh_several_times()
|
|
|
|
|
{
|
|
|
|
|
ModelManagerTestHelper helper;
|
|
|
|
|
CppModelManager *mm = CppModelManager::instance();
|
|
|
|
|
@@ -275,17 +330,18 @@ void CppToolsPlugin::test_modelmanager_refresh_2()
|
|
|
|
|
const QString testHeader2(testDataDir.file(QLatin1String("header.h")));
|
|
|
|
|
const QString testCpp(testDataDir.file(QLatin1String("source.cpp")));
|
|
|
|
|
|
|
|
|
|
Project *project = helper.createProject(QLatin1String("test_modelmanager_refresh_2"));
|
|
|
|
|
Project *project = helper.createProject(
|
|
|
|
|
QLatin1String("test_modelmanager_refresh_several_times"));
|
|
|
|
|
ProjectInfo pi = mm->projectInfo(project);
|
|
|
|
|
QCOMPARE(pi.project().data(), project);
|
|
|
|
|
|
|
|
|
|
ProjectPart::Ptr part(new ProjectPart);
|
|
|
|
|
pi.appendProjectPart(part);
|
|
|
|
|
part->cxxVersion = ProjectPart::CXX98;
|
|
|
|
|
part->qtVersion = ProjectPart::Qt5;
|
|
|
|
|
part->files.append(ProjectFile(testHeader1, ProjectFile::CXXHeader));
|
|
|
|
|
part->files.append(ProjectFile(testHeader2, ProjectFile::CXXHeader));
|
|
|
|
|
part->files.append(ProjectFile(testCpp, ProjectFile::CXXSource));
|
|
|
|
|
pi.appendProjectPart(part);
|
|
|
|
|
|
|
|
|
|
mm->updateProjectInfo(pi);
|
|
|
|
|
|
|
|
|
|
@@ -293,8 +349,21 @@ void CppToolsPlugin::test_modelmanager_refresh_2()
|
|
|
|
|
QStringList refreshedFiles;
|
|
|
|
|
CPlusPlus::Document::Ptr document;
|
|
|
|
|
|
|
|
|
|
QByteArray defines = "#define FIRST_DEFINE";
|
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
|
mm->updateSourceFiles(QStringList() << testHeader1 << testHeader2 << testCpp);
|
|
|
|
|
pi.clearProjectParts();
|
|
|
|
|
ProjectPart::Ptr part(new ProjectPart);
|
|
|
|
|
// Simulate project configuration change by having different defines each time.
|
|
|
|
|
defines += "\n#define ANOTHER_DEFINE";
|
|
|
|
|
part->defines = defines;
|
|
|
|
|
part->cxxVersion = ProjectPart::CXX98;
|
|
|
|
|
part->qtVersion = ProjectPart::Qt5;
|
|
|
|
|
part->files.append(ProjectFile(testHeader1, ProjectFile::CXXHeader));
|
|
|
|
|
part->files.append(ProjectFile(testHeader2, ProjectFile::CXXHeader));
|
|
|
|
|
part->files.append(ProjectFile(testCpp, ProjectFile::CXXSource));
|
|
|
|
|
pi.appendProjectPart(part);
|
|
|
|
|
|
|
|
|
|
mm->updateProjectInfo(pi);
|
|
|
|
|
refreshedFiles = helper.waitForRefreshedSourceFiles();
|
|
|
|
|
|
|
|
|
|
QCOMPARE(refreshedFiles.size(), 3);
|
|
|
|
|
@@ -319,6 +388,40 @@ void CppToolsPlugin::test_modelmanager_refresh_2()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// QTCREATORBUG-9581
|
|
|
|
|
/// Check: If nothing has changes, nothing should be reindexed.
|
|
|
|
|
void CppToolsPlugin::test_modelmanager_refresh_test_for_changes()
|
|
|
|
|
{
|
|
|
|
|
ModelManagerTestHelper helper;
|
|
|
|
|
CppModelManager *mm = CppModelManager::instance();
|
|
|
|
|
|
|
|
|
|
const TestDataDirectory testDataDir(QLatin1String("testdata_refresh"));
|
|
|
|
|
const QString testCpp(testDataDir.file(QLatin1String("source.cpp")));
|
|
|
|
|
|
|
|
|
|
Project *project = helper.createProject(QLatin1String("test_modelmanager_refresh_2"));
|
|
|
|
|
ProjectInfo pi = mm->projectInfo(project);
|
|
|
|
|
QCOMPARE(pi.project().data(), project);
|
|
|
|
|
|
|
|
|
|
ProjectPart::Ptr part(new ProjectPart);
|
|
|
|
|
part->cxxVersion = ProjectPart::CXX98;
|
|
|
|
|
part->qtVersion = ProjectPart::Qt5;
|
|
|
|
|
part->files.append(ProjectFile(testCpp, ProjectFile::CXXSource));
|
|
|
|
|
pi.appendProjectPart(part);
|
|
|
|
|
|
|
|
|
|
// Reindexing triggers a reparsing thread
|
|
|
|
|
QFuture<void> firstFuture = mm->updateProjectInfo(pi);
|
|
|
|
|
QVERIFY(firstFuture.isStarted() || firstFuture.isRunning());
|
|
|
|
|
const QStringList refreshedFiles = helper.waitForRefreshedSourceFiles();
|
|
|
|
|
QCOMPARE(refreshedFiles.size(), 1);
|
|
|
|
|
QVERIFY(refreshedFiles.contains(testCpp));
|
|
|
|
|
|
|
|
|
|
// No reindexing since nothing has changed
|
|
|
|
|
QFuture<void> subsequentFuture = mm->updateProjectInfo(pi);
|
|
|
|
|
QVERIFY(subsequentFuture.isCanceled() && subsequentFuture.isFinished());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Check: If a second project is opened, the code model is still aware of
|
|
|
|
|
/// files of the first project.
|
|
|
|
|
void CppToolsPlugin::test_modelmanager_snapshot_after_two_projects()
|
|
|
|
|
{
|
|
|
|
|
QStringList refreshedFiles;
|
|
|
|
|
@@ -328,14 +431,13 @@ void CppToolsPlugin::test_modelmanager_snapshot_after_two_projects()
|
|
|
|
|
CppModelManager *mm = CppModelManager::instance();
|
|
|
|
|
|
|
|
|
|
// Project 1
|
|
|
|
|
project1.create(QLatin1String("snapshot_after_two_projects.1"),
|
|
|
|
|
project1.create(QLatin1String("test_modelmanager_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();
|
|
|
|
|
@@ -344,14 +446,13 @@ void CppToolsPlugin::test_modelmanager_snapshot_after_two_projects()
|
|
|
|
|
QVERIFY(mm->snapshot().contains(file));
|
|
|
|
|
|
|
|
|
|
// Project 2
|
|
|
|
|
project2.create(QLatin1String("snapshot_after_two_projects.2"),
|
|
|
|
|
project2.create(QLatin1String("test_modelmanager_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());
|
|
|
|
|
|
|
|
|
|
@@ -365,6 +466,10 @@ void CppToolsPlugin::test_modelmanager_snapshot_after_two_projects()
|
|
|
|
|
QVERIFY(mm->snapshot().contains(file));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Check: (1) For a project with a *.ui file an AbstractEditorSupport object
|
|
|
|
|
/// is added for the ui_* file.
|
|
|
|
|
/// Check: (2) The CppPreprocessor can successfully resolve the ui_* file
|
|
|
|
|
/// though it might not be actually generated in the build dir.
|
|
|
|
|
void CppToolsPlugin::test_modelmanager_extraeditorsupport_uiFiles()
|
|
|
|
|
{
|
|
|
|
|
TestDataDirectory testDataDirectory(QLatin1String("testdata_guiproject1"));
|
|
|
|
|
@@ -372,10 +477,8 @@ void CppToolsPlugin::test_modelmanager_extraeditorsupport_uiFiles()
|
|
|
|
|
|
|
|
|
|
// 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());
|
|
|
|
|
ExampleProjectConfigurator exampleProjectConfigurator(projectFile, pe);
|
|
|
|
|
Project *project = exampleProjectConfigurator.project();
|
|
|
|
|
|
|
|
|
|
// Check working copy.
|
|
|
|
|
// An AbstractEditorSupport object should have been added for the ui_* file.
|
|
|
|
|
|