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
				
			@@ -49,9 +49,10 @@
 | 
			
		||||
#include <QTemporaryDir>
 | 
			
		||||
#include <QtTest>
 | 
			
		||||
 | 
			
		||||
using namespace CppTools::Internal;
 | 
			
		||||
using namespace ProjectExplorer;
 | 
			
		||||
using namespace CppTools;
 | 
			
		||||
using namespace CppTools::Internal;
 | 
			
		||||
using namespace CppTools::Tests;
 | 
			
		||||
using namespace ProjectExplorer;
 | 
			
		||||
 | 
			
		||||
typedef CPlusPlus::Document Document;
 | 
			
		||||
 | 
			
		||||
@@ -112,46 +113,6 @@ public:
 | 
			
		||||
    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
 | 
			
		||||
class FileChangerAndRestorer
 | 
			
		||||
{
 | 
			
		||||
@@ -657,16 +618,19 @@ void CppToolsPlugin::test_modelmanager_snapshot_after_two_projects()
 | 
			
		||||
///            is added for the ui_* file.
 | 
			
		||||
/// Check: (2) The CppSourceProcessor can successfully resolve the ui_* file
 | 
			
		||||
///            though it might not be actually generated in the build dir.
 | 
			
		||||
///
 | 
			
		||||
 | 
			
		||||
void CppToolsPlugin::test_modelmanager_extraeditorsupport_uiFiles()
 | 
			
		||||
{
 | 
			
		||||
    ModelManagerTestHelper helper;
 | 
			
		||||
    VerifyCleanCppModelManager verify;
 | 
			
		||||
 | 
			
		||||
    MyTestDataDir testDataDirectory(_("testdata_guiproject1"));
 | 
			
		||||
    const QString projectFile = testDataDirectory.file(_("testdata_guiproject1.pro"));
 | 
			
		||||
    TemporaryCopiedDir temporaryDir(MyTestDataDir(QLatin1String("testdata_guiproject1")).path());
 | 
			
		||||
    QVERIFY(temporaryDir.isValid());
 | 
			
		||||
    const QString projectFile = temporaryDir.absolutePath("testdata_guiproject1.pro");
 | 
			
		||||
 | 
			
		||||
    // Open project with *.ui file
 | 
			
		||||
    ExampleProjectConfigurator exampleProjectConfigurator(projectFile);
 | 
			
		||||
    Project *project = exampleProjectConfigurator.project();
 | 
			
		||||
    ProjectOpenerAndCloser projects(/*waitForFinishedGcOnDestruction=*/ true);
 | 
			
		||||
    ProjectInfo projectInfo = projects.open(projectFile, /*configureAsExampleProject=*/ true);
 | 
			
		||||
    QVERIFY(projectInfo.isValid());
 | 
			
		||||
 | 
			
		||||
    // Check working copy.
 | 
			
		||||
    // An AbstractEditorSupport object should have been added for the ui_* file.
 | 
			
		||||
@@ -688,7 +652,7 @@ void CppToolsPlugin::test_modelmanager_extraeditorsupport_uiFiles()
 | 
			
		||||
 | 
			
		||||
    // Check CppSourceProcessor / includes.
 | 
			
		||||
    // 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))
 | 
			
		||||
        QCoreApplication::processEvents();
 | 
			
		||||
 | 
			
		||||
@@ -699,10 +663,6 @@ void CppToolsPlugin::test_modelmanager_extraeditorsupport_uiFiles()
 | 
			
		||||
    QCOMPARE(includedFiles.size(), 2);
 | 
			
		||||
    QCOMPARE(QFileInfo(includedFiles.at(0)).fileName(), _("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
 | 
			
		||||
 
 | 
			
		||||
@@ -30,6 +30,8 @@
 | 
			
		||||
 | 
			
		||||
#include "cpptoolstestcase.h"
 | 
			
		||||
 | 
			
		||||
#include "cppworkingcopy.h"
 | 
			
		||||
 | 
			
		||||
#include <coreplugin/editormanager/editormanager.h>
 | 
			
		||||
#include <projectexplorer/projectexplorer.h>
 | 
			
		||||
#include <projectexplorer/session.h>
 | 
			
		||||
@@ -214,18 +216,30 @@ bool TestCase::writeFile(const QString &filePath, const QByteArray &contents)
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ProjectOpenerAndCloser::ProjectOpenerAndCloser()
 | 
			
		||||
ProjectOpenerAndCloser::ProjectOpenerAndCloser(bool waitForFinishedGcOnDestruction)
 | 
			
		||||
    : m_waitForFinishedGcOnDestruction(waitForFinishedGcOnDestruction)
 | 
			
		||||
    , m_gcFinished(false)
 | 
			
		||||
{
 | 
			
		||||
    QVERIFY(!SessionManager::hasProjects());
 | 
			
		||||
    if (m_waitForFinishedGcOnDestruction) {
 | 
			
		||||
        CppModelManager *mm = CppModelManager::instance();
 | 
			
		||||
        connect(mm, &CppModelManager::gcFinished, this, &ProjectOpenerAndCloser::onGcFinished);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ProjectOpenerAndCloser::~ProjectOpenerAndCloser()
 | 
			
		||||
{
 | 
			
		||||
    foreach (Project *project, m_openProjects)
 | 
			
		||||
        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;
 | 
			
		||||
    Project *project = ProjectExplorerPlugin::openProject(projectFile, &error);
 | 
			
		||||
@@ -235,12 +249,20 @@ ProjectInfo ProjectOpenerAndCloser::open(const QString &projectFile)
 | 
			
		||||
        return ProjectInfo();
 | 
			
		||||
    m_openProjects.append(project);
 | 
			
		||||
 | 
			
		||||
    if (configureAsExampleProject)
 | 
			
		||||
        project->configureAsExampleProject(QStringList());
 | 
			
		||||
 | 
			
		||||
    if (TestCase::waitUntilCppModelManagerIsAwareOf(project))
 | 
			
		||||
        return CppModelManager::instance()->projectInfo(project);
 | 
			
		||||
 | 
			
		||||
    return ProjectInfo();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ProjectOpenerAndCloser::onGcFinished()
 | 
			
		||||
{
 | 
			
		||||
    m_gcFinished = true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TemporaryCopiedDir::TemporaryCopiedDir(const QString &sourceDirPath)
 | 
			
		||||
    : m_temporaryDir(QDir::tempPath() + QLatin1String("/qtcreator-tests-XXXXXX"))
 | 
			
		||||
    , m_isValid(m_temporaryDir.isValid())
 | 
			
		||||
@@ -301,5 +323,18 @@ IAssistProposalScopedPointer::~IAssistProposalScopedPointer()
 | 
			
		||||
        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 CppTools
 | 
			
		||||
 
 | 
			
		||||
@@ -106,15 +106,21 @@ private:
 | 
			
		||||
    bool m_runGarbageCollector;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class CPPTOOLS_EXPORT ProjectOpenerAndCloser
 | 
			
		||||
class CPPTOOLS_EXPORT ProjectOpenerAndCloser : public QObject
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    ProjectOpenerAndCloser();
 | 
			
		||||
    ProjectOpenerAndCloser(bool waitForFinishedGcOnDestruction = false);
 | 
			
		||||
    ~ProjectOpenerAndCloser(); // Closes opened projects
 | 
			
		||||
 | 
			
		||||
    ProjectInfo open(const QString &projectFile);
 | 
			
		||||
    ProjectInfo open(const QString &projectFile, bool configureAsExampleProject = false);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    void onGcFinished();
 | 
			
		||||
 | 
			
		||||
    bool m_waitForFinishedGcOnDestruction;
 | 
			
		||||
    bool m_gcFinished;
 | 
			
		||||
    QList<ProjectExplorer::Project *> m_openProjects;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@@ -132,6 +138,14 @@ private:
 | 
			
		||||
    bool m_isValid;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class VerifyCleanCppModelManager
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    VerifyCleanCppModelManager() { verify(); }
 | 
			
		||||
    ~VerifyCleanCppModelManager() { verify(); }
 | 
			
		||||
    static void verify();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class FileWriterAndRemover
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
 
 | 
			
		||||
@@ -30,6 +30,7 @@
 | 
			
		||||
 | 
			
		||||
#include "modelmanagertesthelper.h"
 | 
			
		||||
 | 
			
		||||
#include "cpptoolstestcase.h"
 | 
			
		||||
#include "cppworkingcopy.h"
 | 
			
		||||
 | 
			
		||||
#include <QtTest>
 | 
			
		||||
@@ -68,13 +69,13 @@ ModelManagerTestHelper::ModelManagerTestHelper(QObject *parent) :
 | 
			
		||||
    connect(mm, SIGNAL(gcFinished()), this, SLOT(gcFinished()));
 | 
			
		||||
 | 
			
		||||
    cleanup();
 | 
			
		||||
    verifyClean();
 | 
			
		||||
    Tests::VerifyCleanCppModelManager::verify();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ModelManagerTestHelper::~ModelManagerTestHelper()
 | 
			
		||||
{
 | 
			
		||||
    cleanup();
 | 
			
		||||
    verifyClean();
 | 
			
		||||
    Tests::VerifyCleanCppModelManager::verify();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ModelManagerTestHelper::cleanup()
 | 
			
		||||
@@ -90,20 +91,6 @@ void ModelManagerTestHelper::cleanup()
 | 
			
		||||
        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)
 | 
			
		||||
{
 | 
			
		||||
    TestProject *tp = new TestProject(name, this);
 | 
			
		||||
 
 | 
			
		||||
@@ -76,7 +76,6 @@ public:
 | 
			
		||||
    ~ModelManagerTestHelper();
 | 
			
		||||
 | 
			
		||||
    void cleanup();
 | 
			
		||||
    static void verifyClean();
 | 
			
		||||
 | 
			
		||||
    Project *createProject(const QString &name);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user