forked from qt-creator/qt-creator
		
	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:
		
				
					committed by
					
						
						Erik Verbruggen
					
				
			
			
				
	
			
			
			
						parent
						
							613304edfc
						
					
				
				
					commit
					ef403a4515
				
			@@ -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)
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -37,6 +37,7 @@
 | 
			
		||||
#include <coreplugin/editormanager/ieditor.h>
 | 
			
		||||
 | 
			
		||||
#include <QStringList>
 | 
			
		||||
#include <QTemporaryDir>
 | 
			
		||||
 | 
			
		||||
namespace CPlusPlus {
 | 
			
		||||
class Document;
 | 
			
		||||
@@ -44,6 +45,7 @@ class Snapshot;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace Core { class IEditor; }
 | 
			
		||||
namespace ProjectExplorer { class Project; }
 | 
			
		||||
 | 
			
		||||
namespace TextEditor {
 | 
			
		||||
class BaseTextEditor;
 | 
			
		||||
@@ -87,6 +89,8 @@ public:
 | 
			
		||||
    static CPlusPlus::Snapshot globalSnapshot();
 | 
			
		||||
    static bool garbageCollectGlobalSnapshot();
 | 
			
		||||
 | 
			
		||||
    static bool waitUntilCppModelManagerIsAwareOf(ProjectExplorer::Project *project,
 | 
			
		||||
                                                  int timeOut = 30 * 1000 /*= 30 secs*/);
 | 
			
		||||
    static CPlusPlus::Document::Ptr waitForFileInGlobalSnapshot(const QString &filePath);
 | 
			
		||||
    static QList<CPlusPlus::Document::Ptr> waitForFilesInGlobalSnapshot(
 | 
			
		||||
            const QStringList &filePaths);
 | 
			
		||||
@@ -102,6 +106,32 @@ private:
 | 
			
		||||
    bool m_runGarbageCollector;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class CPPTOOLS_EXPORT ProjectOpenerAndCloser
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    ProjectOpenerAndCloser();
 | 
			
		||||
    ~ProjectOpenerAndCloser(); // Closes opened projects
 | 
			
		||||
 | 
			
		||||
    ProjectInfo open(const QString &projectFile);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    QList<ProjectExplorer::Project *> m_openProjects;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class CPPTOOLS_EXPORT TemporaryCopiedDir
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    TemporaryCopiedDir(const QString &sourceDirPath);
 | 
			
		||||
 | 
			
		||||
    bool isValid() const { return m_isValid; }
 | 
			
		||||
    QString path() const { return m_temporaryDir.path(); }
 | 
			
		||||
    QString absolutePath(const QByteArray &relativePath) const;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    QTemporaryDir m_temporaryDir;
 | 
			
		||||
    bool m_isValid;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class FileWriterAndRemover
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user