Commit c264c0d2 authored by Nikolai Kosjar's avatar Nikolai Kosjar

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: default avatarChristian Stenger <christian.stenger@digia.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
Reviewed-by: default avatarRobert Loehning <robert.loehning@digia.com>
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 69a00cba
......@@ -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);
......
// Copyright license
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
// Copyright license
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
// Copyright license
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle" >
<string>MainWindow</string>
</property>
<widget class="QMenuBar" name="menuBar" />
<widget class="QToolBar" name="mainToolBar" />
<widget class="QWidget" name="centralWidget" />
<widget class="QStatusBar" name="statusBar" />
</widget>
<layoutDefault spacing="6" margin="11" />
<pixmapfunction></pixmapfunction>
<resources/>
<connections/>
</ui>
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = testdata_guiproject1
TEMPLATE = app
SOURCES += main.cpp mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment