diff --git a/plugins/subversion/tests/CMakeLists.txt b/plugins/subversion/tests/CMakeLists.txt index c3ef3d1fd..a18a0c177 100644 --- a/plugins/subversion/tests/CMakeLists.txt +++ b/plugins/subversion/tests/CMakeLists.txt @@ -1,9 +1,9 @@ -ecm_add_test(svnrecursiveadd.cpp LINK_LIBRARIES +ecm_add_test(test_svnrecursiveadd.cpp LINK_LIBRARIES Qt5::Test Qt5::Gui KDev::Tests KDev::Util KDev::Vcs ) -ecm_add_test(svnimport.cpp LINK_LIBRARIES +ecm_add_test(test_svnimport.cpp LINK_LIBRARIES Qt5::Test Qt5::Gui KDev::Tests KDev::Util KDev::Vcs ) diff --git a/plugins/subversion/tests/svnimport.cpp b/plugins/subversion/tests/test_svnimport.cpp similarity index 93% rename from plugins/subversion/tests/svnimport.cpp rename to plugins/subversion/tests/test_svnimport.cpp index d4a6ef8ca..96708d90a 100644 --- a/plugins/subversion/tests/svnimport.cpp +++ b/plugins/subversion/tests/test_svnimport.cpp @@ -1,164 +1,165 @@ /*************************************************************************** * This file is part of KDevelop * * Copyright 2009 Fabian Wiesel * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#include "svnimport.h" +#include "test_svnimport.h" + #include #include #include #include #include #include #include #include #include #include #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 SvnImport::initTestCase() +void TestSvnImport::initTestCase() { QLoggingCategory::setFilterRules(QStringLiteral("*.debug=false\ndefault.debug=true\nkdevplatform.plugins.svn.debug=true\n")); AutoTestShell::init({QStringLiteral("kdevsubversion")}); TestCore::initialize(); QList plugins = Core::self()->pluginController()->allPluginsForExtension(QStringLiteral("org.kdevelop.IBasicVersionControl")); foreach(IPlugin* p, plugins) { qDebug() << "checking plugin" << p; ICentralizedVersionControl* icentr = p->extension(); if (!icentr) continue; if (icentr->name() == QLatin1String("Subversion")) { vcs = icentr; break; } } qDebug() << "ok, got vcs" << vcs; QVERIFY(vcs); } -void SvnImport::cleanupTestCase() +void TestSvnImport::cleanupTestCase() { TestCore::shutdown(); } -void SvnImport::testBasic() +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 SvnImport::testImportWithMissingDirs() +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 SvnImport::testImportIntoDir() +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 SvnImport::validateImport( const QString& repourl, QTemporaryDir& checkoutdir, const QString& 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(SvnImport) +QTEST_MAIN(TestSvnImport) diff --git a/plugins/subversion/tests/svnimport.h b/plugins/subversion/tests/test_svnimport.h similarity index 98% rename from plugins/subversion/tests/svnimport.h rename to plugins/subversion/tests/test_svnimport.h index fe5139240..bd1b81c91 100644 --- a/plugins/subversion/tests/svnimport.h +++ b/plugins/subversion/tests/test_svnimport.h @@ -1,46 +1,47 @@ /*************************************************************************** * This file is part of KDevelop * * Copyright 2009 Fabian Wiesel * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #ifndef KDEVPLATFORM_PLUGIN_SVNIMPORT_H #define KDEVPLATFORM_PLUGIN_SVNIMPORT_H + #include class QTemporaryDir; namespace KDevelop { class TestCore; class ICentralizedVersionControl; } -class SvnImport +class TestSvnImport : public QObject { Q_OBJECT private slots: void initTestCase(); void cleanupTestCase(); void testBasic(); void testImportIntoDir(); void testImportWithMissingDirs(); private: void validateImport( const QString& repo, QTemporaryDir& checkout, const QString& origcontent ); KDevelop::ICentralizedVersionControl* vcs = nullptr; }; #endif // KDEVPLATFORM_PLUGIN_SVNRECURSIVEADD_H diff --git a/plugins/subversion/tests/svnrecursiveadd.cpp b/plugins/subversion/tests/test_svnrecursiveadd.cpp similarity index 97% rename from plugins/subversion/tests/svnrecursiveadd.cpp rename to plugins/subversion/tests/test_svnrecursiveadd.cpp index e447a2241..fe4120433 100644 --- a/plugins/subversion/tests/svnrecursiveadd.cpp +++ b/plugins/subversion/tests/test_svnrecursiveadd.cpp @@ -1,160 +1,160 @@ /*************************************************************************** * This file is part of KDevelop * * Copyright 2009 Fabian Wiesel * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#include "svnrecursiveadd.h" +#include "test_svnrecursiveadd.h" #include #include #include #include #include #include #include #include #include #define PATHETIC // A little motivator to make things work right :) #if defined(PATHETIC) inline QString vcsTestDir0() { return QStringLiteral("testdir0"); } inline QString vcsTestDir1() { return QStringLiteral("testdir1"); } inline QString vcsTest_FileName0() { return QStringLiteral("foo"); } inline QString vcsTest_FileName1() { return QStringLiteral("bar"); } inline QString keywordText() { return QStringLiteral("text"); } #else inline QString vcsTestDir0() { return QStringLiteral("dvcs\t testdir"); } // Directory containing whitespaces inline QString vcsTestDir1() { return QStringLiteral("--help"); } // Starting with hyphen for command-line tools inline QString vcsTest_FileName0() { return QStringLiteral("foo\t bar"); } inline QString vcsTest_FileName1() { return QStringLiteral("--help"); } inline QString keywordText() { return QStringLiteral("Author:\nDate:\nCommit:\n------------------------------------------------------------------------\nr999999 | ehrman | 1989-11-09 18:53:00 +0100 (Thu, 09 Nov 1989) | 1 lines\nthe line\n"); } // Text containing keywords of the various vcs-programs #endif inline QString simpleText() { return QStringLiteral("It's foo!\n"); } inline QString simpleAltText() { return QStringLiteral("No, foo()! It's bar()!\n"); } #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); // Print the commands in full, for easier bug location #if 0 if (QLatin1String(j->metaObject()->className()) == "DVcsJob") { qDebug() << "Command: \"" << ((DVcsJob*)j)->getChildproc()->program() << ((DVcsJob*)j)->getChildproc()->workingDirectory(); qDebug() << "Output: \"" << ((DVcsJob*)j)->output(); } #endif if (!j->exec()) { qDebug() << "ooops, no exec"; qDebug() << j->errorString(); // On error, wait for key in order to allow manual state inspection #if 0 char c; std::cin.read(&c, 1); #endif } QCOMPARE(j->status(), status); } void verifiedWrite(QUrl const & url, QString const & contents) { QFile f(url.path()); QVERIFY(f.open(QIODevice::WriteOnly)); QTextStream filecontents(&f); filecontents << contents; filecontents.flush(); f.flush(); } void fillWorkingDirectory(QString const & dirname) { QDir dir(dirname); //we start it after repoInit, so we still have empty dvcs repo QVERIFY(dir.mkdir(vcsTestDir0())); QVERIFY(dir.cd(vcsTestDir0())); QUrl file0 = QUrl::fromLocalFile(dir.absoluteFilePath(vcsTest_FileName0())); QVERIFY(dir.mkdir(vcsTestDir1())); QVERIFY(dir.cd(vcsTestDir1())); QUrl file1 = QUrl::fromLocalFile(dir.absoluteFilePath(vcsTest_FileName1())); verifiedWrite(file0, simpleText()); verifiedWrite(file1, keywordText()); } -void SvnRecursiveAdd::initTestCase() +void TestSvnRecursiveAdd::initTestCase() { AutoTestShell::init({"kdevsubversion"}); TestCore::initialize(); } -void SvnRecursiveAdd::cleanupTestCase() +void TestSvnRecursiveAdd::cleanupTestCase() { TestCore::shutdown(); } -void SvnRecursiveAdd::test() +void TestSvnRecursiveAdd::test() { QTemporaryDir reposDir; KProcess cmd; cmd.setWorkingDirectory(reposDir.path()); cmd << QStringLiteral("svnadmin") << QStringLiteral("create") << reposDir.path(); QCOMPARE(cmd.execute(10000), 0); QList plugins = Core::self()->pluginController()->allPluginsForExtension(QStringLiteral("org.kdevelop.IBasicVersionControl")); IBasicVersionControl* vcs = nullptr; foreach(IPlugin* p, plugins) { qDebug() << "checking plugin" << p; ICentralizedVersionControl* icentr = p->extension(); if (!icentr) continue; if (icentr->name() == QLatin1String("Subversion")) { vcs = icentr; break; } } qDebug() << "ok, got vcs" << vcs; QVERIFY(vcs); VcsLocation reposLoc; reposLoc.setRepositoryServer("file://" + reposDir.path()); QTemporaryDir checkoutDir; QUrl checkoutLoc = QUrl::fromLocalFile(checkoutDir.path()); qDebug() << "Checking out from " << reposLoc.repositoryServer() << " to " << checkoutLoc; qDebug() << "creating job"; VcsJob* job = vcs->createWorkingCopy( reposLoc, checkoutLoc ); validatingExecJob(job); qDebug() << "filling wc"; fillWorkingDirectory(checkoutDir.path()); QUrl addUrl = QUrl::fromLocalFile( checkoutDir.path() + '/' + vcsTestDir0() ); qDebug() << "Recursively adding files at " << addUrl; validatingExecJob(vcs->add({addUrl}, IBasicVersionControl::Recursive)); qDebug() << "Recursively reverting changes at " << addUrl; validatingExecJob(vcs->revert({addUrl}, IBasicVersionControl::Recursive)); } -QTEST_MAIN(SvnRecursiveAdd) +QTEST_MAIN(TestSvnRecursiveAdd) diff --git a/plugins/subversion/tests/svnrecursiveadd.h b/plugins/subversion/tests/test_svnrecursiveadd.h similarity index 98% rename from plugins/subversion/tests/svnrecursiveadd.h rename to plugins/subversion/tests/test_svnrecursiveadd.h index 65659885b..fab45bb48 100644 --- a/plugins/subversion/tests/svnrecursiveadd.h +++ b/plugins/subversion/tests/test_svnrecursiveadd.h @@ -1,35 +1,36 @@ /*************************************************************************** * This file is part of KDevelop * * Copyright 2009 Fabian Wiesel * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #ifndef KDEVPLATFORM_PLUGIN_SVNRECURSIVEADD_H #define KDEVPLATFORM_PLUGIN_SVNRECURSIVEADD_H + #include -class SvnRecursiveAdd +class TestSvnRecursiveAdd : public QObject { Q_OBJECT private slots: void initTestCase(); void cleanupTestCase(); void test(); }; #endif // KDEVPLATFORM_PLUGIN_SVNRECURSIVEADD_H