forked from qt-creator/qt-creator
CppTools: Fix test_modelmanager_extraeditorsupport_uiFiles
The test was broken since the QmakeProject was changed to work asynchronously. FAIL! : CppTools::Internal::CppToolsPlugin::test_modelmanager_extraeditorsupport_uiFiles() Compared values are not the same Actual (workingCopy.size()): 1 Expected (2) : 2 Change-Id: I6f7d05fb70af3def5fc371a9783b606309686e32 Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
committed by
Erik Verbruggen
parent
ef403a4515
commit
b94b7b3ee6
@@ -59,6 +59,11 @@ QString TestDataDir::file(const QString &fileName) const
|
|||||||
return directory() + fileName;
|
return directory() + fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString TestDataDir::path() const
|
||||||
|
{
|
||||||
|
return m_directory;
|
||||||
|
}
|
||||||
|
|
||||||
QString TestDataDir::directory(const QString &subdir, bool clean) const
|
QString TestDataDir::directory(const QString &subdir, bool clean) const
|
||||||
{
|
{
|
||||||
QString path = m_directory;
|
QString path = m_directory;
|
||||||
|
|||||||
@@ -51,9 +51,12 @@ class CORE_EXPORT TestDataDir
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TestDataDir(const QString &directory);
|
TestDataDir(const QString &directory);
|
||||||
|
|
||||||
QString file(const QString &fileName) const;
|
QString file(const QString &fileName) const;
|
||||||
QString directory(const QString &subdir = QString(), bool clean = true) const;
|
QString directory(const QString &subdir = QString(), bool clean = true) const;
|
||||||
|
|
||||||
|
QString path() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_directory;
|
QString m_directory;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -49,9 +49,10 @@
|
|||||||
#include <QTemporaryDir>
|
#include <QTemporaryDir>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
using namespace CppTools::Internal;
|
|
||||||
using namespace ProjectExplorer;
|
|
||||||
using namespace CppTools;
|
using namespace CppTools;
|
||||||
|
using namespace CppTools::Internal;
|
||||||
|
using namespace CppTools::Tests;
|
||||||
|
using namespace ProjectExplorer;
|
||||||
|
|
||||||
typedef CPlusPlus::Document Document;
|
typedef CPlusPlus::Document Document;
|
||||||
|
|
||||||
@@ -112,46 +113,6 @@ public:
|
|||||||
QStringList projectFiles;
|
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)
|
|
||||||
{
|
|
||||||
const QString projectUserFile = projectFile + _(".user");
|
|
||||||
QVERIFY(!QFileInfo::exists(projectUserFile));
|
|
||||||
|
|
||||||
// Open project
|
|
||||||
QString errorOpeningProject;
|
|
||||||
m_project = ProjectExplorerPlugin::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));
|
|
||||||
}
|
|
||||||
|
|
||||||
Project *project() const
|
|
||||||
{
|
|
||||||
return m_project;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Project *m_project;
|
|
||||||
QString m_fileToRemove;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Changes a file on the disk and restores its original contents on destruction
|
/// Changes a file on the disk and restores its original contents on destruction
|
||||||
class FileChangerAndRestorer
|
class FileChangerAndRestorer
|
||||||
{
|
{
|
||||||
@@ -657,16 +618,19 @@ void CppToolsPlugin::test_modelmanager_snapshot_after_two_projects()
|
|||||||
/// is added for the ui_* file.
|
/// is added for the ui_* file.
|
||||||
/// Check: (2) The CppSourceProcessor can successfully resolve the ui_* file
|
/// Check: (2) The CppSourceProcessor can successfully resolve the ui_* file
|
||||||
/// though it might not be actually generated in the build dir.
|
/// though it might not be actually generated in the build dir.
|
||||||
|
///
|
||||||
|
|
||||||
void CppToolsPlugin::test_modelmanager_extraeditorsupport_uiFiles()
|
void CppToolsPlugin::test_modelmanager_extraeditorsupport_uiFiles()
|
||||||
{
|
{
|
||||||
ModelManagerTestHelper helper;
|
VerifyCleanCppModelManager verify;
|
||||||
|
|
||||||
MyTestDataDir testDataDirectory(_("testdata_guiproject1"));
|
TemporaryCopiedDir temporaryDir(MyTestDataDir(QLatin1String("testdata_guiproject1")).path());
|
||||||
const QString projectFile = testDataDirectory.file(_("testdata_guiproject1.pro"));
|
QVERIFY(temporaryDir.isValid());
|
||||||
|
const QString projectFile = temporaryDir.absolutePath("testdata_guiproject1.pro");
|
||||||
|
|
||||||
// Open project with *.ui file
|
ProjectOpenerAndCloser projects(/*waitForFinishedGcOnDestruction=*/ true);
|
||||||
ExampleProjectConfigurator exampleProjectConfigurator(projectFile);
|
ProjectInfo projectInfo = projects.open(projectFile, /*configureAsExampleProject=*/ true);
|
||||||
Project *project = exampleProjectConfigurator.project();
|
QVERIFY(projectInfo.isValid());
|
||||||
|
|
||||||
// Check working copy.
|
// Check working copy.
|
||||||
// An AbstractEditorSupport object should have been added for the ui_* file.
|
// An AbstractEditorSupport object should have been added for the ui_* file.
|
||||||
@@ -688,7 +652,7 @@ void CppToolsPlugin::test_modelmanager_extraeditorsupport_uiFiles()
|
|||||||
|
|
||||||
// Check CppSourceProcessor / includes.
|
// Check CppSourceProcessor / includes.
|
||||||
// The CppSourceProcessor is expected to find the ui_* file in the working copy.
|
// The CppSourceProcessor is expected to find the ui_* file in the working copy.
|
||||||
const QString fileIncludingTheUiFile = testDataDirectory.file(_("mainwindow.cpp"));
|
const QString fileIncludingTheUiFile = temporaryDir.absolutePath("mainwindow.cpp");
|
||||||
while (!mm->snapshot().document(fileIncludingTheUiFile))
|
while (!mm->snapshot().document(fileIncludingTheUiFile))
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
|
|
||||||
@@ -699,10 +663,6 @@ void CppToolsPlugin::test_modelmanager_extraeditorsupport_uiFiles()
|
|||||||
QCOMPARE(includedFiles.size(), 2);
|
QCOMPARE(includedFiles.size(), 2);
|
||||||
QCOMPARE(QFileInfo(includedFiles.at(0)).fileName(), _("mainwindow.h"));
|
QCOMPARE(QFileInfo(includedFiles.at(0)).fileName(), _("mainwindow.h"));
|
||||||
QCOMPARE(QFileInfo(includedFiles.at(1)).fileName(), _("ui_mainwindow.h"));
|
QCOMPARE(QFileInfo(includedFiles.at(1)).fileName(), _("ui_mainwindow.h"));
|
||||||
|
|
||||||
// Close Project
|
|
||||||
SessionManager::removeProject(project);
|
|
||||||
helper.waitForFinishedGc();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// QTCREATORBUG-9828: Locator shows symbols of closed files
|
/// QTCREATORBUG-9828: Locator shows symbols of closed files
|
||||||
|
|||||||
@@ -30,6 +30,8 @@
|
|||||||
|
|
||||||
#include "cpptoolstestcase.h"
|
#include "cpptoolstestcase.h"
|
||||||
|
|
||||||
|
#include "cppworkingcopy.h"
|
||||||
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <projectexplorer/projectexplorer.h>
|
#include <projectexplorer/projectexplorer.h>
|
||||||
#include <projectexplorer/session.h>
|
#include <projectexplorer/session.h>
|
||||||
@@ -214,18 +216,30 @@ bool TestCase::writeFile(const QString &filePath, const QByteArray &contents)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectOpenerAndCloser::ProjectOpenerAndCloser()
|
ProjectOpenerAndCloser::ProjectOpenerAndCloser(bool waitForFinishedGcOnDestruction)
|
||||||
|
: m_waitForFinishedGcOnDestruction(waitForFinishedGcOnDestruction)
|
||||||
|
, m_gcFinished(false)
|
||||||
{
|
{
|
||||||
QVERIFY(!SessionManager::hasProjects());
|
QVERIFY(!SessionManager::hasProjects());
|
||||||
|
if (m_waitForFinishedGcOnDestruction) {
|
||||||
|
CppModelManager *mm = CppModelManager::instance();
|
||||||
|
connect(mm, &CppModelManager::gcFinished, this, &ProjectOpenerAndCloser::onGcFinished);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectOpenerAndCloser::~ProjectOpenerAndCloser()
|
ProjectOpenerAndCloser::~ProjectOpenerAndCloser()
|
||||||
{
|
{
|
||||||
foreach (Project *project, m_openProjects)
|
foreach (Project *project, m_openProjects)
|
||||||
ProjectExplorerPlugin::unloadProject(project);
|
ProjectExplorerPlugin::unloadProject(project);
|
||||||
|
|
||||||
|
if (m_waitForFinishedGcOnDestruction) {
|
||||||
|
m_gcFinished = false;
|
||||||
|
while (!m_gcFinished)
|
||||||
|
QCoreApplication::processEvents();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectInfo ProjectOpenerAndCloser::open(const QString &projectFile)
|
ProjectInfo ProjectOpenerAndCloser::open(const QString &projectFile, bool configureAsExampleProject)
|
||||||
{
|
{
|
||||||
QString error;
|
QString error;
|
||||||
Project *project = ProjectExplorerPlugin::openProject(projectFile, &error);
|
Project *project = ProjectExplorerPlugin::openProject(projectFile, &error);
|
||||||
@@ -235,12 +249,20 @@ ProjectInfo ProjectOpenerAndCloser::open(const QString &projectFile)
|
|||||||
return ProjectInfo();
|
return ProjectInfo();
|
||||||
m_openProjects.append(project);
|
m_openProjects.append(project);
|
||||||
|
|
||||||
|
if (configureAsExampleProject)
|
||||||
|
project->configureAsExampleProject(QStringList());
|
||||||
|
|
||||||
if (TestCase::waitUntilCppModelManagerIsAwareOf(project))
|
if (TestCase::waitUntilCppModelManagerIsAwareOf(project))
|
||||||
return CppModelManager::instance()->projectInfo(project);
|
return CppModelManager::instance()->projectInfo(project);
|
||||||
|
|
||||||
return ProjectInfo();
|
return ProjectInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProjectOpenerAndCloser::onGcFinished()
|
||||||
|
{
|
||||||
|
m_gcFinished = true;
|
||||||
|
}
|
||||||
|
|
||||||
TemporaryCopiedDir::TemporaryCopiedDir(const QString &sourceDirPath)
|
TemporaryCopiedDir::TemporaryCopiedDir(const QString &sourceDirPath)
|
||||||
: m_temporaryDir(QDir::tempPath() + QLatin1String("/qtcreator-tests-XXXXXX"))
|
: m_temporaryDir(QDir::tempPath() + QLatin1String("/qtcreator-tests-XXXXXX"))
|
||||||
, m_isValid(m_temporaryDir.isValid())
|
, m_isValid(m_temporaryDir.isValid())
|
||||||
@@ -301,5 +323,18 @@ IAssistProposalScopedPointer::~IAssistProposalScopedPointer()
|
|||||||
delete d->model();
|
delete d->model();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VerifyCleanCppModelManager::verify()
|
||||||
|
{
|
||||||
|
CppModelManager *mm = CppModelManager::instance();
|
||||||
|
QVERIFY(mm);
|
||||||
|
QVERIFY(mm->projectInfos().isEmpty());
|
||||||
|
QVERIFY(mm->headerPaths().isEmpty());
|
||||||
|
QVERIFY(mm->definedMacros().isEmpty());
|
||||||
|
QVERIFY(mm->projectFiles().isEmpty());
|
||||||
|
QVERIFY(mm->snapshot().isEmpty());
|
||||||
|
QCOMPARE(mm->workingCopy().size(), 1);
|
||||||
|
QVERIFY(mm->workingCopy().contains(mm->configurationFileName()));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Tests
|
} // namespace Tests
|
||||||
} // namespace CppTools
|
} // namespace CppTools
|
||||||
|
|||||||
@@ -106,15 +106,21 @@ private:
|
|||||||
bool m_runGarbageCollector;
|
bool m_runGarbageCollector;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CPPTOOLS_EXPORT ProjectOpenerAndCloser
|
class CPPTOOLS_EXPORT ProjectOpenerAndCloser : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ProjectOpenerAndCloser();
|
ProjectOpenerAndCloser(bool waitForFinishedGcOnDestruction = false);
|
||||||
~ProjectOpenerAndCloser(); // Closes opened projects
|
~ProjectOpenerAndCloser(); // Closes opened projects
|
||||||
|
|
||||||
ProjectInfo open(const QString &projectFile);
|
ProjectInfo open(const QString &projectFile, bool configureAsExampleProject = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void onGcFinished();
|
||||||
|
|
||||||
|
bool m_waitForFinishedGcOnDestruction;
|
||||||
|
bool m_gcFinished;
|
||||||
QList<ProjectExplorer::Project *> m_openProjects;
|
QList<ProjectExplorer::Project *> m_openProjects;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -132,6 +138,14 @@ private:
|
|||||||
bool m_isValid;
|
bool m_isValid;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class VerifyCleanCppModelManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
VerifyCleanCppModelManager() { verify(); }
|
||||||
|
~VerifyCleanCppModelManager() { verify(); }
|
||||||
|
static void verify();
|
||||||
|
};
|
||||||
|
|
||||||
class FileWriterAndRemover
|
class FileWriterAndRemover
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
#include "modelmanagertesthelper.h"
|
#include "modelmanagertesthelper.h"
|
||||||
|
|
||||||
|
#include "cpptoolstestcase.h"
|
||||||
#include "cppworkingcopy.h"
|
#include "cppworkingcopy.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
@@ -68,13 +69,13 @@ ModelManagerTestHelper::ModelManagerTestHelper(QObject *parent) :
|
|||||||
connect(mm, SIGNAL(gcFinished()), this, SLOT(gcFinished()));
|
connect(mm, SIGNAL(gcFinished()), this, SLOT(gcFinished()));
|
||||||
|
|
||||||
cleanup();
|
cleanup();
|
||||||
verifyClean();
|
Tests::VerifyCleanCppModelManager::verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
ModelManagerTestHelper::~ModelManagerTestHelper()
|
ModelManagerTestHelper::~ModelManagerTestHelper()
|
||||||
{
|
{
|
||||||
cleanup();
|
cleanup();
|
||||||
verifyClean();
|
Tests::VerifyCleanCppModelManager::verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelManagerTestHelper::cleanup()
|
void ModelManagerTestHelper::cleanup()
|
||||||
@@ -90,20 +91,6 @@ void ModelManagerTestHelper::cleanup()
|
|||||||
waitForFinishedGc();
|
waitForFinishedGc();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelManagerTestHelper::verifyClean()
|
|
||||||
{
|
|
||||||
CppModelManager *mm = CppModelManager::instance();
|
|
||||||
assert(mm);
|
|
||||||
|
|
||||||
QVERIFY(mm->projectInfos().isEmpty());
|
|
||||||
QVERIFY(mm->headerPaths().isEmpty());
|
|
||||||
QVERIFY(mm->definedMacros().isEmpty());
|
|
||||||
QVERIFY(mm->projectFiles().isEmpty());
|
|
||||||
QVERIFY(mm->snapshot().isEmpty());
|
|
||||||
QCOMPARE(mm->workingCopy().size(), 1);
|
|
||||||
QVERIFY(mm->workingCopy().contains(mm->configurationFileName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
ModelManagerTestHelper::Project *ModelManagerTestHelper::createProject(const QString &name)
|
ModelManagerTestHelper::Project *ModelManagerTestHelper::createProject(const QString &name)
|
||||||
{
|
{
|
||||||
TestProject *tp = new TestProject(name, this);
|
TestProject *tp = new TestProject(name, this);
|
||||||
|
|||||||
@@ -76,7 +76,6 @@ public:
|
|||||||
~ModelManagerTestHelper();
|
~ModelManagerTestHelper();
|
||||||
|
|
||||||
void cleanup();
|
void cleanup();
|
||||||
static void verifyClean();
|
|
||||||
|
|
||||||
Project *createProject(const QString &name);
|
Project *createProject(const QString &name);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user