Commit 94258120 authored by Nikolai Kosjar's avatar Nikolai Kosjar

CppTools: Export ModelManagerTestHelper

Needed for tests in ClangCodeModel.

Change-Id: I58bdb35811776751a95b5db198ea8d6cdb0cd6de
Reviewed-by: default avatarMarco Bubke <marco.bubke@theqtcompany.com>
parent e661a9c1
...@@ -59,6 +59,9 @@ class WorkingCopy; ...@@ -59,6 +59,9 @@ class WorkingCopy;
namespace Internal { namespace Internal {
class CppSourceProcessor; class CppSourceProcessor;
class CppModelManagerPrivate; class CppModelManagerPrivate;
}
namespace Tests {
class ModelManagerTestHelper; class ModelManagerTestHelper;
} }
...@@ -177,7 +180,7 @@ public slots: ...@@ -177,7 +180,7 @@ public slots:
private slots: private slots:
// This should be executed in the GUI thread. // This should be executed in the GUI thread.
friend class Internal::ModelManagerTestHelper; friend class Tests::ModelManagerTestHelper;
void onAboutToLoadSession(); void onAboutToLoadSession();
void onAboutToUnloadSession(); void onAboutToUnloadSession();
void renameIncludes(const QString &oldFileName, const QString &newFileName); void renameIncludes(const QString &oldFileName, const QString &newFileName);
......
...@@ -167,15 +167,6 @@ private: ...@@ -167,15 +167,6 @@ private:
const QString &m_filePath; const QString &m_filePath;
}; };
static QSet<QString> updateProjectInfo(CppModelManager *modelManager, ModelManagerTestHelper *helper,
const ProjectInfo &projectInfo)
{
helper->resetRefreshedSourceFiles();
modelManager->updateProjectInfo(projectInfo).waitForFinished();
QCoreApplication::processEvents();
return helper->waitForRefreshedSourceFiles();
}
void waitForProcessedEditorDocument(const QString &filePath) void waitForProcessedEditorDocument(const QString &filePath)
{ {
CppEditorDocumentHandle *editorDocument CppEditorDocumentHandle *editorDocument
...@@ -297,7 +288,7 @@ void CppToolsPlugin::test_modelmanager_refresh_also_includes_of_project_files() ...@@ -297,7 +288,7 @@ void CppToolsPlugin::test_modelmanager_refresh_also_includes_of_project_files()
pi.appendProjectPart(part); pi.appendProjectPart(part);
pi.finish(); pi.finish();
QSet<QString> refreshedFiles = updateProjectInfo(mm, &helper, pi); QSet<QString> refreshedFiles = helper.updateProjectInfo(pi);
QCOMPARE(refreshedFiles.size(), 1); QCOMPARE(refreshedFiles.size(), 1);
QVERIFY(refreshedFiles.contains(testCpp)); QVERIFY(refreshedFiles.contains(testCpp));
CPlusPlus::Snapshot snapshot = mm->snapshot(); CPlusPlus::Snapshot snapshot = mm->snapshot();
...@@ -315,7 +306,7 @@ void CppToolsPlugin::test_modelmanager_refresh_also_includes_of_project_files() ...@@ -315,7 +306,7 @@ void CppToolsPlugin::test_modelmanager_refresh_also_includes_of_project_files()
pi.appendProjectPart(part); pi.appendProjectPart(part);
pi.finish(); pi.finish();
refreshedFiles = updateProjectInfo(mm, &helper, pi); refreshedFiles = helper.updateProjectInfo(pi);
QCOMPARE(refreshedFiles.size(), 1); QCOMPARE(refreshedFiles.size(), 1);
QVERIFY(refreshedFiles.contains(testCpp)); QVERIFY(refreshedFiles.contains(testCpp));
...@@ -376,7 +367,7 @@ void CppToolsPlugin::test_modelmanager_refresh_several_times() ...@@ -376,7 +367,7 @@ void CppToolsPlugin::test_modelmanager_refresh_several_times()
pi.appendProjectPart(part); pi.appendProjectPart(part);
pi.finish(); pi.finish();
refreshedFiles = updateProjectInfo(mm, &helper, pi); refreshedFiles = helper.updateProjectInfo(pi);
QCOMPARE(refreshedFiles.size(), 3); QCOMPARE(refreshedFiles.size(), 3);
QVERIFY(refreshedFiles.contains(testHeader1)); QVERIFY(refreshedFiles.contains(testHeader1));
...@@ -461,7 +452,7 @@ void CppToolsPlugin::test_modelmanager_refresh_added_and_purge_removed() ...@@ -461,7 +452,7 @@ void CppToolsPlugin::test_modelmanager_refresh_added_and_purge_removed()
CPlusPlus::Snapshot snapshot; CPlusPlus::Snapshot snapshot;
QSet<QString> refreshedFiles; QSet<QString> refreshedFiles;
refreshedFiles = updateProjectInfo(mm, &helper, pi); refreshedFiles = helper.updateProjectInfo(pi);
QCOMPARE(refreshedFiles.size(), 2); QCOMPARE(refreshedFiles.size(), 2);
QVERIFY(refreshedFiles.contains(testHeader1)); QVERIFY(refreshedFiles.contains(testHeader1));
...@@ -481,7 +472,7 @@ void CppToolsPlugin::test_modelmanager_refresh_added_and_purge_removed() ...@@ -481,7 +472,7 @@ void CppToolsPlugin::test_modelmanager_refresh_added_and_purge_removed()
pi.appendProjectPart(newPart); pi.appendProjectPart(newPart);
pi.finish(); pi.finish();
refreshedFiles = updateProjectInfo(mm, &helper, pi); refreshedFiles = helper.updateProjectInfo(pi);
// Only the added project file was reparsed // Only the added project file was reparsed
QCOMPARE(refreshedFiles.size(), 1); QCOMPARE(refreshedFiles.size(), 1);
...@@ -527,7 +518,7 @@ void CppToolsPlugin::test_modelmanager_refresh_timeStampModified_if_sourcefiles_ ...@@ -527,7 +518,7 @@ void CppToolsPlugin::test_modelmanager_refresh_timeStampModified_if_sourcefiles_
CPlusPlus::Snapshot snapshot; CPlusPlus::Snapshot snapshot;
QSet<QString> refreshedFiles; QSet<QString> refreshedFiles;
refreshedFiles = updateProjectInfo(mm, &helper, pi); refreshedFiles = helper.updateProjectInfo(pi);
QCOMPARE(refreshedFiles.size(), initialProjectFiles.size()); QCOMPARE(refreshedFiles.size(), initialProjectFiles.size());
snapshot = mm->snapshot(); snapshot = mm->snapshot();
...@@ -557,7 +548,7 @@ void CppToolsPlugin::test_modelmanager_refresh_timeStampModified_if_sourcefiles_ ...@@ -557,7 +548,7 @@ void CppToolsPlugin::test_modelmanager_refresh_timeStampModified_if_sourcefiles_
pi.appendProjectPart(part); pi.appendProjectPart(part);
pi.finish(); pi.finish();
refreshedFiles = updateProjectInfo(mm, &helper, pi); refreshedFiles = helper.updateProjectInfo(pi);
QCOMPARE(refreshedFiles.size(), finalProjectFiles.size()); QCOMPARE(refreshedFiles.size(), finalProjectFiles.size());
snapshot = mm->snapshot(); snapshot = mm->snapshot();
...@@ -610,7 +601,7 @@ void CppToolsPlugin::test_modelmanager_snapshot_after_two_projects() ...@@ -610,7 +601,7 @@ void CppToolsPlugin::test_modelmanager_snapshot_after_two_projects()
<< _("foo.cpp") << _("foo.cpp")
<< _("main.cpp")); << _("main.cpp"));
refreshedFiles = updateProjectInfo(mm, &helper, project1.projectInfo); refreshedFiles = helper.updateProjectInfo(project1.projectInfo);
QCOMPARE(refreshedFiles, project1.projectFiles.toSet()); QCOMPARE(refreshedFiles, project1.projectFiles.toSet());
const int snapshotSizeAfterProject1 = mm->snapshot().size(); const int snapshotSizeAfterProject1 = mm->snapshot().size();
...@@ -624,7 +615,7 @@ void CppToolsPlugin::test_modelmanager_snapshot_after_two_projects() ...@@ -624,7 +615,7 @@ void CppToolsPlugin::test_modelmanager_snapshot_after_two_projects()
<< _("bar.cpp") << _("bar.cpp")
<< _("main.cpp")); << _("main.cpp"));
refreshedFiles = updateProjectInfo(mm, &helper, project2.projectInfo); refreshedFiles = helper.updateProjectInfo(project2.projectInfo);
QCOMPARE(refreshedFiles, project2.projectFiles.toSet()); QCOMPARE(refreshedFiles, project2.projectFiles.toSet());
const int snapshotSizeAfterProject2 = mm->snapshot().size(); const int snapshotSizeAfterProject2 = mm->snapshot().size();
...@@ -824,7 +815,7 @@ void CppToolsPlugin::test_modelmanager_defines_per_project() ...@@ -824,7 +815,7 @@ void CppToolsPlugin::test_modelmanager_defines_per_project()
pi.appendProjectPart(part2); pi.appendProjectPart(part2);
pi.finish(); pi.finish();
updateProjectInfo(mm, &helper, pi); helper.updateProjectInfo(pi);
QCOMPARE(mm->snapshot().size(), 4); QCOMPARE(mm->snapshot().size(), 4);
// Open a file in the editor // Open a file in the editor
...@@ -895,7 +886,7 @@ void CppToolsPlugin::test_modelmanager_precompiled_headers() ...@@ -895,7 +886,7 @@ void CppToolsPlugin::test_modelmanager_precompiled_headers()
pi.appendProjectPart(part2); pi.appendProjectPart(part2);
pi.finish(); pi.finish();
updateProjectInfo(mm, &helper, pi); helper.updateProjectInfo(pi);
QCOMPARE(mm->snapshot().size(), 4); QCOMPARE(mm->snapshot().size(), 4);
// Open a file in the editor // Open a file in the editor
...@@ -977,7 +968,7 @@ void CppToolsPlugin::test_modelmanager_defines_per_editor() ...@@ -977,7 +968,7 @@ void CppToolsPlugin::test_modelmanager_defines_per_editor()
pi.appendProjectPart(part2); pi.appendProjectPart(part2);
pi.finish(); pi.finish();
updateProjectInfo(mm, &helper, pi); helper.updateProjectInfo(pi);
QCOMPARE(mm->snapshot().size(), 4); QCOMPARE(mm->snapshot().size(), 4);
...@@ -1059,7 +1050,7 @@ void CppToolsPlugin::test_modelmanager_updateEditorsAfterProjectUpdate() ...@@ -1059,7 +1050,7 @@ void CppToolsPlugin::test_modelmanager_updateEditorsAfterProjectUpdate()
ProjectInfo pi = ProjectInfo(project); ProjectInfo pi = ProjectInfo(project);
pi.appendProjectPart(part); pi.appendProjectPart(part);
pi.finish(); pi.finish();
updateProjectInfo(mm, &helper, pi); helper.updateProjectInfo(pi);
// ... and check for updated editor document A // ... and check for updated editor document A
while (editorDocumentA->processor()->isParserRunning()) while (editorDocumentA->processor()->isParserRunning())
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
Q_DECLARE_METATYPE(QSet<QString>) Q_DECLARE_METATYPE(QSet<QString>)
using namespace CppTools::Internal; using namespace CppTools::Internal;
using namespace CppTools::Tests;
TestProject::TestProject(const QString &name, QObject *parent) TestProject::TestProject(const QString &name, QObject *parent)
: m_name (name) : m_name (name)
...@@ -95,6 +96,14 @@ ModelManagerTestHelper::Project *ModelManagerTestHelper::createProject(const QSt ...@@ -95,6 +96,14 @@ ModelManagerTestHelper::Project *ModelManagerTestHelper::createProject(const QSt
return tp; return tp;
} }
QSet<QString> ModelManagerTestHelper::updateProjectInfo(const CppTools::ProjectInfo &projectInfo)
{
resetRefreshedSourceFiles();
CppModelManager::instance()->updateProjectInfo(projectInfo).waitForFinished();
QCoreApplication::processEvents();
return waitForRefreshedSourceFiles();
}
void ModelManagerTestHelper::resetRefreshedSourceFiles() void ModelManagerTestHelper::resetRefreshedSourceFiles()
{ {
m_lastRefreshedSourceFiles.clear(); m_lastRefreshedSourceFiles.clear();
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#ifndef CPPTOOLS_INTERNAL_MODELMANAGERTESTHELPER_H #ifndef CPPTOOLS_INTERNAL_MODELMANAGERTESTHELPER_H
#define CPPTOOLS_INTERNAL_MODELMANAGERTESTHELPER_H #define CPPTOOLS_INTERNAL_MODELMANAGERTESTHELPER_H
#include "cpptools_global.h"
#include "cppmodelmanager.h" #include "cppmodelmanager.h"
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
...@@ -38,9 +39,9 @@ ...@@ -38,9 +39,9 @@
#include <QObject> #include <QObject>
namespace CppTools { namespace CppTools {
namespace Internal { namespace Tests {
class TestProject: public ProjectExplorer::Project class CPPTOOLS_EXPORT TestProject: public ProjectExplorer::Project
{ {
Q_OBJECT Q_OBJECT
...@@ -67,7 +68,7 @@ private: ...@@ -67,7 +68,7 @@ private:
QString m_name; QString m_name;
}; };
class ModelManagerTestHelper: public QObject class CPPTOOLS_EXPORT ModelManagerTestHelper: public QObject
{ {
Q_OBJECT Q_OBJECT
...@@ -81,6 +82,8 @@ public: ...@@ -81,6 +82,8 @@ public:
Project *createProject(const QString &name); Project *createProject(const QString &name);
QSet<QString> updateProjectInfo(const ProjectInfo &projectInfo);
void resetRefreshedSourceFiles(); void resetRefreshedSourceFiles();
QSet<QString> waitForRefreshedSourceFiles(); QSet<QString> waitForRefreshedSourceFiles();
void waitForFinishedGc(); void waitForFinishedGc();
...@@ -99,7 +102,7 @@ private: ...@@ -99,7 +102,7 @@ private:
QSet<QString> m_lastRefreshedSourceFiles; QSet<QString> m_lastRefreshedSourceFiles;
}; };
} // namespace Internal } // namespace Tests
} // namespace CppTools } // namespace CppTools
#endif // CPPTOOLS_INTERNAL_MODELMANAGERTESTHELPER_H #endif // CPPTOOLS_INTERNAL_MODELMANAGERTESTHELPER_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment