aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhjk <[email protected]>2024-02-06 17:25:09 +0100
committerhjk <[email protected]>2024-02-07 08:03:18 +0000
commit7da257e6c21a9ad52a7f70801ac1facd6a84fcf5 (patch)
tree83e0aed4d375c95264f678f598b304658005d129
parent8b90a2b1cb13b48feea322f5c12324d6953cb6a2 (diff)
Core: Remove version control tests from public header
Change-Id: Ifc74b939fd8d9f1f1e4def7927ecfbef6a7fb7a3 Reviewed-by: Orgad Shaneh <[email protected]> Reviewed-by: <[email protected]>
-rw-r--r--src/plugins/coreplugin/iversioncontrol.cpp48
-rw-r--r--src/plugins/coreplugin/iversioncontrol.h52
-rw-r--r--src/plugins/coreplugin/vcsmanager.cpp95
3 files changed, 88 insertions, 107 deletions
diff --git a/src/plugins/coreplugin/iversioncontrol.cpp b/src/plugins/coreplugin/iversioncontrol.cpp
index 483dd211e83..4cbc8050a26 100644
--- a/src/plugins/coreplugin/iversioncontrol.cpp
+++ b/src/plugins/coreplugin/iversioncontrol.cpp
@@ -178,51 +178,3 @@ bool IVersionControl::handleLink(const FilePath &workingDirectory, const QString
}
} // namespace Core
-
-#if defined(WITH_TESTS)
-
-namespace Core {
-
-TestVersionControl::~TestVersionControl()
-{
- VcsManager::clearVersionControlCache();
-}
-
-void TestVersionControl::setManagedDirectories(const QHash<FilePath, FilePath> &dirs)
-{
- m_managedDirs = dirs;
- m_dirCount = 0;
- VcsManager::clearVersionControlCache();
-}
-
-void TestVersionControl::setManagedFiles(const QSet<FilePath> &files)
-{
- m_managedFiles = files;
- m_fileCount = 0;
- VcsManager::clearVersionControlCache();
-}
-
-bool TestVersionControl::managesDirectory(const FilePath &filePath, FilePath *topLevel) const
-{
- ++m_dirCount;
-
- if (m_managedDirs.contains(filePath)) {
- if (topLevel)
- *topLevel = m_managedDirs.value(filePath);
- return true;
- }
- return false;
-}
-
-bool TestVersionControl::managesFile(const FilePath &workingDirectory, const QString &fileName) const
-{
- ++m_fileCount;
-
- FilePath full = workingDirectory.pathAppended(fileName);
- if (!managesDirectory(full.parentDir(), nullptr))
- return false;
- return m_managedFiles.contains(full.absoluteFilePath());
-}
-
-} // namespace Core
-#endif
diff --git a/src/plugins/coreplugin/iversioncontrol.h b/src/plugins/coreplugin/iversioncontrol.h
index eaa311d8759..e97749ca1b2 100644
--- a/src/plugins/coreplugin/iversioncontrol.h
+++ b/src/plugins/coreplugin/iversioncontrol.h
@@ -232,55 +232,3 @@ private:
} // namespace Core
Q_DECLARE_OPERATORS_FOR_FLAGS(Core::IVersionControl::SettingsFlags)
-
-#if defined(WITH_TESTS)
-
-#include <QSet>
-
-namespace Core {
-
-class CORE_EXPORT TestVersionControl : public IVersionControl
-{
- Q_OBJECT
-public:
- TestVersionControl(Utils::Id id, const QString &name) :
- m_id(id), m_displayName(name)
- { }
- ~TestVersionControl() override;
-
- bool isVcsFileOrDirectory(const Utils::FilePath &filePath) const final
- { Q_UNUSED(filePath) return false; }
-
- void setManagedDirectories(const QHash<Utils::FilePath, Utils::FilePath> &dirs);
- void setManagedFiles(const QSet<Utils::FilePath> &files);
-
- int dirCount() const { return m_dirCount; }
- int fileCount() const { return m_fileCount; }
-
- // IVersionControl interface
- QString displayName() const override { return m_displayName; }
- Utils::Id id() const override { return m_id; }
- bool managesDirectory(const Utils::FilePath &filePath, Utils::FilePath *topLevel) const override;
- bool managesFile(const Utils::FilePath &workingDirectory, const QString &fileName) const override;
- bool isConfigured() const override { return true; }
- bool supportsOperation(Operation) const override { return false; }
- bool vcsOpen(const Utils::FilePath &) override { return false; }
- bool vcsAdd(const Utils::FilePath &) override { return false; }
- bool vcsDelete(const Utils::FilePath &) override { return false; }
- bool vcsMove(const Utils::FilePath &, const Utils::FilePath &) override { return false; }
- bool vcsCreateRepository(const Utils::FilePath &) override { return false; }
- void vcsAnnotate(const Utils::FilePath &, int) override {}
- void vcsDescribe(const Utils::FilePath &, const QString &) override {}
-
-private:
- Utils::Id m_id;
- QString m_displayName;
- QHash<Utils::FilePath, Utils::FilePath> m_managedDirs;
- QSet<Utils::FilePath> m_managedFiles;
- mutable int m_dirCount = 0;
- mutable int m_fileCount = 0;
-};
-
-} // namespace Core
-
-#endif
diff --git a/src/plugins/coreplugin/vcsmanager.cpp b/src/plugins/coreplugin/vcsmanager.cpp
index 2c9e5439c27..5180a356c26 100644
--- a/src/plugins/coreplugin/vcsmanager.cpp
+++ b/src/plugins/coreplugin/vcsmanager.cpp
@@ -436,14 +436,14 @@ void VcsManager::handleConfigurationChanges(IVersionControl *vc)
} // namespace Core
-#if defined(WITH_TESTS)
+
+#ifdef WITH_TESTS
#include <QtTest>
#include <extensionsystem/pluginmanager.h>
-namespace Core {
-namespace Internal {
+namespace Core::Internal {
const char ID_VCS_A[] = "A";
const char ID_VCS_B[] = "B";
@@ -469,6 +469,88 @@ static QString makeString(const QString &s)
return QString::fromLatin1(TEST_PREFIX) + s;
}
+class TestVersionControl final : public IVersionControl
+{
+public:
+ TestVersionControl(Id id, const QString &name) :
+ m_id(id), m_displayName(name)
+ { }
+ ~TestVersionControl() final;
+
+ bool isVcsFileOrDirectory(const FilePath &filePath) const final
+ { Q_UNUSED(filePath) return false; }
+
+ void setManagedDirectories(const QHash<FilePath, FilePath> &dirs);
+ void setManagedFiles(const QSet<FilePath> &files);
+
+ int dirCount() const { return m_dirCount; }
+ int fileCount() const { return m_fileCount; }
+
+ // IVersionControl interface
+ QString displayName() const final { return m_displayName; }
+ Id id() const final { return m_id; }
+ bool managesDirectory(const FilePath &filePath, FilePath *topLevel) const final;
+ bool managesFile(const FilePath &workingDirectory, const QString &fileName) const final;
+ bool isConfigured() const final { return true; }
+ bool supportsOperation(Operation) const final { return false; }
+ bool vcsOpen(const FilePath &) final { return false; }
+ bool vcsAdd(const FilePath &) final { return false; }
+ bool vcsDelete(const FilePath &) final { return false; }
+ bool vcsMove(const FilePath &, const FilePath &) final { return false; }
+ bool vcsCreateRepository(const FilePath &) final { return false; }
+ void vcsAnnotate(const FilePath &, int) final {}
+ void vcsDescribe(const FilePath &, const QString &) final {}
+
+private:
+ Id m_id;
+ QString m_displayName;
+ QHash<FilePath, FilePath> m_managedDirs;
+ QSet<FilePath> m_managedFiles;
+ mutable int m_dirCount = 0;
+ mutable int m_fileCount = 0;
+};
+
+TestVersionControl::~TestVersionControl()
+{
+ VcsManager::clearVersionControlCache();
+}
+
+void TestVersionControl::setManagedDirectories(const QHash<FilePath, FilePath> &dirs)
+{
+ m_managedDirs = dirs;
+ m_dirCount = 0;
+ VcsManager::clearVersionControlCache();
+}
+
+void TestVersionControl::setManagedFiles(const QSet<FilePath> &files)
+{
+ m_managedFiles = files;
+ m_fileCount = 0;
+ VcsManager::clearVersionControlCache();
+}
+
+bool TestVersionControl::managesDirectory(const FilePath &filePath, FilePath *topLevel) const
+{
+ ++m_dirCount;
+
+ if (m_managedDirs.contains(filePath)) {
+ if (topLevel)
+ *topLevel = m_managedDirs.value(filePath);
+ return true;
+ }
+ return false;
+}
+
+bool TestVersionControl::managesFile(const FilePath &workingDirectory, const QString &fileName) const
+{
+ ++m_fileCount;
+
+ FilePath full = workingDirectory.pathAppended(fileName);
+ if (!managesDirectory(full.parentDir(), nullptr))
+ return false;
+ return m_managedFiles.contains(full.absoluteFilePath());
+}
+
class VcsManagerTest final : public QObject
{
Q_OBJECT
@@ -534,8 +616,8 @@ void VcsManagerTest::testVcsManager()
{
// setup:
QList<IVersionControl *> orig = Core::d->m_versionControlList;
- TestVersionControl *vcsA(new TestVersionControl(ID_VCS_A, QLatin1String("A")));
- TestVersionControl *vcsB(new TestVersionControl(ID_VCS_B, QLatin1String("B")));
+ TestVersionControl *vcsA = new TestVersionControl(ID_VCS_A, "A");
+ TestVersionControl *vcsB = new TestVersionControl(ID_VCS_B, "B");
Core::d->m_versionControlList = {vcsA, vcsB};
@@ -590,8 +672,7 @@ QObject *createVcsManagerTest()
return new VcsManagerTest;
}
-} // namespace Internal
-} // namespace Core
+} // Core::Internal
#endif