Core: Remove version control tests from public header

Change-Id: Ifc74b939fd8d9f1f1e4def7927ecfbef6a7fb7a3
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2024-02-06 17:25:09 +01:00
parent 8b90a2b1cb
commit 7da257e6c2
3 changed files with 88 additions and 107 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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