GenericProjectManager: Tests: Clean up

* Get rid of CppModelManagerHelper.
  Now we simply use CppModelManager::projectInfo(someProject).isValid() to
  test whether a project is loaded.

* Copy project data to temporary dir before opening the projects.
  This avoids creating *.user files in the Qt Creator source tree and
  annoying pop ups on test start.

Change-Id: I1a57441ca2099beb6bb96cf620390d669fb47601
Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
Nikolai Kosjar
2014-12-09 13:01:44 +01:00
committed by Erik Verbruggen
parent 613304edfc
commit ef403a4515
7 changed files with 143 additions and 217 deletions

View File

@@ -31,6 +31,8 @@
#include "cpptoolstestcase.h"
#include <coreplugin/editormanager/editormanager.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
#include <texteditor/texteditor.h>
#include <texteditor/codeassist/iassistproposal.h>
#include <texteditor/codeassist/iassistproposalmodel.h>
@@ -40,6 +42,8 @@
#include <QtTest>
using namespace ProjectExplorer;
static bool closeEditorsWithoutGarbageCollectorInvocation(const QList<Core::IEditor *> &editors)
{
CppTools::CppModelManager::instance()->enableGarbageCollector(false);
@@ -181,6 +185,24 @@ QList<CPlusPlus::Document::Ptr> TestCase::waitForFilesInGlobalSnapshot(
return result;
}
bool TestCase::waitUntilCppModelManagerIsAwareOf(Project *project, int timeOut)
{
if (!project)
return false;
QTime t;
t.start();
CppModelManager *modelManager = CppModelManager::instance();
forever {
if (modelManager->projectInfo(project).isValid())
return true;
if (t.elapsed() > timeOut)
return false;
QCoreApplication::processEvents();
}
}
bool TestCase::writeFile(const QString &filePath, const QByteArray &contents)
{
Utils::FileSaver saver(filePath);
@@ -192,6 +214,60 @@ bool TestCase::writeFile(const QString &filePath, const QByteArray &contents)
return true;
}
ProjectOpenerAndCloser::ProjectOpenerAndCloser()
{
QVERIFY(!SessionManager::hasProjects());
}
ProjectOpenerAndCloser::~ProjectOpenerAndCloser()
{
foreach (Project *project, m_openProjects)
ProjectExplorerPlugin::unloadProject(project);
}
ProjectInfo ProjectOpenerAndCloser::open(const QString &projectFile)
{
QString error;
Project *project = ProjectExplorerPlugin::openProject(projectFile, &error);
if (!error.isEmpty())
qWarning() << error;
if (!project)
return ProjectInfo();
m_openProjects.append(project);
if (TestCase::waitUntilCppModelManagerIsAwareOf(project))
return CppModelManager::instance()->projectInfo(project);
return ProjectInfo();
}
TemporaryCopiedDir::TemporaryCopiedDir(const QString &sourceDirPath)
: m_temporaryDir(QDir::tempPath() + QLatin1String("/qtcreator-tests-XXXXXX"))
, m_isValid(m_temporaryDir.isValid())
{
if (!m_isValid)
return;
if (!sourceDirPath.isEmpty()) {
QFileInfo fi(sourceDirPath);
if (!fi.exists() || !fi.isReadable()) {
m_isValid = false;
return;
}
if (!Utils::FileUtils::copyRecursively(Utils::FileName::fromString(sourceDirPath),
Utils::FileName::fromString(path()))) {
m_isValid = false;
return;
}
}
}
QString TemporaryCopiedDir::absolutePath(const QByteArray &relativePath) const
{
return m_temporaryDir.path() + QLatin1Char('/') + QString::fromUtf8(relativePath);
}
FileWriterAndRemover::FileWriterAndRemover(const QString &filePath, const QByteArray &contents)
: m_filePath(filePath)
{