aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Bubke <[email protected]>2018-09-06 11:57:36 +0200
committerMarco Bubke <[email protected]>2018-09-12 14:32:34 +0000
commite0b7a283332095fea03a5bed310b632e72f7d486 (patch)
tree39298c1fb984c0492da6118bb428385a88e18f75
parent415fc654cce0228d8e3800ddc1ebe3517c3ff119 (diff)
Clang: Add refactoring project updater
The project parts are now first used by the pch manager and then notified by the pch manager to the refactoring plugin. Change-Id: I88074d8891cd0de9721497bbafee0deffc0b6339 Reviewed-by: Ivan Donchevskii <[email protected]>
-rw-r--r--src/plugins/clangpchmanager/clangpchmanagerplugin.cpp3
-rw-r--r--src/plugins/clangrefactoring/clangrefactoring.pro6
-rw-r--r--src/plugins/clangrefactoring/clangrefactoringplugin.cpp8
-rw-r--r--src/plugins/clangrefactoring/qtcreatorrefactoringprojectupdater.cpp98
-rw-r--r--src/plugins/clangrefactoring/qtcreatorrefactoringprojectupdater.h45
-rw-r--r--src/plugins/clangrefactoring/refactoringprojectupdater.cpp16
-rw-r--r--src/plugins/clangrefactoring/refactoringprojectupdater.h27
-rw-r--r--src/plugins/cpptools/cppmodelmanager.h4
-rw-r--r--src/plugins/cpptools/cppmodelmanagerinterface.h40
-rw-r--r--src/plugins/cpptools/cpptools.pro3
-rw-r--r--src/tools/clangpchmanagerbackend/source/pchcreator.cpp7
-rw-r--r--tests/unit/unittest/mockcppmodelmanager.h37
-rw-r--r--tests/unit/unittest/refactoringprojectupdater-test.cpp132
-rw-r--r--tests/unit/unittest/unittest-utility-functions.h6
-rw-r--r--tests/unit/unittest/unittest.pro6
15 files changed, 414 insertions, 24 deletions
diff --git a/src/plugins/clangpchmanager/clangpchmanagerplugin.cpp b/src/plugins/clangpchmanager/clangpchmanagerplugin.cpp
index ee800ad944a..5817db90344 100644
--- a/src/plugins/clangpchmanager/clangpchmanagerplugin.cpp
+++ b/src/plugins/clangpchmanager/clangpchmanagerplugin.cpp
@@ -65,6 +65,9 @@ public:
PrecompiledHeaderStorage<> preCompiledHeaderStorage{database};
PchManagerClient pchManagerClient{preCompiledHeaderStorage};
PchManagerConnectionClient connectionClient{&pchManagerClient};
+ QtCreatorProjectUpdater<PchManagerProjectUpdater> projectUpdate{connectionClient.serverProxy(),
+ pchManagerClient,
+ filePathCache};
};
std::unique_ptr<ClangPchManagerPluginData> ClangPchManagerPlugin::d;
diff --git a/src/plugins/clangrefactoring/clangrefactoring.pro b/src/plugins/clangrefactoring/clangrefactoring.pro
index e859631cbf7..d23e9a9a442 100644
--- a/src/plugins/clangrefactoring/clangrefactoring.pro
+++ b/src/plugins/clangrefactoring/clangrefactoring.pro
@@ -21,7 +21,8 @@ HEADERS += \
sourcelocations.h \
symbolsfindfilterconfigwidget.h \
symbolquery.h \
- qtcreatoreditormanager.h
+ qtcreatoreditormanager.h \
+ qtcreatorrefactoringprojectupdater.h
SOURCES += \
clangrefactoringplugin.cpp \
@@ -35,7 +36,8 @@ SOURCES += \
qtcreatorsearchhandle.cpp \
qtcreatorsymbolsfindfilter.cpp \
symbolsfindfilterconfigwidget.cpp \
- qtcreatoreditormanager.cpp
+ qtcreatoreditormanager.cpp \
+ qtcreatorrefactoringprojectupdater.cpp
FORMS += \
clangqueryprojectsfindfilter.ui
diff --git a/src/plugins/clangrefactoring/clangrefactoringplugin.cpp b/src/plugins/clangrefactoring/clangrefactoringplugin.cpp
index 93dcfa910c6..a0db4712912 100644
--- a/src/plugins/clangrefactoring/clangrefactoringplugin.cpp
+++ b/src/plugins/clangrefactoring/clangrefactoringplugin.cpp
@@ -27,12 +27,13 @@
#include "locatorfilter.h"
#include "qtcreatorsymbolsfindfilter.h"
#include "qtcreatoreditormanager.h"
+#include "qtcreatorrefactoringprojectupdater.h"
#include "querysqlitestatementfactory.h"
#include "sqlitedatabase.h"
#include "sqlitereadstatement.h"
#include "symbolquery.h"
-#include <clangpchmanager/qtcreatorprojectupdater.h>
+#include <clangpchmanager/clangpchmanagerplugin.h>
#include <clangsupport/refactoringdatabaseinitializer.h>
#include <cpptools/cppmodelmanager.h>
@@ -72,7 +73,6 @@ std::unique_ptr<ClangRefactoringPluginData> ClangRefactoringPlugin::d;
class ClangRefactoringPluginData
{
- using ProjectUpdater = ClangPchManager::QtCreatorProjectUpdater<ClangPchManager::ProjectUpdater>;
public:
using QuerySqliteReadStatementFactory = QuerySqliteStatementFactory<Sqlite::Database,
Sqlite::ReadStatement>;
@@ -90,7 +90,9 @@ public:
QtCreatorClangQueryFindFilter qtCreatorfindFilter{connectionClient.serverProxy(),
qtCreatorSearch,
refactoringClient};
- ProjectUpdater projectUpdate{connectionClient.serverProxy(), filePathCache};
+ QtCreatorRefactoringProjectUpdater projectUpdate{connectionClient.serverProxy(),
+ ClangPchManager::ClangPchManagerPlugin::pchManagerClient(),
+ filePathCache};
};
ClangRefactoringPlugin::ClangRefactoringPlugin()
diff --git a/src/plugins/clangrefactoring/qtcreatorrefactoringprojectupdater.cpp b/src/plugins/clangrefactoring/qtcreatorrefactoringprojectupdater.cpp
new file mode 100644
index 00000000000..a35e8b58889
--- /dev/null
+++ b/src/plugins/clangrefactoring/qtcreatorrefactoringprojectupdater.cpp
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "qtcreatorrefactoringprojectupdater.h"
+
+#include <cpptools/abstracteditorsupport.h>
+#include <cpptools/cppmodelmanager.h>
+
+namespace ClangRefactoring {
+
+namespace {
+
+CppTools::CppModelManager *cppModelManager()
+{
+ return CppTools::CppModelManager::instance();
+}
+
+std::vector<ClangBackEnd::V2::FileContainer> createGeneratedFiles()
+{
+ auto abstractEditors = CppTools::CppModelManager::instance()->abstractEditorSupports();
+ std::vector<ClangBackEnd::V2::FileContainer> generatedFiles;
+ generatedFiles.reserve(std::size_t(abstractEditors.size()));
+
+ auto toFileContainer = [] (const CppTools::AbstractEditorSupport *abstractEditor) {
+ return ClangBackEnd::V2::FileContainer(ClangBackEnd::FilePath(abstractEditor->fileName()),
+ Utils::SmallString::fromQByteArray(abstractEditor->contents()),
+ {});
+ };
+
+ std::transform(abstractEditors.begin(),
+ abstractEditors.end(),
+ std::back_inserter(generatedFiles),
+ toFileContainer);
+
+ std::sort(generatedFiles.begin(), generatedFiles.end());
+
+ return generatedFiles;
+}
+}
+
+QtCreatorRefactoringProjectUpdater::QtCreatorRefactoringProjectUpdater(ClangBackEnd::ProjectManagementServerInterface &server,
+ ClangPchManager::PchManagerClient &pchManagerClient,
+ ClangBackEnd::FilePathCachingInterface &filePathCache)
+ : RefactoringProjectUpdater(server, pchManagerClient, *cppModelManager(), filePathCache)
+{
+ connectToCppModelManager();
+}
+
+void QtCreatorRefactoringProjectUpdater::abstractEditorUpdated(const QString &filePath, const QByteArray &contents)
+{
+ RefactoringProjectUpdater::updateGeneratedFiles({{ClangBackEnd::FilePath{filePath}, contents}});
+}
+
+void QtCreatorRefactoringProjectUpdater::abstractEditorRemoved(const QString &filePath)
+{
+ RefactoringProjectUpdater::removeGeneratedFiles({ClangBackEnd::FilePath{filePath}});
+}
+
+void QtCreatorRefactoringProjectUpdater::connectToCppModelManager()
+{
+ RefactoringProjectUpdater::updateGeneratedFiles(createGeneratedFiles());
+
+ QObject::connect(cppModelManager(),
+ &CppTools::CppModelManager::abstractEditorSupportContentsUpdated,
+ [&] (const QString &filePath, const QByteArray &contents) {
+ abstractEditorUpdated(filePath, contents);
+ });
+
+ QObject::connect(cppModelManager(),
+ &CppTools::CppModelManager::abstractEditorSupportRemoved,
+ [&] (const QString &filePath) {
+ abstractEditorRemoved(filePath);
+ });
+}
+
+} // namespace ClangRefactoring
diff --git a/src/plugins/clangrefactoring/qtcreatorrefactoringprojectupdater.h b/src/plugins/clangrefactoring/qtcreatorrefactoringprojectupdater.h
new file mode 100644
index 00000000000..118c15b50c7
--- /dev/null
+++ b/src/plugins/clangrefactoring/qtcreatorrefactoringprojectupdater.h
@@ -0,0 +1,45 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include "refactoringprojectupdater.h"
+
+namespace ClangRefactoring {
+
+class QtCreatorRefactoringProjectUpdater final : public RefactoringProjectUpdater
+{
+public:
+ QtCreatorRefactoringProjectUpdater(ClangBackEnd::ProjectManagementServerInterface &server,
+ ClangPchManager::PchManagerClient &pchManagerClient,
+ ClangBackEnd::FilePathCachingInterface &filePathCache);
+
+private:
+ void abstractEditorUpdated(const QString &filePath, const QByteArray &contents);
+ void abstractEditorRemoved(const QString &filePath);
+ void connectToCppModelManager();
+};
+
+} // namespace ClangRefactoring
diff --git a/src/plugins/clangrefactoring/refactoringprojectupdater.cpp b/src/plugins/clangrefactoring/refactoringprojectupdater.cpp
index 06a4af82d0d..648e458fd5b 100644
--- a/src/plugins/clangrefactoring/refactoringprojectupdater.cpp
+++ b/src/plugins/clangrefactoring/refactoringprojectupdater.cpp
@@ -25,14 +25,22 @@
#include "refactoringprojectupdater.h"
+#include <cpptools/cppmodelmanager.h>
+
namespace ClangRefactoring {
-RefactoringProjectUpdater::RefactoringProjectUpdater(ClangBackEnd::ProjectManagementServerInterface &server,
- RefactoringClient &,
- ClangBackEnd::FilePathCachingInterface &filePathCache)
- : ClangPchManager::ProjectUpdater(server, filePathCache)
+void RefactoringProjectUpdater::precompiledHeaderUpdated(const QString &projectPartId,
+ const QString &,
+ long long)
{
+ auto projectPart = m_cppModelManager.projectPartForId(projectPartId);
+ if (projectPart)
+ updateProjectParts({projectPart.data()});
+}
+void RefactoringProjectUpdater::precompiledHeaderRemoved(const QString &projectPartId)
+{
+ removeProjectParts({projectPartId});
}
} // namespace ClangRefactoring
diff --git a/src/plugins/clangrefactoring/refactoringprojectupdater.h b/src/plugins/clangrefactoring/refactoringprojectupdater.h
index f8b771187ec..8e2652cf237 100644
--- a/src/plugins/clangrefactoring/refactoringprojectupdater.h
+++ b/src/plugins/clangrefactoring/refactoringprojectupdater.h
@@ -26,17 +26,34 @@
#pragma once
#include <clangpchmanager/projectupdater.h>
+#include <clangpchmanager/pchmanagernotifierinterface.h>
-namespace ClangRefactoring {
+#include <cpptools/cppmodelmanagerinterface.h>
-class RefactoringClient;
+namespace ClangRefactoring {
-class RefactoringProjectUpdater : public ClangPchManager::ProjectUpdater
+class RefactoringProjectUpdater : public ClangPchManager::ProjectUpdater,
+ public ClangPchManager::PchManagerNotifierInterface
{
public:
RefactoringProjectUpdater(ClangBackEnd::ProjectManagementServerInterface &server,
- RefactoringClient &client,
- ClangBackEnd::FilePathCachingInterface &filePathCache);
+ ClangPchManager::PchManagerClient &pchManagerClient,
+ CppTools::CppModelManagerInterface &cppModelManager,
+ ClangBackEnd::FilePathCachingInterface &filePathCache)
+ : ClangPchManager::ProjectUpdater(server, filePathCache),
+ ClangPchManager::PchManagerNotifierInterface(pchManagerClient),
+ m_cppModelManager(cppModelManager)
+ {
+
+ }
+
+ void precompiledHeaderUpdated(const QString &projectPartId,
+ const QString &pchFilePath,
+ long long lastModified) override;
+ void precompiledHeaderRemoved(const QString &projectPartId) override;
+
+private:
+ CppTools::CppModelManagerInterface &m_cppModelManager;
};
} // namespace ClangRefactoring
diff --git a/src/plugins/cpptools/cppmodelmanager.h b/src/plugins/cpptools/cppmodelmanager.h
index 70f40aeadea..3d480777416 100644
--- a/src/plugins/cpptools/cppmodelmanager.h
+++ b/src/plugins/cpptools/cppmodelmanager.h
@@ -27,6 +27,7 @@
#include "cpptools_global.h"
+#include "cppmodelmanagerinterface.h"
#include "refactoringengineinterface.h"
#include "projectinfo.h"
#include "projectpart.h"
@@ -83,7 +84,8 @@ enum class RefactoringEngineType : int
};
class CPPTOOLS_EXPORT CppModelManager final : public CPlusPlus::CppModelManagerBase,
- public RefactoringEngineInterface
+ public RefactoringEngineInterface,
+ public CppModelManagerInterface
{
Q_OBJECT
diff --git a/src/plugins/cpptools/cppmodelmanagerinterface.h b/src/plugins/cpptools/cppmodelmanagerinterface.h
new file mode 100644
index 00000000000..cd3fbc615a2
--- /dev/null
+++ b/src/plugins/cpptools/cppmodelmanagerinterface.h
@@ -0,0 +1,40 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include "projectpart.h"
+
+namespace CppTools {
+
+class CppModelManagerInterface
+{
+public:
+ virtual ProjectPart::Ptr projectPartForId(const QString &projectPartId) const = 0;
+
+protected:
+ ~CppModelManagerInterface() = default;
+};
+}
diff --git a/src/plugins/cpptools/cpptools.pro b/src/plugins/cpptools/cpptools.pro
index 272be01fe23..c73fba75f36 100644
--- a/src/plugins/cpptools/cpptools.pro
+++ b/src/plugins/cpptools/cpptools.pro
@@ -100,7 +100,8 @@ HEADERS += \
cursorineditor.h \
wrappablelineedit.h \
usages.h \
- cpptools_clangtidychecks.h
+ cpptools_clangtidychecks.h \
+ cppmodelmanagerinterface.h
SOURCES += \
abstracteditorsupport.cpp \
diff --git a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp b/src/tools/clangpchmanagerbackend/source/pchcreator.cpp
index 5b77fc21b33..d1635dc9445 100644
--- a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp
+++ b/src/tools/clangpchmanagerbackend/source/pchcreator.cpp
@@ -459,9 +459,8 @@ Utils::PathStringVector PchCreator::generateProjectPartHeaderAndSourcePaths(
const V2::ProjectPartContainer &projectPart) const
{
Utils::PathStringVector includeAndSources;
- includeAndSources.reserve(projectPart.headerPathIds.size() + projectPart.sourcePathIds.size());
+ includeAndSources.reserve(projectPart.sourcePathIds.size());
- appendFilePathId(includeAndSources, projectPart.headerPathIds, m_filePathCache);
appendFilePathId(includeAndSources, projectPart.sourcePathIds, m_filePathCache);
return includeAndSources;
@@ -520,10 +519,6 @@ Utils::SmallStringVector PchCreator::generateProjectPartPchCompilerArguments(
arguments.emplace_back("-x");
arguments.emplace_back("c++-header");
-// arguments.emplace_back("-Xclang");
-// arguments.emplace_back("-include-pch");
-// arguments.emplace_back("-Xclang");
-// arguments.emplace_back(generateGlobalPchFilePath());
arguments.emplace_back("-Xclang");
arguments.emplace_back("-emit-pch");
arguments.emplace_back("-o");
diff --git a/tests/unit/unittest/mockcppmodelmanager.h b/tests/unit/unittest/mockcppmodelmanager.h
new file mode 100644
index 00000000000..bbcd95a0a31
--- /dev/null
+++ b/tests/unit/unittest/mockcppmodelmanager.h
@@ -0,0 +1,37 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include "googletest.h"
+
+#include <cpptools/cppmodelmanagerinterface.h>
+
+class MockCppModelManager : public CppTools::CppModelManagerInterface
+{
+public:
+ MOCK_CONST_METHOD1(projectPartForId,
+ CppTools::ProjectPart::Ptr (const QString &projectPartId));
+};
diff --git a/tests/unit/unittest/refactoringprojectupdater-test.cpp b/tests/unit/unittest/refactoringprojectupdater-test.cpp
new file mode 100644
index 00000000000..799ba44c494
--- /dev/null
+++ b/tests/unit/unittest/refactoringprojectupdater-test.cpp
@@ -0,0 +1,132 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "googletest.h"
+
+#include "mockcppmodelmanager.h"
+#include "mockrefactoringserver.h"
+#include "mockprecompiledheaderstorage.h"
+
+#include <sqlitedatabase.h>
+
+#include <filepathcaching.h>
+#include <precompiledheadersupdatedmessage.h>
+#include <refactoringdatabaseinitializer.h>
+#include <clangrefactoringservermessages.h>
+
+#include <pchmanagerclient.h>
+
+#include <refactoringprojectupdater.h>
+
+#include <memory>
+
+namespace {
+
+using CppTools::ProjectPart;
+using ClangBackEnd::UpdateProjectPartsMessage;
+using ClangBackEnd::RemoveProjectPartsMessage;
+
+MATCHER_P(IsProjectPartContainer, projectPartId,
+ std::string(negation ? "hasn't" : "has")
+ + " name " + std::string(projectPartId))
+{
+ const ClangBackEnd::V2::ProjectPartContainer &container = arg;
+
+ return container.projectPartId == projectPartId;
+}
+
+class RefactoringProjectUpdater : public testing::Test
+{
+protected:
+ ProjectPart::Ptr createProjectPart(const char *name)
+ {
+ ProjectPart::Ptr projectPart{new ProjectPart};
+ projectPart->displayName = QString::fromUtf8(name, std::strlen(name));
+ projectPartId = projectPart->id();
+ return projectPart;
+ }
+
+ Utils::SmallString createProjectPartId(const char *name)
+ {
+ ProjectPart::Ptr projectPart{new ProjectPart};
+ projectPart->displayName = QString::fromUtf8(name, std::strlen(name));
+ return projectPart->id();
+ }
+
+ QString createProjectPartQStringId(const char *name)
+ {
+ ProjectPart::Ptr projectPart{new ProjectPart};
+ projectPart->displayName = QString::fromUtf8(name, std::strlen(name));
+ return projectPart->id();
+ }
+
+protected:
+ Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};
+ ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> initializer{database};
+ ClangBackEnd::FilePathCaching filePathCache{database};
+ NiceMock<MockRefactoringServer> mockRefactoringServer;
+ NiceMock<MockPrecompiledHeaderStorage> mockPrecompiledHeaderStorage;
+ ClangPchManager::PchManagerClient pchManagerClient{mockPrecompiledHeaderStorage};
+ MockCppModelManager mockCppModelManager;
+ ClangRefactoring::RefactoringProjectUpdater updater{mockRefactoringServer, pchManagerClient, mockCppModelManager, filePathCache};
+ Utils::SmallString projectPartId;
+};
+
+TEST_F(RefactoringProjectUpdater, DontUpdateProjectPartIfNoProjectPartExistsForId)
+{
+ EXPECT_CALL(mockCppModelManager, projectPartForId(Eq(createProjectPartQStringId("project1"))));
+
+ pchManagerClient.precompiledHeadersUpdated({{{createProjectPartId("project1"), "/path/to/pch", 12}}});
+}
+
+TEST_F(RefactoringProjectUpdater, UpdateProjectPart)
+{
+ EXPECT_CALL(mockCppModelManager, projectPartForId(Eq(createProjectPartQStringId("project1")))).WillRepeatedly(Return(createProjectPart("project1")));
+ EXPECT_CALL(mockRefactoringServer, updateProjectParts(
+ Field(&UpdateProjectPartsMessage::projectsParts,
+ ElementsAre(IsProjectPartContainer(createProjectPartId("project1"))))));
+
+ pchManagerClient.precompiledHeadersUpdated({{{createProjectPartId("project1"), "/path/to/pch", 12}}});
+}
+
+TEST_F(RefactoringProjectUpdater, RemoveProjectPart)
+{
+ EXPECT_CALL(mockRefactoringServer, removeProjectParts(
+ Field(&RemoveProjectPartsMessage::projectsPartIds,
+ ElementsAre(Eq("project1")))));
+
+ pchManagerClient.precompiledHeaderRemoved({"project1"});
+}
+
+TEST_F(RefactoringProjectUpdater, UpdateGeneratedFiles)
+{
+ EXPECT_CALL(mockRefactoringServer, removeProjectParts(
+ Field(&RemoveProjectPartsMessage::projectsPartIds,
+ ElementsAre(Eq("project1")))));
+
+ pchManagerClient.precompiledHeaderRemoved({"project1"});
+}
+
+}
diff --git a/tests/unit/unittest/unittest-utility-functions.h b/tests/unit/unittest/unittest-utility-functions.h
index 5fb9c25882e..52f0489928b 100644
--- a/tests/unit/unittest/unittest-utility-functions.h
+++ b/tests/unit/unittest/unittest-utility-functions.h
@@ -29,6 +29,12 @@
#include <QDir>
+inline
+bool operator==(const QString &first, const char *second)
+{
+ return first == QString::fromUtf8(second, int(std::strlen(second)));
+}
+
namespace UnitTest {
inline
diff --git a/tests/unit/unittest/unittest.pro b/tests/unit/unittest/unittest.pro
index 4ca129f0df4..c55521a7510 100644
--- a/tests/unit/unittest/unittest.pro
+++ b/tests/unit/unittest/unittest.pro
@@ -100,7 +100,8 @@ SOURCES += \
sourcesmanager-test.cpp \
symbolindexertaskqueue-test.cpp \
symbolindexertaskscheduler-test.cpp \
- symbolscollectormanager-test.cpp
+ symbolscollectormanager-test.cpp \
+ refactoringprojectupdater-test.cpp
!isEmpty(LIBCLANG_LIBS) {
SOURCES += \
@@ -239,7 +240,8 @@ HEADERS += \
mockeditormanager.h \
mocksymbolscollectormanager.h \
mocksymbolindexertaskqueue.h \
- mocksymbolindexertaskscheduler.h
+ mocksymbolindexertaskscheduler.h \
+ mockcppmodelmanager.h
!isEmpty(LIBCLANG_LIBS) {
HEADERS += \