1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
|
/*
This file was inspired by KDevelop's git plugin
SPDX-FileCopyrightText: 2008 Evgeniy Ivanov <powerfox@kde.ru>
Adapted for Perforce
SPDX-FileCopyrightText: 2011 Morten Danielsen Volden <mvolden2@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "test_perforce.h"
#include <QTest>
#include <QDir>
#include <QDirIterator>
#include <QStandardPaths>
#include <KPluginMetaData>
#include <tests/autotestshell.h>
#include <tests/plugintesthelpers.h>
#include <tests/testcore.h>
#include <vcs/vcsjob.h>
#include <vcs/vcsannotation.h>
#include <perforceplugin.h>
#define VERIFYJOB(j) \
QVERIFY(j); QVERIFY(j->exec()); QVERIFY((j)->status() == VcsJob::JobSucceeded)
using namespace KDevelop;
PerforcePluginTest::PerforcePluginTest()
: tempDir{QDir::tempPath()}
, perforceTestBaseDirNoSlash{tempDir + QLatin1String("/kdevPerforce_testdir")}
, perforceTestBaseDir{perforceTestBaseDirNoSlash + QLatin1Char('/')}
, perforceConfigFileName{QStringLiteral("p4config.txt")}
, perforceSrcDir{perforceTestBaseDir + QLatin1String("src/")}
, perforceTest_FileName{QStringLiteral("testfile")}
, perforceTest_FileName2{QStringLiteral("foo")}
, perforceTest_FileName3{QStringLiteral("bar")}
{
}
void PerforcePluginTest::initTestCase()
{
AutoTestShell::init({QStringLiteral("kdevperforce")});
TestCore::initialize();
const auto pluginMetaData = makeTestPluginMetaData("TestPerforce");
m_plugin = new PerforcePlugin(TestCore::self(), pluginMetaData);
/// During test we are setting the executable the plugin uses to our own stub
QDirIterator it(QString::fromUtf8(P4_BINARY_DIR), QStringList() << QStringLiteral("*"),
QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
QStringList pathsToSearch;
while (it.hasNext()) {
it.next();
pathsToSearch << it.filePath();
}
QString p4stubPath = QStandardPaths::findExecutable(QStringLiteral("p4clientstub"), pathsToSearch);
qDebug() << "found p4stub executable :" << p4stubPath;
QVERIFY(!p4stubPath.isEmpty());
m_plugin->m_perforceExecutable = p4stubPath;
}
void PerforcePluginTest::cleanupTestCase()
{
delete m_plugin;
TestCore::shutdown();
}
void PerforcePluginTest::init()
{
removeTempDirsIfAny();
createNewTempDirs();
}
void PerforcePluginTest::createNewTempDirs()
{
// Now create the basic directory structure
QDir tmpdir(tempDir);
tmpdir.mkdir(perforceTestBaseDir);
//we start it after repoInit, so we still have empty repo
QFile f(perforceTestBaseDir + perforceConfigFileName);
if (f.open(QIODevice::WriteOnly)) {
QTextStream input(&f);
input << "P4PORT=127.0.0.1:1666\n";
input << "P4USER=mvo\n";
input << "P4CLIENT=testbed\n";
}
f.close();
//Put a file here because the annotate and update function will check for that
QFile g(perforceTestBaseDir + perforceTest_FileName);
if (g.open(QIODevice::WriteOnly)) {
QTextStream input(&g);
input << "HELLO WORLD";
}
g.close();
tmpdir.mkdir(perforceSrcDir);
}
void PerforcePluginTest::removeTempDirsIfAny()
{
QDir dir(perforceTestBaseDir);
if (dir.exists() && !dir.removeRecursively())
qDebug() << "QDir::removeRecursively(" << perforceTestBaseDir << ") returned false";
}
void PerforcePluginTest::cleanup()
{
removeTempDirsIfAny();
}
void PerforcePluginTest::testAdd()
{
VcsJob* j = m_plugin->add(QList<QUrl>({ QUrl::fromLocalFile(perforceTestBaseDir + perforceTest_FileName) } ));
VERIFYJOB(j);
}
void PerforcePluginTest::testEdit()
{
VcsJob* j = m_plugin->edit(QList<QUrl>( { QUrl::fromLocalFile(perforceTestBaseDir + perforceTest_FileName) } ));
VERIFYJOB(j);
}
void PerforcePluginTest::testEditMultipleFiles()
{
QList<QUrl> filesForEdit;
filesForEdit.push_back(QUrl::fromLocalFile(perforceTestBaseDir + perforceTest_FileName));
filesForEdit.push_back(QUrl::fromLocalFile(perforceTestBaseDir + perforceTest_FileName2));
filesForEdit.push_back(QUrl::fromLocalFile(perforceTestBaseDir + perforceTest_FileName3));
VcsJob* j = m_plugin->edit(filesForEdit);
VERIFYJOB(j);
}
void PerforcePluginTest::testStatus()
{
VcsJob* j = m_plugin->status(QList<QUrl>( { QUrl::fromLocalFile(perforceTestBaseDirNoSlash) } ));
VERIFYJOB(j);
}
void PerforcePluginTest::testAnnotate()
{
VcsJob* j = m_plugin->annotate(QUrl( QUrl::fromLocalFile(perforceTestBaseDir + perforceTest_FileName) ));
VERIFYJOB(j);
}
void PerforcePluginTest::testHistory()
{
VcsJob* j = m_plugin->log(QUrl( QUrl::fromLocalFile(perforceTestBaseDir + perforceTest_FileName) ));
VERIFYJOB(j);
}
void PerforcePluginTest::testRevert()
{
VcsJob* j = m_plugin->revert(QList<QUrl>( { QUrl::fromLocalFile(perforceTestBaseDir + perforceTest_FileName) } ));
VERIFYJOB(j);
}
void PerforcePluginTest::testUpdateFile()
{
VcsJob* j = m_plugin->update(QList<QUrl>( { QUrl::fromLocalFile(perforceTestBaseDir + perforceTest_FileName) } ));
VERIFYJOB(j);
}
void PerforcePluginTest::testUpdateDir()
{
VcsJob* j = m_plugin->update(QList<QUrl>( { QUrl::fromLocalFile(perforceTestBaseDirNoSlash) } ));
VERIFYJOB(j);
}
void PerforcePluginTest::testCommit()
{
QString commitMsg(QStringLiteral("this is the commit message"));
VcsJob* j = m_plugin->commit(commitMsg, QList<QUrl>( { QUrl::fromLocalFile(perforceTestBaseDirNoSlash) } ));
VERIFYJOB(j);
}
void PerforcePluginTest::testDiff()
{
VcsRevision srcRevision;
srcRevision.setRevisionValue(QVariant(1), VcsRevision::GlobalNumber);
VcsRevision dstRevision;
dstRevision.setRevisionValue(QVariant(2), VcsRevision::GlobalNumber);
VcsJob* j = m_plugin->diff( QUrl::fromLocalFile(perforceTestBaseDir + perforceTest_FileName), srcRevision, dstRevision);
VERIFYJOB(j);
}
QTEST_MAIN(PerforcePluginTest)
#include "moc_test_perforce.cpp"
|