summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cppmodelmanager_test.cpp
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@digia.com>2013-07-01 10:25:03 +0200
committerNikolai Kosjar <nikolai.kosjar@digia.com>2013-07-02 12:09:43 +0200
commitc264c0d2137d15ec3746ed0f3bd80f225671b4a6 (patch)
tree83f982b9eec9cc55c9186ff227364caca8cec393 /src/plugins/cpptools/cppmodelmanager_test.cpp
parent69a00cbabecd6692a07d688db3fd52d540a0aa84 (diff)
downloadqt-creator-c264c0d2137d15ec3746ed0f3bd80f225671b4a6.tar.gz
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>
Diffstat (limited to 'src/plugins/cpptools/cppmodelmanager_test.cpp')
-rw-r--r--src/plugins/cpptools/cppmodelmanager_test.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/plugins/cpptools/cppmodelmanager_test.cpp b/src/plugins/cpptools/cppmodelmanager_test.cpp
index d01c4ff5ab..305b16b2c2 100644
--- a/src/plugins/cpptools/cppmodelmanager_test.cpp
+++ b/src/plugins/cpptools/cppmodelmanager_test.cpp
@@ -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();
+}