forked from qt-creator/qt-creator
C++: Fix resolving ui_* files in CppPreprocessor
The working copy contains the artificial ui_* files and therefore we have to consider it while resolving include files. Task-number: QTCREATORBUG-9683 Change-Id: Icb3387b4cd885b3652bae3f1da465d3e0f633332 Reviewed-by: Christian Stenger <christian.stenger@digia.com> Reviewed-by: Eike Ziller <eike.ziller@digia.com> Reviewed-by: Daniel Teske <daniel.teske@digia.com> Reviewed-by: Robert Loehning <robert.loehning@digia.com> Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
@@ -32,6 +32,9 @@
|
||||
#include "cpppreprocessor.h"
|
||||
#include "modelmanagertesthelper.h"
|
||||
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/session.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
#include <QtTest>
|
||||
@@ -360,3 +363,53 @@ void CppToolsPlugin::test_modelmanager_snapshot_after_two_projects()
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -231,7 +231,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;
|
||||
}
|
||||
|
||||
|
||||
@@ -164,6 +164,7 @@ private slots:
|
||||
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