summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cpptoolstestcase.cpp
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@theqtcompany.com>2014-12-09 13:01:44 +0100
committerErik Verbruggen <erik.verbruggen@theqtcompany.com>2014-12-19 10:24:48 +0100
commitef403a4515aa93272f6e5155b2897ddd02fb128e (patch)
tree13c652bceaddec4fddd10a80a5173e489791afc0 /src/plugins/cpptools/cpptoolstestcase.cpp
parent613304edfc6e18ae382f4662ffef78706870499f (diff)
downloadqt-creator-ef403a4515aa93272f6e5155b2897ddd02fb128e.tar.gz
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>
Diffstat (limited to 'src/plugins/cpptools/cpptoolstestcase.cpp')
-rw-r--r--src/plugins/cpptools/cpptoolstestcase.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/plugins/cpptools/cpptoolstestcase.cpp b/src/plugins/cpptools/cpptoolstestcase.cpp
index 00750ed0d9..0102384aa8 100644
--- a/src/plugins/cpptools/cpptoolstestcase.cpp
+++ b/src/plugins/cpptools/cpptoolstestcase.cpp
@@ -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)
{