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
|
/*
SPDX-FileCopyrightText: 2009 Fabian Wiesel <fabian.wiesel@googlemail.com>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "test_svnimport.h"
#include <QTest>
#include <QDebug>
#include <QLoggingCategory>
#include <QTemporaryDir>
#include <KProcess>
#include <interfaces/iplugincontroller.h>
#include <tests/autotestshell.h>
#include <tests/testcore.h>
#include <vcs/interfaces/icentralizedversioncontrol.h>
#include <vcs/vcsjob.h>
#include <vcs/vcslocation.h>
#define VERBOSE
#if defined(VERBOSE)
#define TRACE(X) qDebug() << X
#else
#define TRACE(X) { line = line; }
#endif
using namespace KDevelop;
void validatingExecJob(VcsJob* j, VcsJob::JobStatus status = VcsJob::JobSucceeded)
{
QVERIFY(j);
if (!j->exec()) {
qDebug() << j->errorString();
// On error, wait for key in order to allow manual state inspection
}
QCOMPARE(j->status(), status);
}
void setupLocalRepository( const QString& name, VcsLocation & reposLoc )
{
KProcess cmd;
cmd.setWorkingDirectory(name);
cmd << QStringLiteral("svnadmin") << QStringLiteral("create") << name;
QCOMPARE(cmd.execute(10000), 0);
reposLoc.setRepositoryServer("file://" + name );
}
void setupSampleProject( const QString& name, const QString& content )
{
QFile sampleFile( name + "/sample.file" );
sampleFile.open( QIODevice::WriteOnly );
sampleFile.write( content.toUtf8() );
sampleFile.close();
}
void TestSvnImport::initTestCase()
{
QLoggingCategory::setFilterRules(QStringLiteral("*.debug=false\ndefault.debug=true\nkdevelop.plugins.svn.debug=true\n"));
AutoTestShell::init({QStringLiteral("kdevsubversion"), QStringLiteral("KDevStandardOutputView")});
TestCore::initialize();
const QList<IPlugin*> plugins = Core::self()->pluginController()->allPluginsForExtension(QStringLiteral("org.kdevelop.IBasicVersionControl"));
for (IPlugin* p : plugins) {
qDebug() << "checking plugin" << p;
auto* icentr = p->extension<ICentralizedVersionControl>();
if (!icentr)
continue;
if (icentr->name() == QLatin1String("Subversion")) {
vcs = icentr;
break;
}
}
qDebug() << "ok, got vcs" << vcs;
QVERIFY(vcs);
}
void TestSvnImport::cleanupTestCase()
{
TestCore::shutdown();
}
void TestSvnImport::testBasic()
{
QTemporaryDir reposDir;
VcsLocation reposLoc;
setupLocalRepository( reposDir.path(), reposLoc );
QTemporaryDir projectDir;
QString origcontent = QStringLiteral("This is a Test");
setupSampleProject( projectDir.path(), origcontent );
VcsJob* job = vcs->import( QStringLiteral("import test"), QUrl::fromLocalFile( projectDir.path() ), reposLoc );
validatingExecJob(job);
QTemporaryDir checkoutDir;
validateImport( reposLoc.repositoryServer(), checkoutDir, origcontent );
}
void TestSvnImport::testImportWithMissingDirs()
{
QTemporaryDir reposDir;
VcsLocation reposLoc;
setupLocalRepository( reposDir.path(), reposLoc );
QTemporaryDir projectDir;
QString origcontent = QStringLiteral("This is a Test");
setupSampleProject( projectDir.path(), origcontent );
reposLoc.setRepositoryServer( reposLoc.repositoryServer() + "/foobar/" + QDir( projectDir.path() ).dirName() );
VcsJob* job = vcs->import( QStringLiteral("import test"), QUrl::fromLocalFile( projectDir.path() ), reposLoc );
validatingExecJob(job);
QTemporaryDir checkoutDir;
validateImport( reposLoc.repositoryServer(), checkoutDir, origcontent );
}
void TestSvnImport::testImportIntoDir()
{
QTemporaryDir reposDir;
VcsLocation reposLoc;
setupLocalRepository( reposDir.path(), reposLoc );
QTemporaryDir projectDir;
QString origcontent = QStringLiteral("This is a Test");
setupSampleProject( projectDir.path(), origcontent );
reposLoc.setRepositoryServer( reposLoc.repositoryServer() + '/' + QDir( projectDir.path() ).dirName() );
VcsJob* job = vcs->import( QStringLiteral("import test"), QUrl::fromLocalFile( projectDir.path() ), reposLoc );
validatingExecJob(job);
QTemporaryDir checkoutDir;
validateImport( reposLoc.repositoryServer(), checkoutDir, origcontent );
}
void TestSvnImport::validateImport( const QString& repourl, QTemporaryDir& checkoutdir, const QString& origcontent )
{
VcsLocation reposLoc;
reposLoc.setRepositoryServer( repourl );
VcsJob* job = vcs->createWorkingCopy( reposLoc, QUrl::fromLocalFile(checkoutdir.path()) );
validatingExecJob(job);
QFile newfile( checkoutdir.path() + "/sample.file" );
QVERIFY(newfile.exists());
QVERIFY(newfile.open(QIODevice::ReadOnly));
QCOMPARE(QString::fromUtf8( newfile.readAll() ), origcontent);
}
QTEST_MAIN(TestSvnImport)
#include "moc_test_svnimport.cpp"
|